Skip to content

Commit

Permalink
MainWindow: Fix unsaved dialog is shown after saving (take 2)
Browse files Browse the repository at this point in the history
Alternative to #141
  • Loading branch information
ryonakano committed Feb 11, 2024
1 parent 48fe929 commit 417c68a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class MainWindow : Adw.ApplicationWindow {
});

edit_view.file_updated.connect (() => {
desktop_file.copy_to (backup_desktop_file);
overlay.add_toast (updated_toast);
});

Expand Down Expand Up @@ -158,7 +159,8 @@ public class MainWindow : Adw.ApplicationWindow {

public void show_edit_view (Model.DesktopFile file) {
desktop_file = file;
backup_desktop_file = new Model.DesktopFile.copy (file);
backup_desktop_file = new Model.DesktopFile (desktop_file.path);
desktop_file.copy_to (backup_desktop_file);

edit_view.load_file (desktop_file);
leaflet.show_content = true;
Expand Down
21 changes: 11 additions & 10 deletions src/Model/DesktopFile.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ public class Model.DesktopFile : Object {
);
}

/**
* The copy constructor.
*
* @param other Another DesktopFile.
*/
public DesktopFile.copy (DesktopFile other) {
string data = other.to_data ();
load_from_data (data);
}

construct {
keyfile = new KeyFile ();
}
Expand All @@ -58,6 +48,17 @@ public class Model.DesktopFile : Object {
return this_data == other_data;
}

/**
* Copy and set data from this to another DesktopFile.
*
* @param dest Another DesktopFile to copy this data to.
* @return true if successfully copied, false otherwise.
*/
public bool copy_to (DesktopFile dest) {
string data = to_data ();
return dest.load_from_data (data);
}

////////////////////////////////////////////////////////////////////////////
//
// Key Opearations
Expand Down

0 comments on commit 417c68a

Please sign in to comment.