[geary/wip/730682-refine-convo-list] Hook up ConversationListBox's selection mode support to the main window.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/730682-refine-convo-list] Hook up ConversationListBox's selection mode support to the main window.
- Date: Sun, 24 Dec 2017 08:11:37 +0000 (UTC)
commit e93495ff99200b964d8f1afdb928c6a4b4635eb0
Author: Michael James Gratton <mike vee net>
Date: Sun Dec 24 18:40:25 2017 +1030
Hook up ConversationListBox's selection mode support to the main window.
* src/client/components/main-window.vala (MainWindow): Add actions for
enabling and disabling selection mode. Update the toolbar as this and
the marked conversation count changes.
* src/client/components/main-toolbar.vala (MainToolbar): Add support for
showing the selection mode header bar and updating its label as needed.
* ui/main-toolbar.ui: Add an additional (initially hidden) Gtk.HeaderBar
for handling selection mode when enabled.
src/client/components/main-toolbar.vala | 38 ++++++++++++++-
src/client/components/main-window.vala | 45 ++++++++++++++++
ui/geary.css | 7 +++
ui/main-toolbar.ui | 84 +++++++++++++++++++++++++++----
4 files changed, 162 insertions(+), 12 deletions(-)
---
diff --git a/src/client/components/main-toolbar.vala b/src/client/components/main-toolbar.vala
index 0ea4749..09592a1 100644
--- a/src/client/components/main-toolbar.vala
+++ b/src/client/components/main-toolbar.vala
@@ -7,6 +7,7 @@
// Draws the main toolbar.
[GtkTemplate (ui = "/org/gnome/Geary/main-toolbar.ui")]
public class MainToolbar : Gtk.Box {
+
// How wide the left pane should be. Auto-synced with our settings
public int left_pane_width { get; set; }
// Used to form the title of the folder header
@@ -37,6 +38,13 @@ public class MainToolbar : Gtk.Box {
private Gtk.ToggleButton search_conversations_button;
private Binding guest_header_binding;
+ // Selection header elements
+ [GtkChild]
+ private Gtk.HeaderBar selection_header;
+
+ [GtkChild]
+ private Gtk.Label selection_label;
+
// Conversation header elements
[GtkChild]
private Gtk.HeaderBar conversation_header;
@@ -67,7 +75,12 @@ public class MainToolbar : Gtk.Box {
SettingsBindFlags.GET);
this.bind_property("left-pane-width", this.folder_header, "width-request",
BindingFlags.SYNC_CREATE, (binding, source_value, ref target_value) => {
- target_value = left_pane_width + 6;
+ target_value = left_pane_width;
+ return true;
+ });
+ this.bind_property("left-pane-width", this.selection_header, "width-request",
+ BindingFlags.SYNC_CREATE, (binding, source_value, ref target_value) => {
+ target_value = left_pane_width;
return true;
});
@@ -122,6 +135,29 @@ public class MainToolbar : Gtk.Box {
conversation_header.show();
}
+ internal void set_selection_mode_enabled(bool enabled) {
+ if (enabled) {
+ update_selection_count(0);
+ }
+ this.folder_header.set_visible(!enabled);
+ this.selection_header.set_visible(enabled);
+ }
+
+ internal void update_selection_count(int count) {
+ string text = "";
+ if (count == 0) {
+ text = _("Click to select conversations");
+ } else {
+ text = ngettext(
+ "%d conversation selected",
+ "%d conversations selected",
+ count
+ ).printf(count);
+
+ }
+ this.selection_label.set_text(text);
+ }
+
internal void update_trash_buttons(bool show_trash) {
this.trash_button.set_visible(show_trash);
this.delete_button.set_visible(!show_trash);
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index 0ca66ae..e43cb35 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -8,8 +8,20 @@
[GtkTemplate (ui = "/org/gnome/Geary/main-window.ui")]
public class MainWindow : Gtk.ApplicationWindow {
+
+
+ public const string ACTION_SELECTION_MODE_DISABLE = "selection-mode-disable";
+ public const string ACTION_SELECTION_MODE_ENABLE = "selection-mode-enable";
+
+
private const int STATUS_BAR_HEIGHT = 18;
+ private const ActionEntry[] action_entries = {
+ {ACTION_SELECTION_MODE_DISABLE, on_selection_mode_disabled },
+ {ACTION_SELECTION_MODE_ENABLE, on_selection_mode_enabled }
+ };
+
+
public new GearyApplication application {
get { return (GearyApplication) base.get_application(); }
set { base.set_application(value); }
@@ -69,6 +81,8 @@ public class MainWindow : Gtk.ApplicationWindow {
this.conversation_list = new ConversationList(application.config);
this.conversation_list.conversation_selection_changed.connect(on_conversation_selection_changed);
this.conversation_list.conversation_activated.connect(on_conversation_activated);
+ this.conversation_list.item_marked.connect(on_conversation_item_marked);
+ this.conversation_list.selection_mode_enabled.connect(on_selection_mode_enabled);
this.conversation_list.visible_conversations_changed.connect(on_visible_conversations_changed);
this.conversation_list.load_more.connect(on_load_more);
@@ -83,6 +97,7 @@ public class MainWindow : Gtk.ApplicationWindow {
set_styling();
setup_layout(application.config);
+ setup_actions();
on_change_orientation();
}
@@ -274,6 +289,15 @@ public class MainWindow : Gtk.ApplicationWindow {
return handled;
}
+ private void setup_actions() {
+ add_action_entries(action_entries, this);
+ add_window_accelerators(ACTION_SELECTION_MODE_DISABLE, { "Escape", });
+ }
+
+ private void add_window_accelerators(string action, string[] accelerators) {
+ this.application.set_accels_for_action("win." + action, accelerators);
+ }
+
private void update_headerbar() {
if (this.current_folder == null) {
this.main_toolbar.account = null;
@@ -321,6 +345,13 @@ public class MainWindow : Gtk.ApplicationWindow {
return (SimpleAction) lookup_action(name);
}
+ private void set_selection_mode_enabled(bool enabled) {
+ get_action(ACTION_SELECTION_MODE_DISABLE).set_enabled(enabled);
+ get_action(ACTION_SELECTION_MODE_ENABLE).set_enabled(!enabled);
+ this.main_toolbar.set_selection_mode_enabled(enabled);
+ this.conversation_list.set_selection_mode_enabled(enabled);
+ }
+
private void on_conversation_monitor_changed() {
this.conversation_list.freeze_selection();
ConversationListModel? old_model = this.conversation_list.model;
@@ -481,6 +512,12 @@ public class MainWindow : Gtk.ApplicationWindow {
}
}
+ private void on_conversation_item_marked(ConversationListItem item, bool marked) {
+ this.main_toolbar.update_selection_count(
+ this.conversation_list.get_marked_items().size
+ );
+ }
+
private void on_initial_conversation_load() {
// When not doing autoselect, we never get
// conversations_selected firing from the convo list, so we
@@ -559,6 +596,14 @@ public class MainWindow : Gtk.ApplicationWindow {
}
}
+ private void on_selection_mode_enabled() {
+ set_selection_mode_enabled(true);
+ }
+
+ private void on_selection_mode_disabled() {
+ set_selection_mode_enabled(false);
+ }
+
private void on_visible_conversations_changed(Gee.Set<Geary.App.Conversation> visible) {
this.application.controller.clear_new_messages("on_visible_conversations_changed", visible);
}
diff --git a/ui/geary.css b/ui/geary.css
index 408c6f5..761a8ec 100644
--- a/ui/geary.css
+++ b/ui/geary.css
@@ -49,6 +49,13 @@
border-right-width: 0;
}
+/* MainToolbar */
+
+.geary-titlebar-separator {
+ margin: 0;
+ padding: 0;
+}
+
/* FolderPopover */
row.geary-folder-popover-list-row {
diff --git a/ui/main-toolbar.ui b/ui/main-toolbar.ui
index 544c31c..813c684 100644
--- a/ui/main-toolbar.ui
+++ b/ui/main-toolbar.ui
@@ -14,6 +14,7 @@
<object class="GtkHeaderBar" id="folder_header">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="no_show_all">True</property>
<child>
<object class="GtkButton" id="compose_new_message_button">
<property name="visible">True</property>
@@ -24,6 +25,7 @@
<property name="always_show_image">True</property>
<child>
<object class="GtkImage" id="compose_new_message_image">
+ <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">text-editor-symbolic</property>
</object>
@@ -31,34 +33,45 @@
</object>
</child>
<child>
- <object class="GtkSeparator" id="header_separator">
+ <object class="GtkToggleButton" id="search_conversations_button">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="orientation">vertical</property>
+ <property name="can_focus">True</property>
+ <property name="focus_on_click">False</property>
+ <property name="receives_default">False</property>
+ <property name="always_show_image">True</property>
+ <child>
+ <object class="GtkImage" id="search_conversations_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">preferences-system-search-symbolic</property>
+ </object>
+ </child>
</object>
<packing>
<property name="pack_type">end</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
<child>
- <object class="GtkToggleButton" id="search_conversations_button">
+ <object class="GtkButton" id="selection_mode_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">False</property>
- <property name="tooltip_text" translatable="yes">Toggle search bar</property>
+ <property name="tooltip_text" translatable="yes">Select conversations</property>
+ <property name="action_name">win.selection-mode-enable</property>
<property name="always_show_image">True</property>
<child>
- <object class="GtkImage" id="search_conversations_image">
+ <object class="GtkImage">
+ <property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="icon_name">preferences-system-search-symbolic</property>
+ <property name="icon_name">object-select-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="pack_type">end</property>
- <property name="position">2</property>
+ <property name="position">3</property>
</packing>
</child>
<child>
@@ -71,6 +84,7 @@
<property name="always_show_image">True</property>
<child>
<object class="GtkImage" id="empty_menu_image">
+ <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">edit-clear-all-symbolic</property>
</object>
@@ -78,7 +92,7 @@
</object>
<packing>
<property name="pack_type">end</property>
- <property name="position">3</property>
+ <property name="position">4</property>
</packing>
</child>
<style>
@@ -93,6 +107,54 @@
</packing>
</child>
<child>
+ <object class="GtkHeaderBar" id="selection_header">
+ <property name="can_focus">False</property>
+ <property name="no_show_all">True</property>
+ <child type="title">
+ <object class="GtkLabel" id="selection_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">Label</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="label" translatable="yes">Cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="action_name">win.selection-mode-disable</property>
+ </object>
+ <packing>
+ <property name="pack_type">end</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <style>
+ <class name="geary-titlebar"/>
+ <class name="geary-titlebar-left"/>
+ <class name="selection-mode"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSeparator">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkHeaderBar" id="conversation_header">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -376,7 +438,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">1</property>
+ <property name="position">3</property>
</packing>
</child>
</template>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]