Collapsing favorite folders tree

User Help for Mozilla Thunderbird
Post Reply
fixer1234
Posts: 15
Joined: July 15th, 2021, 9:32 am

Collapsing favorite folders tree

Post by fixer1234 »

(Thunderbird v68.12.0)
I'm looking for a way to keep the trees of favorite folders collapsed. Background:

My historical messages are organized in lengthy trees of nested folders under Local Folders. If I use the "display all folders" option, I can collapse the folder trees so just the limited number of top-level folders show. When needed, it's easy enough to navigate to what you want. The trees of folders can be expanded and collapsed, and they stay the way you leave them from session to session.

My Thunderbird profile includes a couple of active email accounts, plus a number of inactive accounts that I occasionally need to access. I want to hide the inactive accounts when I don't need them. The solution I discovered for that was the "Favorites" feature. Mark the active account folders as favorites, then select the Favorite Folders display option. When I need to access the inactive stuff, I can switch to the Display All Folders option.

Which brings me to the problem. The Favorite Folders option will let you temporarily collapse the folder trees, but its default is to display them all. If you close Thunderbird with the folder trees collapsed, the next session, every favorite folder is displayed again.

Is there a way to keep the folder trees collapsed in the Favorites view, or another method to easily hide/show selected accounts? I'm aware that you can have all your mail go to the Local Folders inbox and not show any accounts, but I need to use the inboxes of the individual accounts.
fixer1234
Posts: 15
Joined: July 15th, 2021, 9:32 am

Re: Collapsing favorite folders tree

Post by fixer1234 »

For now, the best I can come up with is to mark as favorites only the folders in the accounts I want visible, and none of the local folders (where the big folder trees are). To access the local folders, I switch to the All Folders view (the selection can be displayed as a toolbar above the folders, so it's two clicks to change views). But I'm hoping for a better solution, like obviating the need for managing favorites by hiding/showing a group of accounts or individual accounts.
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: Collapsing favorite folders tree

Post by morat »

Favorite Folders doesn't remember collapsed status
http://bugzilla.mozilla.org/show_bug.cgi?id=1656501

That bug was fixed in Thunderbird 87.
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: Collapsing favorite folders tree

Post by morat »

You can use the userChromeJS addon to collapse the favorite folders on startup. (advanced users only)

I recommend using the error console to test the code before installing the userChromeJS addon.

i.e. menu bar > tools > developer tools > error console (ctrl+shift+j)

Code: Select all

/* Thunderbird userChrome.js */

// tested with Thunderbird 102 only

// Thunderbird 68 uses messenger.xul page
// Thunderbird 78 uses messenger.xhtml page

// getModeForIndex method errors on modeHeader indexes, using _mode property to skip

(function () {
  if (location == "chrome://messenger/content/messenger.xul" ||
      location == "chrome://messenger/content/messenger.xhtml") {
    setTimeout(function () {
      try {
        var f = gFolderTreeView;
        for (var i = f.rowCount - 1; i >= 0; i--) {
          if (f.getFTVItemForIndex(i).hasOwnProperty("_mode") == false &&
              f.getModeForIndex(i) == "favorite" &&
              f.isContainer(i) == true &&
              f.isContainerOpen(i) == true) {
            f.toggleOpenState(i);
          }
        }
      } catch (e) {
        Components.utils.reportError(e);
      }
    }, 3000);
  }
})();
userChromeJS by jikamens (compatible with TB 68 through TB 102)
http://addons.thunderbird.net/thunderbird/addon/986610

Instructions:

1. install userChromeJS extension
2. close email client
3. create or edit the userChrome.js file in the chrome folder
4. open email client
fixer1234
Posts: 15
Joined: July 15th, 2021, 9:32 am

Re: Collapsing favorite folders tree

Post by fixer1234 »

morat wrote: (advanced users only)
Thanks for the response. Unfortunately, I'm not in the "advanced user" category, or a programmer, so this approach isn't a great fit for me. But the problem seems to pop up online regularly with people looking for a solution, so maybe having this solution here will benefit some readers who land here. :)
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: Collapsing favorite folders tree

Post by morat »

For other readers...

You can toggle all tree nodes in folder pane using the tbkeys addon.

Here is an example that expand and collapse all tree nodes in folder pane except the [Gmail] folder for a particular account.

Code: Select all

(function () {
  // toggle all tree nodes in folder pane
  var tree = window.document.getElementById('folderTree');
  var splitter = window.document.getElementById('folderpane_splitter');
  var state = splitter.getAttribute('state');
  if (state == 'open') {
    var view = tree.view;
    var columns = tree.columns;
    if (view.isContainer(0) && !view.isContainerOpen(0)) {
      // expand all tree nodes
      for (var i = 0; i < view.rowCount; i++) {
        if (view.isContainer(i) && !view.isContainerOpen(i)) {
          view.toggleOpenState(i);
        }
      }
    } else {
      // collapse all tree nodes except username@gmail.com and [Gmail] folders
      for (var i = view.rowCount - 1; i >= 0; i--) {
        var name = view.getCellText(i, columns.getColumnAt(0));
        if (view.isContainer(i) &&
            view.isContainerOpen(i) &&
            name != 'username@gmail.com' &&
            name != '[Gmail]') {
          view.toggleOpenState(i);
        }
      }
    }
  } else {
    // open folder pane
    goDoCommand('cmd_toggleFolderPane');
  }
})();
tbkeys
http://github.com/wshanks/tbkeys#tbkeys

Tips: http://forums.mozillazine.org/viewtopic ... #p14872763

Online Multiline to Single Line Converter (edit email address and remove comments before converting)
http://tools.knowledgewalls.com/online- ... -converter
siffemoz
Posts: 253
Joined: January 29th, 2016, 4:36 pm

