[texworks] SCRIPTING: readFile() xxxGlobal() and NewFile hook
st.loeffler at gmail.com
Mon Dec 20 21:27:29 CET 2010
On 2010-12-19 20:36, Stefan Löffler wrote:
> That was my first guess as well, but it turned out to be wrong. The
> script manager is initialized from TWApp::init, which is invoked at the
> beginning of main() when the TWApp object is created.
> Instead, there are two varieties of newFile. Those in TeXDocument (which
> correspond to what happens when you click, e.g., on the "New" icon), and
> those in TWApp (which are essentially used by global menus on the Mac, I
> think, but also for the launch action, as there is no *Document object
> present then). I've added the hooks to the TWApp variant in r725, so
> they should be run now.
>> > An "ApplicationLaunched" hook would be a better approach. I don't think that should be hard to add. It could be called at the beginning of TWApp::launchAction(). Note that if filenames are specified on the command line, these would be opened *before* the Launched hook is called, so there may already be document windows at this time.
> OK, I'll look into that. In principle, it should be easy. However, there
> may be some peculiarities (possibly no target object yet, for example).
> It might require moving some stuff around (essentially, move runHooks
> from TWScriptable to TWScriptManager).
...and added a TeXworksLaunched hook in r726.
A few notes:
* The hook is run with an invalid (=null, none, nil, whatever) TW.target
object, as there isn't necessarily any window open at the time
* In case a second instance of Tw is executed (and terminates
immediately, due to the single instance code), the hook is not run again
* In case files are passed on the command line, these are opened before
the hook is run. Thus the LoadFile hook may be invoked before the
TeXworksLaunched. Special care must therefore be taken in scripts
implementing that hook.
Testing builds will be updated soon. Hope I didn't break anything ;).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the texworks