TXS-SCRIPT question

TXS - Help
El Vierde
  • El Vierde

    El Vierde - 2013-06-28

    Hi everyone!

    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());
    % st_obj=st_obj.substr(0,st_obj.lastIndexOf("/Chapters")+1)+"master.tex";
    % app.load(st_obj);
    % documentManager.setMasterDocument(documentManager.findDocument(st_obj));
    % delete(st_obj);

    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!

  • Tim Hoffmann

    Tim Hoffmann - 2013-07-02

    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

    Advantage: the script is generic and doesn't have to be copied in each source file.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks