expfolder.py :  » Development » Leo » Leo-4.7.1-final » leo » plugins » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Leo 
Leo » Leo 4.7.1 final » leo » plugins » expfolder.py
#@+leo-ver=4-thin
#@+node:ajones.20070122153625:@thin expfolder.py
#@<< docstring >>
#@+node:ajones.20070122153625.1:<< docstring >>
'''Makes @expfolder expandable representations of folders in the filesystem.

Double clicking on the icon of an @expfolder heading reads the files in the directory at the path specified and creates child nodes for each file in the subfolder.  Subdirectories are made into child @expfolder nodes so the tree can be easily traversed.  If files have extensions specified in the expfolder.ini file they are made into @text nodes so the content of the files can be easily loaded into leo and edited.  Double clicking a second time will delete all child nodes and refresh the directory listing.  If there are any changed @text nodes contained inside you will be prompted about saving them.

The textextensions field on the expfolder Properties page contains a list of extensions which will be made into @text nodes, seperated by spaces.

For the @text and @expfolder nodes to interact correctly, the textnode plugin must load before the expfolder plugin.  This can be set using the Plugin Manager's Plugin Load Order pane.
'''
#@nonl
#@-node:ajones.20070122153625.1:<< docstring >>
#@nl

#@@language python
#@@tabwidth -4

import leo.core.leoGlobals as g
import leo.core.leoPlugins as leoPlugins
import os
import os.path

if g.isPython3:
    import configparser as ConfigParser
else:
    import ConfigParser

from leo.plugins.textnode import savetextnode

__version__ = "1.0"

textexts = []

#@+others
#@+node:ajones.20070122154835:init
def init():
    g.plugin_signon(__name__)
    leoPlugins.registerHandler("icondclick1", on_icondclick)

    fileName = os.path.join(g.app.loadDir,"../","plugins","expfolder.ini")
    config = ConfigParser.ConfigParser()
    config.read(fileName)


    textexts.extend(config.get("Main", "TextExtensions").split())

    #g.es("textexts =", str(textexts))

    return 1
#@nonl
#@-node:ajones.20070122154835:init
#@+node:ajones.20070122153625.2:on_icondclick
def on_icondclick(tag, keywords):    
    c = keywords.get("c")
    p = keywords.get("p")
    h = p.h
    if g.match_word(h,0,"@expfolder"):
        if p.hasChildren():
            result = g.app.gui.runAskYesNoDialog(c, "Reread?", "Reread contents of folder "+h[11:]+"?")
            if result == "no":
                return
            kids = []
            for cp in p.subtree():
                if cp.isDirty() and g.match_word(cp.h, 0, "@text"):
                    kids.append(cp.copy())
            if kids != []:
                result = g.app.gui.runAskYesNoDialog(c, "Reread?", "Save changed @text nodes?")
                if result == "yes":
                    for kid in kids:
                        savetextnode(c, kid)

            # delete children
            while p.firstChild():
                p.firstChild().doDelete()

        #changed = c.isChanged()
        dir = h[11:]
        dirs = []
        files = []
        for file in os.listdir(dir):
            path = os.path.join(dir, file)
            if os.path.isdir(path):
                dirs.append(path)
            else:
                files.append(path)

        #g.es('dirs: '+str(dirs))
        #g.es('files: '+str(files))

        dirs.sort()
        files.sort()

        for f in files:
            pn = p.insertAsNthChild(0)
            if os.path.splitext(f)[1] in textexts:
                c.setHeadString(pn, "@text "+f)
                pn.clearDirty()
            else:
                c.setHeadString(pn, f)
            #pn.clearDirty()

        for d in dirs:
            pn = p.insertAsNthChild(0)
            c.setHeadString(pn, "@expfolder "+d)
            #pn.clearDirty()

        #p.clearDirty()

        #c.setChanged(changed)

        c.expandSubtree(p)
#@nonl
#@-node:ajones.20070122153625.2:on_icondclick
#@-others
#@nonl
#@-node:ajones.20070122153625:@thin expfolder.py
#@-leo
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.