[geary] Gtk.HeaderBar for main window and composer toolbar: Closes bgo#713478
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary] Gtk.HeaderBar for main window and composer toolbar: Closes bgo#713478
- Date: Tue, 27 May 2014 23:08:40 +0000 (UTC)
commit 546e97bfa5f06efbfbd5b8f62f7a9ca89106530b
Author: Yosef Or Boczko <yoseforb src gnome org>
Date: Wed Jan 29 17:05:01 2014 -0800
Gtk.HeaderBar for main window and composer toolbar: Closes bgo#713478
Nice code reduction using Gtk.HeaderBar in place of Gtk.Toolbar.
Main window no longer has chrome but composer window still does.
Conflicts:
src/client/components/main-window.vala
src/client/components/pill-toolbar.vala
src/client/composer/composer-toolbar.vala
src/client/application/geary-controller.vala | 1 +
src/client/components/main-toolbar.vala | 34 +++++-------
src/client/components/main-window.vala | 41 +++++++++++++--
src/client/components/pill-toolbar.vala | 76 ++++++--------------------
src/client/composer/composer-toolbar.vala | 14 ++---
5 files changed, 75 insertions(+), 91 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 1b29656..6bab943 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -960,6 +960,7 @@ public class GearyController : Geary.BaseObject {
if (folder == null) {
current_folder = null;
main_window.conversation_list_store.clear();
+ main_window.main_toolbar.subtitle = null;
folder_selected(null);
return;
diff --git a/src/client/components/main-toolbar.vala b/src/client/components/main-toolbar.vala
index aced22e..d6cd6e4 100644
--- a/src/client/components/main-toolbar.vala
+++ b/src/client/components/main-toolbar.vala
@@ -17,7 +17,6 @@ public class MainToolbar : PillToolbar {
private Gtk.Button archive_button;
private Gtk.Button trash_buttons[2];
- private Gtk.ToolItem search_container = new Gtk.ToolItem();
private Gtk.SearchEntry search_entry = new Gtk.SearchEntry();
private Geary.ProgressMonitor? search_upgrade_progress_monitor = null;
private MonitoredProgressBar search_upgrade_progress_bar = new MonitoredProgressBar();
@@ -42,27 +41,25 @@ public class MainToolbar : PillToolbar {
application_menu.foreach(GtkUtil.show_menuitem_accel_labels);
// Toolbar setup.
- orientation = Gtk.Orientation.HORIZONTAL;
- get_style_context().add_class(Gtk.STYLE_CLASS_MENUBAR); // Drag window via toolbar.
Gee.List<Gtk.Button> insert = new Gee.ArrayList<Gtk.Button>();
// Compose.
insert.add(create_toolbar_button("text-editor-symbolic", GearyController.ACTION_NEW_MESSAGE));
- add(create_pill_buttons(insert, false));
+ add_start(create_pill_buttons(insert, false));
// Reply buttons
insert.clear();
insert.add(create_toolbar_button(rtl ? "reply-rtl-symbolic" : "reply-symbolic",
GearyController.ACTION_REPLY_TO_MESSAGE));
insert.add(create_toolbar_button(rtl ? "reply-all-rtl-symbolic" : "reply-all-symbolic",
GearyController.ACTION_REPLY_ALL_MESSAGE));
insert.add(create_toolbar_button(rtl ? "forward-rtl-symbolic" : "forward-symbolic",
GearyController.ACTION_FORWARD_MESSAGE));
- add(create_pill_buttons(insert));
+ add_start(create_pill_buttons(insert));
// Mark, copy, move.
insert.clear();
insert.add(create_menu_button("marker-symbolic", mark_menu, GearyController.ACTION_MARK_AS_MENU));
insert.add(create_menu_button(rtl ? "tag-rtl-symbolic" : "tag-symbolic", copy_folder_menu,
GearyController.ACTION_COPY_MENU));
insert.add(create_menu_button("folder-symbolic", move_folder_menu,
GearyController.ACTION_MOVE_MENU));
- add(create_pill_buttons(insert));
+ add_start(create_pill_buttons(insert));
// The toolbar looks bad when you hide one of a pair of pill buttons.
// Unfortunately, this means we have to have one pair for archive/trash
@@ -71,13 +68,10 @@ public class MainToolbar : PillToolbar {
insert.clear();
insert.add(archive_button = create_toolbar_button(null, GearyController.ACTION_ARCHIVE_MESSAGE,
true));
insert.add(trash_buttons[0] = create_toolbar_button(null, GearyController.ACTION_TRASH_MESSAGE,
true));
- add(create_pill_buttons(insert));
+ add_start(create_pill_buttons(insert));
insert.clear();
insert.add(trash_buttons[1] = create_toolbar_button(null, GearyController.ACTION_TRASH_MESSAGE,
true));
- add(create_pill_buttons(insert, false));
-
- // Spacer.
- add(create_spacer());
+ add_start(create_pill_buttons(insert, false));
// Search bar.
search_entry.width_chars = 32;
@@ -86,8 +80,7 @@ public class MainToolbar : PillToolbar {
search_entry.key_press_event.connect(on_search_key_press);
on_search_entry_changed(); // set initial state
search_entry.has_focus = true;
- search_container.add(search_entry);
- add(search_container);
+ add_end(search_entry);
// Search upgrade progress bar.
search_upgrade_progress_bar.margin_top = 3;
@@ -104,7 +97,7 @@ public class MainToolbar : PillToolbar {
if (!Gtk.Settings.get_default().gtk_shell_shows_app_menu) {
insert.clear();
insert.add(create_menu_button("emblem-system-symbolic", application_menu,
GearyController.ACTION_GEAR_MENU));
- add(create_pill_buttons(insert));
+ add_end(create_pill_buttons(insert));
}
set_search_placeholder_text(DEFAULT_SEARCH_TEXT);
@@ -164,14 +157,13 @@ public class MainToolbar : PillToolbar {
}
private void on_search_upgrade_start() {
- search_container.remove(search_container.get_child());
- search_container.add(search_upgrade_progress_bar);
+ search_entry.hide();
search_upgrade_progress_bar.show();
}
private void on_search_upgrade_finished() {
- search_container.remove(search_container.get_child());
- search_container.add(search_entry);
+ search_entry.show();
+ search_upgrade_progress_bar.hide();
}
private void on_account_changed(Geary.Account? account) {
@@ -183,9 +175,10 @@ public class MainToolbar : PillToolbar {
search_upgrade_progress_monitor = null;
}
- if (current_account != null)
+ if (current_account != null) {
current_account.information.notify[Geary.AccountInformation.PROP_NICKNAME].disconnect(
on_nickname_changed);
+ }
if (account != null) {
search_upgrade_progress_monitor = account.search_upgrade_monitor;
@@ -198,11 +191,12 @@ public class MainToolbar : PillToolbar {
account.information.notify[Geary.AccountInformation.PROP_NICKNAME].connect(
on_nickname_changed);
+
+ search_upgrade_progress_bar.text = _("Indexing %s account").printf(account.information.nickname);
}
current_account = account;
- search_upgrade_progress_bar.text = _("Indexing %s account").printf(account.information.nickname);
on_nickname_changed(); // Set new account name.
}
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index 0c45368..d2366b4 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -31,6 +31,7 @@ public class MainWindow : Gtk.ApplicationWindow {
private Geary.AggregateProgressMonitor progress_monitor = new Geary.AggregateProgressMonitor();
private Geary.ProgressMonitor? conversation_monitor_progress = null;
private Geary.ProgressMonitor? folder_progress = null;
+ private Geary.Folder? current_folder = null;
public MainWindow(GearyApplication application) {
Object(application: application);
@@ -73,6 +74,11 @@ public class MainWindow : Gtk.ApplicationWindow {
Geary.Engine.instance.account_unavailable.connect(on_account_unavailable);
create_layout();
+
+ // Toolbar.
+ main_toolbar = new MainToolbar();
+ main_toolbar.show_close_button = true;
+ set_titlebar(main_toolbar);
}
public override void show_all() {
@@ -123,10 +129,6 @@ public class MainWindow : Gtk.ApplicationWindow {
private void create_layout() {
Gtk.Box main_layout = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
- // Toolbar.
- main_toolbar = new MainToolbar();
- main_layout.pack_start(main_toolbar, false, false, 0);
-
// folder list
Gtk.ScrolledWindow folder_list_scrolled = new Gtk.ScrolledWindow(null, null);
folder_list_scrolled.set_size_request(FOLDER_LIST_WIDTH, -1);
@@ -234,6 +236,19 @@ public class MainWindow : Gtk.ApplicationWindow {
folder_progress = folder.opening_monitor;
progress_monitor.add(folder_progress);
}
+
+ // disconnect from old folder
+ if (current_folder != null)
+ current_folder.properties.notify.disconnect(update_headerbar);
+
+ // connect to new folder
+ if (folder != null)
+ folder.properties.notify.connect(update_headerbar);
+
+ // swap it in
+ current_folder = folder;
+
+ update_headerbar();
}
private void on_account_available(Geary.AccountInformation account) {
@@ -253,5 +268,23 @@ public class MainWindow : Gtk.ApplicationWindow {
debug("Could not access account progress monitors: %s", e.message);
}
}
+
+ private void update_headerbar() {
+ if (current_folder == null) {
+ main_toolbar.title = null;
+ main_toolbar.subtitle = null;
+
+ return;
+ }
+
+ main_toolbar.title = current_folder.account.information.nickname;
+ if(current_folder.properties.email_unread > 0) {
+ /// Current folder's name followed by its unread count, i.e. "Inbox (42)"
+ main_toolbar.subtitle = _("%s (%d)").printf(current_folder.get_display_name(),
+ current_folder.properties.email_unread);
+ } else {
+ main_toolbar.subtitle = current_folder.get_display_name();
+ }
+ }
}
diff --git a/src/client/components/pill-toolbar.vala b/src/client/components/pill-toolbar.vala
index f0313ae..bfc22d8 100644
--- a/src/client/components/pill-toolbar.vala
+++ b/src/client/components/pill-toolbar.vala
@@ -7,13 +7,24 @@
/**
* Class for creating a Nautilus-style "pill" toolbar. Use only as directed.
*/
-public class PillToolbar : Gtk.Toolbar {
+public class PillToolbar : Gtk.HeaderBar {
private Gtk.ActionGroup action_group;
+ private Gtk.SizeGroup size = new Gtk.SizeGroup(Gtk.SizeGroupMode.VERTICAL);
public PillToolbar(Gtk.ActionGroup toolbar_action_group) {
action_group = toolbar_action_group;
}
+ public void add_start(Gtk.Widget *widget) {
+ pack_start(widget);
+ size.add_widget(widget);
+ }
+
+ public void add_end(Gtk.Widget *widget) {
+ pack_end(widget);
+ size.add_widget(widget);
+ }
+
protected void setup_button(Gtk.Button b, string? icon_name, string action_name,
bool show_label = false) {
b.related_action = action_group.get_action(action_name);
@@ -22,16 +33,9 @@ public class PillToolbar : Gtk.Toolbar {
b.image = new Gtk.Image.from_icon_name(icon_name != null ? icon_name :
b.related_action.icon_name, Gtk.IconSize.MENU);
b.always_show_image = true;
- b.image.margin = get_icon_margin();
if (!show_label)
b.label = null;
-
- if (show_label && !Geary.String.is_empty(b.related_action.label))
- if (b.get_direction() == Gtk.TextDirection.RTL)
- b.image.margin_left += 4;
- else
- b.image.margin_right += 4;
}
/**
@@ -70,65 +74,21 @@ public class PillToolbar : Gtk.Toolbar {
* toolbar. Optionally adds spacers "before" and "after" the buttons (those terms depending
* on Gtk.TextDirection)
*/
- public Gtk.ToolItem create_pill_buttons(Gee.Collection<Gtk.Button> buttons,
+ public Gtk.Box create_pill_buttons(Gee.Collection<Gtk.Button> buttons,
bool before_spacer = true, bool after_spacer = false) {
Gtk.Box box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
+ box.valign = Gtk.Align.CENTER;
+ box.halign = Gtk.Align.CENTER;
if (buttons.size > 1) {
box.get_style_context().add_class(Gtk.STYLE_CLASS_RAISED);
box.get_style_context().add_class(Gtk.STYLE_CLASS_LINKED);
}
- int i = 0;
- foreach(Gtk.Button button in buttons) {
+ foreach(Gtk.Button button in buttons)
box.add(button);
-
- // Place the right spacer on the button itself. This way if the button is not displayed,
- // the spacer will not appear.
- if (i == buttons.size - 1 && after_spacer) {
- if (button.get_direction() == Gtk.TextDirection.RTL)
- button.set_margin_left(12);
- else
- button.set_margin_right(12);
- }
-
- i++;
- }
-
- Gtk.ToolItem tool_item = new Gtk.ToolItem();
- tool_item.add(box);
-
- if (before_spacer) {
- if (box.get_direction() == Gtk.TextDirection.RTL)
- box.set_margin_right(12);
- else
- box.set_margin_left(12);
- }
-
- return tool_item;
- }
-
- /**
-- * Computes the margin for each icon (shamelessly stolen from Nautilus.)
-- */
- private int get_icon_margin() {
- Gtk.IconSize toolbar_size = get_icon_size();
- int toolbar_size_px, menu_size_px;
-
- Gtk.icon_size_lookup(Gtk.IconSize.MENU, out menu_size_px, null);
- Gtk.icon_size_lookup(toolbar_size, out toolbar_size_px, null);
-
- return Geary.Numeric.int_floor((int) ((toolbar_size_px - menu_size_px) / 2.0), 0);
- }
-
- /**
- * Returns an expandable spacer item.
- */
- public Gtk.ToolItem create_spacer() {
- Gtk.ToolItem spacer = new Gtk.ToolItem();
- spacer.set_expand(true);
-
- return spacer;
+
+ return box;
}
}
diff --git a/src/client/composer/composer-toolbar.vala b/src/client/composer/composer-toolbar.vala
index 8896e08..4699ddd 100644
--- a/src/client/composer/composer-toolbar.vala
+++ b/src/client/composer/composer-toolbar.vala
@@ -15,32 +15,28 @@ public class ComposerToolbar : PillToolbar {
insert.add(create_toggle_button(null, ComposerWidget.ACTION_ITALIC));
insert.add(create_toggle_button(null, ComposerWidget.ACTION_UNDERLINE));
insert.add(create_toggle_button(null, ComposerWidget.ACTION_STRIKETHROUGH));
- Gtk.ToolItem font_format_item = create_pill_buttons(insert, false, true);
- add(font_format_item);
+ add_start(create_pill_buttons(insert, false, true));
// Indent level.
insert.clear();
insert.add(create_toolbar_button(null, ComposerWidget.ACTION_INDENT));
insert.add(create_toolbar_button(null, ComposerWidget.ACTION_OUTDENT));
- add(create_pill_buttons(insert, false));
+ add_start(create_pill_buttons(insert, false));
// Link.
insert.clear();
insert.add(create_toolbar_button(null, ComposerWidget.ACTION_INSERT_LINK));
- add(create_pill_buttons(insert));
+ add_start(create_pill_buttons(insert));
// Remove formatting.
insert.clear();
insert.add(create_toolbar_button(null, ComposerWidget.ACTION_REMOVE_FORMAT));
- add(create_pill_buttons(insert));
-
- // Spacer.
- add(create_spacer());
+ add_start(create_pill_buttons(insert));
// Menu.
insert.clear();
insert.add(create_menu_button(null, menu, ComposerWidget.ACTION_MENU));
- add(create_pill_buttons(insert));
+ add_end(create_pill_buttons(insert));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]