General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Structure view: how to set the initial collapse level?

  • JOSK2

    Structure view: how to set the initial collapse level?

    Participants 7
    Replies 8
    Last Activity 7 years, 2 months ago

    XMetaL Author Enterprise 9.0 (9.0.0.053)

    Hi,

    Is there an easy way to set the initial collapse level in the structure view?

    E.g. in our environment we want that the default expansion when we open an XML (DITA) file is set to level “3”. Can this be done in the CSS? as a macro? or in a .ini file?

    Best regards
    Jan Ove

    Reply

    Derek Read

    Reply to: Structure view: how to set the initial collapse level?

    There is an API for this called SVCollapsedContainer (see the Programmers Guide for details).

    However, because this is DITA that makes things a bit trickier since making modifications to the DITA customization's functionality is not really supported. In this case I don't see any potential for conflict with the normal DITA authoring scripts though.

    The API doesn't work the same way as the built-in UI for the Structure View though. Calling the API collapses a particular element, so it would need to be called repeatedly on all the different nodes you want to collapse. I'll see if I can hack something together for you that does something similar.

    I'm a bit curious this would be something people need for DITA though. How big are your topics?

    Reply

    Derek Read

    Reply to: Structure view: how to set the initial collapse level?

    Perhaps a different solution would be to modify the Structure View CSS file for the document type to hide elements that you do not want displayed?
    I'm not sure if you really mean collapse (which would require scripting) or permanently hide (not display) particular elements?
    If you have large enough documents that Structure View is really useful to you I suspect that means you are primarily using it for navigation?
    In other words, you collapse them but perhaps only because that is the only feature you know of but might not really be what you want.

    The CSS files are located here for each DITA document type:
    C:Program FilesXMetaL 9.0AuthorDITAXACs_ditabase_structure.css
    Note: On 64-bit machines adjust the path to C:Program Files (x86)

    So for the DITA 1.2 topic.dtd the Structure View CSS file is this:
    C:Program FileXMetaL 9.0AuthorDITAXACs1.2topictopic_ditabase_structure.css

    Since it seems you want to display very few elements (at least as your default state) you could hide everything and then selectively start adding stuff back. In order to display an element its ancestor must be visible. Here's an example that hides everything except title elements for both the topic and section elements:

    [code]* { display: none; font-family: Arial; font-size: 10px; margin: 0px; padding: 0px}
    topic {display: block}
    body {display: block}
    section { display: block}
    title {display: inline}
    topic > title {font-size: 14px; font-weight: bold}[/code]

    Here's the same thing for DITA Concepts:
    [code]* { display: none; font-family: Arial; font-size: 10px; margin: 0px; padding: 0px}
    concept {display: block}
    conbody {display: block}
    section { display: block}
    title {display: inline}
    concept > title {font-size: 14px; font-weight: bold}[/code]

    Reply

    Derek Read

    Reply to: Structure view: how to set the initial collapse level?

    Anyone that wants to mess around with a scripting solution could start with the following as a base to work from.

    It works at least as far as I understand the original request but I haven't done that much testing.

    Also, how useful it is I don't really know. I think the best solution for most people would be to create CSS for the Structure View that gives you exactly what you want to see, including hiding anything you don't want to see. That way you don't need to mess around with collapsing anything. I think that assumes the primary purpose of the Structure View for you is navigation. See my previous response for info on that.

    To use this, create an MCR file (choose whatever name you like) containing the following and place it in the Startup subfolder. As written, it should run for all document types. Remove line 3 in an end user environment. That's just there for testing.

    [code=structureViewDefaultCollapse.mcr]

    //change the following line to the “collapse level” you want
    var level = 3;
    Application.Alert(“collapsing structure view at level ” + level); //hopefully you don't need to change anything from here on down
    var origSelection = ActiveDocument.Range;
    var ancestors = level – 1;
    var xpath = “//*[count(ancestor::*) = ” + ancestors + “]”;
    var nodes = ActiveDocument.documentElement.getNodesByXPath(xpath);
    ActiveDocument.FormattingUpdating = false;
    for(i=0;i Selection.SelectNodeContents(nodes.item(i));
    Selection.SVCollapsedContainer = true;
    }
    ActiveDocument.FormattingUpdating = true;
    origSelection.Select();
    ]]>

    [/code]

    The SVCollapsedContainer API is kind of finicky and (unlike almost all other APIs) doesn't work the same with Selection and Range objects. That's why I ended up using Selection here and not Range. Since moving the Selection around is visible I have also toggled formatting off and on.

    Storing the Range in origSelection and restoring it is probably not necessary in this event but it probably would be for other events or in a user-initiated macro.

    Reply

    JOSK2

    Reply to: Structure view: how to set the initial collapse level?

    Hi Derek,

    Thank for your replies.

    We are actually doing a DITA specialization where our Topics are more like traditional numbered sections and subsections.
    Doing it this way sometimes causes our “topics” to be quite large, and then increases the need to use the structure view as a mean for navigation.

    I have already changed the _structure.css to hide the unnecessary levels, however the remaining lowest level (see screendump “Expanded_3_levels”), I really would like to keep, but not show initially.

    I will sure try to implement your macro suggestion. Thanks

    Jan Ove

    Reply

    MDTOberhausen

    Reply to: Structure view: how to set the initial collapse level?

    Hi Derek
    using your macro with XMetaL Author Essential 7.0 only the first level is collapsed while opening the document. How it works to collaps all lower level, too?

    Reply

    Derek Read

    Reply to: Structure view: how to set the initial collapse level?

    I'm not sure I understand. Have you tried changing the value for the variable I named “level”?

    If you have made that change and it doesn't do what you expect perhaps you need a more robust method for walking your documents and deciding which elements to collapse in the Structure View. The script as written was only minimally tested on one document type.

    The main logic of this script is:

    1. Save the user's original selection.
    2. Turn off document formatting. We are moving the selection around so that would be annoying for the user to see.
    3. Loop the next two parts until some condition is met:
        a. move the Selection to some location in the document
        b. call the API Selection.SVCollapsedContainer = true;
    5. Turn document formatting back on.

    Reply

    MDTOberhausen

    Reply to: Structure view: how to set the initial collapse level?

    It does what to do but no more. It collapses the level 3 (or which ever choosed) but only this level. I expected it collapses also all “child levels”, like with the context menu -Totaly collapse on level …-.

    Reply

    Derek Read

    Reply to: Structure view: how to set the initial collapse level?

    I'm still not exactly sure what you want, but I will take a guess that adding another loop will be enough. In this example the nodes in the Structure View at a specific level as well as nodes within that level will be collapsed. The user will then need to expand multiple levels to see the inner content. That seems annoying to me, so I'm not sure that is what you really want.

    If that sounds right please try the following.

    [code=structureViewDefaultCollapse.mcr]

    var level = 3; //hopefully you don't need to change anything from here on down
    ActiveDocument.FormattingUpdating = false;
    var origSelection = ActiveDocument.Range; for(var j=0;j var ancestors = j;
    var xpath = “//*[count(ancestor::*) = ” + ancestors + “]”;
    var nodes = ActiveDocument.documentElement.getNodesByXPath(xpath);
    for(var i=0;i Selection.SelectNodeContents(nodes.item(i));
    Selection.SVCollapsedContainer = true;
    } } origSelection.Select();
    ActiveDocument.FormattingUpdating = true;
    ]]>

    [/code]

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support