fix: add back save_state() when shuting down

This commit is contained in:
Romain Failliot 2023-04-16 11:34:15 -04:00
parent f8f0b0618c
commit feb557d99b
3 changed files with 10 additions and 4 deletions

View File

@ -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) - Some signals weren't properly renamed from the previous GTK3 migration (@MightyCreak)
- The syntax menu wasn't working anymore (@MightyCreak) - The syntax menu wasn't working anymore (@MightyCreak)
- Properly handles SIGINT (i.e. Ctrl+C) now (@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 ## 0.8.1 - 2023-04-07

View File

@ -43,6 +43,8 @@ class DiffuseApplication(Gtk.Application):
self.window = None self.window = None
self.sysconfigdir = sysconfigdir self.sysconfigdir = sysconfigdir
self.connect('shutdown', self.on_shutdown)
self.add_main_option( self.add_main_option(
'version', 'version',
ord('v'), ord('v'),
@ -249,7 +251,7 @@ also retrieve revisions of files from several VCSs for comparison and merging.''
# load state # load state
self.statepath = os.path.join(data_dir, '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 # process remaining command line arguments
encoding = None encoding = None
@ -366,6 +368,9 @@ also retrieve revisions of files from several VCSs for comparison and merging.''
self.activate() self.activate()
return 0 return 0
def on_shutdown(self, application: Gio.Application) -> None:
self.window.save_state(self.statepath)
def main(version: str, sysconfigdir: str) -> int: def main(version: str, sysconfigdir: str) -> int:
"""The application's entry point.""" """The application's entry point."""

View File

@ -985,7 +985,7 @@ class DiffuseWindow(Gtk.ApplicationWindow):
page.open_file(f, True) page.open_file(f, True)
# record the window's position and size # 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 # read the state directly instead of using window_maximized as the order
# of configure/window_state events is undefined # of configure/window_state events is undefined
if (widget.get_window().get_state() & Gdk.WindowState.MAXIMIZED) == 0: 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 # 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): if os.path.isfile(statepath):
try: try:
f = open(statepath, 'r') f = open(statepath, 'r')
@ -1030,7 +1030,7 @@ class DiffuseWindow(Gtk.ApplicationWindow):
self.maximize() self.maximize()
# save state information that should persist across sessions # save state information that should persist across sessions
def saveState(self, statepath: str) -> None: def save_state(self, statepath: str) -> None:
try: try:
ss = [] ss = []
for k, v in self.bool_state.items(): for k, v in self.bool_state.items():