Prompt to save before closing document

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
vwegert
Posts: 23
Joined: Fri Oct 30, 2020 12:04 am

Prompt to save before closing document

Post by vwegert »

TL;DR: Attempting to close a document with unsaved changes through the File menu brings up a dialog box "Do you want to save your changes...". Doing the same thing through the context menu of the Model tree does not, immediately and irrevocably discarding all changes. I'd consider that a bug, to be honest.

Steps to reproduce:
  • Create new document.
  • Create a sketch. Settings are irrelevant, just choose any plane and select OK. Close the sketch again.
  • Optional step to illustrate: Select File --> Close.
    File-Close.png
    File-Close.png (166.4 KiB) Viewed 1544 times
    This brings up the following dialog:
    File-Close-Dialog.png
    File-Close-Dialog.png (122.89 KiB) Viewed 1544 times
    Choose "Cancel".
  • Right-click on the unnamed document and choose "Close document" from the context menu:
    ContextMenu-Close.png
    ContextMenu-Close.png (79.25 KiB) Viewed 1544 times
  • Result: The document is closed immediately without prior warning or a prompt to save the changes.
This happens with models that have been saved before as well.

OS: macOS 10.15
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22846 (Git)
Build type: Release
Branch: master
Hash: 1f46b72491a0008384a6db4f2615a656249f6f08
Python version: 3.8.6
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: C/Default (C)
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Prompt to save before closing document

Post by openBrain »

Confirmed. I think it's pretty easy to fix, but if it's not patched in the coming days, it will be worth opening a ticket.

OS: Ubuntu 18.04.5 LTS (KDE/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Branch: unknown
Hash: f7532b91d47f1048f54a42038ac5595592ff76a4
Python version: 3.6.9
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: French/France (fr_FR)
TedM
Posts: 142
Joined: Fri Apr 17, 2020 6:30 pm

Re: Prompt to save before closing document

Post by TedM »

Confirmed on Windows too.

Code: Select all

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22665 (Git)
Build type: Release
Branch: master
Hash: b0d7850406e046f3b7a8cd5da261e7d54df6bd99
Python version: 3.8.6
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United States (en_US)
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Prompt to save before closing document

Post by openBrain »

Hmmm, actually it's not exactly so simple.
There is a behavioral difference between "Close" in the File menu, and "Close document" in the tree context menu :
  • "Close" in the File menu : it closes the current view, and only this one. Which means if a document has several views opened, other views will remain, document will still be opened and user won't be prompted for save. Obviously if this closes the last active view of a document, user is prompted for save then document is closed.
  • "Close document in the tree context menu : it really closes the document hence destroys all of its active views. It has the flaw already mentioned.
So first, do we need to keep this behavioral difference ? Or should we align both commands ?
My opinion on this point is that I would also expect that "Close" command in the File menu closes the document and all its views. To get the current behavior (close only one view/subwindow), I use the MDI area subwindow buttons.
What are your opinions ?

I looked at the code and can confirm that both commands use 2 different implementation. Current behavior is "normal" regarding the used functions.
chrisb
Veteran
Posts: 54213
Joined: Tue Mar 17, 2015 9:14 am

Re: Prompt to save before closing document

Post by chrisb »

I could very well live without the close in the context menu at all. Remove the entry and remove the code. Anyone here who will miss it?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
kisolre
Veteran
Posts: 4166
Joined: Wed Nov 21, 2018 1:13 pm

Re: Prompt to save before closing document

Post by kisolre »

IMO "File/Close" should act on the File and close the active document, not just the active View. And RMB menu option should just invoke the same command.
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Prompt to save before closing document

Post by wmayer »

wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Prompt to save before closing document

Post by wmayer »

kisolre wrote: Mon Nov 02, 2020 7:27 am IMO "File/Close" should act on the File and close the active document, not just the active View. And RMB menu option should just invoke the same command.
The command originally was part of the Windows menu and uses functions of QMdiArea. Thus it really acts on mdi windows and not on documents directly. A few years ago somebody moved these commands to the File menu.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Prompt to save before closing document

Post by openBrain »

wmayer wrote: Tue Nov 03, 2020 11:14 am The command originally was part of the Windows menu and uses functions of QMdiArea. Thus it really acts on mdi windows and not on documents directly. A few years ago somebody moved these commands to the File menu.
Thx for patching. I think we can live with the current File/Close behavior, but if this were the community vote, would it be difficult to make it act as the Tree/Close do ?
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Prompt to save before closing document

Post by wmayer »

openBrain wrote: Tue Nov 03, 2020 12:18 pm
wmayer wrote: Tue Nov 03, 2020 11:14 am The command originally was part of the Windows menu and uses functions of QMdiArea. Thus it really acts on mdi windows and not on documents directly. A few years ago somebody moved these commands to the File menu.
Thx for patching. I think we can live with the current File/Close behavior, but if this were the community vote, would it be difficult to make it act as the Tree/Close do ?
No, it would be easy to change but unfortunately it will break the behaviour for MDI views that are not attached to a document.

If you open a document and e.g. the Python editor and make the latter the active window the command will close the document instead of the editor and this won't be the expected behaviour. The behaviour of the StdCmdCloseActiveWindow command is the same as when you click on the X of the corresponding tab of the view.
Post Reply