Changeset 1457
- Timestamp:
- 07/05/08 09:43:06 (2 months ago)
- Location:
- trunk/peppy
- Files:
-
- 4 modified
-
frame.py (modified) (1 diff)
-
fundamental_menu.py (modified) (3 diffs)
-
lib/userparams.py (modified) (3 diffs)
-
major.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/peppy/frame.py
r1450 r1457 344 344 _("Edit"): 0.001, 345 345 _("View"): 0.003, 346 _("View/Apply Settings"): -980, 346 347 _("Tools"): 0.004, 347 348 _("Transform"): 0.005, -
trunk/peppy/fundamental_menu.py
r1453 r1457 10 10 from peppy.actions.minibuffer import * 11 11 from peppy.fundamental import * 12 from peppy.lib.userparams import * 12 13 13 14 … … 312 313 313 314 315 class 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 333 class 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 314 348 class FundamentalMenu(IPeppyPlugin): 315 349 """Trac plugin that provides the global menubar and toolbar. … … 343 377 EOLModeSelect, SelectBraces, 344 378 345 ElectricReturn, ElectricDelete, ElectricBackspace] 379 ElectricReturn, ElectricDelete, ElectricBackspace, 380 381 ApplySettingsSameMode, ApplySettingsAll, 382 ] 346 383 return [] -
trunk/peppy/lib/userparams.py
r1440 r1457 1300 1300 def __call__(self, name): 1301 1301 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']] 1302 1308 1303 1309 def _get(self, name, user=True, default=True): … … 1469 1475 pass 1470 1476 1471 1472 1477 class ClassPrefs(object): 1473 1478 """Base class to extend in order to support class prefs. … … 1509 1514 #dprint("setting classpref %s to %s" % (param.keyword, self.classprefs._get(param.keyword))) 1510 1515 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 1511 1575 1512 1576 def classprefsUpdateLocals(self, new_locals): -
trunk/peppy/major.py
r1439 r1457 858 858 859 859 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) 864 871 else: 865 872 self.dprint("%s not found in %s" % (self.__class__, str(locals)))
