예제 #1
0
    def cm_external_editor_f(event):
        """ Open node in external editor

        Set LEO_EDITOR/EDITOR environment variable to get the editor you want.
        """
        c = event['c']
        editor = g.guessExternalEditor()
        d = {'kind': 'subprocess.Popen', 'args': [editor], 'ext': None}
        c.openWith(d=d)
예제 #2
0
    def cm_external_editor_f(event):
        """ Open node in external editor

        Set LEO_EDITOR/EDITOR environment variable to get the editor you want.
        """
        c = event['c']
        editor = g.guessExternalEditor()
        d = {'kind':'subprocess.Popen','args':[editor],'ext':None}
        c.openWith(d=d)
예제 #3
0
def editnode_rclick(c,p,menu):
    """ Provide "edit in EDITOR" context menu item """

    editor = g.guessExternalEditor()
    if editor:

        def editnode_rclick_cb():
            d = {'kind':'subprocess.Popen','args':[editor],'ext':None}
            c.openWith(d=d)

        action = menu.addAction("Edit in " + editor)
        action.triggered.connect(editnode_rclick_cb)
예제 #4
0
def editnode_rclick(c, p, menu):
    """ Provide "edit in EDITOR" context menu item """

    editor = g.guessExternalEditor()
    if editor:

        def editnode_rclick_cb():
            d = {'kind': 'subprocess.Popen', 'args': [editor], 'ext': None}
            c.openWith(d=d)

        action = menu.addAction("Edit in " + editor)
        action.triggered.connect(editnode_rclick_cb)
예제 #5
0
def editnode_rclick(c,p, menu):
    """ Provide "edit in EDITOR" context menu item """

    editor = g.guessExternalEditor()
    if not editor:
        return
    action = menu.addAction("Edit in " + editor)

    def editnode_rclick_cb():
        # c.openWith(data = ('subprocess.Popen', [editor], None))
        d = {'kind':'subprocess.Popen','args':[editor],'ext':None}
        c.openWith(d=d)

    action.connect(action, QtCore.SIGNAL("triggered()"), editnode_rclick_cb)
예제 #6
0
def editnode_rclick(c, p, menu):
    """ Provide "edit in EDITOR" context menu item """

    editor = g.guessExternalEditor()
    if not editor:
        return
    action = menu.addAction("Edit in " + editor)

    def editnode_rclick_cb():
        # c.openWith(data = ('subprocess.Popen', [editor], None))
        d = {'kind': 'subprocess.Popen', 'args': [editor], 'ext': None}
        c.openWith(d=d)

    action.connect(action, QtCore.SIGNAL("triggered()"), editnode_rclick_cb)
예제 #7
0
def getEditor(c):
    """Return system's best guess editor quoted.

    RETURNS
    A tuple (editor_path, editor_name_minus_extension)
    """
    editor = g.guessExternalEditor(c)
    if editor:
        basename = os.path.basename(editor).split('.')[0]
        if not editor.startswith('"'):
            editor = '"' + editor
        if not editor.endswith('"'):
            editor = editor + '"'
        return editor, basename
    return "", ""
