fix: rethink stack logic

instead of appending views indefinitely (including doubles like DMs -> Search -> DMs), remove the previous view and then append (this also ensures that the previous view is always Home)

feat: add Home to the sidebar
fix: selected sidebar row
This commit is contained in:
Evangelos Paterakis 2022-11-15 17:46:34 +02:00
parent 96671a9217
commit 5ba32dfa83
No known key found for this signature in database
GPG key ID: FE5185F095BFC8C9
4 changed files with 24 additions and 0 deletions

View file

@ -22,6 +22,7 @@
<!-- </child> -->
<child type="content">
<object class="AdwLeaflet" id="leaflet">
<property name="transition_type">slide</property>
<property name="can-navigate-back">1</property>
<property name="can-unfold">0</property>
<property name="homogeneous">0</property>

View file

@ -30,11 +30,15 @@ public class Tooth.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
title: Build.NAME,
resizable: true
);
sidebar.set_sidebar_selected_item(0);
open_view (new Views.Main ());
}
public Views.Base open_view (Views.Base view) {
if (last_view.label == view.label) return view;
if (last_view != null && last_view.label != _("Home")) {
leaflet.remove(last_view);
}
leaflet.append (view);
leaflet.visible_child = view;
@ -42,6 +46,9 @@ public class Tooth.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
}
public bool back () {
if (last_view == null) return true;
sidebar.set_sidebar_selected_item(0);
leaflet.navigate (Adw.NavigationDirection.BACK);
return true;
}

View file

@ -25,6 +25,15 @@ public class Tooth.Mastodon.Account : InstanceAccount {
});
}
public static Place PLACE_HOME = new Place() {
title = _("Home"),
icon = "user-home-symbolic",
open_func = win => {
// win.open_view (new Views.Main ());
win.back();
}
};
public static Place PLACE_NOTIFICATIONS = new Place () {
title = _("Notifications"),
icon = "bell-symbolic",
@ -74,6 +83,7 @@ public class Tooth.Mastodon.Account : InstanceAccount {
};
public override void register_known_places (GLib.ListStore places) {
places.append (PLACE_HOME);
places.append (PLACE_NOTIFICATIONS);
places.append (PLACE_MESSAGES);
places.append (PLACE_BOOKMARKS);

View file

@ -69,6 +69,12 @@ public class Tooth.Views.Sidebar : Box, AccountHolder {
saved_accounts.append (new_acc_row);
}
public void set_sidebar_selected_item(int index) {
if (items != null) {
items.select_row(items.get_row_at_index(index));
}
}
protected virtual void on_account_changed (InstanceAccount? account) {
this.account = account;
accounts_button.active = false;