Bug 159380 - UNO command to close all documents
Summary: UNO command to close all documents
Status: ASSIGNED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium enhancement
Assignee: wildgugu2020
URL:
Whiteboard: target:25.2.0 inReleaseNotes:25.2
Keywords: difficultyInteresting, easyHack, skillCpp
Depends on:
Blocks: UNO-Command-New
  Show dependency treegraph
 
Reported: 2024-01-26 03:31 UTC by peter josvai
Modified: 2024-07-05 06:12 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description peter josvai 2024-01-26 03:31:29 UTC
hi, 

Below "close" in the File menu, a "close all" could be extremely convenient...

I know, it's not necessary...
But it is like "save a copy"... 
an extra level of application "intelligence" ("intuitiveness")..
If it's there, everyone like is, even uses it, but if it's not, people will argue, oh, nobody needs that...

"Close all" is a key functionality for those who have working sessions... 
groups of documents that she or he opens at once...
and wants to close them at once, too.. when it comes to that...


We already have "save a copy" ! :) 


Peter

- - - thank you for developing Libreoffice & Writer - - - -
Comment 1 peter josvai 2024-01-26 03:36:52 UTC
PS:

just an additional note...

"Close" is at a very good place in the File menu!!! (below Recent Documents, in the top 1 section)

I remember some programs (applications) that have "close" down-down in the FILE menu... and it is a pain in the A to get down there -- especially given that the X in the window's right corner (forget Mac) offers itself as a quick and easy way...

So, this part needs NO change, cause it's great already :)
Comment 2 Stéphane Guillou (stragu) 2024-02-01 15:41:49 UTC
Thanks for the suggestion, Peter.
What would be the difference with using "Exit LibreOffice" and its shortcut Ctrl + Q ?
Comment 3 peter josvai 2024-03-03 11:52:35 UTC
(In reply to Stéphane Guillou (stragu) from comment #2)
> Thanks for the suggestion, Peter.
> What would be the difference with using "Exit LibreOffice" and its shortcut
> Ctrl + Q ?


Hi, 

The difference would be that you would be able to do what you actually want to do...

When you want to close all your documents (your current working session), you don't have to exit Libreoffice, as a workaround. It is, sure, possible to close all of them like that, but leaving an application (exiting) is a totally different thing than closing a bunch of documents.


Not to mention being able to have a popup window for confirmation...
which could allow to close all but a few (later on)...
The confirmation window could anyway list all the docs to be closed, even if all of them have been saved.

BUT, to answer your question:
You don't want to exit your application, you want to close the files open at the moment. It's 2 different things.

ALSO: when you close them, you'll land on the visual 'recent files list' surface, which is a good thing...
and you couldn't get there otherwise, but by exiting, opening, and closing the blank document :) :) 


Now, once again, I'm not talking about something without which life and work stops on the planet :) I'm talking about a next level of UI intelligence (intuitiveness), and a smooth workflow.
Comment 4 QA Administrators 2024-03-04 03:13:09 UTC Comment hidden (obsolete)
Comment 5 Stéphane Guillou (stragu) 2024-03-04 03:28:43 UTC
Thanks for clarifying.
On which operating system are you? Because how the Start Center and components behave might differ slightly.

(In reply to peter josvai from comment #3)
> and you couldn't get there otherwise, but by exiting, opening, and closing
> the blank document :) :) 
It should be possible to open directly the Start Center (the grey document icon in your applications), no need to create a new document then close it.

UX/Design team, thoughts on a "close all documents and open start center" command?
I think that, once more, this fits into your original request in bug 117237. If we are able to keep track of a group of documents aka a "session", we should also be able to close them all at once.
Comment 6 Heiko Tietze 2024-03-04 10:32:59 UTC
I wonder is all means all or just all from the current module, ie. Writer. 

Related is bug 133542 "Pressing CTRL+W with a single document open closes LibreOffice" rejected as CloseWin behaves differently from CloseDoc. Some wisdom in bug 85978 comment 15 (File > New is not the same as Window > New).