예제 #8
0
def openwith_rclick(c,p,menu):
    """
    Show "Edit with" in context menu for external file root nodes (@thin, @auto...)

    This looks like "Edit contextmenu.py in scite"

    """
    # define callbacks
    #@+others
    #@+node:ekr.20140613141207.17666: *4* openwith_rclick_cb
    def openwith_rclick_cb():

        #print "Editing", path, fname
        if editor:
            cmd = '%s "%s"' % (editor, absp)
            g.es('Edit: %s' % cmd)
            subprocess.Popen(cmd, shell=True)
    #@+node:ekr.20140613141207.17667: *4* openfolder_rclick_cb
    def openfolder_rclick_cb():

        g.os_startfile(path)

    #@+node:ekr.20140613141207.17668: *4* create_rclick_cb
    def create_rclick_cb():

        os.makedirs(absp)
        g.es("Created " + absp)
    #@+node:ekr.20140613141207.17669: *4* importfiles_rclick_cb
    def importfiles_rclick_cb():

        def shorten(pth, prefix):
            if not pth.startswith(prefix):
                return pth
            return pth[len(prefix):]

        aList = g.get_directives_dict_list(p)
        path = c.scanAtPathDirectives(aList) + "/"
        table = [
            ("All files","*"),
            ("Python files","*.py"),
        ]
        fnames = g.app.gui.runOpenFileDialog(c,
            title = "Import files",filetypes = table,
            defaultextension = '.notused',
            multiple=True, startpath = path)
        adds = [guess_file_type(pth) + " " + shorten(pth, path) for pth in fnames]
        for a in adds:
            chi = p.insertAsLastChild()
            chi.h = a
        c.readAtFileNodes()
    #@-others
    h = p.h
    parts = h.split(None, 1)
    if len(parts) < 2:
        return
    fname = None
    # argh, we need g.getAbsFileName(c,p)
    head, bname = parts
    fname = p.anyAtFileNodeName()
    if not fname and head != "@path":
        return
    path = g.scanAllAtPathDirectives(c,p)
    editor = g.guessExternalEditor()
    absp = g.os_path_finalize_join(path, fname)
    exists = os.path.exists(absp)
    if not exists and head == "@path":
        action = menu.addAction("Create dir " + absp + "/" )
        action.triggered.connect(create_rclick_cb)
    if exists and head == "@path":
        action = menu.addAction("Import files")
        action.triggered.connect(importfiles_rclick_cb)
    if editor and exists and head != "@path":
        action = menu.addAction("Edit " + bname + " in " + os.path.basename(editor))
        action.triggered.connect(openwith_rclick_cb)
    action = menu.addAction("Open " + path)
    action.triggered.connect(openfolder_rclick_cb)
예제 #9
0
def openwith_rclick(c, p, menu):
    """
    Show "Edit with" in context menu for external file root nodes (@thin, @auto...)

    This looks like "Edit contextmenu.py in scite"

    """

    # define callbacks
    #@+others
    #@+node:ekr.20140613141207.17666: *4* openwith_rclick_cb
    def openwith_rclick_cb():

        #print "Editing", path, fname
        if editor:
            cmd = '%s "%s"' % (editor, absp)
            g.es('Edit: %s' % cmd)
            p = subprocess.Popen(cmd, shell=True)

    #@+node:ekr.20140613141207.17667: *4* openfolder_rclick_cb
    def openfolder_rclick_cb():

        g.os_startfile(path)

    #@+node:ekr.20140613141207.17668: *4* create_rclick_cb
    def create_rclick_cb():

        os.makedirs(absp)
        g.es("Created " + absp)

    #@+node:ekr.20140613141207.17669: *4* importfiles_rclick_cb
    def importfiles_rclick_cb():
        def shorten(pth, prefix):
            if not pth.startswith(prefix):
                return pth
            return pth[len(prefix):]

        aList = g.get_directives_dict_list(p)
        path = c.scanAtPathDirectives(aList) + "/"
        table = [
            ("All files", "*"),
            ("Python files", "*.py"),
        ]
        fnames = g.app.gui.runOpenFileDialog(c,
                                             title="Import files",
                                             filetypes=table,
                                             defaultextension='.notused',
                                             multiple=True,
                                             startpath=path)
        adds = [
            guess_file_type(pth) + " " + shorten(pth, path) for pth in fnames
        ]
        for a in adds:
            chi = p.insertAsLastChild()
            chi.h = a
        c.readAtFileNodes()

    #@-others
    h = p.h
    parts = h.split(None, 1)
    if len(parts) < 2:
        return
    fname = None
    # argh, we need g.getAbsFileName(c,p)
    head, bname = parts
    fname = p.anyAtFileNodeName()
    if not fname and head != "@path":
        return
    path = g.scanAllAtPathDirectives(c, p)
    editor = g.guessExternalEditor()
    # g.trace(repr(path),repr(fname))
    absp = g.os_path_finalize_join(path, fname)
    exists = os.path.exists(absp)
    if not exists and head == "@path":
        action = menu.addAction("Create dir " + absp + "/")
        action.triggered.connect(create_rclick_cb)
    if exists and head == "@path":
        action = menu.addAction("Import files")
        action.triggered.connect(importfiles_rclick_cb)
    if editor and exists and head != "@path":
        action = menu.addAction("Edit " + bname + " in " +
                                os.path.basename(editor))
        action.triggered.connect(openwith_rclick_cb)
    action = menu.addAction("Open " + path)
    action.triggered.connect(openfolder_rclick_cb)