Skip to content

Save all open editors before running Save As #939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2022
Merged

Conversation

msujew
Copy link
Contributor

@msujew msujew commented Apr 4, 2022

Motivation

Closes #896

Change description

Invokes the saveAll operation of the ApplicationShell before saving the sketch to a new location.

Other information

This saves any unsaved changes to the current sketch as well. Is this alright with the usability concept? Or should the new changes exclusively be saved to the new sketch? (this would be a bit more involved)

Reviewer checklist

  • PR addresses a single concern.
  • The PR has no duplicates (please search among the Pull Requests before creating one)
  • PR title and description are properly filled.
  • Docs have been added / updated (for bug fixes / features)

@fstasi fstasi requested review from ubidefeo and per1234 April 4, 2022 14:52
Copy link
Contributor

@AlbyIanna AlbyIanna left a comment

Choose a reason for hiding this comment

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

@msujew Works for me. I have just one doubt: why do we need a timeout? Since saveAll() returns a Promise, I would expect not to need any timeout after that.

@msujew
Copy link
Contributor Author

msujew commented Apr 4, 2022

@AlbyIanna Yeah, sadly the internal Theia 1.22 code for saveAll looks like this

Promise.all(widgets, widget => {
  if (Saveable.is(widget)) {
    Saveable.save(widget); // Note the missing "await" here
  }
});

Which is why we need to wait. But you're right, overriding the saveAll method of the Applicationshell to locally fix this would probably the better idea than waiting. I'll address this.

Note that the saving functionality has been moved into its own service which correctly uses await in version 1.23 and onward. We should probably update soon anyway.

Perhaps we should try to update to 1.24 soon?

@AlbyIanna
Copy link
Contributor

Thanks @msujew!

Perhaps we should try to update to 1.24 soon?

Yes, I think we should.
cc: @fstasi

@ubidefeo
Copy link

ubidefeo commented Apr 5, 2022

If I create a new Sketch and try to close it, it triggers a "Save sketch folder as..." (should be "Save Sketch as...") but no matter how many times I click on "Save" it won't happen and the dialog will keep popping up.
Clicking "Cancel" will continue the operation and the Sketch will be reloaded, proving that it has been indeed saved

CleanShot 2022-04-05 at 11 25 45@2x

@AlbyIanna
Copy link
Contributor

@ubidefeo oh right that happens to me too with new sketches.
If I follow instructions in #896 👇

  1. Select File > Preferences from the Arduino IDE menus.
  2. Uncheck the box next to "☐ Auto save"
  3. Click the OK button.
  4. Select File > New from the Arduino IDE menus.
    ℹ️ The bug is not limited to new sketches. It also occurs with sketches that have been previously saved to a permanent location on the disk.
  5. Make some change to the sketch.
  6. ❗ Do not save.
  7. Select File > Save As... from the Arduino IDE menus.
  8. Click the Save button.

I get the same buggy behaviour @ubidefeo is describing. 🐛

@msujew
Copy link
Contributor Author

msujew commented Apr 6, 2022

@AlbyIanna @ubidefeo the weird behavior when closing app is related to this code, and will likely be addressed by #893. It's independent of this change.

@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Apr 6, 2022
Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

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

UPDATE: fixed by https://github.com/arduino/arduino-ide/compare/51af711f7b70f6310787360a25294193ddefb280..2543d1b0c81f437e3f8c6dbc60f064bcdb425236

>This saves any unsaved changes to the current sketch as well. Is this alright with the usability concept? Or should the new changes exclusively be saved to the new sketch?

They must be saved exclusively to the new sketch, just as "Save as" works in every other application ever made.

@AlbyIanna
Copy link
Contributor

AlbyIanna commented Apr 12, 2022

We are going to merge this PR only when #893 will be approved because we want to solve all the major saving issues together.

Copy link
Contributor

@AlbyIanna AlbyIanna left a comment

Choose a reason for hiding this comment

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

As @per1234 suggested – we should save the new changes exclusively in the new sketch.

@msujew msujew force-pushed the msujew/save-on-save-as branch from 51af711 to 2543d1b Compare April 20, 2022 10:51
@msujew
Copy link
Contributor Author

msujew commented Apr 20, 2022

@per1234 @AlbyIanna Thanks for the feedback, I've changed the code to only save the changes to the new sketch. Mind retesting?

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

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

UPDATE: Fixed by https://github.com/arduino/arduino-ide/compare/2543d1b0c81f437e3f8c6dbc60f064bcdb425236..6299e87015c745f7e1588e4b438df893d2c300de

### Describe the problem

When using the build from this PR, performing a "Save As..." operation when the sketch has unsaved changes produces an unexpected dialog about quitting:

image

To reproduce

  1. Select File > Preferences from the Arduino IDE menus.
  2. Uncheck the box next to "☐ Auto save"
  3. Click the OK button.
  4. Make some change to the sketch (I will refer to this as "Sketch A" from here on).
    ❗ Do not save.
  5. Select File > Save As... from the Arduino IDE menus.
  6. Click the Save button.
    (I will refer to this as "Sketch B" from here on)

🐛 An unexpected and confusing dialog appears:

Are you sure you want to quit?

Any unsaved changes will not be saved.

Expected behavior

No quit confirmation dialog on "Save As...".

The IDE must be smart enough to understand that, even though it is true that the unsaved changes are not saved to "Sketch A", they are saved to "Sketch B" and it is standard and expected by the user that changes would not be saved to "Sketch A".

The IDE must be smart enough to understand that the closure of "Sketch A" when saving as "Sketch B" is different from a normal close of a window. The replacement of "Sketch A" by "Sketch B" in the application after a "Save As..." operation is simply standard and expected behavior of any application and the user should not be consulted about it or exposed to whatever specific mechanism the IDE is using to accomplish that replacement.

Arduino IDE version

2.0.0-rc6-snapshot-7ef629a

(the tester build for 2543d1b)

Operating system

Windows 10

@msujew msujew force-pushed the msujew/save-on-save-as branch from 2543d1b to 6299e87 Compare April 21, 2022 16:26
@msujew
Copy link
Contributor Author

msujew commented Apr 21, 2022

@per1234 Sorry, small oversight, should be fixed now. That was the underlying Theia onWillStop check that popped up.

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

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

This solves #896 for me.
Thanks @msujew!

@fstasi fstasi merged commit 11961bb into main Apr 29, 2022
@fstasi fstasi deleted the msujew/save-on-save-as branch April 29, 2022 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unsaved changes lost after "**Save As...**" operation
5 participants