Example #1
0
def init ():
    '''Return True if the plugin has loaded successfully.'''
    if g.app.gui.guiName() != "qt":
        return False
    g.visit_tree_item.add(colorize_headlines_visitor)
    g.registerHandler('after-create-leo-frame',onCreate)
    # can't use before-create-leo-frame because Qt dock's not ready
    g.loadOnePlugin("backlink.py")
    g.plugin_signon(__name__)
    return True
Example #2
0
def init():
    '''Return True if the plugin has loaded successfully.'''
    if g.app.gui.guiName() != "qt":
        return False
    g.visit_tree_item.add(colorize_headlines_visitor)
    g.registerHandler('after-create-leo-frame', onCreate)
    # can't use before-create-leo-frame because Qt dock's not ready
    g.loadOnePlugin("backlink.py")
    g.plugin_signon(__name__)
    return True
Example #3
0
    def handleAtPluginNode(self, p):
        '''Handle @plugin nodes.'''

        c = self.c
        tag = "@plugin"
        h = p.h
        assert (g.match(h, 0, tag))

        # Get the name of the module.
        theFile = h[len(tag):].strip()

        # The following two lines break g.loadOnePlugin
        #if theFile[-3:] == ".py":
        #    theFile = theFile[:-3]

        # in fact, I believe the opposite behavior is intended: add .py if it doesn't exist
        if theFile[-3:] != ".py":
            theFile = theFile + ".py"

        theFile = g.toUnicode(theFile)

        if not self.atPluginNodes:
            g.warning("disabled @plugin: %s" % (theFile))
        # elif theFile in g.app.loadedPlugins:
        elif g.pluginIsLoaded(theFile):
            g.warning("plugin already loaded: %s" % (theFile))
        else:
            theModule = g.loadOnePlugin(theFile)
Example #4
0
    def handleAtPluginNode (self,p):

        '''Handle @plugin nodes.'''

        c = self.c
        tag = "@plugin"
        h = p.h
        assert(g.match(h,0,tag))

        # Get the name of the module.
        theFile = h[len(tag):].strip()
        
        # The following two lines break g.loadOnePlugin
        #if theFile[-3:] == ".py":
        #    theFile = theFile[:-3]
        
        # in fact, I believe the opposite behavior is intended: add .py if it doesn't exist
        if theFile[-3:] != ".py":
            theFile = theFile + ".py"
        
        theFile = g.toUnicode(theFile)

        if not self.atPluginNodes:
            g.warning("disabled @plugin: %s" % (theFile))
        # elif theFile in g.app.loadedPlugins:
        elif g.pluginIsLoaded(theFile):
            g.warning("plugin already loaded: %s" % (theFile))
        else:
            theModule = g.loadOnePlugin(theFile)
Example #5
0
def open_in_emacs_helper(c, p):
    global contextmenu_message_given
    v = p.v
    # Load contextmenu plugin if required.
    contextMenu = g.loadOnePlugin('contextmenu.py', verbose=True)
    if not contextMenu:
        if not contextmenu_message_given:
            contextmenu_message_given = True
            g.trace('can not load contextmenu.py')
        return
    # Search the open-files list for a file corresponding to v.
    efc = g.app.externalFilesController
    path = efc and efc.find_path_for_node(p)
    emacs_cmd = c.config.getString('xemacs-exe') or _emacs_cmd
    if (
        not path or
        not g.os_path_exists(path) or
        not hasattr(v, 'OpenWithOldBody') or
        v.b != v.OpenWithOldBody
    ):
        # Open a new temp file.
        if path:
            # Don't do this: it prevents efc from reopening paths.
                # efc = g.app.externalFilesController
                # if efc: efc.forget_path(path)
            os.remove(path)
            os.system(emacs_cmd)
        v.OpenWithOldBody = v.b  # Remember the old contents
        # open the node in emacs (note the space after _emacs_cmd)
        # data = "os.spawnl", emacs_cmd, None
        d = {'kind': 'os.spawnl', 'args': [emacs_cmd], 'ext': None}
        c.openWith(d=d)
    else:
        # Reopen the old temp file.
        os.system(emacs_cmd)
Example #6
0
 def load_context_menu(self):
     '''Load the contextmenu plugin.'''
     global contextmenu_message_given
     contextMenu = g.loadOnePlugin('contextmenu.py', verbose=True)
     if not contextMenu and not contextmenu_message_given:
         contextmenu_message_given = True
         self.error('can not load contextmenu.py')
     return contextMenu
Example #7
0
 def load_context_menu(self):
     '''Load the contextmenu plugin.'''
     global contextmenu_message_given
     contextMenu = g.loadOnePlugin('contextmenu.py', verbose=True)
     if not contextMenu and not contextmenu_message_given:
         contextmenu_message_given = True
         self.error('can not load contextmenu.py')
     return contextMenu
