[geary/wip/743960-split-header-2: 4/8] Provide custom close-and-save and close-and-discard buttons for composer
- From: Robert Schroll <rschroll src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/743960-split-header-2: 4/8] Provide custom close-and-save and close-and-discard buttons for composer
- Date: Sun, 22 Feb 2015 04:57:57 +0000 (UTC)
commit 877c9414246932446c91a7b9ed164fcc8f9797c8
Author: Robert Schroll <rschroll gmail com>
Date: Sat Feb 21 19:02:12 2015 -0500
Provide custom close-and-save and close-and-discard buttons for composer
This ensures that we only have a single close button at any time, and
it always closes the whole application. The close buttons are grouped
with the detach and send buttons, as all of them alter the window
structure. We no longer adjust these based on the side on which the
close button is by default.
src/client/components/main-toolbar.vala | 6 ++-
src/client/composer/composer-headerbar.vala | 74 +++++----------------------
src/client/composer/composer-widget.vala | 15 +++++
src/client/composer/composer-window.vala | 3 +-
ui/composer.glade | 16 ++++++
5 files changed, 51 insertions(+), 63 deletions(-)
---
diff --git a/src/client/components/main-toolbar.vala b/src/client/components/main-toolbar.vala
index 79c5563..2585d9f 100644
--- a/src/client/components/main-toolbar.vala
+++ b/src/client/components/main-toolbar.vala
@@ -170,17 +170,19 @@ public class MainToolbar : Gtk.Box {
search_entry.placeholder_text = placeholder;
}
- public void set_conversation_header(Gtk.Widget header) {
+ public void set_conversation_header(Gtk.HeaderBar header) {
conversation_header.hide();
header.get_style_context().add_class("titlebar");
header.get_style_context().add_class("geary-titlebar-right");
+ header.show_close_button = show_close_button;
pack_start(header, true, true);
}
- public void remove_conversation_header(Gtk.Widget header) {
+ public void remove_conversation_header(Gtk.HeaderBar header) {
remove(header);
header.get_style_context().remove_class("titlebar");
header.get_style_context().remove_class("geary-titlebar-right");
+ header.show_close_button = false;
conversation_header.show();
}
diff --git a/src/client/composer/composer-headerbar.vala b/src/client/composer/composer-headerbar.vala
index ce8f7b8..bea026b 100644
--- a/src/client/composer/composer-headerbar.vala
+++ b/src/client/composer/composer-headerbar.vala
@@ -9,51 +9,34 @@ public class ComposerHeaderbar : PillHeaderbar {
public ComposerWidget.ComposerState state { get; set; }
public bool show_pending_attachments { get; set; default = false; }
public bool send_enabled { get; set; default = false; }
+ public bool show_detach_button { get; set; default = true; }
private Gtk.Button recipients;
private Gtk.Label recipients_label;
- private Gtk.Box win_buttons_start;
- private Gtk.Box win_buttons_end;
public ComposerHeaderbar(Gtk.ActionGroup action_group) {
base(action_group);
show_close_button = false;
- Gtk.Button send_button = create_toolbar_button(null, ComposerWidget.ACTION_SEND, true);
- send_button.get_style_context().add_class("suggested-action");
-
- bool rtl = (get_direction() == Gtk.TextDirection.RTL);
+ // Toolbar setup.
+ Gee.List<Gtk.Button> insert = new Gee.ArrayList<Gtk.Button>();
- win_buttons_start = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
+ // Window management.
+ insert.add(create_toolbar_button(null, ComposerWidget.ACTION_CLOSE_DISCARD));
+ insert.add(create_toolbar_button(null, ComposerWidget.ACTION_CLOSE_SAVE));
Gtk.Button detach_button = create_toolbar_button(null, ComposerWidget.ACTION_DETACH);
- Gtk.Button close_button = create_toolbar_button(null, ComposerWidget.ACTION_CLOSE);
- detach_button.set_relief(Gtk.ReliefStyle.NONE);
- close_button.set_relief(Gtk.ReliefStyle.NONE);
- if (rtl)
- detach_button.set_margin_left(6);
- else
- detach_button.set_margin_right(6);
- win_buttons_start.pack_start(close_button);
- win_buttons_start.pack_start(detach_button);
- win_buttons_start.pack_start(new Gtk.Separator(Gtk.Orientation.VERTICAL));
+ bind_property("show-detach-button", detach_button, "visible", BindingFlags.SYNC_CREATE);
+ insert.add(detach_button);
+ Gtk.Button send_button = create_toolbar_button(null, ComposerWidget.ACTION_SEND, true);
+ send_button.get_style_context().add_class("suggested-action");
+ insert.add(send_button);
+ Gtk.Box window_buttons = create_pill_buttons(insert, false);
- win_buttons_end = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
- detach_button = create_toolbar_button(null, ComposerWidget.ACTION_DETACH);
- close_button = create_toolbar_button(null, ComposerWidget.ACTION_CLOSE);
- detach_button.set_relief(Gtk.ReliefStyle.NONE);
- close_button.set_relief(Gtk.ReliefStyle.NONE);
- if (rtl)
- detach_button.set_margin_right(6);
- else
- detach_button.set_margin_left(6);
- win_buttons_end.pack_end(close_button);
- win_buttons_end.pack_end(detach_button);
- win_buttons_end.pack_end(new Gtk.Separator(Gtk.Orientation.VERTICAL));
+ insert.clear();
Gtk.Box attach_buttons = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
Gtk.Button attach_only = create_toolbar_button(null, ComposerWidget.ACTION_ADD_ATTACHMENT);
- Gee.List<Gtk.Button> insert = new Gee.ArrayList<Gtk.Button>();
insert.add(create_toolbar_button(null, ComposerWidget.ACTION_ADD_ATTACHMENT));
insert.add(create_toolbar_button(null, ComposerWidget.ACTION_ADD_ORIGINAL_ATTACHMENTS));
Gtk.Box attach_pending = create_pill_buttons(insert, false);
@@ -67,12 +50,6 @@ public class ComposerHeaderbar : PillHeaderbar {
recipients.add(recipients_label);
recipients.clicked.connect(() => { state = ComposerWidget.ComposerState.INLINE; });
- notify["state"].connect((s, p) => {
- if (state == ComposerWidget.ComposerState.DETACHED) {
- get_style_context().changed.disconnect(set_win_buttons_side);
- win_buttons_start.visible = win_buttons_end.visible = false;
- }
- });
bind_property("state", recipients, "visible", BindingFlags.SYNC_CREATE,
(binding, source_value, ref target_value) => {
target_value = (state == ComposerWidget.ComposerState.INLINE_COMPACT);
@@ -84,37 +61,14 @@ public class ComposerHeaderbar : PillHeaderbar {
BindingFlags.SYNC_CREATE);
bind_property("send-enabled", send_button, "sensitive", BindingFlags.SYNC_CREATE);
- add_start(win_buttons_start);
add_start(attach_buttons);
add_start(recipients);
-#if !GTK_3_12
- add_end(send_button);
-#endif
- add_end(win_buttons_end);
-#if GTK_3_12
- add_end(send_button);
-#endif
- get_style_context().changed.connect(set_win_buttons_side);
- realize.connect(set_win_buttons_side);
+ add_end(window_buttons);
}
public void set_recipients(string label, string tooltip) {
recipients_label.label = label;
recipients.tooltip_text = tooltip;
}
-
- private void set_win_buttons_side() {
- string layout;
- bool at_end = false;
- get_toplevel().style_get("decoration-button-layout", out layout);
- // Based on logic of close_button_at_end in gtkheaderbar.c: Close button appears
- // at end iff "close" follows a colon in the layout string.
- if (layout != null) {
- int colon_ind = layout.index_of(":");
- at_end = (colon_ind >= 0 && layout.index_of("close", colon_ind) >= 0);
- }
- win_buttons_start.visible = !at_end;
- win_buttons_end.visible = at_end;
- }
}
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 8e5ea3a..d8cfd96 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -51,6 +51,8 @@ public class ComposerWidget : Gtk.EventBox {
public const string ACTION_COMPOSE_AS_HTML = "compose as html";
public const string ACTION_SHOW_EXTENDED = "show extended";
public const string ACTION_CLOSE = "close";
+ public const string ACTION_CLOSE_SAVE = "close and save";
+ public const string ACTION_CLOSE_DISCARD = "close and discard";
public const string ACTION_DETACH = "detach";
public const string ACTION_SEND = "send";
public const string ACTION_ADD_ATTACHMENT = "add attachment";
@@ -424,6 +426,8 @@ public class ComposerWidget : Gtk.EventBox {
actions.get_action(ACTION_INSERT_LINK).activate.connect(on_insert_link);
actions.get_action(ACTION_CLOSE).activate.connect(on_close);
+ actions.get_action(ACTION_CLOSE_SAVE).activate.connect(on_close_and_save);
+ actions.get_action(ACTION_CLOSE_DISCARD).activate.connect(on_close_and_discard);
actions.get_action(ACTION_DETACH).activate.connect(on_detach);
actions.get_action(ACTION_SEND).activate.connect(on_send);
@@ -1082,6 +1086,17 @@ public class ComposerWidget : Gtk.EventBox {
container.close_container();
}
+ private void on_close_and_save() {
+ if (can_save())
+ save_and_exit_async.begin();
+ else
+ container.close_container();
+ }
+
+ private void on_close_and_discard() {
+ discard_and_exit_async.begin();
+ }
+
private void on_detach() {
if (state == ComposerState.DETACHED)
return;
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index ea5048b..f8a892f 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -14,8 +14,9 @@ public class ComposerWindow : Gtk.Window, ComposerContainer {
add(composer);
+ composer.header.show_detach_button = false;
+
if (!GearyApplication.instance.is_running_unity) {
- composer.header.show_close_button = true;
if (composer.header.parent != null)
composer.header.parent.remove(composer.header);
set_titlebar(composer.header);
diff --git a/ui/composer.glade b/ui/composer.glade
index dfa7d41..f3a23ba 100644
--- a/ui/composer.glade
+++ b/ui/composer.glade
@@ -152,6 +152,22 @@
<accelerator key="w" modifiers="GDK_CONTROL_MASK"/>
</child>
<child>
+ <object class="GtkAction" id="close and save">
+ <property name="label" translatable="yes">Close and Save</property>
+ <property name="short_label" translatable="yes">Close and Save</property>
+ <property name="tooltip" translatable="yes">Close and Save</property>
+ <property name="icon_name">document-save-symbolic</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkAction" id="close and discard">
+ <property name="label" translatable="yes">Close and Discard</property>
+ <property name="short_label" translatable="yes">Close and Discard</property>
+ <property name="tooltip" translatable="yes">Close and Discard</property>
+ <property name="icon_name">user-trash-symbolic</property>
+ </object>
+ </child>
+ <child>
<object class="GtkAction" id="font_large">
<property name="label" translatable="yes">Lar_ge</property>
<property name="short_label" translatable="yes">Large</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]