Show
Ignore:
Timestamp:
07/06/08 16:09:42 (5 months ago)
Author:
rob
Message:

Fixed #484: Added RunFilter? command to run an arbitary program using current buffer as input

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/mainmenu.py

    r1453 r1459  
    469469        self.frame.open("about:demo.txt") 
    470470 
    471 class RunScript(SelectAction): 
     471 
     472class RunMixin(object): 
     473    @classmethod 
     474    def worksWithMajorMode(cls, mode): 
     475        return hasattr(mode, 'startInterpreter') 
     476     
     477    def isEnabled(self): 
     478        return hasattr(self.mode, 'startInterpreter') and not hasattr(self.mode, 'process') 
     479 
     480class RunScript(RunMixin, SelectAction): 
    472481    alias = "run-script" 
    473482    name = "Run" 
     
    477486    key_bindings = {'default': "F5"} 
    478487 
    479     @classmethod 
    480     def worksWithMajorMode(cls, mode): 
    481         return hasattr(mode, 'startInterpreter') 
    482      
    483     def isEnabled(self): 
    484         return hasattr(self.mode, 'startInterpreter') and not hasattr(self.mode, 'process') 
    485  
    486488    def action(self, index=-1, multiplier=1): 
    487489        self.mode.startInterpreter() 
    488490 
    489  
    490 class RunScriptWithArgs(RunScript): 
     491class RunScriptWithArgs(RunMixin, SelectAction): 
    491492    alias = "run-script-with-args" 
    492493    name = "Run with Args" 
     
    494495    icon = "icons/script_edit.png" 
    495496    default_menu = ("Tools", 2) 
    496      
    497     # If subclassing another action, make sure to reset global_id, or the 
    498     # menu system will use the existing global id for the new action 
    499     global_id = None 
    500497    key_bindings = {'default': "C-F5"} 
    501498 
     
    508505        self.mode.startInterpreter(text) 
    509506 
    510  
    511 class StopScript(RunScript): 
     507class RunFilter(RunMixin, SelectAction): 
     508    """Run an external program on this file""" 
     509    alias = "run-filter" 
     510    name = "Run Filter" 
     511    default_menu = ("Tools", 3) 
     512 
     513    def action(self, index=-1, multiplier=1): 
     514        minibuffer = TextMinibuffer(self.mode, self, label="Command line:", 
     515                                    initial = self.mode.getScriptArgs()) 
     516        self.mode.setMinibuffer(minibuffer) 
     517        self.mode.setStatusText("Enter command line, %s will be replaced by full path to file") 
     518 
     519    def processMinibuffer(self, minibuffer, mode, text): 
     520        self.mode.startCommandLine(text) 
     521 
     522class StopScript(RunMixin, SelectAction): 
    512523    alias = "stop-script" 
    513524    name = "Stop" 
    514525    tooltip = "Stop the currently running script" 
    515526    icon = 'icons/stop.png' 
    516     default_menu = ("Tools", 3) 
    517     global_id = None 
     527    default_menu = ("Tools", 9) 
    518528    key_bindings = {'win': "C-CANCEL", 'emacs': "C-CANCEL", 'mac': 'C-.'} 
    519529     
     
    884894                Undo, Redo, Cut, Copy, Paste, PasteAtColumn, SelectAll, 
    885895 
    886                 RunScript, RunScriptWithArgs, StopScript, 
     896                RunScript, RunScriptWithArgs, RunFilter, StopScript, 
    887897 
    888898                MajorModeSelect, MinorModeShow, SidebarShow,