Example #8
0
def onCreate(tag, keys):
    
    c = keys.get('c')
    
    if 1: # New code.
        assert c.free_layout
        BookMarkDisplayProvider(c)
    else: # Old code.
        if hasattr(c, "free_layout"):
            m = g.loadOnePlugin('free_layout.py',verbose=True)
            assert m
            if not c.free_layout:
                m.FreeLayoutController(c)
            assert c.free_layout
            assert hasattr(c.free_layout,'get_top_splitter')
            BookMarkDisplayProvider(c)
Example #9
0
def onCreate(tag, keys):

    c = keys.get('c')

    if 1:  # New code.
        assert c.free_layout
        BookMarkDisplayProvider(c)
    else:  # Old code.
        if hasattr(c, "free_layout"):
            m = g.loadOnePlugin('free_layout.py', verbose=True)
            assert m
            if not c.free_layout:
                m.FreeLayoutController(c)
            assert c.free_layout
            assert hasattr(c.free_layout, 'get_top_splitter')
            BookMarkDisplayProvider(c)
Example #10
0
def open_in_emacs_helper(c, p):

    v = p.v

    # Load contextmenu plugin if required.
    contextMenu = g.loadOnePlugin('contextmenu.py', verbose=True)
    if not contextMenu:
        if not contextmenu_message_given:
            contextmenu_message_given = True
            g.trace('can not load contextmenu.py')
        return

    # Search g.app.openWithFiles for a file corresponding to v.
    for d in g.app.openWithFiles:
        if d.get('v') == id(v):
            path = d.get('path', '')
            break
    else:
        path = ''

    # g.trace('config',c.config.getString('xemacs_exe'))
    emacs_cmd = c.config.getString(
        'xemacs_exe') or _emacs_cmd  # 2010/01/18: found by pylint.

    if (not g.os_path_exists(path) or not hasattr(v, 'OpenWithOldBody')
            or v.b != v.OpenWithOldBody):
        # Open a new temp file.
        if path:
            # Remove the old file and the entry in g.app.openWithFiles.
            os.remove(path)
            g.app.openWithFiles = [
                d for d in g.app.openWithFiles if d.get('path') != path
            ]
            os.system(emacs_cmd)
        v.OpenWithOldBody = v.b  # Remember the old contents

        # open the node in emacs (note the space after _emacs_cmd)
        # data = "os.spawnl", emacs_cmd, None
        d = {'kind': 'os.spawnl', 'args': [emacs_cmd], 'ext': None}
        c.openWith(d=d)
    else:
        # Reopen the old temp file.
        os.system(emacs_cmd)
Example #11
0
def open_in_emacs_helper(c,p):
    
    v = p.v
    
    # Load contextmenu plugin if required.
    contextMenu = g.loadOnePlugin('contextmenu.py',verbose=True)
    if not contextMenu:
        if not contextmenu_message_given:
            contextmenu_message_given = True
            g.trace('can not load contextmenu.py')
        return

    # Search g.app.openWithFiles for a file corresponding to v.
    for d in g.app.openWithFiles:
        if d.get('v') == id(v):
            path = d.get('path','') ; break
    else: path = ''

    # g.trace('config',c.config.getString('xemacs_exe'))
    emacs_cmd = c.config.getString('xemacs_exe') or _emacs_cmd # 2010/01/18: found by pylint.

    if (
        not g.os_path_exists(path) or
        not hasattr(v,'OpenWithOldBody') or
        v.b != v.OpenWithOldBody
    ):
        # Open a new temp file.
        if path:
            # Remove the old file and the entry in g.app.openWithFiles.
            os.remove(path)
            g.app.openWithFiles = [d for d in g.app.openWithFiles
                if d.get('path') != path]
            os.system(emacs_cmd)
        v.OpenWithOldBody=v.b # Remember the old contents

        # open the node in emacs (note the space after _emacs_cmd)
        # data = "os.spawnl", emacs_cmd, None
        d = {'kind':'os.spawnl','args':[emacs_cmd],'ext':None}
        c.openWith(d=d)
    else:
        # Reopen the old temp file.
        os.system(emacs_cmd)
Example #12
0
def open_in_emacs_helper(c,p):
    
    v = p.v

    # Load contextmenu plugin if required.
    contextMenu = g.loadOnePlugin('contextmenu.py',verbose=True)
    if not contextMenu:
        if not contextmenu_message_given:
            contextmenu_message_given = True
            g.trace('can not load contextmenu.py')
        return

    # Search the open-files list for a file corresponding to v.
    efc = g.app.externalFilesController
    path = efc and efc.find_path_for_node(p)

    # g.trace('config',c.config.getString('xemacs_exe'))
    emacs_cmd = c.config.getString('xemacs_exe') or _emacs_cmd
        # 2010/01/18: found by pylint.

    if (
        not path or
        not g.os_path_exists(path) or
        not hasattr(v,'OpenWithOldBody') or
        v.b != v.OpenWithOldBody
    ):
        # Open a new temp file.
        if path:
            ### Don't do this: it prevents efc from reopening paths.
            ### efc = g.app.externalFilesController
            ### if efc: efc.forget_path(path)
            os.remove(path)
            os.system(emacs_cmd)
        v.OpenWithOldBody=v.b # Remember the old contents

        # open the node in emacs (note the space after _emacs_cmd)
        # data = "os.spawnl", emacs_cmd, None
        d = {'kind':'os.spawnl','args':[emacs_cmd],'ext':None}
        c.openWith(d=d)
    else:
        # Reopen the old temp file.
        os.system(emacs_cmd)
