Changeset 351

Show
Ignore:
Timestamp:
07/02/12 11:37:23 (12 months ago)
Author:
mbutscher
Message:

branches/mbutscher/work:
* Vi improvements (Ross' repSVN:

533b0ba5dd4f899f4d73f3ac3e17ceeea421477a,
8061c1f34cf07d09d6bef8b8e7746c1f9568aa40)

  • Add :reloadplugins cmd to allow live reloading of vi plugins (calls
    reloadMenuPlugins so suffers from the same problems)
Location:
branches/mbutscher/work/lib/pwiki
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/mbutscher/work/lib/pwiki/ViHelper.py

    r343 r351  
    232232                continue 
    233233 
     234    def ReloadPlugins(self, name): 
     235        self.RegisterPlugins() 
     236        self.LoadPlugins(name) 
    234237 
    235238    def LoadSettings(self): 
     
    495498        selected_text = None 
    496499        if self.mode == ViHelper.VISUAL: 
     500            # TODO: fix line selection mode 
    497501            selected_text = self.GetSelectionDetails(selection_type) 
    498502 
     
    10831087        searchString = self.tfInput.GetValue() 
    10841088 
    1085         foundPos = -2 
     1089        foundPos = -26 
    10861090        if accP in ((wx.ACCEL_NORMAL, wx.WXK_NUMPAD_ENTER), 
    10871091                (wx.ACCEL_NORMAL, wx.WXK_RETURN)): 
     
    13001304            "tabparents" : (self.GetParentPages, self.OpenWikiPageNewTab), 
    13011305            "bgparents" : (self.GetParentPages, self.OpenWikiPageBackgroundTab), 
     1306            "w" : (self.Pass, self.SaveCurrentPage), 
    13021307            "write" : (self.Pass, self.SaveCurrentPage), 
    13031308            "open" : (self.GetWikiPages, self.OpenWikiPageCurrentTab), 
     
    13141319            # TODO: rewrite with vi like confirmation 
    13151320            "deletepage" : (self.GetDefinedWikiPages, self.ctrl.presenter.getMainControl().showWikiWordDeleteDialog), 
    1316             "dlpage" : (self.GetDefinedWikiPages, self.ctrl.presenter.getMainControl().showWikiWordDeleteDialog), 
    1317  
    1318             "renamepage" : (self.GetDefinedWikiPages, self.Pass), 
     1321            "delpage" : (self.GetDefinedWikiPages, self.ctrl.presenter.getMainControl().showWikiWordDeleteDialog), 
     1322 
     1323            #"renamepage" : (self.GetDefinedWikiPages, self.Pass), 
    13191324 
    13201325            # Currently bdelete and bwipeout are currently synonymous 
     
    13251330            "tabonly" : (self.GetTabs, self.CloseOtherTabs), 
    13261331            "exit" : (self.Pass, self.CloseWiki), 
     1332 
     1333            "reloadplugins" : (self.Pass, self.ReloadPlugins), 
    13271334            } 
    13281335 
     
    15911598        self.data = [] 
    15921599 
     1600    def ReloadPlugins(self, args=None): 
     1601        """ 
     1602        Reload plugins globally using reloadMenuPlugins() and then 
     1603        on a per tab basis 
     1604        """ 
     1605        self.ctrl.presenter.getMainControl().reloadMenuPlugins() 
     1606 
     1607        # NOTE: should probably unify names 
     1608        for scName, name in (("textedit", "editor"), ("preview", "preview")): 
     1609            for tab in self.ctrl.presenter.getMainControl().getMainAreaPanel().getPresenters(): 
     1610                # Try and reload key bindings for each presenter on each tab 
     1611                # (if they exist) 
     1612                try: 
     1613                    tab.getSubControl(scName).vi.ReloadPlugins(name) 
     1614                except AttributeError: 
     1615                    pass 
     1616 
     1617         
     1618 
    15931619    def OpenPageInGoogle(self, text_input=None): 
    15941620        if type(text_input) == tuple: 
     
    18401866        self.selection_range = None 
    18411867 
     1868        self.block_kill_focus = False 
    18421869        wx.EVT_KILL_FOCUS(self.ctrls.viInputTextField, self.OnKillFocus) 
    18431870 
     
    19111938        Called if a user clicks outside of the viInputPanel 
    19121939        """ 
    1913         if self.search: 
     1940        if self.search and not self.block_kill_focus: 
    19141941            self.Close() 
    19151942 
     
    19241951        return self.ctrls.viInputTextField.GetValue() 
    19251952 
    1926     def SetInput(self, text): 
     1953    def SetInput(self, text, clear=False): 
    19271954        # Check if we just want to change the cmd argument 
    1928         current_text = self.GetInput().split(" ") 
    1929         if len(current_text) > 1: 
    1930             text = "{0} {1}".format(current_text[0], text) 
     1955        if not clear: 
     1956            current_text = self.GetInput().split(" ") 
     1957            if len(current_text) > 1: 
     1958                text = "{0} {1}".format(current_text[0], text) 
    19311959         
    19321960        if text: 
     
    19581986        """ 
    19591987        if self.search: 
    1960             text = self.GetInput() 
    1961  
    1962             if len(text) < 1: 
    1963                 return 
    1964  
    1965             self.search_args[u"text"] = text 
    1966  
    1967             # would .copy() be better? 
    1968             temp_search_args = dict(self.search_args) 
    1969  
    1970             temp_search_args[u"select_text"] = True 
    1971  
    1972             # TODO: set flags from config? 
    1973             result = self.ctrl.vi._SearchText(**temp_search_args) 
    1974  
    1975             if not result: 
    1976                 self.ctrl.vi.visualBell("RED") 
    1977                 self.ctrls.viInputTextField.SetBackgroundColour(ViInputDialog.COLOR_YELLOW) 
    1978             else: 
    1979                 self.ctrls.viInputTextField.SetBackgroundColour(ViInputDialog.COLOR_GREEN) 
     1988            self.RunSearch() 
    19801989 
    19811990        # cmd 
     
    19962005            else: 
    19972006                self.ctrls.viInputTextField.SetBackgroundColour(ViInputDialog.COLOR_RED) 
     2007 
     2008    def RunSearch(self): 
     2009        text = self.GetInput() 
     2010 
     2011        if len(text) < 1: 
     2012            return 
     2013 
     2014        self.search_args[u"text"] = text 
     2015 
     2016        # would .copy() be better? 
     2017        temp_search_args = dict(self.search_args) 
     2018 
     2019        temp_search_args[u"select_text"] = True 
     2020 
     2021        self.block_kill_focus = True 
     2022        # TODO: set flags from config? 
     2023        result = self.ctrl.vi._SearchText(**temp_search_args) 
     2024        self.FocusInputField() 
     2025        self.block_kill_focus = False 
     2026 
     2027        if not result: 
     2028            self.ctrl.vi.visualBell("RED") 
     2029            self.ctrls.viInputTextField.SetBackgroundColour(ViInputDialog.COLOR_YELLOW) 
     2030        else: 
     2031            self.ctrls.viInputTextField.SetBackgroundColour(ViInputDialog.COLOR_GREEN) 
    19982032 
    19992033    def ExecuteCmd(self, text_input): 
     
    21202154        # Arrow keys can be used to navigate the cmd_lie history 
    21212155        elif accP == (wx.ACCEL_NORMAL, wx.WXK_UP): 
    2122             self.SetInput(self.cmd_history.GoBackwardsInHistory()) 
     2156            self.SetInput(self.cmd_history.GoBackwardsInHistory(), clear=True) 
    21232157 
    21242158        elif accP == (wx.ACCEL_NORMAL, wx.WXK_DOWN): 
    2125             self.SetInput(self.cmd_history.GoForwardInHistory()) 
     2159            self.SetInput(self.cmd_history.GoForwardInHistory(), clear=True) 
    21262160 
    21272161        elif accP == (wx.ACCEL_NORMAL, wx.WXK_TAB): 
  • branches/mbutscher/work/lib/pwiki/WikiTxtCtrl.py

    r344 r351  
    39323932                } 
    39333933 
     3934        self.LoadKeybindings() 
     3935        self.LoadPlugins(u"editor") 
     3936        self.GenerateKeyBindings() 
     3937 
     3938        self.SINGLE_LINE_WHITESPACE = [9, 11, 12, 32] 
     3939        self.WORD_BREAK =   '!"#$%&\'()*+,-./:;<=>?@[\\]^`{|}~' 
     3940        self.WORD_BREAK_INCLUDING_WHITESPACE = \ 
     3941                            '!"#$%&\'()*+,-./:;<=>?@[\\]^`{|}~ \n\r' 
     3942        self.SENTENCE_ENDINGS = (".", "!", "?", "\n\n") 
     3943        self.SENTENCE_ENDINGS_SUFFIXS = '\'")]' 
     3944 
     3945        self.BRACES = { 
     3946                        u"(" : u")", 
     3947                        u"[" : u"]", 
     3948                        u"{" : u"}", 
     3949                        u"<" : u">", 
     3950                        u"<<" : u">>", 
     3951                      } 
     3952        self.REVERSE_BRACES = dict((v,k) for k, v in self.BRACES.iteritems()) 
     3953 
     3954 
     3955        self.SURROUND_REPLACEMENTS = { 
     3956                        ")" : ("(", ")"), 
     3957                        "b" : ("(", ")"), 
     3958                        "}" : ("{", "}"), 
     3959                        "B" : ("{", "}"), 
     3960                        "]" : ("[", "]"), 
     3961                        "r" : ("[", "]"), 
     3962                        ">" : ("<", ">"), 
     3963                        "a" : ("<", ">"), 
     3964 
     3965                        "(" : ("( ", " )"), 
     3966                        "{" : ("{ ", " }"), 
     3967                        "[" : ("[ ", " ]"), 
     3968 
     3969                        # TODO 
     3970                        #"t" : ("<{0}>", "</{0}>"), 
     3971                        #"<" : ("<{0}>", "</{0}>"), 
     3972 
     3973                        "'" : ("'", "'"), 
     3974                        '"' : ('"', '"'), 
     3975                        "`" : ("`", "`"), 
     3976 
     3977                        } 
     3978 
     3979 
     3980 
     3981 
     3982        self._undo_state = 0 
     3983        self._undo_pos = -1 
     3984        self._undo_start_position = None 
     3985        self._undo_positions = [] 
     3986 
     3987        self._line_column_pos = 0 
     3988 
     3989        self._visual_start_pos = None 
     3990 
     3991        self.isLinux = isLinux() 
     3992 
     3993    def LoadKeybindings(self): 
     3994        """ 
     3995        Function called to load keybindings. 
     3996 
     3997        Must call GenerateKeyBindings after this. 
     3998        """ 
    39343999    # Format 
    39354000    # key code : (command type, (function, arguments), repeatable, selection_type) 
     
    42624327        self.keys[3] = {} 
    42634328 
    4264              
    4265         self.LoadPlugins(u"editor") 
    4266  
     4329 
     4330    def GenerateKeyBindings(self): 
    42674331 
    42684332        #self._motion_chains = self.GenerateMotionKeyChains(self.keys) 
     
    42734337        # Used for rewriting menu shortcuts 
    42744338        self.viKeyAccels = self.GenerateKeyAccelerators(self.keys) 
    4275  
    4276  
    4277         self.SINGLE_LINE_WHITESPACE = [9, 11, 12, 32] 
    4278         self.WORD_BREAK =   '!"#$%&\'()*+,-./:;<=>?@[\\]^`{|}~' 
    4279         self.WORD_BREAK_INCLUDING_WHITESPACE = \ 
    4280                             '!"#$%&\'()*+,-./:;<=>?@[\\]^`{|}~ \n\r' 
    4281         self.SENTENCE_ENDINGS = (".", "!", "?", "\n\n") 
    4282         self.SENTENCE_ENDINGS_SUFFIXS = '\'")]' 
    4283  
    4284         self.BRACES = { 
    4285                         u"(" : u")", 
    4286                         u"[" : u"]", 
    4287                         u"{" : u"}", 
    4288                         u"<" : u">", 
    4289                         u"<<" : u">>", 
    4290                       } 
    4291         self.REVERSE_BRACES = dict((v,k) for k, v in self.BRACES.iteritems()) 
    4292  
    4293  
    4294         self.SURROUND_REPLACEMENTS = { 
    4295                         ")" : ("(", ")"), 
    4296                         "b" : ("(", ")"), 
    4297                         "}" : ("{", "}"), 
    4298                         "B" : ("{", "}"), 
    4299                         "]" : ("[", "]"), 
    4300                         "r" : ("[", "]"), 
    4301                         ">" : ("<", ">"), 
    4302                         "a" : ("<", ">"), 
    4303  
    4304                         "(" : ("( ", " )"), 
    4305                         "{" : ("{ ", " }"), 
    4306                         "[" : ("[ ", " ]"), 
    4307  
    4308                         # TODO 
    4309                         #"t" : ("<{0}>", "</{0}>"), 
    4310                         #"<" : ("<{0}>", "</{0}>"), 
    4311  
    4312                         "'" : ("'", "'"), 
    4313                         '"' : ('"', '"'), 
    4314                         "`" : ("`", "`"), 
    4315  
    4316                         } 
    4317  
    4318  
    4319  
    4320  
    4321         self._undo_state = 0 
    4322         self._undo_pos = -1 
    4323         self._undo_start_position = None 
    4324         self._undo_positions = [] 
    4325  
    4326         self._line_column_pos = 0 
    4327  
    4328         self._visual_start_pos = None 
    4329  
    4330         self.isLinux = isLinux() 
    43314339 
    43324340