Save window geometry

This commit is contained in:
kramo
2023-02-18 21:16:57 +01:00
parent 1acca573e2
commit 8718a6a170
4 changed files with 21 additions and 6 deletions

View File

@@ -22,7 +22,18 @@
<key name="bottles-location" type="s">
<default>"~/.var/app/com.usebottles.bottles/data/bottles/"</default>
</key>
<key name="sort-mode" type="s">
</schema>
<schema id="hu.kramo.Cartridge.State" path="/hu/kramo/Cartridges/State/">
<key name="width" type="i">
<default>1110</default>
</key>
<key name="height" type="i">
<default>820</default>
</key>
<key name="is-maximized" type="b">
<default>false</default>
</key>
<key name="sort-mode" type="s">
<choices>
<choice value="a-z"/>
<choice value="z-a"/>
@@ -32,5 +43,5 @@
</choices>
<default>"a-z"</default>
</key>
</schema>
</schema>
</schemalist>

View File

@@ -56,6 +56,12 @@ class CartridgesApplication(Adw.Application):
if not self.win:
self.win = CartridgesWindow(application=self)
# Save window geometry
state_settings = Gio.Settings(schema_id="hu.kramo.Cartridge.State")
state_settings.bind("width", self.win, "default-width", Gio.SettingsBindFlags.DEFAULT)
state_settings.bind("height", self.win, "default-height", Gio.SettingsBindFlags.DEFAULT)
state_settings.bind("is-maximized", self.win, "maximized", Gio.SettingsBindFlags.DEFAULT)
self.win.present()
# Create actions for the main window
@@ -68,7 +74,7 @@ class CartridgesApplication(Adw.Application):
self.win.sort = Gio.SimpleAction.new_stateful("sort_by", GLib.VariantType.new("s"), GLib.Variant("s", "a-z"))
self.win.add_action(self.win.sort)
self.win.sort.connect("activate", self.win.on_sort_action)
self.win.on_sort_action(self.win.sort, self.win.schema.get_value("sort-mode"))
self.win.on_sort_action(self.win.sort, state_settings.get_value("sort-mode"))
def on_about_action(self, widget, callback=None):
about = Adw.AboutWindow(transient_for=self.win,

View File

@@ -27,8 +27,6 @@ Adw.StatusPage hidden_notice_empty {
template CartridgesWindow : Adw.ApplicationWindow {
title: _("Cartridges");
default-width: 1110;
default-height: 820;
Adw.ToastOverlay toast_overlay {
Stack stack {

View File

@@ -325,7 +325,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
elif state == "last_played":
sort_func = self.last_played_sort
self.schema.set_string("sort-mode", state)
Gio.Settings(schema_id="hu.kramo.Cartridge.State").set_string("sort-mode", state)
self.library.set_sort_func(sort_func)
self.hidden_library.set_sort_func(sort_func)