>> The next step will be to discover what kind of data leoFileCommands.getLeoFile presently sets in the commander.
>
> A little experimentation revealed that the proper question is what
> kind of dummy commander is required.
Using a dummy commander probably creates more work than is necessary.
The following puts up an empty window.
c,frame = g.app.newLeoCommanderAndFrame(
fileName=fn,gui=g.app.gui)
fc = c.fileCommands
ok,ratio = fc.getLeoFile(theFile,fn,readAtFileNodesFlag=False,silent=False)
This topic is enough to make my head explode, but I think Leo can load
a .leo file in a single pass, using a single commander, provided that
we adopt the following rule:
** The startup code should use settings only in the finishCreate methods. **
There are several violations of this rule at present, including the following::
1. fc.getLeoFile contains::
if c.config.getBool('check_outline_after_read'):
c.checkOutline(event=None,verbose=True,unittest=False,full=True)
It will not be a big problem to honor this setting (say in
g.openWithFileName) after config settings have been handled.
2. g.openWrapperLeoFile contains:
if c.config.getBool('use_chapters') and c.chapterController:
c.chapterController.finishCreate()
This should be even easier to deal with, as follows...
At present, several finishCreate methods call other finishCreate
methods. It be better to have a single method,
LoadManager.finishCreate, be responsible for calling all other
finishCreate methods. This removes tricky order considerations from
the subsidiary finishCreate methods, and puts them in a single place
where the order is made completely explicit.
lm.finishCreate will be called after all settings have been handled,
so all the other finishCreate methods can use settings.
To make this as painless as possible, I plan to retain the overall
loading structure. This means retaining the names and calling
sequences of load-related methods . In particular, I want to retain
the signatures of the following methods:
g.openWithFileName
g.app.newLeoCommanderAndFrame
fc.getLeoFile
fc.open
The signature of g.openWithFileName will remain unchanged, but its
entire code will probably move to the LoadManager.
The status of the following settings methods is unclear. Their
signatures may change, or perhaps they may disappear completely.
g.app.config.openSettingsFile
g.app.config.updateSettings
===== Conclusions
We are getting close to a strategy. The "use no settings until
finishCreate time" rule is easy to understand and should be relatively
easy to enforce. Indeed a single assert in the config code could
ensure that no calls to it are made until a LoadManager flag is set.
This strategy is still provisional. More experimentation is required,
but I am beginning to have hopes that the new loading code will work.
Edward
> Work continues. As my brother would say, slow but slow.
I've just seen how to take smaller bites of the elephant.
The Aha is this: there are two parts of the LoadManager class:
1. The part that controls the overall load process. This is the
analog to the run() function in runLeo.py.
2. Various components that init settings and do other "smallish" tasks.
I can develop the pieces of part 2 without using part 1. Indeed,
specific parts of Leo's existing code can call parts of part 2 now.
For example, I can change the *existing* doPrePluginsInit in runLeo.py
as follows:
if g.new_load:
g.app.lm.readGlobalSettingsFiles(file)
# reads only standard settings files, using a null gui.
# uses files[0] to compute the local directory
# that might contain myLeoSettings.leo.
else:
g.app.config.readSettingsFiles(None,verbose)
for fn in files:
g.app.config.readSettingsFiles(fn,verbose)
Imo, this kind of strategy is essential in order to manage the
complexity of the required changes. There is simply no reasonable way
to eat the elephant in a single bite. An incremental approach allows
me to do full tests after each of these smallish bites.
This will continue to be a slow, picky process. For example, there
will be ongoing issues of initing the LoadManager class while we
incorporate more and more of the LoadManager code into Leo.
Edward