Re: Collapsing favorite folders tree

Post by siffemoz »

morat wrote: August 18th, 2022, 7:26 am For other readers...

You can toggle all tree nodes in folder pane using the tbkeys addon.

Here is an example that expand and collapse all tree nodes in folder pane except the [Gmail] folder for a particular account.

Code: Select all

(function () {
  // toggle all tree nodes in folder pane
  var tree = window.document.getElementById('folderTree');
  var splitter = window.document.getElementById('folderpane_splitter');
  var state = splitter.getAttribute('state');
  if (state == 'open') {
    var view = tree.view;
    var columns = tree.columns;
    if (view.isContainer(0) && !view.isContainerOpen(0)) {
      // expand all tree nodes
      for (var i = 0; i < view.rowCount; i++) {
        if (view.isContainer(i) && !view.isContainerOpen(i)) {
          view.toggleOpenState(i);
        }
      }
    } else {
      // collapse all tree nodes except username@gmail.com and [Gmail] folders
      for (var i = view.rowCount - 1; i >= 0; i--) {
        var name = view.getCellText(i, columns.getColumnAt(0));
        if (view.isContainer(i) &&
            view.isContainerOpen(i) &&
            name != 'username@gmail.com' &&
            name != '[Gmail]') {
          view.toggleOpenState(i);
        }
      }
    }
  } else {
    // open folder pane
    goDoCommand('cmd_toggleFolderPane');
  }
})();
@morat, this isn't working for me in TB 115.x. Nor is this, which used to work in 102.x:

Code: Select all

"q": "(function () {  var f = window.gFolderTreeView;  for (var i = f.rowCount - 1; i >= 0; i--) {    if (f.isContainer(i) && f.isContainerOpen(i)) {      f.toggleOpenState(i);    }  }})();"
This is what I'm using; the others work:

Code: Select all

{
    "a": "",
    "c": "func:MsgNewMessage",
    "d": "cmd:cmd_delete",
    "h": "cmd:cmd_viewNormalHeader",
    "r": "cmd:cmd_reply",
 "esc": "tbkeys:closeMessageAndRefresh",
    "q": "(function () {  var f = window.gFolderTreeView;  for (var i = f.rowCount - 1; i >= 0; i--) {    if (f.isContainer(i) && f.isContainerOpen(i)) {      f.toggleOpenState(i);    }  }})();"
}
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: Collapsing favorite folders tree

Post by morat »

@siffemoz

Thunderbird 102
http://github.com/wshanks/tbkeys/issues/121

Thunderbird 115:

* collapse all tree nodes in folder pane

Code: Select all

(function () {
  var folderTree = window.gTabmail.currentAbout3Pane.folderTree;
  for (var i = folderTree.rows.length - 1; i >= 0; i--) {
    folderTree.collapseRowAtIndex(i);
  }
})();
* expand all tree nodes in folder pane

Code: Select all

(function () {
  var folderTree = window.gTabmail.currentAbout3Pane.folderTree;
  for (var i = 0; i < folderTree.rows.length; i++) {
    folderTree.expandRowAtIndex(i);
  }
})();
Reference - see collapseRowAtIndex(index) and expandRowAtIndex(index)
http://searchfox.org/comm-esr115/source ... listbox.js

Similar tweak:

Thunderbird 102
http://github.com/wshanks/tbkeys/issues ... 1283186707

Thunderbird 115
http://github.com/wshanks/tbkeys/issues ... 1753293125
siffemoz
Posts: 253
Joined: January 29th, 2016, 4:36 pm

Re: Collapsing favorite folders tree

Post by siffemoz »

morat wrote: November 14th, 2023, 8:40 pm @siffemoz

Thunderbird 115:

* collapse all tree nodes in folder pane

Code: Select all

(function () {
  var folderTree = window.gTabmail.currentAbout3Pane.folderTree;
  for (var i = folderTree.rows.length - 1; i >= 0; i--) {
    folderTree.collapseRowAtIndex(i);
  }
})();
Not working.

Code: Select all

{
"a": "",
"c": "func:MsgNewMessage",
"d": "cmd:cmd_delete",
"h": "cmd:cmd_viewNormalHeader",
"r": "cmd:cmd_reply",
"esc": "tbkeys:closeMessageAndRefresh",
"q": (function () {
  var folderTree = window.gTabmail.currentAbout3Pane.folderTree;
  for (var i = folderTree.rows.length - 1; i >= 0; i--) {
    folderTree.collapseRowAtIndex(i);
  }
})();
}
jsonlint.com:

Error: Parse error on line 8:
...geAndRefresh","q": (function () { var
----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: Collapsing favorite folders tree

Post by morat »

@siffemoz

Both code snippets work for me using the error console.

Troubleshooting: viewtopic.php?p=14872763#p14872763

Remember to remove the newline characters in custom commands so the input is a valid JSON string.

Online Multiline to Single Line Converter
http://tools.knowledgewalls.com/online- ... -converter
siffemoz
Posts: 253
Joined: January 29th, 2016, 4:36 pm

Re: Collapsing favorite folders tree

Post by siffemoz »

morat wrote: November 15th, 2023, 7:20 am
Remember to remove the newline characters in custom commands so the input is a valid JSON string.

Online Multiline to Single Line Converter
http://tools.knowledgewalls.com/online- ... -converter
Thanks! Not having done that was the problem. Although, the code for 102 worked not having done that :-/
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: Collapsing favorite folders tree

Post by morat »

@siffemoz

You are missing a command and quotes after the colon as well.

Wrong: "a": "",

Right: "a": "unset",

Wrong: "q": (function () { ... })();

Right: "q": "(function () { ... })();"
Post Reply