Binding the close all function to the session idea is interesting. But then you cannot close all (random) documents.
Comment 7 peter josvai 2024-03-04 17:25:41 UTC
(In reply to Stéphane Guillou (stragu) from comment #5)
> Thanks for clarifying.
> On which operating system are you? Because how the Start Center and
> components behave might differ slightly.
> 
> (In reply to peter josvai from comment #3)
> > and you couldn't get there otherwise, but by exiting, opening, and closing
> > the blank document :) :) 
> It should be possible to open directly the Start Center (the grey document
> icon in your applications), no need to create a new document then close it.
> 
> UX/Design team, thoughts on a "close all documents and open start center"
> command?
> I think that, once more, this fits into your original request in bug 117237.
> If we are able to keep track of a group of documents aka a "session", we
> should also be able to close them all at once.


I'm on Linux, Debian based... Star Center cannot be accessed via the grey icon, unfortunately.. (I've checked it on 2 machines)

But the point, I believe, is not getting to the Start Center...
but to handle groups of documents as sessions...

Per program module, i.e. Writer (Heiko)...
Start Center is just a device which could lead to sessions... 

Closing documents at once could lead to 
grouping them in the recent documents list... 
by two separators...
which could be the start of something, still...

But all roads seem to slope toward Sessions, somehow :)
Comment 8 QA Administrators 2024-03-05 03:13:40 UTC Comment hidden (obsolete)
Comment 9 Eyal Rozenberg 2024-03-09 08:35:43 UTC
I'm not sure this is important enough to merit a slot on the file menu by default.

How about a command for closing all the documents which the user can, optionally, place on a menu? Peter, do you find that sufficient?
Comment 10 Bdac 2024-03-11 16:30:17 UTC
Many different programs (like Krita and others) use this concept about « Close all » function and this feature comes in handy when you want to close any open session but continue to use the sotfware already open.

