def fastAddLastChild(self,parent_v,gnxString): '''Create new vnode as last child of the receiver. If the gnx exists already, create a clone instead of new vnode. ''' trace = False and not g.unitTesting c = self.c indices = g.app.nodeIndices gnxDict = c.fileCommands.gnxDict if gnxString is None: v = None else: v = gnxDict.get(gnxString) is_clone = v is not None if trace: g.trace( 'clone','%-5s' % (is_clone), 'parent_v',parent_v,'gnx',gnxString,'v',repr(v)) if is_clone: pass else: v = leoNodes.vnode(context=c) if gnxString: gnx = indices.scanGnx(gnxString,0) v.fileIndex = gnx gnxDict[gnxString] = v else: g.trace('**** no gnx for',v) child_v = v child_v._linkAsNthChild(parent_v,parent_v.numberOfChildren()) child_v.setVisited() # Supress warning/deletion of unvisited nodes. return is_clone,child_v
def from_dict(self, d): """from_dict - make a Leo subtree from a dict :param dict d: input dict :return: vnode """ return self._from_dict_recursive(vnode(self.c), d)
def createFirstTreeNode(self): c = self.c v = leoNodes.vnode(context=c) p = leoNodes.position(v) v.initHeadString("NewHeadline") # New in Leo 4.5: p.moveToRoot would be wrong: # the node hasn't been linked yet. p._linkAsRoot(oldRoot=None)
def _from_dict_recursive(self, top, d): """see from_dict()""" top.h = d['h'] top.b = d['b'] top.u = d['u'] top.children[:] = [] for child in d['children']: top.children.append(self._from_dict_recursive(vnode(self.c), child)) return top
def from_dict(self, d): """from_dict - make a Leo subtree from a dict Args: d (dict): input dict Returns: vnode """ return self._from_dict_recursive(vnode(self.c), d)
def createFirstTreeNode (self): f = self ; c = f.c v = leoNodes.vnode(context=c) p = leoNodes.position(v) v.initHeadString("NewHeadline") # New in Leo 4.5: p.moveToRoot would be wrong: the node hasn't been linked yet. p._linkAsRoot(oldRoot=None) # c.setRootPosition(p) # New in 4.4.2. c.editPosition(p)
def createVnode(self, c, node, v=None): if not v: v = leoNodes.vnode(context=c) v.b, v.h = node.bodyString, node.headString if node.gnx: v.fileIndex = g.app.nodeIndices.scanGnx(node.gnx, 0) self.generated_gnxs[node.gnx] = v self.handleVnodeAttributes(node, v) return v
def createFirstTreeNode(self): c = self.c # # #1631: Initialize here, not in p._linkAsRoot. c.hiddenRootNode.children = [] # # #1817: Clear the gnxDict. c.fileCommands.gnxDict = {} # v = leoNodes.vnode(context=c) p = leoNodes.position(v) v.initHeadString("NewHeadline") # New in Leo 4.5: p.moveToRoot would be wrong: # the node hasn't been linked yet. p._linkAsRoot()
def diff_trees(vf, vt, path): fonly = [] # nodes only in from tree tonly = [] # nodes only in to tree diffs = [] # nodes which occur in both but have different descendants # count number of times each headline occurs as a child of # each node being compared count_f = {} for cf in vf.children: count_f[cf.h] = count_f.get(cf.h, 0) + 1 count_t = {} for ct in vt.children: count_t[ct.h] = count_t.get(ct.h, 0) + 1 for cf in vf.children: for ct in vt.children: if count_f[cf.h] == 1 and count_t[ct.h] == 1: equal = text_match else: equal = gnx_match head_eq, body_eq = equal(cf, ct) if body_eq: diffs.append(diff_trees(cf, ct, path+[vf.h])) break elif head_eq: d = diff_trees(cf, ct, path+[vf.h]) if d: d.h = '!v '+d.h else: d = vnode(nd.v.context) d.h = '!v '+cf.h d.b = "#%s\n\n%s" % ( '-->'.join((path+[vf.h]+[cf.h])[1:]), cf.b ) diffs.append(d) d = vnode(nd.v.context) d.h = '!^ '+cf.h d.b = "#%s\n\n%s" % ( '-->'.join((path+[vt.h]+[ct.h])[1:]), ct.b ) d.b = d.b.replace(' ', '%20') diffs.append(d) break else: fonly.append(cf) for ct in vt.children: for cf in vf.children: if count_f[cf.h] == 1 and count_t[ct.h] == 1: equal = text_match else: equal = gnx_match head_eq, body_eq = equal(cf, ct) if head_eq or body_eq: # no need to recurse matches again break else: tonly.append(ct) if not any(diffs) and not fonly and not tonly: return None vd = vnode(nd.v.context) vd.h = vf.h for d in diffs: if d: vd.children.append(d) for f in fonly: n = vd.insertAsLastChild() n.h = '- '+f.h n.b = "#%s" % ('-->'.join((path+[vf.h]+[f.h])[1:])) n.b = n.b.replace(' ', '%20') for t in tonly: n = vd.insertAsLastChild() n.h = '+ '+t.h n.b = "#%s" % ('-->'.join((path+[vf.h]+[t.h])[1:])) n.b = n.b.replace(' ', '%20') return vd
def ialc(self): vnode(self.context)._linkAsNthChild(self, len(self.children)) return self.children[-1]