I have a master document and a series of slave documents (I understand that this definition is not required anymore but having a document defined as master in the editor has a series of added benefits that I like).
I am also in the situation where I need to have the master open in order to compile my document (external calls to makeindex with data in the slaves and results in the master, etc). Also, I would like to able to just open the slave and have the master automatically opened and identified as master.
So I decided to tackle the problem with a nice script triggered on ?load-this-file.
What I would like to achieve is this:
1 - whenever I open one of the slaves
2 - it opens a well defined master
3 - it toggles to master mode with that master
4 - focuses the editor back to the original slave that I've opened
I've managed to achieve 1-3 with the following script placed in each slave.txt:
% !TeX TXS-SCRIPT = openroot
% //Trigger = ?load-this-file
% var st_obj = new String(app.getCurrentFileName());
but I cannot manage to change focus to the actual slave.txt I've just opened: whatever I tried (using various methods from the different classes) the focus remained on the master.tex. (I can indeed change it with the mouse, but it would be nice to actually have the focus on the file I wanted to open to start with).
As a side note, if I open the master.txt and set it as master with the above script, I cannot close it unless:
- I select "close all"
- I remove the master document role. In this case, it will automatically close if I've already attempted to close it.
Any suggestion? (Or even a better way to achieve the whole thing).
Thanks for your time!
This is indeed not so simple, as the editor tabs are not exposed through the scipt interface. You can use the following workaround:
edView = documentManager.currentDocument.editorView
line = cursor.lineNumber()
col = cursor.columnNumber()
% do your stuff here
app.gotoLine(line, col, edView)
Alternative approach for loading a master document when opening a slave:
1. use the % !TeX root = masterfile magic comment in each slave
2. create a script with trigger ?load-file:
- scan the first lines for % !TeX root
- extract the master
- open it
- restore the view as above
% !TeX root = masterfile
% !TeX root
Advantage: the script is generic and doesn't have to be copied in each source file.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.