In relation to what Peter was saying, it’s true that the various functions are often grouped together by logic at the end of the file menu : Close, Close all and Exit program.
Comment 11 Cor Nouws 2024-03-13 17:59:30 UTC
(In reply to Eyal Rozenberg from comment #9)
> I'm not sure this is important enough to merit a slot on the file menu by
> default.
Indeed. Esp. since there is a quit, and restarting is fast enough..
Comment 12 Heiko Tietze 2024-03-14 10:17:10 UTC
We discussed the topic in the design meeting.

The requested command could be implemented but not added to the UI (just for customization). It should close documents from all modules as it intends to re-open the start center. Alternatively, and probably the better solution, is to show the start center while modules are open, see bug 77590.

Adding a UNO command is not too difficult, prototypes are likely in the resolved issues at the META ticket. Hossein, please add some code pointer how to close all open documents.
Comment 13 Hossein 2024-04-12 15:48:45 UTC
Let's begin with the commands to "close a document" and "quit" LibreOffice. Finding the implementation of the "close", and "quit" commands in LibreOffice code starts from finding their UNO commands:

Close document: .uno:CloseDoc
Quit LibreOffice: .uno:Quit

Development/DispatchCommands
https://wiki.documentfoundation.org/Development/DispatchCommands

Looking into the list of dispatch commands, one can find .uno:CloseDocs, which looks like a similar command but works for multiple documents. It was even removed in the past with 08f4ecd5823c420bb7157c238460d50f1f1f9791 as it was unused, but it was then reverted back with b9b2ab0f9f1ad91bba899068d2be7fc7767f41c9.

These are implemented in sfx2/source/appl/appserv.cxx.

When testing .uno:CloseDocs with this BASIC code while having a few Writer pages open with unsaved data, I see LibreOffice hangs:

Sub basicIDE
    Set oDispatch = CreateUnoService("com.sun.star.frame.DispatchHelper")
    Dim args(0) As New com.sun.star.beans.PropertyValue
    oDispatch.executeDispatch(StarDesktop.ActiveFrame, ".uno:CloseDocs", "", 0, args)
End Sub

I think the best would be starting from this part of the code in sfx2/source/appl/appserv.cxx, and try to reuse parts from "case SID_QUITAPP":

        case SID_CLOSEDOCS:
        {
            ...
        }

When there is some unsaved data, it should be asked about weather to save or not, for each of the files with unsaved data.
Comment 14 wildgugu2020 2024-04-12 16:54:57 UTC
Hi, thank you very much for the code pointers. I am currently an assignee and please feel free to point out my mistakes.

Since, the new uno command will close all documents and open the start center, Should the new uno command name be ".uno:RestartApp" ?

Currently, the old implementation in case SID_CLOSEDOCS, have a bug with indexing. The idea of this implementation seems to be to iterate over all the frames even if one of the frames fails to close. But since xTasks is a reference, xTasks->getCount() also reduces with every frames closed, which leads to not all documents closing. I have fixed it but should I submit a patch for SID_CLOSEDOCS separate from this bug? 

SID_CLOSEDOC, have an accelerator shortcut, "ctrl + f4". When using this shortcut it closes the document for one type and also prompts for unsaved changes and also starts the start center in case of the last document. 

Iterating over the Object Shells to execute the slot SID_CLOSEDOC closes every document, prompts dialogs for unsaved changes but it doesn't automatically start the start center like using the shortcut. 

The case SID_RESTARTAPP, will implemented be in appserv.cxx, MiscExec_Impl.

At the moment, I am currently learning for manually dispatching and looking for what have started the closedispatcher in case of the using the shortcuts like (ctrl+f4 , ctrl+w) since closedispatcher.cxx is responsible for loading the start center into the last frame.
Comment 15 wildgugu2020 2024-04-12 17:29:22 UTC
Sorry, after re-reading the comments, I have understood the requirements wrong. The requirement of the command is only to close all open documents, but not include automatically relaunching the start center. I will submit it soon.

comment 12 -> It should close documents from all modules as it intends to re-open the start center -> as it intends to re-open.
Comment 16 Commit Notification 2024-06-27 06:05:32 UTC
AungKhantOo committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/9d9cd7804919c518ed12875a81f520bee878d737

tdf#159380 Add an UNO command to close all documents

It will be available in 25.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 17 Stéphane Guillou (stragu) 2024-06-28 16:08:54 UTC
Thanks for the patch, AungKhantOo!

If you are finished with it, please set this report to "resolved - fixed".

Added to release notes: https://wiki.documentfoundation.org/index.php?title=ReleaseNotes%2F25.2&type=revision&diff=756430&oldid=756411

Verified in:

Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 97833217ebacd77d01b8e06ee1eb05cc06c17afc
CPU threads: 8; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: CL threaded
Comment 18 wildgugu2020 2024-07-01 11:49:09 UTC
(In reply to Stéphane Guillou (stragu) from comment #17)
> Thanks for the patch, AungKhantOo!
> 
> If you are finished with it, please set this report to "resolved - fixed".
> 
> Added to release notes:
> https://wiki.documentfoundation.org/index.php?title=ReleaseNotes%2F25.
> 2&type=revision&diff=756430&oldid=756411
> 
> Verified in:
> 
> Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
> Build ID: 97833217ebacd77d01b8e06ee1eb05cc06c17afc
> CPU threads: 8; OS: Linux 6.5; UI render: default; VCL: gtk3
> Locale: en-AU (en_AU.UTF-8); UI: en-US
> Calc: CL threaded

Thank you, it still need a couple of fixes for now at the moment.
Comment 19 Commit Notification 2024-07-05 06:12:46 UTC
AungKhantOo committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/07a166790b6c6c0b0bce96ce25d970a636ba55d6

tdf#159380 Fix for Add an UNO command to close all documents

It will be available in 25.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.