Changeset 1443

Show
Ignore:
Timestamp:
07/01/08 21:49:54 (5 months ago)
Author:
rob
Message:

Refs #158: Added create project actions
* added Buffer.iterViewers
* changed position of File/New/Text file so that the create project actions can appear before them
* added project name to project ini file
* fixed problem with shell command that left spaces at the end of the command line -- ctags was barfing on those

Location:
trunk/peppy
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/buffers.py

    r1413 r1443  
    348348        self.viewers.append(mode) # keep track of views 
    349349        assert self.dprint("views of %s: %s" % (self,self.viewers)) 
     350     
     351    def iterViewers(self): 
     352        """Return an iterator over all the views of this buffer""" 
     353        for view in self.viewers: 
     354            yield view 
    350355     
    351356    def forEachView(self, func_name): 
  • trunk/peppy/mainmenu.py

    r1427 r1443  
    6464    tooltip = "New plain text file" 
    6565    icon = "icons/page_white_text_new.png" 
    66     default_menu = ("File/New", -2) 
     66    default_menu = ("File/New", -99) 
    6767    key_bindings = {'win': "C-N", 'mac': "C-N"} 
    6868 
  • trunk/peppy/plugins/project.py

    r1442 r1443  
    1717import peppy.vfs as vfs 
    1818 
     19from peppy.buffers import * 
    1920from peppy.yapsy.plugins import * 
    2021from peppy.actions import * 
     
    4950        wildcards = self.ctags_exclude.split() 
    5051        excludes = " ".join(["--exclude=%s" % w for w in wildcards]) 
    51         args = "-o %s %s %s %s" % (ctags_file, ProjectPlugin.classprefs.ctags_args, self.ctags_extra_args, excludes) 
     52         
     53        # Put the output file last in this list because extra spaces at the end 
     54        # don't get squashed like they do from the shell.  Ctags will actually 
     55        # try to look for a filename called " ", which fails. 
     56        args = "%s %s %s -o %s" % (ProjectPlugin.classprefs.ctags_args, self.ctags_extra_args, excludes, ctags_file) 
    5257        cmd = "%s %s" % (ProjectPlugin.classprefs.ctags_command, args) 
    5358        dprint(cmd) 
     
    8691                else: 
    8792                    self.dprint(line) 
    88         except Exception, e: 
    89             raise 
    90         dprint(self.tags.keys()) 
     93        except LookupError, e: 
     94            dprint("Tag file %s not found" % filename) 
     95            pass 
    9196     
    9297    def getTag(self, tag): 
     
    96101class ProjectInfo(CTAGS): 
    97102    default_prefs = ( 
     103        StrParam('project_name', '', 'Project name'), 
    98104        DirParam('build_dir', '', 'working directory in which to build', fullwidth=True), 
    99105        StrParam('build_command', '', 'shell command to build project, relative to working directory', fullwidth=True), 
     
    277283 
    278284 
    279 class ShowProjectSettings(SelectAction): 
    280     """Edit project settigns""" 
     285 
     286class ProjectActionMixin(object): 
     287    def getProjectDir(self, cwd): 
     288        dlg = wx.DirDialog(self.frame, "Choose Top Level Directory", 
     289                           defaultPath = cwd) 
     290        retval = dlg.ShowModal() 
     291        if retval == wx.ID_OK: 
     292            path = dlg.GetPath() 
     293            dprint(path) 
     294            info = ProjectPlugin.createProject(path) 
     295        else: 
     296            info = None 
     297        dlg.Destroy() 
     298        return info 
     299     
     300    def showProjectPreferences(self, info): 
     301        dlg = ProjectSettings(self.frame, info) 
     302        retval = dlg.ShowModal() 
     303        if retval == wx.ID_OK: 
     304            dlg.applyPreferences() 
     305            info.savePrefs() 
     306     
     307    def createProject(self): 
     308        cwd = self.frame.cwd() 
     309        info = self.getProjectDir(cwd) 
     310        if info: 
     311            self.showProjectPreferences(info) 
     312            info.regenerateTags() 
     313 
     314 
     315class CreateProject(ProjectActionMixin, SelectAction): 
     316    """Create a new project""" 
     317    name = "Project..." 
     318    default_menu = ("File/New", 20) 
     319 
     320    def action(self, index=-1, multiplier=1): 
     321        self.createProject() 
     322 
     323 
     324class CreateProjectFromExisting(ProjectActionMixin, SelectAction): 
     325    """Create a new project""" 
     326    name = "Project From Existing Code..." 
     327    default_menu = ("File/New", 21) 
     328 
     329    def action(self, index=-1, multiplier=1): 
     330        self.createProject() 
     331 
     332class ShowProjectSettings(ProjectActionMixin, SelectAction): 
     333    """Edit project settings""" 
    281334    name = "Project Settings..." 
    282335    default_menu = ("Project", -990) 
     
    285338        if self.mode.project_info: 
    286339            info = self.mode.project_info 
    287             dlg = ProjectSettings(self.frame, info) 
    288             retval = dlg.ShowModal() 
    289             if retval == wx.ID_OK: 
    290                 dlg.applyPreferences() 
    291                 info.savePrefs() 
     340            self.showProjectPreferences(info) 
    292341 
    293342 
     
    398447 
    399448    @classmethod 
    400     def registerProject(cls, mode): 
    401         url = cls.findProjectURL(mode.buffer.url) 
     449    def registerProject(cls, mode, url=None): 
     450        if url is None: 
     451            url = cls.findProjectURL(mode.buffer.url) 
    402452        if url: 
    403             if str(url) not in cls.known_projects: 
     453            if url not in cls.known_projects: 
    404454                info = ProjectInfo(url) 
    405                 cls.known_projects[str(url)] = info 
     455                cls.known_projects[url] = info 
    406456            else: 
    407                 info = cls.known_projects[str(url)] 
    408             mode.project_info = info 
     457                info = cls.known_projects[url] 
     458            if mode: 
     459                mode.project_info = info 
    409460            dprint("found project %s" % info) 
    410         else: 
     461            return info 
     462        elif mode: 
    411463            mode.project_info = None 
    412464     
     
    414466    def getProjectInfo(cls, mode): 
    415467        url = cls.findProjectURL(mode.buffer.url) 
    416         if url and str(url) in cls.known_projects: 
    417             return cls.known_projects[str(url)] 
     468        if url and url in cls.known_projects: 
     469            return cls.known_projects[url] 
    418470        return None 
     471     
     472    @classmethod 
     473    def createProject(cls, topdir): 
     474        url = vfs.normalize(topdir) 
     475        if url in cls.known_projects: 
     476            raise TypeError("Project already exists.") 
     477        proj_dir = url.resolve2(cls.classprefs.project_directory) 
     478        vfs.make_folder(proj_dir) 
     479        info = cls.registerProject(None, proj_dir) 
     480        info.savePrefs() 
     481        dprint(info) 
     482        buffers = BufferList.getBuffers() 
     483        for buffer in buffers: 
     484            if buffer.url.scheme != "file": 
     485                continue 
     486            dprint("prefix=%s topdir=%s" % (buffer.url.path.get_prefix(url.path), url.path)) 
     487            if buffer.url.path.get_prefix(url.path) == url.path: 
     488                dprint("belongs in project! %s" % buffer.url.path) 
     489                for mode in buffer.iterViewers(): 
     490                    mode.project_info = info 
     491            else: 
     492                dprint("not in project: %s" % buffer.url.path) 
     493        return info 
    419494 
    420495    @classmethod 
     
    438513        if mode.buffer.url in self.known_project_dirs: 
    439514            actions.extend([SaveProjectTemplate, BuildProject, RunProject, RebuildCtags]) 
    440         actions.append(ShowProjectSettings) 
     515        actions.extend([CreateProject, CreateProjectFromExisting, ShowProjectSettings]) 
    441516        return actions 
    442517