Skip to content

[Feat] Add close all files/workspaces function#6209

Merged
nathanlesage merged 32 commits into
Zettlr:developfrom
benniekiss:close-all
Mar 9, 2026
Merged

[Feat] Add close all files/workspaces function#6209
nathanlesage merged 32 commits into
Zettlr:developfrom
benniekiss:close-all

Conversation

@benniekiss

Copy link
Copy Markdown
Collaborator

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 Files or Workspaces dropdown arrow, at which point, it will turn into an X. When the X is double-clicked, all files or workspaces are closed.

As a result, the documents-provider now exposes the closeFileEverywhere function via the ipc interface, and an additional method was added, getOpenWorkspaceFiles. This is needed when closing workspaces.

The closeFileEverywhere was refactored to re-use the logic of forEachLeaf.

Another button was added to Workspace section 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 askSaveChanges dialogue now takes an additional detail parameter. 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

@benniekiss

Copy link
Copy Markdown
Collaborator Author

Forgot to add that this also includes shift+clicking the empty sidebar to open a file instead of a workspace

@nathanlesage nathanlesage left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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.
  2. This context menu should have two entries, one per action.
  3. 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.
  4. 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 :)

Comment thread source/app/service-providers/documents/index.ts Outdated
Comment thread source/app/service-providers/documents/index.ts Outdated
Comment thread source/win-main/file-manager/util/item-composable.ts
Comment thread source/win-main/file-manager/util/item-composable.ts
Comment thread source/win-main/file-manager/util/item-composable.ts
Comment thread source/win-main/file-manager/util/item-composable.ts
Comment thread source/win-main/file-manager/TreeItem.vue
Comment thread source/app/service-providers/commands/file-new.ts Outdated
@benniekiss

Copy link
Copy Markdown
Collaborator Author

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.

And one last thing: Could you elaborate a little bit more on how you changed the uncollapseIfApplicable behavior

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 uncollapseIfApplicable function, and removing it cleared up the issue I was seeing.

@nathanlesage

Copy link
Copy Markdown
Member

Gotcha, thank you!

@benniekiss

Copy link
Copy Markdown
Collaborator Author

This should be good to go on my end! I implemented the context menus and confirmation dialogue, and it's working in my tests.

@nathanlesage

Copy link
Copy Markdown
Member

Thank you for the changes! I've just tested it out locally.

  1. When uncollapsing a bunch of directories, then right-clicking the workspaces section title, and selecting "Collapse directories", it only collapses directories up until the first level below the workspaces. Selecting the menu item a second time then finally collapses everything as expected.
  2. The dialog boxes should also feature a question ("Do you really want to close all workspaces/files?"). Without, it looks empty and a bit weird, as if someone had forgotten something.
  3. Now that I've observed it myself, I do believe that, adding an ellipsis button ("…") to the right of the section headers that also summons the context menu might be good UX so that users can discover the new functionality.

Other than that, it looks and works great!

@benniekiss

Copy link
Copy Markdown
Collaborator Author

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

@benniekiss

Copy link
Copy Markdown
Collaborator Author

Screenshots of the button, I'm open to styling changes.

The file button is hovered, which is why it is a different color

Screenshot 2026-03-08 at 11 30 30

@nathanlesage

Copy link
Copy Markdown
Member

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!

@benniekiss

Copy link
Copy Markdown
Collaborator Author

Squarer corners and smaller border line:

Screenshot 2026-03-08 at 12 00 53

@nathanlesage

Copy link
Copy Markdown
Member

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 :)

@benniekiss

Copy link
Copy Markdown
Collaborator Author

I'd like to make the ellipsis a little bolder, but I'm not sure if that's possible with icon, otherwise I'm liking how this is so far.

Screenshot 2026-03-08 at 12 59 24 Screenshot 2026-03-08 at 12 59 30

@nathanlesage

Copy link
Copy Markdown
Member

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!

@nathanlesage

Copy link
Copy Markdown
Member

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.:

  • "Collapse folders"
  • "Collapse workspaces"

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.

@nathanlesage

Copy link
Copy Markdown
Member

Let me implement the setting, I will have to think about where to place it, so I'll take that onto my todo list

@benniekiss

Copy link
Copy Markdown
Collaborator Author

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
@nathanlesage nathanlesage merged commit 1e003bd into Zettlr:develop Mar 9, 2026
1 check passed
@nathanlesage

Copy link
Copy Markdown
Member

One final comment on this: The trans function is less smart than you think. I have now fixed it in such a way that we can actually translate everything. In some instances, the strings workspace or file wasn't translated, and the gettext system can't decode conditionals in the translate function (it takes the string as a literal), so I fixed that. Just so you know!

@benniekiss

Copy link
Copy Markdown
Collaborator Author

ahh, good too know

@benniekiss benniekiss deleted the close-all branch March 9, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add modifier key for simultaneously closing tab and its associated file.

2 participants