Changeset 1477

Show
Ignore:
Timestamp:
07/09/08 16:10:29 (2 months ago)
Author:
rob
Message:

Added actions to modify tab size, indent size, and tabs/spaces
* added FundamentalBooleanRadioToggle? and FundamentalIntRadioToggle? action classes
* broke out MinibufferMixin? from MinibufferAction? so that the FundamentalIntRadioToggle? doesn't have to instances of SelectAction? in its mro

Location:
trunk/peppy
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/actions/minibuffer.py

    r1467 r1477  
    1212from peppy.lib.controls import StatusBarButton 
    1313 
    14 class MinibufferAction(TextModificationAction): 
     14class MinibufferMixin(object): 
     15    minibuffer = None 
    1516    minibuffer_label = None 
    16     key_needs_focus = False 
     17     
     18    def getMinibufferLabel(self): 
     19        return self.minibuffer_label 
    1720     
    1821    def getInitialValueHook(self): 
     
    2528        return "" 
    2629     
    27     def action(self, index=-1, multiplier=1): 
     30    def showMinibuffer(self, mode): 
    2831        initial = self.getInitialValueHook() 
     32        label = self.getMinibufferLabel() 
    2933        if isinstance(self.minibuffer, list): 
    30             minibuffer = MultiMinibuffer(self.mode, self, label=self.minibuffer_label, 
    31                                          initial=initial, multi=self.minibuffer) 
     34            minibuffer = MultiMinibuffer(mode, self, label=label, initial=initial, multi=self.minibuffer) 
    3235        else: 
    33             minibuffer = self.minibuffer(self.mode, self, label=self.minibuffer_label, 
    34                                        initial=initial) 
     36            minibuffer = self.minibuffer(mode, self, label=label, initial=initial) 
    3537        #print minibuffer.win 
    36         self.mode.setMinibuffer(minibuffer) 
     38        mode.setMinibuffer(minibuffer) 
    3739 
    3840    def processMinibuffer(self, minibuffer, mode, text): 
    3941        assert self.dprint("processing %s" % text) 
     42 
     43 
     44class MinibufferAction(MinibufferMixin, TextModificationAction): 
     45    key_needs_focus = False 
     46     
     47    def action(self, index=-1, multiplier=1): 
     48        self.showMinibuffer(self.mode) 
    4049 
    4150 
  • trunk/peppy/fundamental_menu.py

    r1458 r1477  
    9292        self.mode.applyDefaultSettings() 
    9393 
     94class FundamentalBooleanRadioToggle(ClassprefsTooltipMixin, RadioAction): 
     95    local_setting = None 
     96    local_true = None 
     97    local_false = None 
     98 
     99    def getIndex(self): 
     100        # True is shown first 
     101        if getattr(self.mode.locals, self.local_setting): 
     102            return 0 
     103        return 1 
     104                                            
     105    def getItems(self): 
     106        return [self.local_true, self.local_false] 
     107 
     108    def action(self, index=-1, multiplier=1): 
     109        state = (index == 0) 
     110        setattr(self.mode.locals, self.local_setting, state) 
     111        self.mode.applyDefaultSettings() 
     112 
     113 
     114class FundamentalIntRadioToggle(ClassprefsTooltipMixin, RadioAction, MinibufferMixin): 
     115    local_setting = None 
     116    local_values = None 
     117    allow_other = True 
     118    other_name = _("other") 
     119    minibuffer = IntMinibuffer 
     120     
     121    def getIndex(self): 
     122        val = getattr(self.mode.locals, self.local_setting) 
     123        try: 
     124            return self.local_values.index(val) 
     125        except ValueError: 
     126            if self.allow_other: 
     127                # Other is always last, after the local values 
     128                return len(self.local_values) 
     129            return 0 
     130                                            
     131    def getItems(self): 
     132        items = [str(i) for i in self.local_values] 
     133        if self.allow_other: 
     134            items.append(self.other_name) 
     135        return items 
     136 
     137    def action(self, index=-1, multiplier=1): 
     138        if index < len(self.local_values): 
     139            setattr(self.mode.locals, self.local_setting, self.local_values[index]) 
     140            self.mode.applyDefaultSettings() 
     141        else: 
     142            self.showMinibuffer(self.mode) 
     143     
     144    def processMinibuffer(self, minibuffer, mode, value): 
     145        dprint(value) 
     146        setattr(self.mode.locals, self.local_setting, value) 
     147        self.mode.applyDefaultSettings() 
     148 
     149 
    94150class LineNumbers(FundamentalSettingToggle): 
    95151    local_setting = 'line_numbers' 
     
    139195    name = "Indentation Guides" 
    140196    default_menu = ("View", 306) 
     197 
     198class IndentSize(FundamentalIntRadioToggle): 
     199    local_setting = 'indent_size' 
     200    local_values = [2, 4, 8] 
     201    allow_other = True 
     202    name = "Indentation Size" 
     203    minibuffer_label = "Number of spaces per indent:" 
     204    default_menu = ("View", 306.5) 
     205 
     206class IndentWithTabsOrSpaces(FundamentalBooleanRadioToggle): 
     207    local_setting = 'use_tab_characters' 
     208    local_true = 'tab characters' 
     209    local_false = 'spaces' 
     210    name = "Indent With" 
     211    default_menu = ("View", 307) 
     212 
     213class TabSize(FundamentalIntRadioToggle): 
     214    local_setting = 'tab_size' 
     215    local_values = [2, 4, 8] 
     216    allow_other = True 
     217    name = "Tab Size" 
     218    minibuffer_label = "Number of spaces per tab:" 
     219    default_menu = ("View", 308) 
     220 
     221    def isEnabled(self): 
     222        return self.mode.locals.use_tab_characters 
    141223 
    142224class TabHighlight(FundamentalRadioToggle): 
     
    372454        if issubclass(mode.__class__, FundamentalMode): 
    373455            return [WordCount, Wrapping, WordWrap, LineNumbers, Folding, 
    374                     ViewEOL, IndentationGuides, CaretLineHighlight, CaretWidth, 
    375                     ViewWhitespace, LongLineIndicator, TabHighlight, 
    376                     RevertEncoding, 
     456                    ViewEOL, 
     457                     
     458                    IndentationGuides, IndentSize, IndentWithTabsOrSpaces, 
     459                    TabSize, 
     460                     
     461                    CaretLineHighlight, CaretWidth, ViewWhitespace, 
     462                    LongLineIndicator, TabHighlight, RevertEncoding, 
    377463                     
    378464                    FontZoom, FontZoomIncrease, FontZoomDecrease,