Skip to content

Commit

Permalink
feat(Sidebar): move header button to the menu (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Aug 31, 2023
1 parent 31f4606 commit 81e79ac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 111 deletions.
76 changes: 6 additions & 70 deletions data/ui/views/sidebar/view.ui
Original file line number Diff line number Diff line change
Expand Up @@ -47,76 +47,12 @@
<object class="GtkStackPage">
<property name="name">items</property>
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>

<!-- Header -->
<child>
<object class="GtkButton">
<signal name="clicked" handler="on_open" />
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<property name="spacing">12</property>
<child>
<object class="TubaWidgetsAvatar" id="avatar">
<property name="size">48</property>
<property name="halign">start</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="valign">center</property>
<property name="hexpand">true</property>
<property name="spacing">4</property>
<child>
<object class="TubaWidgetsEmojiLabel" id="title">
</object>
</child>
<child>
<object class="GtkLabel" id="subtitle">
<property name="label">Handle</property>
<property name="xalign">0</property>
<property name="lines">0</property>
<property name="wrap">1</property>
<property name="wrap_mode">word-char</property>
<style>
<class name="body" />
<class name="dim-label" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
<style>
<class name="flat" />
<class name="no-border-radius" />
</style>
</object>
</child>

<child>
<object class="GtkSeparator">
</object>
</child>

<child>
<object class="GtkListBox" id="items">
<property name="selection_mode">single</property>
<signal name="row_activated" handler="on_item_activated" />
<style>
<class name="navigation-sidebar" />
</style>
</object>
</child>

<object class="GtkListBox" id="items">
<property name="selection_mode">single</property>
<signal name="row_activated" handler="on_item_activated" />
<style>
<class name="navigation-sidebar" />
</style>
</object>
</property>
</object>
Expand Down
14 changes: 13 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ namespace Tuba {
{ "back-home", back_home_activated },
{ "scroll-page-down", scroll_view_page_down },
{ "scroll-page-up", scroll_view_page_up },
{ "open-preferences", open_preferences }
{ "open-preferences", open_preferences },
{ "open-current-account-profile", open_current_account_profile }
};

construct {
Expand Down Expand Up @@ -253,6 +254,17 @@ namespace Tuba {
Dialogs.Preferences.open ();
}

void open_current_account_profile () {
accounts.active.open ();
close_sidebar ();
}

private void close_sidebar () {
var split_view = app.main_window.split_view;
if (split_view.collapsed)
split_view.show_sidebar = false;
}

string troubleshooting = "os: %s %s\nprefix: %s\nflatpak: %s\nversion: %s (%s)\ngtk: %u.%u.%u (%d.%d.%d)\nlibadwaita: %u.%u.%u (%d.%d.%d)\nlibsoup: %u.%u.%u (%d.%d.%d)%s".printf ( // vala-lint=line-length
GLib.Environment.get_os_info ("NAME"), GLib.Environment.get_os_info ("VERSION"),
Build.PREFIX,
Expand Down
52 changes: 12 additions & 40 deletions src/Views/Sidebar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ public class Tuba.Views.Sidebar : Gtk.Widget, AccountHolder {
[GtkChild] unowned Widgets.Avatar accounts_button_avi;
[GtkChild] unowned Gtk.MenuButton menu_btn;

[GtkChild] unowned Widgets.Avatar avatar;
[GtkChild] unowned Widgets.EmojiLabel title;
[GtkChild] unowned Gtk.Label subtitle;

protected InstanceAccount? account { get; set; default = null; }

protected GLib.ListStore app_items;
Expand All @@ -24,9 +20,17 @@ public class Tuba.Views.Sidebar : Gtk.Widget, AccountHolder {

construct {
var menu_model = new GLib.Menu ();
menu_model.append (_("Preferences"), "app.open-preferences");
menu_model.append (_("Keyboard Shortcuts"), "win.show-help-overlay");
menu_model.append (_("About"), "app.about");

var account_submenu_model = new GLib.Menu ();
account_submenu_model.append (_("Open Profile"), "app.open-current-account-profile");
menu_model.append_section (null, account_submenu_model);

var misc_submenu_model = new GLib.Menu ();
misc_submenu_model.append (_("Preferences"), "app.open-preferences");
misc_submenu_model.append (_("Keyboard Shortcuts"), "win.show-help-overlay");
misc_submenu_model.append (_("About"), "app.about");
menu_model.append_section (null, misc_submenu_model);

menu_btn.menu_model = menu_model;

app_items = new GLib.ListStore (typeof (Place));
Expand Down Expand Up @@ -66,15 +70,10 @@ public class Tuba.Views.Sidebar : Gtk.Widget, AccountHolder {
}
}

private Binding sidebar_handle_short;
private Binding sidebar_avatar;
private Binding sidebar_display_name;
private Binding sidebar_avatar_btn;
protected virtual void on_account_changed (InstanceAccount? account) {
if (this.account != null) {
sidebar_handle_short.unbind ();
sidebar_avatar.unbind ();
sidebar_display_name.unbind ();
sidebar_avatar_btn.unbind ();
}

if (app?.main_window != null)
Expand All @@ -84,28 +83,11 @@ public class Tuba.Views.Sidebar : Gtk.Widget, AccountHolder {
accounts_button.active = false;

if (account != null) {
sidebar_handle_short = this.account.bind_property ("handle_short", subtitle, "label", BindingFlags.SYNC_CREATE);
sidebar_avatar = this.account.bind_property ("avatar", avatar, "avatar-url", BindingFlags.SYNC_CREATE);
sidebar_avatar_btn = this.account.bind_property ("avatar", accounts_button_avi, "avatar-url", BindingFlags.SYNC_CREATE);
sidebar_display_name = this.account.bind_property (
"display-name",
title,
"content",
BindingFlags.SYNC_CREATE,
(b, src, ref target) => {
title.instance_emojis = this.account.emojis_map;
target.set_string (src.get_string ());
return true;
}
);

account_items.model = account.known_places;
} else {
saved_accounts.unselect_all ();

title.content = _("Anonymous");
subtitle.label = _("No account selected");
avatar.account = null;
account_items.model = null;
accounts_button_avi.account = null;
}
Expand All @@ -115,16 +97,6 @@ public class Tuba.Views.Sidebar : Gtk.Widget, AccountHolder {
mode.visible_child_name = accounts_button.active ? "saved_accounts" : "items";
}

[GtkCallback] void on_open () {
if (account == null) return;
account.open ();

var split_view = app.main_window.split_view;
if (split_view.collapsed)
split_view.show_sidebar = false;
}


// Item

[GtkTemplate (ui = "/dev/geopjr/Tuba/ui/views/sidebar/item.ui")]
Expand Down

0 comments on commit 81e79ac

Please sign in to comment.