mirror of
https://gitlab.gnome.org/World/tootle
synced 2025-02-17 03:51:11 +01:00
Remove HeaderBar.vala
This commit is contained in:
parent
96b50cefe4
commit
c1940730a6
@ -35,7 +35,6 @@ executable(
|
||||
'src/API/Notification.vala',
|
||||
'src/API/NotificationType.vala',
|
||||
'src/API/Attachment.vala',
|
||||
'src/Widgets/HeaderBar.vala',
|
||||
'src/Widgets/AlignedLabel.vala',
|
||||
'src/Widgets/RichLabel.vala',
|
||||
'src/Widgets/ImageToggleButton.vala',
|
||||
|
@ -59,8 +59,6 @@ namespace Tootle{
|
||||
else {
|
||||
window = new MainWindow (this);
|
||||
window.present ();
|
||||
accounts.switched (accounts.current);
|
||||
accounts.signal_current ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,21 @@
|
||||
using Gtk;
|
||||
|
||||
public class Tootle.MainWindow: Gtk.Window {
|
||||
|
||||
private weak SettingsManager settings;
|
||||
|
||||
private Gtk.Overlay overlay;
|
||||
private Granite.Widgets.Toast toast;
|
||||
private Gtk.Grid grid;
|
||||
public Tootle.HeaderBar header;
|
||||
public Stack primary_stack;
|
||||
public Stack secondary_stack;
|
||||
private Stack primary_stack;
|
||||
private Stack secondary_stack;
|
||||
|
||||
public Gtk.HeaderBar header;
|
||||
private Granite.Widgets.ModeButton button_mode;
|
||||
private AccountsButton button_accounts;
|
||||
private Spinner spinner;
|
||||
private Button button_toot;
|
||||
private Button button_back;
|
||||
|
||||
construct {
|
||||
settings = Tootle.settings;
|
||||
|
||||
var provider = new Gtk.CssProvider ();
|
||||
provider.load_from_resource ("/com/github/bleakgrey/tootle/app.css");
|
||||
StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
@ -33,15 +35,54 @@ public class Tootle.MainWindow: Gtk.Window {
|
||||
primary_stack.add_named (secondary_stack, "0");
|
||||
primary_stack.hexpand = true;
|
||||
primary_stack.vexpand = true;
|
||||
header = new Tootle.HeaderBar ();
|
||||
|
||||
spinner = new Spinner ();
|
||||
spinner.active = true;
|
||||
|
||||
button_accounts = new AccountsButton ();
|
||||
|
||||
button_back = new Button ();
|
||||
button_back.label = _("Back");
|
||||
button_back.get_style_context ().add_class (Granite.STYLE_CLASS_BACK_BUTTON);
|
||||
button_back.clicked.connect (() => back ());
|
||||
|
||||
button_toot = new Button ();
|
||||
button_toot.tooltip_text = _("Toot");
|
||||
button_toot.image = new Gtk.Image.from_icon_name ("document-edit-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
|
||||
button_toot.clicked.connect (() => PostDialog.open ());
|
||||
|
||||
button_mode = new Granite.Widgets.ModeButton ();
|
||||
button_mode.get_style_context ().add_class ("mode");
|
||||
button_mode.mode_changed.connect (widget => {
|
||||
secondary_stack.set_visible_child_name (widget.tooltip_text);
|
||||
});
|
||||
button_mode.show ();
|
||||
|
||||
header = new Gtk.HeaderBar ();
|
||||
header.show_close_button = true;
|
||||
header.custom_title = button_mode;
|
||||
header.show_all ();
|
||||
header.pack_start (button_back);
|
||||
header.pack_start (button_toot);
|
||||
header.pack_end (button_accounts);
|
||||
header.pack_end (spinner);
|
||||
|
||||
grid = new Gtk.Grid ();
|
||||
grid.set_size_request (400, 500);
|
||||
grid.attach (primary_stack, 0, 0, 1, 1);
|
||||
grid.attach (overlay, 0, 0, 1, 1);
|
||||
|
||||
add_header_view (new TimelineView ("home"));
|
||||
add_header_view (new NotificationsView ());
|
||||
add_header_view (new LocalView ());
|
||||
add_header_view (new FederatedView ());
|
||||
button_mode.set_active (0);
|
||||
update_header ();
|
||||
|
||||
add (grid);
|
||||
show_all ();
|
||||
|
||||
button_mode.valign = Gtk.Align.FILL;
|
||||
}
|
||||
|
||||
public MainWindow (Gtk.Application application) {
|
||||
@ -53,36 +94,16 @@ public class Tootle.MainWindow: Gtk.Window {
|
||||
set_titlebar (header);
|
||||
window_position = WindowPosition.CENTER;
|
||||
|
||||
Tootle.accounts.switched.connect(on_account_switched);
|
||||
Tootle.app.toast.connect (on_toast);
|
||||
}
|
||||
|
||||
private void reset () {
|
||||
header.button_mode.clear_children ();
|
||||
secondary_stack.forall (widget => widget.destroy ());
|
||||
}
|
||||
|
||||
private void on_account_switched(Account? account){
|
||||
header.button_mode.clear_children ();
|
||||
secondary_stack.forall (widget => widget.destroy ());
|
||||
|
||||
if (account == null)
|
||||
return;
|
||||
build_main_view ();
|
||||
}
|
||||
|
||||
private void build_main_view (){
|
||||
add_header_view (new TimelineView ("home"));
|
||||
add_header_view (new NotificationsView ());
|
||||
add_header_view (new LocalView ());
|
||||
add_header_view (new FederatedView ());
|
||||
header.update (true);
|
||||
app.toast.connect (on_toast);
|
||||
network.started.connect (() => spinner.show ());
|
||||
network.finished.connect (() => spinner.hide ());
|
||||
accounts.signal_current ();
|
||||
}
|
||||
|
||||
private void add_header_view (AbstractView view) {
|
||||
var img = new Gtk.Image.from_icon_name(view.get_icon (), Gtk.IconSize.LARGE_TOOLBAR);
|
||||
img.tooltip_text = view.get_name ();
|
||||
header.button_mode.append (img);
|
||||
button_mode.append (img);
|
||||
view.image = img;
|
||||
secondary_stack.add_named(view, view.get_name ());
|
||||
|
||||
@ -101,18 +122,15 @@ public class Tootle.MainWindow: Gtk.Window {
|
||||
widget.show ();
|
||||
primary_stack.add_named (widget, i.to_string ());
|
||||
primary_stack.set_visible_child_name (i.to_string ());
|
||||
header.update (false);
|
||||
update_header ();
|
||||
}
|
||||
|
||||
public void back () {
|
||||
var i = get_visible_id ();
|
||||
primary_stack.set_visible_child_name ((i-1).to_string ());
|
||||
|
||||
var child = primary_stack.get_child_by_name (i.to_string ());
|
||||
primary_stack.set_visible_child_name ((i-1).to_string ());
|
||||
child.destroy ();
|
||||
|
||||
var is_root = primary_stack.get_visible_child_name () == "0";
|
||||
header.update (is_root);
|
||||
update_header ();
|
||||
}
|
||||
|
||||
public void reopen_view (int view_id) {
|
||||
@ -143,8 +161,15 @@ public class Tootle.MainWindow: Gtk.Window {
|
||||
var theme = is_dark ? "dark" : "light";
|
||||
provider.load_from_resource ("/com/github/bleakgrey/tootle/%s.css".printf (theme));
|
||||
StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = is_dark;
|
||||
}
|
||||
|
||||
private void update_header () {
|
||||
bool primary_mode = get_visible_id () == 0;
|
||||
button_mode.set_visible (primary_mode);
|
||||
button_toot.set_visible (primary_mode);
|
||||
button_back.set_visible (!primary_mode);
|
||||
button_accounts.set_visible (true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -105,6 +105,11 @@ public class Tootle.TimelineView : AbstractView {
|
||||
}
|
||||
|
||||
public virtual void request (){
|
||||
if (accounts.current == null) {
|
||||
empty_state ();
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = new Soup.Message("GET", get_url ());
|
||||
msg.finished.connect (() => empty_state ());
|
||||
Tootle.network.queue(msg, (sess, mess) => {
|
||||
|
@ -96,8 +96,8 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
||||
add(avatar);
|
||||
show_all ();
|
||||
|
||||
Tootle.accounts.updated.connect (accounts_updated);
|
||||
Tootle.accounts.switched.connect (account_switched);
|
||||
accounts.updated.connect (accounts_updated);
|
||||
accounts.switched.connect (account_switched);
|
||||
list.row_activated.connect (row => {
|
||||
var widget = row as AccountView;
|
||||
if (widget.id == -1) {
|
||||
@ -135,7 +135,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
||||
if (account == null)
|
||||
avatar.show_default (24);
|
||||
else
|
||||
Tootle.network.load_avatar (account.avatar, avatar, 24);
|
||||
network.load_avatar (account.avatar, avatar, 24);
|
||||
}
|
||||
|
||||
private void update_selection () {
|
||||
|
@ -1,63 +0,0 @@
|
||||
using Gtk;
|
||||
|
||||
public class Tootle.HeaderBar : Gtk.HeaderBar{
|
||||
|
||||
public Granite.Widgets.ModeButton button_mode;
|
||||
AccountsButton button_accounts;
|
||||
Spinner spinner;
|
||||
Button button_toot;
|
||||
Button button_back;
|
||||
|
||||
private int last_tab = 0;
|
||||
|
||||
construct {
|
||||
spinner = new Spinner ();
|
||||
spinner.active = true;
|
||||
|
||||
button_accounts = new AccountsButton ();
|
||||
|
||||
button_back = new Button ();
|
||||
button_back.label = _("Back");
|
||||
button_back.get_style_context ().add_class (Granite.STYLE_CLASS_BACK_BUTTON);
|
||||
button_back.clicked.connect (() => Tootle.window.back ());
|
||||
|
||||
button_toot = new Button ();
|
||||
button_toot.tooltip_text = "Toot";
|
||||
button_toot.image = new Gtk.Image.from_icon_name ("document-edit-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
|
||||
button_toot.clicked.connect (() => PostDialog.open ());
|
||||
|
||||
button_mode = new Granite.Widgets.ModeButton ();
|
||||
button_mode.get_style_context ().add_class ("mode");
|
||||
button_mode.mode_changed.connect(widget => {
|
||||
last_tab = button_mode.selected;
|
||||
Tootle.window.secondary_stack.set_visible_child_name(widget.tooltip_text);
|
||||
});
|
||||
button_mode.show ();
|
||||
|
||||
Tootle.network.started.connect (() => spinner.show ());
|
||||
Tootle.network.finished.connect (() => spinner.hide ());
|
||||
|
||||
pack_start (button_back);
|
||||
pack_start (button_toot);
|
||||
pack_end (button_accounts);
|
||||
pack_end (spinner);
|
||||
}
|
||||
|
||||
public HeaderBar () {
|
||||
custom_title = button_mode;
|
||||
show_close_button = true;
|
||||
show ();
|
||||
button_mode.valign = Gtk.Align.FILL;
|
||||
}
|
||||
|
||||
public void update (bool primary_mode){
|
||||
button_mode.set_active (last_tab);
|
||||
//button_mode.opacity = primary_mode ? 1 : 0;
|
||||
//button_mode.sensitive = primary_mode ? true : false;
|
||||
button_mode.set_visible (primary_mode);
|
||||
button_toot.set_visible (primary_mode);
|
||||
button_back.set_visible (!primary_mode);
|
||||
button_accounts.set_visible (true);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user