def add_var(varname): # pylint: disable=E1101 # E1101:add_var: Class 'LeoNode' has no 'p' member c = g_ipm.c # g.trace(varname) if not c: return r = rootnode() try: if r is None: p2 = g.findNodeAnywhere(c,varname) else: p2 = g.findNodeInChildren(c,r.p,varname) if p2: return LeoNode(p2) if r is not None: p2 = r.p.insertAsLastChild() else: p2 = c.currentPosition().insertAfter() c.setHeadString(p2,varname) return LeoNode(p2) finally: c.redraw()
def openDir(c, parent, d): """ Expand / refresh an existing folder Note: With the addition of per folder inclusion/exclusion a check is done against both the current list of nodes and against the files/folders as they exist on the system. This check must be done in both places to keep the node list in sync with the file system while respecting the inc/exc lists - John Lunzer """ # compare folder content to children try: path, dirs, files = next(os.walk(d)) except StopIteration: # directory deleted? c.setHeadString(parent, '*' + parent.h.strip('*') + '*') return # parent.expand() # why? oldlist = set() toRemove = set() newlist = [] bodySplit = parent.b.splitlines() excdirs = False excfiles = False regEx = False if re.search('^excdirs', parent.b, flags=re.MULTILINE): excdirs = True if re.search('^excfiles', parent.b, flags=re.MULTILINE): excfiles = True if re.search('^re', parent.b, flags=re.MULTILINE): regEx = True inc = [ line.replace('inc=', '') for line in bodySplit if line.startswith('inc=') ] exc = [ line.replace('exc=', '') for line in bodySplit if line.startswith('exc=') ] #flatten lists if using comma separations inc = [item for line in inc for item in line.strip(' ').split(',')] exc = [item for line in exc for item in line.strip(' ').split(',')] # get children info for p in flattenOrganizers(parent): entry = p.h.strip('/*') if entry.startswith('@'): # remove only the @part directive = entry.split(None, 1) if len(directive) > 1: entry = entry[len(directive[0]):].strip() #find existing inc/exc nodes to remove #using p.h allows for example exc=/ to remove all directories if not checkIncExc(p.h,inc,exc, regEx) or \ (excdirs and entry in dirs) or \ (excfiles and entry in files): toRemove.add(p.h) #must not strip '/', so nodes can be removed else: oldlist.add(entry) # remove existing found inc/exc nodes for headline in toRemove: found = g.findNodeInChildren(c, parent, headline) if found: found.doDelete() # dirs trimmed by toRemove to remove redundant checks for d2 in set(dirs) - set([h.strip('/') for h in toRemove]): if d2 in oldlist: oldlist.discard(d2) else: if checkIncExc(d2, [i.strip('/') for i in inc], [e.strip('/') for e in exc], regEx) and not excdirs: newlist.append('/' + d2 + '/') # files trimmed by toRemove, retains original functionality of plugin for f in set(files) - toRemove: if f in oldlist: oldlist.discard(f) else: if checkIncExc(f, inc, exc, regEx) and not excfiles: newlist.append(f) # insert newlist newlist.sort() ignored = 0 newlist.reverse() # un-reversed by the following loop for name in newlist: if inReList(name, c.__active_path['ignore']): ignored += 1 continue p = parent.insertAsNthChild(0) c.setChanged(True) c.setHeadString(p, name) if name.startswith('/'): # sufficient test of dirness as we created newlist c.setBodyString(p, '@path ' + name.strip('/')) elif (c.__active_path['do_autoload'] and inReList(name, c.__active_path['autoload'])): openFile(c, p, os.path.join(d, p.h), autoload=True) elif (c.__active_path['do_autoload'] and c.__active_path['load_docstring'] and name.lower().endswith(".py")): # do_autoload suppresses doc string loading because turning # autoload off is supposed to address situations where autoloading # causes problems, so don't still do some form of autoloading p.b = c.__active_path['DS_SENTINEL'] + "\n\n" + loadDocstring( os.path.join(d, p.h)) p.setMarked() p.contract() if ignored: g.es('Ignored %d files in directory' % ignored) # warn / mark for orphan oldlist for p in flattenOrganizers(parent): h = p.h.strip('/*') # strip / and * if (h not in oldlist or (p.hasChildren() and not isDirNode(p))): # clears bogus '*' marks nh = p.h.strip('*') # strip only * else: nh = '*' + p.h.strip('*') + '*' if isDirNode(p): for orphan in p.subtree(): c.setHeadString(orphan, '*' + orphan.h.strip('*') + '*') if p.h != nh: # don't dirty node unless we must c.setHeadString(p, nh) c.selectPosition(parent)