Skip to content

Commit

Permalink
feat(Preferences): use navigation subpages (#1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Nov 28, 2024
1 parent 68d272d commit c8ed010
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 124 deletions.
223 changes: 109 additions & 114 deletions data/ui/dialogs/filter_edit.ui
Original file line number Diff line number Diff line change
@@ -1,116 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0" />
<requires lib="libadwaita" version="1.0" />
<template class="TubaDialogsFilterEdit" parent="AdwDialog">
<property name="content_width">460</property>
<property name="content_height">520</property>
<property name="title" translatable="yes">Edit Filter</property>
<child>
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar">
<property name="show-end-title-buttons">0</property>
<property name="show-start-title-buttons">0</property>
<child type="start">
<object class="GtkButton">
<property name="label" translatable="yes">Cancel</property>
<signal name="clicked" handler="on_close" swapped="no" />
</object>
</child>
<child type="end">
<object class="GtkButton" id="save_btn">
<property name="receives_default">1</property>
<property name="sensitive">0</property>
<property name="label" translatable="yes">Save</property>
<signal name="clicked" handler="on_save_clicked" swapped="no" />
<style>
<class name="suggested-action" />
</style>
</object>
</child>
</object>
</child>
<property name="content">
<object class="AdwToastOverlay" id="toast_overlay">
<property name="child">
<object class="GtkScrolledWindow">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<child>
<object class="AdwClamp">
<property name="valign">start</property>
<property name="tightening-threshold">100</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="margin-top">24</property>
<property name="margin-bottom">24</property>
<property name="spacing">24</property>
<child>
<object class="GtkListBox">
<property name="selection-mode">none</property>
<style>
<class name="boxed-list" />
</style>
<child>
<object class="AdwEntryRow" id="title_row">
<property name="input-purpose">free-form</property>
<property name="title" translatable="yes">Title</property>
<signal name="changed" handler="on_title_row_changed" swapped="no" />
</object>
</child>
<child>
<object class="AdwComboRow" id="expire_in_row">
<property name="title" translatable="yes">Expires In</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="hide_row">
<property name="title" translatable="yes">Hide Completely</property>
<property name="subtitle" translatable="yes">Otherwise a warning will be used</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup" id="context_group">
<property name="title" translatable="yes">Contexts</property>
<property name="description" translatable="yes">One or multiple contexts where the filter should apply</property>
</object>
</child>
<child>
<object class="AdwPreferencesGroup" id="keywords_group">
<property name="title" translatable="yes">Keywords or Phrases</property>
<child type="header-suffix">
<object class="GtkButton">
<property name="valign">center</property>
<signal name="clicked" handler="add_keyword_row" swapped="no" />
<child>
<object class="AdwButtonContent">
<property name="icon-name">tuba-plus-large-symbolic</property>
<property name="label" translatable="yes">Add Keyword</property>
</object>
</child>
<style>
<class name="flat" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</property>
</object>
</child>
<style>
<class name="profile-editor" />
</style>
</template>
</interface>
<requires lib="gtk" version="4.0" />
<requires lib="libadwaita" version="1.0" />
<template class="TubaDialogsFilterEdit" parent="AdwNavigationPage">
<property name="title" translatable="yes">Edit Filter</property>
<property name="can-pop">0</property>
<child>
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar">
<property name="show-end-title-buttons">0</property>
<property name="show-start-title-buttons">0</property>
<child type="start">
<object class="GtkButton">
<property name="label" translatable="yes">Cancel</property>
<signal name="clicked" handler="on_close" swapped="no" />
</object>
</child>
<child type="end">
<object class="GtkButton" id="save_btn">
<property name="receives_default">1</property>
<property name="sensitive">0</property>
<property name="label" translatable="yes">Save</property>
<signal name="clicked" handler="on_save_clicked" swapped="no" />
<style>
<class name="suggested-action" />
</style>
</object>
</child>
</object>
</child>
<property name="content">
<object class="GtkScrolledWindow">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<child>
<object class="AdwClamp">
<property name="valign">start</property>
<property name="tightening-threshold">100</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="margin-top">24</property>
<property name="margin-bottom">24</property>
<property name="spacing">24</property>
<child>
<object class="GtkListBox">
<property name="selection-mode">none</property>
<style>
<class name="boxed-list" />
</style>
<child>
<object class="AdwEntryRow" id="title_row">
<property name="input-purpose">free-form</property>
<property name="title" translatable="yes">Title</property>
<signal name="changed" handler="on_title_row_changed" swapped="no" />
</object>
</child>
<child>
<object class="AdwComboRow" id="expire_in_row">
<property name="title" translatable="yes">Expires In</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="hide_row">
<property name="title" translatable="yes">Hide Completely</property>
<property name="subtitle" translatable="yes">Otherwise a warning will be used</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup" id="context_group">
<property name="title" translatable="yes">Contexts</property>
<property name="description" translatable="yes">One or multiple contexts where the filter should apply</property>
</object>
</child>
<child>
<object class="AdwPreferencesGroup" id="keywords_group">
<property name="title" translatable="yes">Keywords or Phrases</property>
<child type="header-suffix">
<object class="GtkButton">
<property name="valign">center</property>
<signal name="clicked" handler="add_keyword_row" swapped="no" />
<child>
<object class="AdwButtonContent">
<property name="icon-name">tuba-plus-large-symbolic</property>
<property name="label" translatable="yes">Add Keyword</property>
</object>
</child>
<style>
<class name="flat" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</child>
<style>
<class name="profile-editor" />
</style>
</template>
</interface>
13 changes: 5 additions & 8 deletions src/Dialogs/FilterEdit.vala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[GtkTemplate (ui = "/dev/geopjr/Tuba/ui/dialogs/filter_edit.ui")]
public class Tuba.Dialogs.FilterEdit : Adw.Dialog {
public class Tuba.Dialogs.FilterEdit : Adw.NavigationPage {
[GtkChild] unowned Adw.EntryRow title_row;
[GtkChild] unowned Adw.ComboRow expire_in_row;
[GtkChild] unowned Adw.PreferencesGroup context_group;
[GtkChild] unowned Adw.PreferencesGroup keywords_group;
[GtkChild] unowned Gtk.Button save_btn;
[GtkChild] unowned Adw.SwitchRow hide_row;
[GtkChild] unowned Adw.ToastOverlay toast_overlay;

public signal void saved (API.Filters.Filter filter);
public signal void toast (string toast_content, int dismiss_time);

const API.Filters.Filter.ContextType[] ALL_CONTEXT = {HOME, NOTIFICATIONS, PUBLIC, THREAD, ACCOUNT};
const FilterExpiration[] ALL_EXP = {NEVER, MINUTES_30, HOUR_1, HOUR_6, HOUR_12, DAY_1, WEEK_1};
Expand Down Expand Up @@ -99,7 +99,7 @@ public class Tuba.Dialogs.FilterEdit : Adw.Dialog {
}

string? filter_id = null;
public FilterEdit (Gtk.Widget win, API.Filters.Filter? filter = null) {
public FilterEdit (API.Filters.Filter? filter = null) {
populate_exp_row ();

if (filter != null) {
Expand All @@ -126,7 +126,6 @@ public class Tuba.Dialogs.FilterEdit : Adw.Dialog {
}

validate ();
this.present (win);
}

class ExpWrapper : Object {
Expand Down Expand Up @@ -246,7 +245,7 @@ public class Tuba.Dialogs.FilterEdit : Adw.Dialog {

[GtkCallback]
void on_close () {
force_close ();
this.activate_action ("navigation.pop", null);
}

[GtkCallback]
Expand Down Expand Up @@ -294,9 +293,7 @@ public class Tuba.Dialogs.FilterEdit : Adw.Dialog {
})
.on_error ((code, message) => {
this.sensitive = true;
toast_overlay.add_toast (new Adw.Toast (_("Couldn't edit filter: %s").printf (message)) {
timeout = 0
});
this.toast (_("Couldn't edit filter: %s").printf (message), 0);
warning (@"Couldn't edit filter: $code $message");
})
.exec ();
Expand Down
14 changes: 12 additions & 2 deletions src/Dialogs/Preferences.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public class Tuba.Dialogs.Preferences : Adw.PreferencesDialog {
}

private void on_edit () {
var dlg = new Dialogs.FilterEdit (win, filter);
var dlg = new Dialogs.FilterEdit (filter);
dlg.saved.connect (on_save);
dlg.toast.connect (this.win.on_toast);
this.win.push_subpage (dlg);
}

private void on_save (API.Filters.Filter filter) {
Expand Down Expand Up @@ -327,8 +329,16 @@ public class Tuba.Dialogs.Preferences : Adw.PreferencesDialog {

[GtkCallback]
private void add_keyword_row () {
var dlg = new Dialogs.FilterEdit (this);
var dlg = new Dialogs.FilterEdit ();
dlg.saved.connect (on_filter_save);
dlg.toast.connect (on_toast);
this.push_subpage (dlg);
}

public void on_toast (string toast_content, int dismiss_time) {
this.add_toast (new Adw.Toast (toast_content) {
timeout = dismiss_time
});
}

private void on_filter_save (API.Filters.Filter filter) {
Expand Down

0 comments on commit c8ed010

Please sign in to comment.