[geary/mjog/email-templates: 4/17] Sidebar.Entry: Coalesce multiple entry changed signals into one
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/email-templates: 4/17] Sidebar.Entry: Coalesce multiple entry changed signals into one
- Date: Wed, 8 Apr 2020 09:22:48 +0000 (UTC)
commit 9e7f21dbb60724282f901671bfa74f4708f1d099
Author: Michael Gratton <mike vee net>
Date: Thu Apr 2 14:43:42 2020 +1100
Sidebar.Entry: Coalesce multiple entry changed signals into one
Don't have a separate blah_changed signal for each property, just have
one and update all props when it is emitted. This happens infrequently
enough that the extra overhead is trivial and simplifies the code base.
.../folder-list/folder-list-folder-entry.vala | 12 +--
.../folder-list-inbox-folder-entry.vala | 2 +-
.../folder-list/folder-list-search-branch.vala | 6 +-
src/client/sidebar/sidebar-common.vala | 2 +-
src/client/sidebar/sidebar-entry.vala | 9 +-
src/client/sidebar/sidebar-tree.vala | 110 +++++++--------------
6 files changed, 50 insertions(+), 91 deletions(-)
---
diff --git a/src/client/folder-list/folder-list-folder-entry.vala
b/src/client/folder-list/folder-list-folder-entry.vala
index d27c46fc..c69ef56c 100644
--- a/src/client/folder-list/folder-list-folder-entry.vala
+++ b/src/client/folder-list/folder-list-folder-entry.vala
@@ -75,7 +75,7 @@ public class FolderList.FolderEntry :
return;
this.has_new = has_new;
- is_emphasized_changed(has_new);
+ entry_changed();
}
public bool internal_drop_received(Application.MainWindow main_window,
@@ -94,11 +94,6 @@ public class FolderList.FolderEntry :
return true;
}
- private void on_counts_changed() {
- sidebar_count_changed(get_count());
- sidebar_tooltip_changed(get_sidebar_tooltip());
- }
-
public override int get_count() {
switch (this.context.displayed_count) {
case TOTAL:
@@ -111,4 +106,9 @@ public class FolderList.FolderEntry :
return 0;
}
}
+
+ private void on_counts_changed() {
+ entry_changed();
+ }
+
}
diff --git a/src/client/folder-list/folder-list-inbox-folder-entry.vala
b/src/client/folder-list/folder-list-inbox-folder-entry.vala
index 53c7a50e..14bbdc98 100644
--- a/src/client/folder-list/folder-list-inbox-folder-entry.vala
+++ b/src/client/folder-list/folder-list-inbox-folder-entry.vala
@@ -32,7 +32,7 @@ public class FolderList.InboxFolderEntry : FolderList.FolderEntry {
private void on_information_changed(Geary.AccountInformation config) {
if (this.display_name != config.display_name) {
this.display_name = config.display_name;
- sidebar_name_changed(this.display_name);
+ entry_changed();
}
}
}
diff --git a/src/client/folder-list/folder-list-search-branch.vala
b/src/client/folder-list/folder-list-search-branch.vala
index 038e6f6c..f3c27ab4 100644
--- a/src/client/folder-list/folder-list-search-branch.vala
+++ b/src/client/folder-list/folder-list-search-branch.vala
@@ -69,9 +69,7 @@ public class FolderList.SearchEntry : FolderList.AbstractFolderEntry {
private void on_accounts_changed(Geary.Engine engine,
Geary.AccountInformation config) {
- sidebar_name_changed(get_sidebar_name());
- sidebar_tooltip_changed(get_sidebar_tooltip());
-
+ entry_changed();
try {
this.account_count = engine.get_accounts().size;
} catch (GLib.Error error) {
@@ -80,7 +78,7 @@ public class FolderList.SearchEntry : FolderList.AbstractFolderEntry {
}
private void on_email_total_changed() {
- sidebar_tooltip_changed(get_sidebar_tooltip());
+ entry_changed();
}
public override int get_count() {
diff --git a/src/client/sidebar/sidebar-common.vala b/src/client/sidebar/sidebar-common.vala
index 7e3c6e62..d4c702c7 100644
--- a/src/client/sidebar/sidebar-common.vala
+++ b/src/client/sidebar/sidebar-common.vala
@@ -20,7 +20,7 @@ public class Sidebar.Grouping : Geary.BaseObject, Sidebar.Entry, Sidebar.Expanda
public void rename(string name) {
this.name = name;
- sidebar_name_changed(name);
+ entry_changed();
}
public bool is_user_renameable() {
diff --git a/src/client/sidebar/sidebar-entry.vala b/src/client/sidebar/sidebar-entry.vala
index 5c653f31..efbc5905 100644
--- a/src/client/sidebar/sidebar-entry.vala
+++ b/src/client/sidebar/sidebar-entry.vala
@@ -5,11 +5,10 @@
*/
public interface Sidebar.Entry : Object {
- public signal void sidebar_name_changed(string name);
- public signal void sidebar_tooltip_changed(string? tooltip);
- public signal void sidebar_count_changed(int count);
+ public signal void entry_changed();
+
public abstract string get_sidebar_name();
@@ -36,8 +35,6 @@ public interface Sidebar.SelectableEntry : Sidebar.Entry {
}
public interface Sidebar.RenameableEntry : Sidebar.Entry {
- public signal void sidebar_name_changed(string name);
-
public abstract void rename(string new_name);
// Return true to allow the user to rename the sidebar entry in the UI.
@@ -45,8 +42,6 @@ public interface Sidebar.RenameableEntry : Sidebar.Entry {
}
public interface Sidebar.EmphasizableEntry : Sidebar.Entry {
- public signal void is_emphasized_changed(bool emphasized);
-
public abstract bool is_emphasized();
}
diff --git a/src/client/sidebar/sidebar-tree.vala b/src/client/sidebar/sidebar-tree.vala
index e01103ab..a5f95092 100644
--- a/src/client/sidebar/sidebar-tree.vala
+++ b/src/client/sidebar/sidebar-tree.vala
@@ -481,22 +481,16 @@ public class Sidebar.Tree : Gtk.TreeView {
assert(!entry_map.has_key(entry));
entry_map.set(entry, wrapper);
- store.set(assoc_iter, Columns.NAME, get_name_for_entry(entry));
- store.set(assoc_iter, Columns.TOOLTIP, entry.get_sidebar_tooltip() != null ?
- Geary.HTML.escape_markup(entry.get_sidebar_tooltip()) : null);
- store.set(assoc_iter, Columns.WRAPPER, wrapper);
- store.set(assoc_iter, Columns.COUNTER, entry.get_count());
- load_entry_icons(assoc_iter);
-
- entry.sidebar_tooltip_changed.connect(on_sidebar_tooltip_changed);
-
- entry.sidebar_name_changed.connect(on_sidebar_name_changed);
- entry.sidebar_count_changed.connect(on_sidebar_count_changed);
-
- Sidebar.EmphasizableEntry? emphasizable = entry as Sidebar.EmphasizableEntry;
- if (emphasizable != null)
- emphasizable.is_emphasized_changed.connect(on_is_emphasized_changed);
-
+ store.set(
+ assoc_iter,
+ Columns.WRAPPER, wrapper,
+ Columns.ICON, entry.get_sidebar_icon(),
+ Columns.NAME, get_name_for_entry(entry),
+ Columns.TOOLTIP, entry.get_sidebar_tooltip() != null ?
+ Geary.HTML.escape_markup(entry.get_sidebar_tooltip()) : null,
+ Columns.COUNTER, entry.get_count()
+ );
+ entry.entry_changed.connect(on_entry_changed);
entry.grafted(this);
}
@@ -506,15 +500,17 @@ public class Sidebar.Tree : Gtk.TreeView {
bool removed = entry_map.unset(entry);
assert(removed);
- EntryWrapper new_wrapper = new EntryWrapper(store, entry, store.get_path(new_iter));
- entry_map.set(entry, new_wrapper);
-
- store.set(new_iter, Columns.NAME, get_name_for_entry(entry));
- store.set(new_iter, Columns.TOOLTIP, Geary.HTML.escape_markup(entry.get_sidebar_tooltip()));
- store.set(new_iter, Columns.COUNTER, entry.get_count());
- store.set(new_iter, Columns.WRAPPER, new_wrapper);
- load_entry_icons(new_iter);
-
+ var new_wrapper = new EntryWrapper(store, entry, store.get_path(new_iter));
+ this.entry_map.set(entry, new_wrapper);
+ this.store.set(
+ new_iter,
+ Columns.WRAPPER, new_wrapper,
+ Columns.ICON, entry.get_sidebar_icon(),
+ Columns.NAME, get_name_for_entry(entry),
+ Columns.TOOLTIP, entry.get_sidebar_tooltip() != null ?
+ Geary.HTML.escape_markup(entry.get_sidebar_tooltip()) : null,
+ Columns.COUNTER, entry.get_count()
+ );
return new_wrapper;
}
@@ -596,19 +592,10 @@ public class Sidebar.Tree : Gtk.TreeView {
selected_wrapper = null;
Sidebar.Entry entry = wrapper.entry;
-
entry.pruned(this);
+ entry.entry_changed.disconnect(on_entry_changed);
- entry.sidebar_tooltip_changed.disconnect(on_sidebar_tooltip_changed);
- entry.sidebar_name_changed.disconnect(on_sidebar_name_changed);
- entry.sidebar_count_changed.disconnect(on_sidebar_count_changed);
-
- Sidebar.EmphasizableEntry? emphasizable = entry as Sidebar.EmphasizableEntry;
- if (emphasizable != null)
- emphasizable.is_emphasized_changed.disconnect(on_is_emphasized_changed);
-
- bool removed = entry_map.unset(entry);
- assert(removed);
+ this.entry_map.unset(entry);
}
private void on_branch_entry_added(Sidebar.Branch branch, Sidebar.Entry entry) {
@@ -728,42 +715,21 @@ public class Sidebar.Tree : Gtk.TreeView {
branch_shown(branch, shown);
}
- private void on_sidebar_tooltip_changed(Sidebar.Entry entry, string? tooltip) {
- EntryWrapper? wrapper = get_wrapper(entry);
- assert(wrapper != null);
-
- store.set(wrapper.get_iter(), Columns.TOOLTIP, tooltip != null ?
- Geary.HTML.escape_markup(tooltip) : null);
- }
-
- private void rename_entry(Sidebar.Entry entry) {
- EntryWrapper? wrapper = get_wrapper(entry);
- assert(wrapper != null);
-
- store.set(wrapper.get_iter(), Columns.NAME, get_name_for_entry(entry));
- }
-
- private void on_sidebar_name_changed(Sidebar.Entry entry, string name) {
- rename_entry(entry);
- }
-
- private void on_is_emphasized_changed(Sidebar.EmphasizableEntry entry, bool is_emphasized) {
- rename_entry(entry);
- }
-
- private void on_sidebar_count_changed(Sidebar.Entry entry, int coun) {
- EntryWrapper? wrapper = get_wrapper(entry);
- assert(wrapper != null);
-
- store.set(wrapper.get_iter(), Columns.COUNTER, entry.get_count());
- }
-
- private void load_entry_icons(Gtk.TreeIter iter) {
- EntryWrapper? wrapper = get_wrapper_at_iter(iter);
- if (wrapper == null)
- return;
- string? icon = wrapper.entry.get_sidebar_icon();
- store.set(iter, Columns.ICON, icon);
+ private void on_entry_changed(Sidebar.Entry entry) {
+ var wrapper = get_wrapper(entry);
+ if (wrapper != null) {
+ var tooltip = entry.get_sidebar_tooltip();
+ if (tooltip != null) {
+ tooltip = Geary.HTML.escape_markup(tooltip);
+ }
+ store.set(
+ wrapper.get_iter(),
+ Columns.ICON, entry.get_sidebar_icon(),
+ Columns.NAME, get_name_for_entry(entry),
+ Columns.TOOLTIP, tooltip,
+ Columns.COUNTER, entry.get_count()
+ );
+ }
}
private bool on_selection(Gtk.TreeSelection selection, Gtk.TreeModel model, Gtk.TreePath path,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]