[XYS] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Discuss and share scripts and script files...
autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

[XYS] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

DISCONTINUED

CONTENTS

:!: INTRO
:cup: OPERATION and SETTINGS
:ball: DOWNLOADS
:?: SET UP
     Toolbar Button
     Compatibility with SessionManager
:bug: KNOWN LIMITATIONS


:!: INTRO

The following script can:
  • Update the Mini Tree to include only the paths of the currently open tabs (of the current pane) and ...
  • ..., additionally, expand the current location in the tree.
  • Always include permanent paths, specified by the user, in the so generated Mini Tree.
  • Highlight the currently open tabs (of the current pane) in the tree.
  • Update the Mini Tree automatically on each location change or manually by clicking on the script's toolbar button.
The features of updating (1) the Mini Tree's structure and (2) the current tabs' highlighting in the tree can be controlled and used independently of each other. The text and background color for highlighting can be customized. Minimum requirement is XYplorer version "22.40.0001", published on October 27, 2021.

Despite some known limitations (see "KNOWN LIMITATIONS" below), I find the script very useful when someone knows the folder structure. It keeps the tree lean at alomst all times, yet shows the folders of the current location and, thus, allows to hide the folders in the file list. It also helps me to keep an overview of the open tabs, since I often have many tabs open.


:cup: OPERATION and SETTINGS

Once the script is set up (see "SET UP" below), the script's behavior is primarily controlled through a Custom Toolbar Button (CTB). Left-clicking the button will run the script once. Right-clicking it pops the CTB's context menu that allows to turn on or off automatic execution. It also gives access to the script's other settings. The settings are remembered across sessions. They are the following:
 
MiniTreeWithOpenTabs - CTB context menu - v9 - factory defaults.png
MiniTreeWithOpenTabs - CTB context menu - v9 - factory defaults.png (40.03 KiB) Viewed 5492 times
  • Use This Script to Update Mini Tree Structure
    Possible values: [is ON] or [is OFF] (can be toggled)

    When turned on, the script will immediately try to trigger an update of the Mini Tree's structure, as described in "INTRO" above, and then do so again each time it is run. Whether or not the Mini Tree gets activated, whenever it is not active already, is controlled by the next setting.

    When off, the script will leave the tree as is, be it the Mini Tree or the normal tree.
     
  • +Switch to Mini Tree if Normal Tree Is Present
    Possible values: [is ON] or [is OFF] (can be toggled)

    When turned on, then the Mini Tree will get activated on each structure update if it is not already active. Turning this setting on will also try to trigger an update of the Mini Tree structure immediately.

    When off, the Mini Tree can only be updated if it is active. If the normal tree is active, the Mini Tree will not get activated by running the script.
     
  • Edit Permanent Paths
    Possible values: User specified paths

    When clicking this entry, a dialog pops up in which paths can be entered - or existing ones edited - that should always be included in the Mini Tree generated by the script. One path per line. The paths are remembered across sessions.

    The script will check the paths for existence as soon as the dialog is "OK"ed. If "wrong" paths have been entered that the script cannot find, then this is pointed out to the user in separate message boxes, one for each "wrong" path. Such paths will most likely not appear in the Mini Tree. However, this is also influenced by the setting "Tools > Configuration... > General > Controls and More > Miscellaneous > Allow zombies in the Mini Tree". (Be aware, though, that when UNticking this XY setting, XY must be restartet for the unticking to take full effect. See also viewtopic.php?f=2&t=23680.)

    At least any string that is not in the format of a path at all, should normally not appear, with the exceptions of "special paths" (see below). Unfortunately, paper folders are among those strings that are not supported by the tree of XY. Because one might wonder and try to add one anyway, a special warning message will pop in case that a paper folder was entered, even if that should be rare.

    "Special paths" are supported by XY's Mini Tree. That would be: "Desktop", "Documents", "Downloads", "Links", the user folder with its name, "Network", and "Recycle Bin", yet, these have to be entered with their localized language names, as far as I can tell from how it works here for me. Ofc, if your OS language is set to English, then ... :whistle:, well I might have the English names wrong, so double check for yourself. I cannot think of any other "special paths" right now, besides "This PC" but that is anyway included in the tree at all times.

    Still, you can try anything. If the script does not recognize it as currently available, it will pop a warning message upon "OK"ing the dialog but still save it and foreward it to the tree. The tree might then show it or not.

    An interesting application of ths is to untick "Allow zombies in the Mini Tree" (see above), add all possible drive letters to the script's "permanent paths", and call the script also from the CEA "Drive added or removed". Thus, e.g. any USB drive will automatically be added to the Mini Tree, when it's available, and hidden, when it's disconnected.
     
  • Use This Script to ICF-Highlight Current Tabs in Tree
    Possible values: [is ON] or [is OFF] (can be toggled)

    When turned on, the script will immediately try to trigger an update of the script's highlighting in the tree with the use of Instant Color Filters (ICFs) and then do so again each time it is run. Whether or not any existing ICF-highlighting is replaced, is controlled by the next setting.

    When off, there will be no highlighting by the script. If some other highlighting is activated, it is left untouched.

    The colors can be customized in the 3rd line of the script's code. The factory settings are white text on green background.

    Highlighting can also be toggled on and off by using the Instant Color Filter's toolbar button, however this does not change any of the scripts behavior when being run.
     
  • +Overwrite Other ICF-Highlighting if Present
    Possible values: [is ON] or [is OFF] (can be toggled)

    When turned on, the script will overwrite any existing ICF-highlighting that might be present. Turning this setting on will also try to trigger an update of the script's highlighting immediately.

    When off, the script only updates the highlighting when no other ICF-highlighting is present. If other highlighting is present, it must first be toggled off, so that the script can take effect again.
     
  • Automatic Updating
    Possible values: [is ON] or [is OFF] (can be toggled)

    When turned on, the script will run once immediately and then each time that a location change or pane switch occurs.

    When off, the script will not run automatically.

    As mentioned above, the script can always be run manually by left-clicking the script's toolbar button, regardless of the automatic behavior. Being able to run the script manually can sometimes be helpful, since it is not possible for the automatic behavior to work all the time (see "KNOWN LIMITATIONS" below). Some people might also prefer to generally turn automatic behavior off and run the script only by hand.
     
  • Location CEAs
    Possible values: [are ON] or [are OFF] (can be toggled)

    The context menu of the script's CTB finally shows an extra option to turn XYplorer's "Changing Locations" Custom Event Actions (CEAs) on and off all together. This option is only meant for people who know what this is doing. Under normal conditions, this setting should always be kept on.

