From 41e2c7d7ee849364bd647123dc9c54680e1698be Mon Sep 17 00:00:00 2001 From: heliguy Date: Wed, 27 Mar 2024 04:32:26 -0400 Subject: [PATCH] Convert snapshots window to adw.dialog --- data/ui/snapshots.blp | 9 ++++----- src/app_row_widget.py | 2 +- src/snapshots_window.py | 31 ++++++++++++------------------- src/window.py | 2 +- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/data/ui/snapshots.blp b/data/ui/snapshots.blp index 988b2bc..6946529 100644 --- a/data/ui/snapshots.blp +++ b/data/ui/snapshots.blp @@ -1,14 +1,13 @@ using Gtk 4.0; using Adw 1; -template $SnapshotsWindow: Adw.Window { - default-width: 500; - default-height: 455; - modal: true; +template $SnapshotsWindow: Adw.Dialog { + content-width: 500; + content-height: 455; Adw.ToolbarView main_toolbar_view { [top] - HeaderBar header_bar { + Adw.HeaderBar header_bar { [end] Button open_folder_button { icon-name: "document-open-symbolic"; diff --git a/src/app_row_widget.py b/src/app_row_widget.py index 1b5917a..323a8c7 100644 --- a/src/app_row_widget.py +++ b/src/app_row_widget.py @@ -289,7 +289,7 @@ class AppRow(Adw.ActionRow): ("snapshot" + str(index)), lambda *_, row=current_flatpak: SnapshotsWindow( parent_window, row - ).present(), + ), ) snapshot_item = Gio.MenuItem.new( _("Manage Snapshots"), f"win.snapshot{index}" diff --git a/src/snapshots_window.py b/src/snapshots_window.py index 296f319..a5bc1c7 100644 --- a/src/snapshots_window.py +++ b/src/snapshots_window.py @@ -7,7 +7,7 @@ import time @Gtk.Template(resource_path="/io/github/flattool/Warehouse/../data/ui/snapshots.ui") -class SnapshotsWindow(Adw.Window): +class SnapshotsWindow(Adw.Dialog): __gtype_name__ = "SnapshotsWindow" new_env = dict(os.environ) @@ -36,10 +36,8 @@ class SnapshotsWindow(Adw.Window): self.close() def show_list_or_empty(self): - try: - self.disconnect(self.no_close_id) # Make window able to close - except: - pass + # Make window able to close + self.set_can_close(True) self.action_bar.set_revealed(True) if os.path.exists(self.snapshots_of_app_path): @@ -129,8 +127,7 @@ class SnapshotsWindow(Adw.Window): Adw.Toast.new(_("Could not trash snapshot")) ) - dialog = Adw.MessageDialog.new( - self, + dialog = Adw.AlertDialog.new( _("Trash Snapshot?"), _("This snapshot and its contents will be sent to the trash."), ) @@ -139,7 +136,7 @@ class SnapshotsWindow(Adw.Window): dialog.add_response("continue", _("Trash Snapshot")) dialog.set_response_appearance("continue", Adw.ResponseAppearance.DESTRUCTIVE) dialog.connect("response", on_response, dialog.choose_finish) - dialog.present() + dialog.present(self) def create_snapshot(self): epoch = int(time.time()) @@ -161,9 +158,8 @@ class SnapshotsWindow(Adw.Window): if self.show_list_or_empty() == "list": self.create_row(f"{epoch}_{self.app_version}.tar.zst") - self.no_close_id = self.connect( - "close-request", lambda event: True - ) # Make window unable to close + # Make window unable to close + self.set_can_close(False) self.loading_label.set_label(_("Creating Snapshot…")) self.action_bar.set_revealed(False) self.main_stack.set_visible_child(self.loading) @@ -226,9 +222,8 @@ class SnapshotsWindow(Adw.Window): ) return - self.no_close_id = self.connect( - "close-request", lambda event: True - ) # Make window unable to close + # Make window unable to close + self.set_can_close(False) self.loading_label.set_label(_("Applying Snapshot…")) self.action_bar.set_revealed(False) self.main_stack.set_visible_child(self.loading) @@ -236,8 +231,7 @@ class SnapshotsWindow(Adw.Window): task = Gio.Task.new(None, None, lambda *_: callback()) task.run_in_thread(lambda *_: thread()) - dialog = Adw.MessageDialog.new( - self, + dialog = Adw.AlertDialog.new( _("Apply Snapshot?"), _("Applying this snapshot will trash any current user data for {}.").format( self.app_name @@ -248,7 +242,7 @@ class SnapshotsWindow(Adw.Window): dialog.add_response("continue", _("Apply Snapshot")) dialog.set_response_appearance("continue", Adw.ResponseAppearance.DESTRUCTIVE) dialog.connect("response", on_response, dialog.choose_finish) - dialog.present() + dialog.present(self) def open_button_handler(self, widget, path): try: @@ -294,5 +288,4 @@ class SnapshotsWindow(Adw.Window): # Window stuffs self.set_title(_("{} Snapshots").format(self.app_name)) - self.set_transient_for(parent_window) - self.set_size_request(0, 230) + self.present(parent_window) diff --git a/src/window.py b/src/window.py index 9c052e0..c2ee440 100644 --- a/src/window.py +++ b/src/window.py @@ -849,7 +849,7 @@ class WarehouseWindow(Adw.ApplicationWindow): def __init__(self, **kwargs): super().__init__(**kwargs) self.my_utils = myUtils(self) - self.set_size_request(0, 230) + self.set_size_request(0, 354) self.settings = Gio.Settings.new("io.github.flattool.Warehouse") self.settings.bind( "window-width", self, "default-width", Gio.SettingsBindFlags.DEFAULT