From feb557d99b858e9c5070df3060a38e8b86ba268c Mon Sep 17 00:00:00 2001 From: Romain Failliot Date: Sun, 16 Apr 2023 11:34:15 -0400 Subject: [PATCH] fix: add back save_state() when shuting down --- CHANGELOG.md | 1 + src/diffuse/main.py | 7 ++++++- src/diffuse/window.py | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e30422a..b2fdf37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Some signals weren't properly renamed from the previous GTK3 migration (@MightyCreak) - The syntax menu wasn't working anymore (@MightyCreak) - Properly handles SIGINT (i.e. Ctrl+C) now (@MightyCreak) +- Add back `save_state()` to remember window's width and height (@MightyCreak) ## 0.8.1 - 2023-04-07 diff --git a/src/diffuse/main.py b/src/diffuse/main.py index befa6b4..6454225 100644 --- a/src/diffuse/main.py +++ b/src/diffuse/main.py @@ -43,6 +43,8 @@ class DiffuseApplication(Gtk.Application): self.window = None self.sysconfigdir = sysconfigdir + self.connect('shutdown', self.on_shutdown) + self.add_main_option( 'version', ord('v'), @@ -249,7 +251,7 @@ also retrieve revisions of files from several VCSs for comparison and merging.'' # load state self.statepath = os.path.join(data_dir, 'state') - diff_window.loadState(self.statepath) + diff_window.load_state(self.statepath) # process remaining command line arguments encoding = None @@ -366,6 +368,9 @@ also retrieve revisions of files from several VCSs for comparison and merging.'' self.activate() return 0 + def on_shutdown(self, application: Gio.Application) -> None: + self.window.save_state(self.statepath) + def main(version: str, sysconfigdir: str) -> int: """The application's entry point.""" diff --git a/src/diffuse/window.py b/src/diffuse/window.py index 7f6e53a..58b1073 100644 --- a/src/diffuse/window.py +++ b/src/diffuse/window.py @@ -985,7 +985,7 @@ class DiffuseWindow(Gtk.ApplicationWindow): page.open_file(f, True) # record the window's position and size - def configure_cb(self, widget, event): + def configure_cb(self, widget: Gtk.Widget, event: Gdk.EventConfigure) -> None: # read the state directly instead of using window_maximized as the order # of configure/window_state events is undefined if (widget.get_window().get_state() & Gdk.WindowState.MAXIMIZED) == 0: @@ -1000,7 +1000,7 @@ class DiffuseWindow(Gtk.ApplicationWindow): ) # load state information that should persist across sessions - def loadState(self, statepath: str) -> None: + def load_state(self, statepath: str) -> None: if os.path.isfile(statepath): try: f = open(statepath, 'r') @@ -1030,7 +1030,7 @@ class DiffuseWindow(Gtk.ApplicationWindow): self.maximize() # save state information that should persist across sessions - def saveState(self, statepath: str) -> None: + def save_state(self, statepath: str) -> None: try: ss = [] for k, v in self.bool_state.items():