Example #13
0
    def handleAtPluginNode(self, p):
        '''Handle @plugin nodes.'''

        c = self.c
        tag = "@plugin"
        h = p.h
        assert (g.match(h, 0, tag))

        # Get the name of the module.
        theFile = h[len(tag):].strip()
        if theFile[-3:] == ".py":
            theFile = theFile[:-3]
        theFile = g.toUnicode(theFile)

        if not self.atPluginNodes:
            g.warning("disabled @plugin: %s" % (theFile))
        # elif theFile in g.app.loadedPlugins:
        elif g.pluginIsLoaded(theFile):
            g.warning("plugin already loaded: %s" % (theFile))
        else:
            theModule = g.loadOnePlugin(theFile)
Example #14
0
    def handleAtPluginNode (self,p):

        '''Handle @plugin nodes.'''

        c = self.c
        tag = "@plugin"
        h = p.h
        assert(g.match(h,0,tag))

        # Get the name of the module.
        theFile = h[len(tag):].strip()
        if theFile[-3:] == ".py":
            theFile = theFile[:-3]
        theFile = g.toUnicode(theFile)

        if not self.atPluginNodes:
            g.warning("disabled @plugin: %s" % (theFile))
        # elif theFile in g.app.loadedPlugins:
        elif g.pluginIsLoaded(theFile):
            g.warning("plugin already loaded: %s" % (theFile))
        else:
            theModule = g.loadOnePlugin(theFile)
Example #15
0
File: vim.py Project: AG4GitHub/leo
def open_in_vim_helper (c):
    
    p = c.p
    v = p.v

    # Load contextmenu plugin if required.
    contextMenu = g.loadOnePlugin('contextmenu.py',verbose=True)
    if not contextMenu:
        if not contextmenu_message_given:
            contextmenu_message_given = True
            g.trace('can not load contextmenu.py')
        return

    if p.h.find('file-ref') == 1: # Must be at 2nd position
        return

    #URL nodes
    openURLNodes = c.config.getBool('vim_plugin_opens_url_nodes')
    if not openURLNodes and p.h.startswith('@url'):
        return # Avoid conflicts with @url nodes.

    vim_cmd = c.config.getString('vim_cmd') or _vim_cmd
    vim_exe = c.config.getString('vim_exe') or _vim_exe

    global locationMessageGiven

    if not locationMessageGiven:
        locationMessageGiven = True
        print('vim_cmd: %s' % vim_cmd)
        print('vim_exe: %s' % vim_exe)

    #Cursor positioning
    Lnum = ""
    if c.config.getBool('vim_plugin_positions_cursor'):    
        #Line number - start at same line as Leo cursor
        #  get node's body text
        bodyCtrl = c.frame.body.bodyCtrl
        s = bodyCtrl.getAllText()    
        #  Get cursors row & column number
        index = bodyCtrl.getInsertPoint()
        row,col = g.convertPythonIndexToRowCol(s,index)
        #  Build gVim command line parameter for setting cursor row
        Lnum = "+" + str(row + 1)

    #Vim's tab card stack
    useTabs = ""

    if c.config.getBool('vim_plugin_uses_tab_feature'):    
        useTabs = "-tab"

    # Search g.app.openWithFiles for a file corresponding to v.
    for d in g.app.openWithFiles:
        if d.get('v') == id(v):
            path = d.get('path','') ; break
    else: path = ''

    # if the body has changed we need to open a new 
    # temp file containing the new body in vim
    if (
        not g.os_path_exists(path) or 
        not hasattr(v,'OpenWithOldBody') or
        v.b != v.OpenWithOldBody
    ):
        # Open a new temp file.
        if path:
            # Remove the old file and the entry in g.app.openWithFiles.
            os.remove(path)
            g.app.openWithFiles = [d for d in g.app.openWithFiles if d.get('path') != path]
            os.system(vim_cmd+"--remote-send '<C-\\><C-N>:bd "+path+"<CR>'")

        v.OpenWithOldBody=v.b # Remember the previous contents.
    
        # New code by Jim Sizemore. TL: added support for gVim tabs.
        args = [vim_exe,"--servername","LEO","--remote"+useTabs+"-silent",Lnum]
        d = {'kind':'subprocess.Popen','args':args,'ext':None}
        c.openWith(d=d)
    else:
        # Reopen the old temp file.
        os.system(vim_cmd+"--remote-send '<C-\\><C-N>:e "+path+"<CR>'")