pref: add preferences for clear after send

This commit is contained in:
0xMRTT 2023-04-27 00:32:36 +02:00
parent 399982ea15
commit 211ae80e93
3 changed files with 60 additions and 0 deletions

View file

@ -1,5 +1,6 @@
blueprints = custom_target('blueprints',
input: files(
'preferences.blp',
'window.blp',
),
output: '.',

28
data/ui/preferences.blp Normal file
View file

@ -0,0 +1,28 @@
using Gtk 4.0;
using Adw 1;
template GradiencePreferencesWindow : Adw.PreferencesWindow {
title: _("Preferences");
default-height: 400;
default-width: 600;
modal: true;
Adw.PreferencesPage general_page {
Adw.PreferencesGroup prompt_group {
title: _("Prompt");
Adw.ActionRow {
title: _("Clear prompt after send");
subtitle: _("The prompt will be cleared after send");
activatable-widget: clear_after_send_switch;
Gtk.Switch clear_after_send_switch {
valign: center;
}
}
}
}
}

31
src/preferences.py Normal file
View file

@ -0,0 +1,31 @@
from gi.repository import Gtk, Adw
@Gtk.Template(resource_path="/com/github/Bavarder/Bavarder/ui/preferences.ui")
class Preferences(Adw.PreferencesWindow):
__gtype_name__ = "GradiencePreferencesWindow"
clear_after_send_switch = Gtk.Template.Child()
def __init__(self, application, **kwargs):
super().__init__(**kwargs)
self.app = application
self.settings = application.settings
self.win = self.app.get_active_window()
self.setup()
def setup(self):
clear_after_send = self.settings.get_boolean("clear-after-send")
self.clear_after_send_switch.connect("state-set", self.on_clear_after_send_switch_toggled)
def on_clear_after_send_switch_toggled(self, *args):
state = self.clear_after_send_switch.props.state
if state:
self.settings.set_boolean("clear-after-send", True)
else:
self.settings.set_boolean("clear-after-send", False)