Changeset 1428

Show
Ignore:
Timestamp:
06/28/08 08:10:10 (5 months ago)
Author:
rob
Message:

Refs #318: added command to save template as the global template for the major mode

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/plugins/project.py

    r1424 r1428  
    1818from peppy.actions import * 
    1919from peppy.lib.userparams import * 
     20 
     21 
     22class SaveGlobalTemplate(OnDemandActionNameMixin, SelectAction): 
     23    """Save as the default (application-wide) template for this major mode. 
     24    """ 
     25    name = "Save as Global %s Template" 
     26    default_menu = (("Project/Templates", -700), -100) 
     27 
     28    def getMenuItemName(self): 
     29        return self.__class__.name % self.mode.keyword 
     30 
     31    def action(self, index=-1, multiplier=1): 
     32        pathname = ProjectPlugin.getFilename(self.mode.keyword) 
     33        dprint(pathname) 
     34        self.mode.save(pathname) 
     35 
     36 
    2037 
    2138def findGlobalTemplate(subdir, mode, url): 
     
    3956        except: 
    4057            pass 
    41     template = "# template for %s\n\n" % str(url) 
    42     return template 
     58    return None 
     59 
    4360 
    4461class ProjectPlugin(IPeppyPlugin): 
     
    5774    def deactivateHook(self): 
    5875        Publisher().unsubscribe(self.getTemplate) 
    59  
     76     
     77    @classmethod 
     78    def getFilename(self, template_name): 
     79        return wx.GetApp().config.fullpath("%s/%s" % (self.classprefs.template_directory, template_name)) 
     80     
    6081    def getTemplate(self, msg): 
    6182        info = msg.data 
     
    6384        if template: 
    6485            info['templates'].append([1, template]) 
     86     
     87    def getCompatibleActions(self, mode): 
     88        if hasattr(mode, 'applyTemplate'): 
     89            return [SaveGlobalTemplate, 
     90                    ] 
     91        return []