Changeset 1457

Show
Ignore:
Timestamp:
07/05/08 09:43:06 (2 months ago)
Author:
rob
Message:

Fixed #393: added ApplySettingsSameMode? to make view settings default for current mode
* added ApplySettingsAll? to erase default values in the GlobalPrefs? for subclasses of FundamentalMode? so that the settings become the defaults for all modes

Location:
trunk/peppy
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/frame.py

    r1450 r1457  
    344344        _("Edit"): 0.001, 
    345345        _("View"): 0.003, 
     346        _("View/Apply Settings"): -980, 
    346347        _("Tools"): 0.004, 
    347348        _("Transform"): 0.005, 
  • trunk/peppy/fundamental_menu.py

    r1453 r1457  
    1010from peppy.actions.minibuffer import * 
    1111from peppy.fundamental import * 
     12from peppy.lib.userparams import * 
    1213 
    1314 
     
    312313 
    313314 
     315class ApplySettingsSameMode(OnDemandActionNameMixin, SelectAction): 
     316    """Apply view settings to all tabs""" 
     317    name = "As Defaults for %s Mode" 
     318    default_menu = ("View/Apply Settings", 100) 
     319 
     320    def getMenuItemName(self): 
     321        """Override in subclass to provide the menu item name.""" 
     322        return self.name % self.mode.keyword 
     323 
     324    def action(self, index=-1, multiplier=1): 
     325        locals = {} 
     326        locals[self.mode.__class__] = self.mode.classprefsDictFromLocals() 
     327        Publisher().sendMessage('peppy.preferences.changed', locals) 
     328        # Make the local values the defaults so that they'll become persistent 
     329        # by getting saved in the configuration file 
     330        self.mode.classprefsCopyFromLocals() 
     331 
     332 
     333class ApplySettingsAll(SelectAction): 
     334    """Apply view settings to editors""" 
     335    name = "As Defaults for All Modes" 
     336    default_menu = ("View/Apply Settings", 110) 
     337 
     338    def action(self, index=-1, multiplier=1): 
     339        msg_data = {} 
     340        settings = self.mode.classprefsDictFromLocals() 
     341        msg_data[FundamentalMode] = settings 
     342        msg_data['subclass'] = FundamentalMode 
     343        Publisher().sendMessage('peppy.preferences.changed', msg_data) 
     344         
     345        FundamentalMode.classprefsOverrideSubclassDefaults(settings) 
     346 
     347 
    314348class FundamentalMenu(IPeppyPlugin): 
    315349    """Trac plugin that provides the global menubar and toolbar. 
     
    343377                    EOLModeSelect, SelectBraces, 
    344378                     
    345                     ElectricReturn, ElectricDelete, ElectricBackspace] 
     379                    ElectricReturn, ElectricDelete, ElectricBackspace, 
     380                     
     381                    ApplySettingsSameMode, ApplySettingsAll, 
     382                    ] 
    346383        return [] 
  • trunk/peppy/lib/userparams.py

    r1440 r1457  
    13001300    def __call__(self, name): 
    13011301        return self._get(name) 
     1302     
     1303    def _getNameHierarchy(self): 
     1304        return GlobalPrefs.name_hierarchy[self.__dict__['_startSearch']] 
     1305 
     1306    def _getClassHierarchy(self): 
     1307        return GlobalPrefs.class_hierarchy[self.__dict__['_startSearch']] 
    13021308 
    13031309    def _get(self, name, user=True, default=True): 
     
    14691475    pass 
    14701476 
    1471  
    14721477class ClassPrefs(object): 
    14731478    """Base class to extend in order to support class prefs. 
     
    15091514                    #dprint("setting classpref %s to %s" % (param.keyword, self.classprefs._get(param.keyword))) 
    15101515                    self.classprefs._set(param.keyword, getattr(self.locals, param.keyword)) 
     1516     
     1517    @classmethod 
     1518    def classprefsSetDefaults(cls, new_locals): 
     1519        """Update the class defaults from the locals 
     1520        """ 
     1521        hier = cls.classprefs._getMRO() 
     1522        #dprint(hier) 
     1523        updated = {} 
     1524        for cls in hier: 
     1525            if 'default_classprefs' not in dir(cls): 
     1526                continue 
     1527            for param in cls.default_classprefs: 
     1528                if param.local and param.keyword in new_locals: 
     1529                    #dprint("setting classpref %s to %s" % (param.keyword, self.classprefs._get(param.keyword))) 
     1530                    cls.classprefs._set(param.keyword, new_locals[param.keyword]) 
     1531     
     1532    @classmethod 
     1533    def classprefsOverrideSubclassDefaults(cls, new_locals): 
     1534        """Override settings of this class and all subclasses 
     1535         
     1536        Remove all the user values from GlobalPrefs of items that would 
     1537        override these class settings definitions.  All subclasses of this 
     1538        class will have their settings removed so that this class becomes the 
     1539        default value for all of its subclasses. 
     1540         
     1541        This is used to change the settings of FundamentalMode so that 
     1542        subclasses like PythonMode or CPlusPlusMode will take their settings 
     1543        from Fundamental mode. 
     1544        """ 
     1545        cls.classprefsSetDefaults(new_locals) 
     1546        #dprint("fund: %s" % GlobalPrefs.user) 
     1547        #dprint("defaults: %s" % GlobalPrefs.default) 
     1548        #dprint("name: %s" % GlobalPrefs.name_hierarchy) 
     1549        parent = cls.__name__ 
     1550        for name, hier in GlobalPrefs.name_hierarchy.iteritems(): 
     1551            if parent in hier: 
     1552                if name == parent: 
     1553                    # Override fundamental mode defaults with user settings 
     1554                    #dprint("before: %s: %s" % (name, GlobalPrefs.user[name])) 
     1555                    for k in new_locals.keys(): 
     1556                        if k in GlobalPrefs.default[name] and GlobalPrefs.default[name] != new_locals[k]: 
     1557                            GlobalPrefs.user[name][k] = new_locals[k] 
     1558                    #dprint("after: %s: %s" % (name, GlobalPrefs.user[name])) 
     1559                else: 
     1560                    # erase user settings so that fundamental mode settings 
     1561                    # will show through 
     1562                    #dprint("before: %s: %s" % (name, GlobalPrefs.user[name])) 
     1563                    for k in new_locals.keys(): 
     1564                        if k in GlobalPrefs.user[name]: 
     1565                            del GlobalPrefs.user[name][k] 
     1566                    #dprint("after: %s: %s" % (name, GlobalPrefs.user[name])) 
     1567 
     1568    def classprefsDictFromLocals(self): 
     1569        """Return a dict copy of the local settings""" 
     1570        copy = {} 
     1571        for k in dir(self.locals): 
     1572            if not k.startswith('_'): 
     1573                copy[k] = getattr(self.locals, k) 
     1574        return copy 
    15111575     
    15121576    def classprefsUpdateLocals(self, new_locals): 
  • trunk/peppy/major.py

    r1439 r1457  
    858858     
    859859    def applyLocals(self, locals): 
    860         if locals and self.__class__ in locals: 
    861             pairs = locals[self.__class__] 
    862             self.dprint("applying local variables from %s" % str(pairs)) 
    863             self.classprefsUpdateLocals(pairs) 
     860        if locals: 
     861            pairs = None 
     862            if self.__class__ in locals: 
     863                pairs = locals[self.__class__] 
     864            elif 'subclass' in locals: 
     865                cls = locals['subclass'] 
     866                if issubclass(self.__class__, cls): 
     867                    pairs = locals[cls] 
     868            if pairs: 
     869                self.dprint("applying local variables from %s" % str(pairs)) 
     870                self.classprefsUpdateLocals(pairs) 
    864871        else: 
    865872            self.dprint("%s not found in %s" % (self.__class__, str(locals)))