:ball: DOWNLOADS

Here you can download the script file and/or copy the code.
Attention! Major Changes! Both the script's name and the setup process slightly changed in version 6. It is recommended that upgraders go through the setup process again. Besides, also the script's operation and behavior changed a bit. E.g., some hard coded "smartness" has been turned into settings.
  old versions: (change "log" below throughout the posts of this thread)

Code of the Script

Code: Select all

// MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted; version: 9; date: 211028
function _getColorfilterColors() {
  return "FFFFFF,70B926"; // text color, background color for highlighting tabs' folders in tree: RRGGBB style
}

function _getScriptName($returnShort = 0) {
  $scriptName = "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted";
  $scriptNameShort = "MiniTreeWithOpenTabs";
  return $returnShort ? $scriptNameShort : $scriptName;
}

"main"
  // Version compatibility check
  $minver = "22.40.0001";
  end (<xyver> < $minver), _getScriptName() . " requires at least XY version """ . $minver . """.<crlf 2>However, the current XY version is ""<xyver>"".";
  
  if (tab("get", "mode") == 1 or tab("get", "mode") == 6 or substr(tab("get", "data"), 0, strlen("paper:")) == "paper:") {
    end 1;
  }
  _readINI_UseMiniTree_toPermIfNotSet();
  _readINI_UseMiniTreeWhenMaxiTree_toPermIfNotSet();
  _readINI_UseHighlightingInTree_toPermIfNotSet();
  _readINI_UseHighlightingInTreeWhenOtherICF_toPermIfNotSet();
  _readINI_UseAutoUpdate_toPermIfNotSet();

  if (get("Trigger", "context") == 2 or $p_autocart_MiniTreeWithOpenTabs_UseAutoUpdate) { // get("Trigger", "context") == 2 = script triggered by CTB
    if (_conditionally_updateMiniTreeToOpenTabsAndCurrentSubfolders()) {
        status "MiniTree updated";
    }
    
    _conditionally_updateICFInTreeForOpenTabs(_getColorfilterColors());
  }

function _conditionally_updateMiniTreeToOpenTabsAndCurrentSubfolders() {
  if ($p_autocart_MiniTreeWithOpenTabs_UseMiniTree == 1) {
    if ($p_autocart_MiniTreeWithOpenTabs_UseMiniTreeWhenMaxiTree == 1) {
      _updateMiniTreeToOpenTabsAndCurrentSubfolders();
      return 1;
    } elseif (get("#489") == 1) { // #489 = Mini Tree
      _updateMiniTreeToOpenTabsAndCurrentSubfolders();
      return 1;
    }
  }
  return 0;
}

function _updateMiniTreeToOpenTabsAndCurrentSubfolders() {
  if (tab("get", "count") == 1) {
    $curpathAsIs = get("Tabs");
  } else {
    $lengthCurTabPath = strpos(get("Tabs_sf"), "|");
    $curpathAsIs = substr(get("Tabs_sf"), 0, $lengthCurTabPath);
  }
  $curSubfolders = (exists($curpathAsIs) == 2) ? (listfolder($curpathAsIs, , 2 + 64)) : "";
  $curSubfolders = $curSubfolders ? ("|" . $curSubfolders) : "";
  $inactiveTabPathsAsIs = ((tab("get", "count") == 1) ? "" : ("|" . substr(get("Tabs_sf"), $lengthCurTabPath + 1)));
  _readINI_PermanentPathsInMiniTree_toPermIfNotSet();
  loadtree $curpathAsIs . $curSubfolders . $inactiveTabPathsAsIs . "|" . $p_autocart_MiniTreeWithOpenTabs_PermanentPathsInMiniTree, 0;
}

function _conditionally_updateICFInTreeForOpenTabs($colorfilterColors) {
  if ($p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTree == 1) {
    if ($p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTreeWhenOtherICF == 1) {
      _updateICFInTreeForOpenTabs($colorfilterColors);
      return 1;
    } elseif (substr(colorfilter(), 0, strlen('"autocart_MiniTreeWithOpenTabs" ')) == '"autocart_MiniTreeWithOpenTabs" ' or colorfilter() == "") {
      _updateICFInTreeForOpenTabs($colorfilterColors);
      return 1;
    }
  }
  return 0;
}

function _updateICFInTreeForOpenTabs($colorfilterColors) {
  $instantColorfilterDefinition = '"autocart_MiniTreeWithOpenTabs" ';
  foreach($path, get("Tabs")) {
    $filterPath = (regexmatches($path, "(:|\\)")) ? quote($path . "\") : quote($path);
    $instantColorfilterDefinition .= "T:dir:" . $filterPath . ">" . $colorfilterColors . "||";
  }
  if (colorfilter() != $instantColorfilterDefinition) {
    colorfilter($instantColorfilterDefinition);
  }
}

"Toggle UseMiniTree"
  if ($p_autocart_MiniTreeWithOpenTabs_UseMiniTree == 1) {
    setkey 0, "UseMiniTree", "INI", self("file");
    perm $p_autocart_MiniTreeWithOpenTabs_UseMiniTree = 0;
  } else {
    setkey 1, "UseMiniTree", "INI", self("file");
    perm $p_autocart_MiniTreeWithOpenTabs_UseMiniTree = 1;
    if (_conditionally_updateMiniTreeToOpenTabsAndCurrentSubfolders()) {
      status "MiniTree updated";
    }
  }

"Toggle UseMiniTreeWhenMaxiTree"
  if ($p_autocart_MiniTreeWithOpenTabs_UseMiniTreeWhenMaxiTree == 1) {
    setkey 0, "UseMiniTreeWhenMaxiTree", "INI", self("file");
    perm $p_autocart_MiniTreeWithOpenTabs_UseMiniTreeWhenMaxiTree = 0;
  } else {
    setkey 1, "UseMiniTreeWhenMaxiTree", "INI", self("file");
    perm $p_autocart_MiniTreeWithOpenTabs_UseMiniTreeWhenMaxiTree = 1;
    if (_conditionally_updateMiniTreeToOpenTabsAndCurrentSubfolders()) {
        status "MiniTree updated";
    }
  }

"Toggle UseHighlightingInTree"
  if ($p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTree == 1) {
    setkey 0, "UseHighlightingInTree", "INI", self("file");
    perm $p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTree = 0;
    if (substr(colorfilter(), 0, strlen('"autocart_MiniTreeWithOpenTabs" ')) == '"autocart_MiniTreeWithOpenTabs" ') {
      colorfilter("");
    }
  } else {
    setkey 1, "UseHighlightingInTree", "INI", self("file");
    perm $p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTree = 1;
    _conditionally_updateICFInTreeForOpenTabs(_getColorfilterColors());
  }

"Toggle UseHighlightingInTreeWhenOtherICF"
  if ($p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTreeWhenOtherICF == 1) {
    setkey 0, "UseHighlightingInTreeWhenOtherICF", "INI", self("file");
    perm $p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTreeWhenOtherICF = 0;
  } else {
    setkey 1, "UseHighlightingInTreeWhenOtherICF", "INI", self("file");
    perm $p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTreeWhenOtherICF = 1;
    // if (colorfilter() != "") {
      _conditionally_updateICFInTreeForOpenTabs(_getColorfilterColors());
    // }
  }
  
"Toggle UseAutoUpdate"
  if ($p_autocart_MiniTreeWithOpenTabs_UseAutoUpdate == 1) {
    setkey 0, "UseAutoUpdate", "INI", self("file");
    perm $p_autocart_MiniTreeWithOpenTabs_UseAutoUpdate = 0;
  } else {
    setkey 1, "UseAutoUpdate", "INI", self("file");
    perm $p_autocart_MiniTreeWithOpenTabs_UseAutoUpdate = 1;
    load "*", "main";
  }

"Toggle location CEAs"
  if (tweak("SkipBrowseEvents") == 1) {
    tweak("SkipBrowseEvents", 0);
  } else {
    tweak("SkipBrowseEvents", 1);
  }

"Edit PermanentPathsInMiniTree"
  _readINI_PermanentPathsInMiniTree_toPermIfNotSet();
  $defaultInput = replacelist(trim($p_autocart_MiniTreeWithOpenTabs_PermanentPathsInMiniTree, "|"), "|", "<crlf>");
  $returnInput = input(_getScriptName("short") . " - Edit Permanent Paths", "Edit the Permanent Paths that should always be included in the Mini Tree generated by this script. One path per line.", $defaultInput, w, 0);
  if ($returnInput != 0) {
    foreach($path, $returnInput, "<crlf>") {
      $resolvedpath = resolvepath($path);
      if (substr($path, 0, strlen("paper:")) == "paper:") {
        if (exists($path) == 2) {
          msg _getScriptName("short") . "<crlf><crlf>The path<crlf>""" . $path . """<crlf>points to an existing paper folder! However, paper folders are not supported in the tree. The path will be safed but will not appear in the Mini Tree. You may want to check it again.";
        } else {
          msg _getScriptName("short") . "<crlf><crlf>The path<crlf>""" . $path . """<crlf>points to a non-existent paper folder! However, even if it were created later on, paper folders are not supported in the tree. The path will be safed but will not appear in the Mini Tree. You may want to check it again.";
        }
      } elseif ($path and not (exists($path) == 2 or ($resolvedpath == $path and strpos($path, ":") == -1))) {
        msg _getScriptName("short") . "<crlf><crlf>The path<crlf>""" . $path . """<crlf>can not be verified to exist! The path will be safed but might not appear in the Mini Tree. You may want to check it again.";
      }
    }
    $returnInput = trim(replacelist($returnInput, "<crlf>,<crlf><crlf>", "|", ","), " |");
    setkey $returnInput, "PermanentPathsInMiniTree", "INI", self("file"), 1;
    $p_autocart_MiniTreeWithOpenTabs_PermanentPathsInMiniTree = $returnInput;
    load "*", "main";
  }

"Read INI UseMiniTree to Perm if not set"
  _readINI_UseMiniTree_toPermIfNotSet();

"Read INI UseMiniTreeWhenMaxiTree to Perm if not set"
  _readINI_UseMiniTreeWhenMaxiTree_toPermIfNotSet();

"Read INI UseHighlightingInTree to Perm if not set"
  _readINI_UseHighlightingInTree_toPermIfNotSet();

"Read INI UseHighlightingInTreeWhenOtherICF to Perm if not set"
  _readINI_UseHighlightingInTreeWhenOtherICF_toPermIfNotSet();

"Read INI UseAutoUpdate to Perm if not set"
  _readINI_UseAutoUpdate_toPermIfNotSet();

"Read INI PermanentPathsInMiniTree to Perm if not set"
  _readINI_PermanentPathsInMiniTree_toPermIfNotSet();

function _readINI_UseMiniTree_toPermIfNotSet() {
  if (not isset($p_autocart_MiniTreeWithOpenTabs_UseMiniTree))
  {
    perm $p_autocart_MiniTreeWithOpenTabs_UseMiniTree = getkey("UseMiniTree", "INI", self("file"));
  }
}

function _readINI_UseMiniTreeWhenMaxiTree_toPermIfNotSet() {
  if (not isset($p_autocart_MiniTreeWithOpenTabs_UseMiniTreeWhenMaxiTree))
  {
    perm $p_autocart_MiniTreeWithOpenTabs_UseMiniTreeWhenMaxiTree = getkey("UseMiniTreeWhenMaxiTree", "INI", self("file"));
  }
}

function _readINI_UseHighlightingInTree_toPermIfNotSet() {
  if (not isset($p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTree))
  {
    perm $p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTree = getkey("UseHighlightingInTree", "INI", self("file"));
  }
}

function _readINI_UseHighlightingInTreeWhenOtherICF_toPermIfNotSet() {
  if (not isset($p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTreeWhenOtherICF))
  {
    perm $p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTreeWhenOtherICF = getkey("UseHighlightingInTreeWhenOtherICF", "INI", self("file"));
  }
}

function _readINI_UseAutoUpdate_toPermIfNotSet() {
  if (not isset($p_autocart_MiniTreeWithOpenTabs_UseAutoUpdate))
  {
    perm $p_autocart_MiniTreeWithOpenTabs_UseAutoUpdate = getkey("UseAutoUpdate", "INI", self("file"));
  }
}

function _readINI_PermanentPathsInMiniTree_toPermIfNotSet() {
  if (not isset($p_autocart_MiniTreeWithOpenTabs_PermanentPathsInMiniTree))
  {
    perm $p_autocart_MiniTreeWithOpenTabs_PermanentPathsInMiniTree = getkey("PermanentPathsInMiniTree", "INI", self("file"));
  }
}

/* ###   INI Settings - Do not tamper with nor remove   ###
[INI]
UseMiniTree=1
UseMiniTreeWhenMaxiTree=0
UseHighlightingInTree=1
UseHighlightingInTreeWhenOtherICF=0
UseAutoUpdate=1
PermanentPathsInMiniTree=""
[INI END]
*/
Snippet Code for the Toolbar Button (see "SET UP" below)

Code: Select all

Snip: CTB 1
  XYplorer 22.40.0003, 28.10.2021 23:03:51
Action
  NewUserButton
Name
  Update MiniTreeWithOpenTabs
Icon
  :minitree*#DEDEF0,r
ScriptL
  load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "main";
ScriptR
  "_Initialize"
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Read INI UseMiniTree to Perm if not set";
   if ($p_autocart_MiniTreeWithOpenTabs_UseMiniTree==1) {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTree=Use This Script to Update Mini Tree Structure:  [is ON]  - Turn off";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTree_Icon=:select";
   } else {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTree=Use This Script to Update Mini Tree Structure:  [is OFF]  - Turn on (takes effect immediately)";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTree_Icon=:dark";
   }
  //-----------------------
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Read INI UseMiniTreeWhenMaxiTree to Perm if not set";
   if ($p_autocart_MiniTreeWithOpenTabs_UseMiniTreeWhenMaxiTree==1) {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTreeWhenMaxiTree=+Switch to Mini Tree if Normal Tree Is Present:  [is ON]  - Turn off";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTreeWhenMaxiTree_Icon=:select";
   } else {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTreeWhenMaxiTree=+Switch to Mini Tree if Normal Tree Is Present:  [is OFF]  - Turn on (takes effect immediately)";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTreeWhenMaxiTree_Icon=:dark";
   }
  //-----------------------
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Read INI PermanentPathsInMiniTree to Perm if not set";
   if ($p_autocart_MiniTreeWithOpenTabs_PermanentPathsInMiniTree=="") {
    perm $p_autocart_MiniTreeWithOpenTabs_start_of_content_PermanentPathsInMiniTree = "empty";
   } else {
    perm $p_autocart_MiniTreeWithOpenTabs_start_of_content_PermanentPathsInMiniTree = strlen($p_autocart_MiniTreeWithOpenTabs_PermanentPathsInMiniTree) <= 40 ? substr($p_autocart_MiniTreeWithOpenTabs_PermanentPathsInMiniTree, 0, 40) : (substr($p_autocart_MiniTreeWithOpenTabs_PermanentPathsInMiniTree, 0, 37) . "...");
   }
  //-----------------------
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Read INI UseHighlightingInTree to Perm if not set";
   if ($p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTree==1) {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTree=Use This Script to ICF-Highlight Current Tabs in Tree:  [is ON]  - Turn off";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTree_Icon=:select";
   } else {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTree=Use This Script to ICF-Highlight Current Tabs in Tree:  [is OFF]  - Turn on (takes effect immediately)";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTree_Icon=:dark";
   }
  //-----------------------
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Read INI UseHighlightingInTreeWhenOtherICF to Perm if not set";
   if ($p_autocart_MiniTreeWithOpenTabs_UseHighlightingInTreeWhenOtherICF==1) {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTreeWhenOtherICF=+Overwrite Other ICF-Highlighting if Present:  [is ON]  - Turn off";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTreeWhenOtherICF_Icon=:select";
   } else {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTreeWhenOtherICF=+Overwrite Other ICF-Highlighting if Present:  [is OFF]  - Turn on (takes effect immediately)";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTreeWhenOtherICF_Icon=:dark";
   }
  //-----------------------
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Read INI UseAutoUpdate to Perm if not set";
   if ($p_autocart_MiniTreeWithOpenTabs_UseAutoUpdate==1) {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseAutoUpdate=Automatic Updating:  [is ON]  - Turn off (manual updating stays always possible)";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseAutoUpdate_Icon=:sync";
   } else {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseAutoUpdate=Automatic Updating:  [is OFF]  - Turn on (for location change and pane switch)";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleUseAutoUpdate_Icon=:del";
   }
  //-----------------------
   if (tweak("SkipBrowseEvents")==1) {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleLocationCEAs=Location CEAs:  [are OFF]  - Turn on -- Attention: Might activate multiple CEA scripts!";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleLocationCEAs_Icon=:nuke";
   } else {
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleLocationCEAs=Location CEAs:  [are ON]  (Caution: Turning off breaks this and maybe other CEA scripts!)";
    goto "@autocart_MiniTreeWithOpenTabs_label_ToggleLocationCEAs_Icon=:-";
   }
  //-----------------------
  "<@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTree>|<@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTree_Icon>"
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Toggle UseMiniTree";
  " └  <@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTreeWhenMaxiTree>|<@autocart_MiniTreeWithOpenTabs_label_ToggleUseMiniTreeWhenMaxiTree_Icon>"
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Toggle UseMiniTreeWhenMaxiTree";
  //-----------------------
  "Edit Permanent Paths  --  Content: ['$p_autocart_MiniTreeWithOpenTabs_start_of_content_PermanentPathsInMiniTree']|:udc"
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Edit PermanentPathsInMiniTree";
  //-----------------------
  "-"
  "<@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTree>|<@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTree_Icon>"
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Toggle UseHighlightingInTree";
  " └  <@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTreeWhenOtherICF>|<@autocart_MiniTreeWithOpenTabs_label_ToggleUseHighlightingInTreeWhenOtherICF_Icon>"
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Toggle UseHighlightingInTreeWhenOtherICF";
  //-----------------------
  "-"
  "<@autocart_MiniTreeWithOpenTabs_label_ToggleUseAutoUpdate>|<@autocart_MiniTreeWithOpenTabs_label_ToggleUseAutoUpdate_Icon>"
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Toggle UseAutoUpdate";
  //-----------------------
  "-"
  "-"
  "<@autocart_MiniTreeWithOpenTabs_label_ToggleLocationCEAs>|<@autocart_MiniTreeWithOpenTabs_label_ToggleLocationCEAs_Icon>"
   load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "Toggle location CEAs";
FireClick
  0

:?: SET UP

The script is primarily intended to work with the location change CEA "After browsing a folder" in order to update the tree on each location change and with the CEA "Switch panes" to update the tree on each pane change. Download the script file from the "DOWNLOADS" section (and remove the version number at the end) or copy and save the code and load that script file from inside of the location change CEA "After browsing a folder", for example, with load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "main"; as well as from within the CEA "Switch panes" to work also when switching panes. One might also want to load it from within the CEA "Drive added or removed" (compare "OPERATION and SETTINGS" > "Edit Permanent Paths" above). Of course, the script file name must be adapted if you save it under a different name.
Hint:
Activating the setting "Tabs|Reuse existing tabs when changing the location" in the configuration dialog will make tabs be reused, even when changing locations through the tree. I feel that this is very practical.
Toolbar Button

Technically the script will work also without the toolbar button. The factory defaults for the settings are:
  • Use This Script to Update Mini Tree Structure: [is ON]
  • +Switch to Mini Tree if Normal Tree Is Present: [is OFF]
  • Edit Permanent Paths: [empty]
  • Use This Script to ICF-Highlight Current Tabs in Tree: [is ON]
  • +Overwrite Other ICF-Highlighting if Present: [is OFF]
  • Automatic Updating: [is ON]
  • Location CEAs: This is an XY setting and can be changed also outside of the script.
However, I would recommend to add a user button to the toolbar to be able to call the script manually and change the script's settings on the fly. To do so, add a Custom Toolbar Button (CTB), copy the code under "Snippet Code for the Toolbar Button" from the "DOWNLOADS" section, and paste it as a snippet into the CTB. This is done by editing the CTB's properties (right-click on the CTB and clicking "Edit...") and then pasting the previously copied snippet code through the right-click context menu of the "Clear" button in that "Edit User Button" dialog. (Another method of adding the CTB is shown here: snippet lab.) As icon for the toolbar button I chose the original Mini Tree icon with a colored square as background. It can easily be changed in the very same edit dialog.

Compatibility with SessionManager

To make the script compatible with the famous SessionManager script, all the lines sub "_AutorunScript" in the SessionManager code (there should be 2 occurrences) should be replaced with:
sub "_AutorunScript";
load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "main";
. (Of course, here too, if a different script file name is used, the line must be adapted accordingly.)


:bug: KNOWN LIMITATIONS

(1) If the instant color filter is set to a different value, then any current script's highlighting is overwritten and can only be restored by triggering or calling the script again, e.g. by clicking on the script's toolbar button.

(2) If a tab is closed or opened in the background, it does not trigger any event. Thus, the script cannot react to that. This can happen, e.g., if a different tab than the current one is closed. (If the current tab is closed, then that would normally trigger a change location event, which the script can react to.) It can also happen if tab sessions are switched with, e.g., the famous SessionManager script. In the latter chase it seems that sometimes some tabs are only opened after the current tab has been loaded and thus are not yet existing when script reacts to the location change event of the current tab.

In such cases, the script must be triggered or called again manually to update the tree, e.g. with the toolbar button. However, compatibility with SessionManager in particular can be restored. See "SET UP" above.

(3) If a folder is created or deleted in the current location, then this also does not constitute a location change and, thus, the script cannot react to that. Again, the script would have to be triggered or called manually to update the tree, e.g. with the toolbar button.

(4) So far, the script handles the tree for each pane separately. I am open to improvements.
Last edited by autocart on 23 Jan 2024 19:11, edited 99 times in total.

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Keeps MiniTree in sync w/ opened tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

Update to version 2.

Changes:
Mainly made it compatible with switching panes.
Last edited by autocart on 17 Oct 2021 15:35, edited 1 time in total.

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Keeps MiniTree in sync w/ opened tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

Update to version 3

Changes:
Small status bar message improvements.

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Keeps MiniTree in sync w/ opened tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

Update to version 4.

Changes:
The script now only works when Mini Tree has been activated. It will not activate Mini Tree automatically anymore. This is on purpose so that one can deactivate the script temporarily on the fly. Otherwise, one might result in having a hard time wanting to modify the folder structure in the tree. For an alternative way of deactivating the script temporarily see the workarounds.

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Keeps MiniTree in sync w/ opened tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

Update to version 5.

Changes:
The highlighting with Instant Color Filters (ICFs) can now be (temporarily) disabled by deactivating the ICF, e.g., with its toolbar button. The script will not activate the ICF automatically anymore.

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

Update to version 6.

Changes:
Major update. Major changes.
More or less reworked the whole script.
Don also improved a few details about XY itself that help the script, e.g. there is no more danger that the CEAs "Changing Locations" got broken if the script ran into an error.
XY also now reuses open tabs when locations are changed in the tree - if "Tabs|Reuse existing tabs when changing the location" is set in XY's config dialog.
Also, the script's "smartness" can now be controlled with major settings available in the script's CTB context menu.
Updating the Mini Tree's structure and highlighting the tabs in the tree can also be used separately. Each option can be turned off on its own.

This is the best version so far, I would say. Enjoy, whoever finds this useful.

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

Update to version 7.

Changes:
Special paths, e.g. "Downloads" as one word without the whole "C:\..." path, are now handled in the tree as they should.
Sorry for that taking so long, but at last it is here now in version 7!

[EDIT: Well, almost. There is still a bug in XY that interferes: viewtopic.php?f=2&t=23666, but should be fixed soon, I guess.]

Planned feature:
Option to add user defined permanent paths to the Mini Tree that will always be shown.

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

Update to version 8.
Crazy :veryconfused:: Three updates within 24 hours. Don't know what to call that. Well, ok ... I just did call it ... crazy. :kidding:

Changes:
  • Minimum requirement now is XYplorer version "22.40.0001", published on October 27, 2021. This is because Don now fixed the small bug mentioned in the EDIT of the previous posting.
  • The user can now specify permanent paths that should always be included in the Mini Tree generated by the script.
I think, that I am now pretty much done with this script.
If someone finds this a bit useful and wants any features still added, then he/she should write it now or be forever ... well, I guess later on will be ok too. Have fun, good luck, bye bye all - for now. 8)

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

Can' get enough of it. Well, I updated the CTB snippet definition a bit, resulting in a better design of the CTB context menu:

I think the arrangement now is more intuitive, since the "permanent paths" feature really belongs with the other features dealing with the tree structure.
Also, I changed the icons a tiny bit, to be more harmonious IMHO.

So, for the one person who downloaded v8 already :mrgreen: there is no new download necessary. If you want the new CTB context menu design, it is enough to copy the new CTB snippet definition and redefine the CTB with it.

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

Update to version 9 (both script code and CTB snippet).

Sorry for the continous updates. I just continue to find out more important issues that need to be improved.

Changes:
  • Script is not run anymore when the active tab is a search results or a paper folder tab. This caused only problems and those tabs are not supported in the tree anyway.
  • Improved the feedback when a path in the permanent paths edit dialog is not recognized. E.g. "Network" and "Recycle Bin" should not return any warnings anymore. But it seems that they have to be added in the local language. At least, here fore me, the English versions do not work, only the localized ones (in my case German). Ofc, if your OS language is set to English, then ... :whistle:, well I might have the English names wrong, so double check for yourself. Paper folders should return warnings now.
  • Added a preview of the specified permanent paths to the "Edit Permanent Paths" item in the CTB context menu. The first 40 characters are shown or - if the content is longer than 40 chars - the first 37 are shown with a trailing ellipsis ("..."). This way one does not have to open the whole dialog but a glance at the context menu might be enough to see/remember what is specified. If there is no content, the preview shows the word "empty".

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

I just realized that the script works much smoother, if it is called from the CEA "Before browsing a folder" or "After browsing a folder", instead of the CEA "After painting the file list".

Just FYI for the few people who downloaded it so far. Have fun.

Horst
Posts: 1176
Joined: 24 Jan 2021 12:27
Location: Germany

Re: [Script] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Post by Horst »

I like the script and the configuration works
but something is wrong with the highlighting or I misunderstand it.
If I switch highlighting on the active entry of my 2 pane tabs are colored white on green.
If I now change the active side or go into some other dir on the active side this never changes the highlight.
So in short the highlight doesn't follow my changes in the list tabs
and also not if I click on some other dir in the tree which changes the tab in the active pane to it.
Therefore I switched off highlighting and also use the manual mode of updating the tree.
Windows 11 Home, Version 24H2 (OS Build 26100.2454)
Portable XYplorer (Actual version, including betas)
Everything 1.5.0.1387a (x64), Everything Toolbar 1.5.1, Listary Pro 6.3.1.84

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

First, thank you for commenting at all! :biggrin:
Glad that you find it a bit useful. 8)

Regarding the highlighting.
I am not sure if I understand you correctly.
How it works is that the currently open tabs (of the current pane) are highlighted in the tree (both the active tab and the inactive background tabs, but only of the current pane). This does nothing more than providing a visual clue as to which folders are open in tabs, when looking at the tree.

If you just switch tabs in the same pane, then, of course nothing happens to the highlighting, because neither the number of tabs nor their folders changed.

If you switch panes, then the script will change the highlighting in the tree to reflect the open tabs that are open in that other (now current) pane. However, for this to happen automatically, the script must be called from the "Other Events | Switch Panes" CEA.

"the highlight doesn't follow my changes in the list tabs" - If "list tabs" means tab bar, then it should do so. It does so for me. But as I said, only for the current pane. And the active tab has nothing to do with the highlighting, since the highlighting is based on all open tabs in the current pane, whether active or not.

Horst
Posts: 1176
Joined: 24 Jan 2021 12:27
Location: Germany

Re: [Script] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Post by Horst »

I added
load "MiniTreeWithOpenTabs_curLocExpanded_tabFoldersHighlighted.xys", "main";
to the CEAs mentioned in the setup instructions but this doesn't change anything in behaviour.

Also I don't understand what you said
"since the highlighting is based on all open tabs in the current pane, whether active or not."
For me the current pane must be the active side of the 2 panes I have.
Windows 11 Home, Version 24H2 (OS Build 26100.2454)
Portable XYplorer (Actual version, including betas)
Everything 1.5.0.1387a (x64), Everything Toolbar 1.5.1, Listary Pro 6.3.1.84

autocart
Posts: 1299
Joined: 26 Sep 2013 15:22

Re: [Script] Mini Tree with open tabs (cur loc expanded, tab folders highlighted)

Post by autocart »

Horst wrote: 31 Oct 2021 18:17 "since the highlighting is based on all open tabs in the current pane, whether active or not."
For me the current pane must be the active side of the 2 panes I have.
Yes, of course, the current pane is the active pane.
At all times, there is only one active tab (in the foreground). There can be many inactive tabs in the background.
The script highlights the folders of all these tabs (active and inactive tabs) in the tree.
Nothing more, nothing less. But only of those tabs that are part of the currently active pane.
It is quite normal, that the highlighting will stay the same most of the time.
Horst wrote: 31 Oct 2021 18:17 but this doesn't change anything in behaviour.
What kind of behaviour do you expect or wish?

EDIT:
In case you want some German support - maybe it will be easier to understand each other? - you can write me a PM.

Post Reply