I have just pushed new branch based on devel which contains all changes 
regarding our recent discussions about decoupling VNode class from 
Commander class. 

All unit test pass except for one failure caused by encoding issue in 
docutils/pdf related test.

The same failure appears also in devel branch.

I am just partially satisfied with the result. It does what I was going 
for, now is possible to instantiate VNode instances without commander 
instance. However, after making all those changes I have realized that 
there are few more things that I would like to change so that overall code 
become more solid.

Theory of operation

VNode class has now few static fields and methods. Here are descriptions (* 
context means string unique to commander instance; for now c.fileName() is 
used):

*_pool *- a dictionary whose keys are fileNames of commanders and values 
are gnxDict dictionaries.
*_roots* - a dictionary which keeps the track of hiddenRootNode-s for every 
commander. Keys are fileNames, and the values are c.hiddenRootNode

VNode constructor accepts both Commander instance as a context value or 
string representing the file name of the outline. If Commander is supplied 
it uses c.fileName() as a string key. There is also possibility to supply 
context=None, in which case VNode instance won't be added to gnxDict.

*getGnxDict(context)* static method returns gnxDict of corresponding outline

*getRoot(context)* static method returns hiddenRootNode of corresponding 
outline

*forgetContext(context)* - static method removes data from _pool and _roots 
for given context

*renameContext(src, dest)* - static method which transfers all data 
connected to src - context to new context dest.


There is also a new function in module leoNodes *getCommander(context) *which 
returns Commander instance whose c.fileName() == context


This function allows all methods of Position class that use commander 
instance to get one from v.context.


c.fileCommands.gnxDict is now a property which is acquired from 
VNode.getGnxDict(fc.c.fileName()). All scripts and Leo internal functions 
that use this field can work with the present code. However, setting this 
field should be discouraged and considered as deprecated. There is a simple 
solution to this that should be used instead. For example:

# instead of using
oldGnxDict = c.fileCommands.gnxDict
c.fileCommands.gnxDict = {}
...
# do something here
...
# and restore original gnxDict
c.fileCommands.gnxDict = oldGnxDict


# one can use the following code with the same effect
oldGnxDict = c.fileCommands.gnxDict.copy()
c.fileCommands.gnxDict.clear()
...
# do something wiht empty gnxDict
...
# and restore original
c.fileCommands.gnxDict.clear()
c.fileCommands.gnxDict.update(oldGnxDict)


While working on this code, one issue I bumped on was opening non-existent 
file. If you try to open new commander with the file path that doesn't 
exist, Leo would add the extension '.leo' to the given file name. That 
forced me to add method VNode.renameContext.


That made me think about whole strategy of keeping track of commander 
instances. It would be much simpler and cleaner to add to the every 
Commander instance one unique value which must not change as long as 
application is running. This value (let's call it cdx for now) should be 
used instead of c.fileName() in new vnode-standalone code.


That is the next thing to do in vnode-standalone branch. It would improve 
code robustness. 


After that I will try to make use of these new code, to demonstrate what 
other simplifications could be achieved thanks to the VNode separation from 
Commander class.


Vitalije


PS: there are also few minor changes in several other Leo modules. Usually 
some assertions that assert v.context == c, had to be changed to `assert 
v.context == c.fileName()`



-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to