Move HeaderBar to separate class
This commit is contained in:
parent
bc5cef17ac
commit
ed5d79d6ea
|
@ -29,6 +29,7 @@ executable(
|
|||
'src/API/StatusVisibility.vala',
|
||||
'src/API/Notification.vala',
|
||||
'src/API/NotificationType.vala',
|
||||
'src/Widgets/HeaderBar.vala',
|
||||
'src/Widgets/AlignedLabel.vala',
|
||||
'src/Widgets/AccountsButton.vala',
|
||||
'src/Widgets/StatusWidget.vala',
|
||||
|
|
|
@ -2,7 +2,7 @@ using GLib;
|
|||
|
||||
public class Tootle.AccountManager : Object{
|
||||
|
||||
public abstract signal void changed_current(Account? account);
|
||||
public abstract signal void switched(Account? account);
|
||||
public abstract signal void added(Account account);
|
||||
public abstract signal void removed(Account account);
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class Tootle.AccountManager : Object{
|
|||
try{
|
||||
var root = NetManager.parse (mess);
|
||||
current = Account.parse(root);
|
||||
changed_current (current);
|
||||
switched (current);
|
||||
}
|
||||
catch (GLib.Error e) {
|
||||
warning ("Can't get current user");
|
||||
|
@ -117,7 +117,7 @@ public class Tootle.AccountManager : Object{
|
|||
|
||||
public void logout (){
|
||||
current = null;
|
||||
changed_current (null);
|
||||
switched (null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Tootle{
|
|||
if(has_token)
|
||||
AccountManager.instance.update_current ();
|
||||
else
|
||||
AccountManager.instance.changed_current (null);
|
||||
AccountManager.instance.switched (null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,32 +2,15 @@ using Gtk;
|
|||
|
||||
public class Tootle.MainWindow: Gtk.Window {
|
||||
|
||||
HeaderBar header;
|
||||
Stack primary_stack;
|
||||
Stack secondary_stack;
|
||||
AccountsButton button_accounts;
|
||||
Granite.Widgets.ModeButton button_mode;
|
||||
Spinner spinner;
|
||||
Button button_toot;
|
||||
Button button_back;
|
||||
Tootle.HeaderBar header;
|
||||
public Stack primary_stack;
|
||||
public Stack secondary_stack;
|
||||
|
||||
public HomeView home = new HomeView ();
|
||||
public LocalView feed_local = new LocalView ();
|
||||
public FederatedView feed_federated = new FederatedView ();
|
||||
public NotificationsView notifications = new NotificationsView ();
|
||||
|
||||
public MainWindow (Gtk.Application application) {
|
||||
Object (application: application,
|
||||
icon_name: "com.github.bleakgrey.tootle",
|
||||
title: "Tootle",
|
||||
resizable: true
|
||||
);
|
||||
set_titlebar (header);
|
||||
window_position = WindowPosition.CENTER;
|
||||
|
||||
AccountManager.instance.changed_current.connect(on_account_changed);
|
||||
}
|
||||
|
||||
construct {
|
||||
var provider = new Gtk.CssProvider ();
|
||||
provider.load_from_resource ("/com/github/bleakgrey/tootle/Application.css");
|
||||
|
@ -41,54 +24,26 @@ public class Tootle.MainWindow: Gtk.Window {
|
|||
primary_stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
|
||||
primary_stack.show ();
|
||||
primary_stack.add_named (secondary_stack, "modes");
|
||||
|
||||
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 (() => {
|
||||
primary_stack.set_visible_child_name ("modes");
|
||||
var child = primary_stack.get_child_by_name ("details");
|
||||
child.destroy ();
|
||||
update_header (true);
|
||||
});
|
||||
|
||||
button_toot = new Button ();
|
||||
button_toot.tooltip_text = "Toot";
|
||||
button_toot.image = new Gtk.Image.from_icon_name ("edit-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
|
||||
button_toot.clicked.connect (() => {
|
||||
PostDialog.open (this);
|
||||
});
|
||||
|
||||
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 HeaderBar ();
|
||||
header.custom_title = button_mode;
|
||||
header.show_close_button = true;
|
||||
header.pack_start (button_back);
|
||||
header.pack_start (button_toot);
|
||||
header.pack_end (button_accounts);
|
||||
header.pack_end (spinner);
|
||||
button_mode.valign = Gtk.Align.FILL;
|
||||
header.show ();
|
||||
header = new Tootle.HeaderBar ();
|
||||
|
||||
add (primary_stack);
|
||||
show_all ();
|
||||
|
||||
NetManager.instance.started.connect (() => spinner.show ());
|
||||
NetManager.instance.finished.connect (() => spinner.hide ());
|
||||
}
|
||||
|
||||
private void on_account_changed(Account? account){
|
||||
public MainWindow (Gtk.Application application) {
|
||||
Object (application: application,
|
||||
icon_name: "com.github.bleakgrey.tootle",
|
||||
title: "Tootle",
|
||||
resizable: true
|
||||
);
|
||||
set_titlebar (header);
|
||||
window_position = WindowPosition.CENTER;
|
||||
|
||||
AccountManager.instance.switched.connect(on_account_switched);
|
||||
}
|
||||
|
||||
private void on_account_switched(Account? account){
|
||||
secondary_stack.forall (widget => secondary_stack.remove (widget));
|
||||
|
||||
if(account == null)
|
||||
|
@ -97,43 +52,27 @@ public class Tootle.MainWindow: Gtk.Window {
|
|||
show_main_views ();
|
||||
}
|
||||
|
||||
private void update_header (bool primary_mode, bool hide_all = false){
|
||||
if (hide_all){
|
||||
button_mode.opacity = 0;
|
||||
button_mode.sensitive = false;
|
||||
button_toot.hide ();
|
||||
button_back.hide ();
|
||||
button_accounts.hide ();
|
||||
return;
|
||||
}
|
||||
button_mode.opacity = primary_mode ? 1 : 0;
|
||||
button_mode.sensitive = primary_mode ? true : false;
|
||||
button_toot.set_visible (primary_mode);
|
||||
button_back.set_visible (!primary_mode);
|
||||
button_accounts.set_visible (true);
|
||||
}
|
||||
|
||||
private void show_setup_views (){
|
||||
var add_account = new AddAccountView ();
|
||||
secondary_stack.add_named (add_account, add_account.get_name ());
|
||||
update_header (false, true);
|
||||
header.update (false, true);
|
||||
}
|
||||
|
||||
private void show_main_views (){
|
||||
button_mode.clear_children ();
|
||||
header.button_mode.clear_children ();
|
||||
add_view (home);
|
||||
add_view (notifications);
|
||||
add_view (feed_local);
|
||||
add_view (feed_federated);
|
||||
button_mode.set_active (0);
|
||||
update_header (true);
|
||||
header.button_mode.set_active (0);
|
||||
header.update (true);
|
||||
}
|
||||
|
||||
private void add_view (AbstractView view) {
|
||||
if (view.show_in_header){
|
||||
var img = new Gtk.Image.from_icon_name(view.get_icon (), Gtk.IconSize.LARGE_TOOLBAR);
|
||||
img.tooltip_text = view.get_name ();
|
||||
button_mode.append (img);
|
||||
header.button_mode.append (img);
|
||||
view.image = img;
|
||||
secondary_stack.add_named(view, view.get_name ());
|
||||
}
|
||||
|
@ -143,7 +82,7 @@ public class Tootle.MainWindow: Gtk.Window {
|
|||
widget.show ();
|
||||
primary_stack.add_named (widget, "details");
|
||||
primary_stack.set_visible_child_name ("details");
|
||||
update_header (false);
|
||||
header.update (false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class Tootle.HomeView : Tootle.AbstractView {
|
|||
show_all();
|
||||
|
||||
view.remove.connect (on_remove);
|
||||
AccountManager.instance.changed_current.connect(on_account_changed);
|
||||
AccountManager.instance.switched.connect(on_account_changed);
|
||||
|
||||
// var s = new Status(1);
|
||||
// s.content = "Test content, wow!";
|
||||
|
|
|
@ -24,7 +24,7 @@ public class Tootle.NotificationsView : Tootle.AbstractView {
|
|||
show_all();
|
||||
|
||||
view.remove.connect (on_remove);
|
||||
AccountManager.instance.changed_current.connect(on_account_changed);
|
||||
AccountManager.instance.switched.connect(on_account_changed);
|
||||
}
|
||||
|
||||
public override string get_icon () {
|
||||
|
|
|
@ -68,7 +68,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
|||
add(avatar);
|
||||
show_all ();
|
||||
|
||||
AccountManager.instance.changed_current.connect (account => {
|
||||
AccountManager.instance.switched.connect (account => {
|
||||
if (account != null){
|
||||
CacheManager.instance.load_avatar (account.avatar, avatar, 24);
|
||||
default_account.display_name.label = "<b>"+account.display_name+"</b>";
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
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;
|
||||
|
||||
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 (() => {
|
||||
var primary_stack = Tootle.window.primary_stack;
|
||||
primary_stack.set_visible_child_name ("modes");
|
||||
var child = primary_stack.get_child_by_name ("details");
|
||||
child.destroy ();
|
||||
update (true);
|
||||
});
|
||||
|
||||
button_toot = new Button ();
|
||||
button_toot.tooltip_text = "Toot";
|
||||
button_toot.image = new Gtk.Image.from_icon_name ("edit-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
|
||||
button_toot.clicked.connect (() => {
|
||||
PostDialog.open (Tootle.window);
|
||||
});
|
||||
|
||||
button_mode = new Granite.Widgets.ModeButton ();
|
||||
button_mode.get_style_context ().add_class ("mode");
|
||||
button_mode.mode_changed.connect(widget => {
|
||||
Tootle.window.secondary_stack.set_visible_child_name(widget.tooltip_text);
|
||||
});
|
||||
button_mode.show ();
|
||||
|
||||
NetManager.instance.started.connect (() => spinner.show ());
|
||||
NetManager.instance.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, bool hide_all = false){
|
||||
if (hide_all){
|
||||
button_mode.opacity = 0;
|
||||
button_mode.sensitive = false;
|
||||
button_toot.hide ();
|
||||
button_back.hide ();
|
||||
button_accounts.hide ();
|
||||
return;
|
||||
}
|
||||
button_mode.opacity = primary_mode ? 1 : 0;
|
||||
button_mode.sensitive = primary_mode ? true : false;
|
||||
button_toot.set_visible (primary_mode);
|
||||
button_back.set_visible (!primary_mode);
|
||||
button_accounts.set_visible (true);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue