[Feat] Add close all files/workspaces function#6209
Conversation
|
Forgot to add that this also includes shift+clicking the empty sidebar to open a file instead of a workspace |
nathanlesage
left a comment
There was a problem hiding this comment.
Thank you, I think this looks great!
The only thing I'm a bit puzzled about is the UX you implemented for this. I feel like the deluge of modifier keys and mouseover interaction is not accessible easily. Let's quickly think through that:
- You want to offer two functions for both workspaces and root files: Closing all roots in the category, and, for the workspaces only, collapse all directories.
- Collapsing directories is a non-destructive action, so I am with you that it could be a visible button.
- Closing roots is a potentially "destructive" action (in terms of the user interface at least), so I am also with you that we should require a bit more than a single (potentially accidental) click from the user.
That being said, Zettlr already provides a mechanism for asking for confirmation via dialog boxes, and I believe we should tap into that to conform with user expectations about how the app queries for potentially destructive actions. Furthermore, we should not clutter the interface with too many buttons. Lastly, exchanging buttons based on the state of modifier keys is a bad practice since that essentially tells users they cannot trust what a button in a specific position does if they are not careful.
So here's how I would solve this issue with minimal changes to the current UI:
- Add a context menu to the section headers. We could also consider adding a dedicated button where currently the "collapse folders" button is to make these "additional actions" more visible, but I'd argue that we should only use this as a last resort based on user feedback. Context menus are everywhere in the app, and we can expect users to try to summon one if they want to act on all root files/workspaces.
- This context menu should have two entries, one per action.
- If users then click the "collapse all folders" action, this simply collapses all folders. This introduces enough friction to prevent super accidental clicks (which will be annoying to some), without being a burden.
- Lastly, if users then click on the "Close all workspaces"/"Close all files" action, this should send a request to main that then first asks the user if they really want to close all files or workspaces, with two buttons, where the "cancel" action is preselected.
This means that we can leave the UI almost entirely untouched, and defer most of this work to main, while still sticking to how Zettlr usually handles these things to tap into user expectations.
And one last thing: Could you elaborate a little bit more on how you changed the uncollapseIfApplicable behavior? I saw you've removed that function in a few places, and I believe this works well, but I just want to understand the logical changes here.
Thank you again for this effort, which I believe is a great addition :)
|
Personally I really do not like context menus, but I see how that approach fits in better with Zettlr here, so I'll get working on that.
I found that currently, if you have a directory selected (highlighted in the sidebar), and then collapse that directory, expanding a separate directory would result in the highlighted directory also expanding. There was also some other strange collapse/uncollapse behavior, but I can't recall specifically. I think there was a lot of overlapping logic going on that I traced to the |
|
Gotcha, thank you! |
* also, when closing a file, pass a `detail` with * the filename of the file to be closed
|
This should be good to go on my end! I implemented the context menus and confirmation dialogue, and it's working in my tests. |
|
Thank you for the changes! I've just tested it out locally.
Other than that, it looks and works great! |
|
a button to summon the context menu sounds great imo! I'll add that. The two-click collapse behavior is intended. This was inspired by VScode's behavior which I quite like |
|
Great! Maybe make the button a bit more squirkly? Like the toolbar buttons? Because afaik we don't have any entirely round borders in regular buttons. Other than that, looks good! |
|
Maybe a bit more padding (= smaller icon) and give it a solid background instead of the border. I think the it's great! Also the I think we can just see how it looks and adapt as we go :) |
|
Yes, this looks nice! Again, there's still time until the next update, so if you or I have some idea it'll make it in! |
|
Ah, one final thing then: It is quite unusual having to click the context menu button twice. To make it more explicit, I'd like to simply exchange the label based on what it will do, e.g.:
We might even want to add a setting so that users can decide if they want all in one go or the two-stage design. I can see the appeal of having a two stage though. |
|
Let me implement the setting, I will have to think about where to place it, so I'll take that onto my todo list |
|
I like that idea. I can ahead and push the conditional label, but I'll leave the setting configuration to you |
* shows "collapse folders" if there are uncollapsed child folders * or "collapse workspaces" if only roots are uncollapsed
|
One final comment on this: The |
|
ahh, good too know |




Description
This PR adds the ability to close all files or workspaces. In addition, it adds a collapse all directories button, a context menu item to the documents tab to close the file, and it improves handling of file closing.
Changes
The main feature is that a button was added to the filetree that allows a user to close all open files or workspaces. The button is accessible by holding shift and hovering over the
FilesorWorkspacesdropdown arrow, at which point, it will turn into anX. When theXis double-clicked, all files or workspaces are closed.As a result, the
documents-providernow exposes thecloseFileEverywherefunction via theipcinterface, and an additional method was added,getOpenWorkspaceFiles. This is needed when closing workspaces.The
closeFileEverywherewas refactored to re-use the logic offorEachLeaf.Another button was added to
Workspacesection heading to collapse all open directories. If child directories are uncollapsed, then on first click, only children will be collapsed, leaving the roots open. If clicked and only root directories are uncollapsed, then they will be collapsed.When a file or workspace is closed from the sidebar, all open tabs are now closed as well.
A context menu item was added to the documents tab bar to close the associated file.
the
askSaveChangesdialogue now takes an additionaldetailparameter. This is used to include the filename of the document currently being asked for confirmation. Because multiple files can be opened from a workspace, when closing an entire workspace and some files have unsaved changes, this makes it easier to know which file is being prompted.Collapsed directory handling UX was refactored in improved in some places. Mainly, this was to prevent uncollapsing the currently selected dir when uncollapsing a different one.
The hover time required to expand a directory when dragging was reduced from 2 seconds to 1 second.
Additional information
This potentially closes #6096, although via a different route.
Some recordings of the new behavior:
Screen.Recording.2026-02-24.at.14.22.37.mov
Screen.Recording.2026-02-24.at.14.23.09.mov
Screen.Recording.2026-02-24.at.14.23.51.mov
Tested on:
macOS 26