[geary/gtk-3.10: 4/4] If Folder's display name changes, signal so UI can update



commit 9134111980d893d91828a84233f446fdda915647
Author: Jim Nelson <jim yorba org>
Date:   Wed Jan 29 17:24:28 2014 -0800

    If Folder's display name changes, signal so UI can update
    
    Noticed this while working on Gtk.HeaderBar patch, that if the display
    name changes it won't be reflected in the UI.

 src/client/components/main-window.vala             |    8 +++++-
 .../folder-list/folder-list-folder-entry.vala      |    6 +++++
 src/engine/abstract/geary-abstract-folder.vala     |   23 +++++++++++++------
 src/engine/api/geary-folder.vala                   |    9 +++++++
 4 files changed, 37 insertions(+), 9 deletions(-)
---
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index ee2f310..0d617de 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -226,12 +226,16 @@ public class MainWindow : Gtk.ApplicationWindow {
     
     private void on_folder_selected(Geary.Folder? folder) {
         // disconnect from old folder
-        if (current_folder != null)
+        if (current_folder != null) {
             current_folder.properties.notify.disconnect(update_headerbar);
+            current_folder.display_name_changed.disconnect(update_headerbar);
+        }
         
         // connect to new folder
-        if (folder != null)
+        if (folder != null) {
             folder.properties.notify.connect(update_headerbar);
+            folder.display_name_changed.connect(update_headerbar);
+        }
         
         // swap it in
         current_folder = folder;
diff --git a/src/client/folder-list/folder-list-folder-entry.vala 
b/src/client/folder-list/folder-list-folder-entry.vala
index 2e78f3d..647153b 100644
--- a/src/client/folder-list/folder-list-folder-entry.vala
+++ b/src/client/folder-list/folder-list-folder-entry.vala
@@ -14,11 +14,13 @@ public class FolderList.FolderEntry : FolderList.AbstractFolderEntry, Sidebar.In
         has_new = false;
         folder.properties.notify[Geary.FolderProperties.PROP_NAME_EMAIL_TOTAL].connect(on_counts_changed);
         folder.properties.notify[Geary.FolderProperties.PROP_NAME_EMAIL_UNREAD].connect(on_counts_changed);
+        folder.display_name_changed.connect(on_display_name_changed);
     }
     
     ~FolderEntry() {
         folder.properties.notify[Geary.FolderProperties.PROP_NAME_EMAIL_TOTAL].disconnect(on_counts_changed);
         
folder.properties.notify[Geary.FolderProperties.PROP_NAME_EMAIL_UNREAD].disconnect(on_counts_changed);
+        folder.display_name_changed.disconnect(on_display_name_changed);
     }
     
     public override string get_sidebar_name() {
@@ -118,6 +120,10 @@ public class FolderList.FolderEntry : FolderList.AbstractFolderEntry, Sidebar.In
         sidebar_tooltip_changed(get_sidebar_tooltip());
     }
     
+    private void on_display_name_changed() {
+        sidebar_name_changed(folder.get_display_name());
+    }
+    
     public override int get_count() {
         if (folder.special_folder_type == Geary.SpecialFolderType.DRAFTS ||
             folder.special_folder_type == Geary.SpecialFolderType.OUTBOX)
diff --git a/src/engine/abstract/geary-abstract-folder.vala b/src/engine/abstract/geary-abstract-folder.vala
index 615d740..5f8890e 100644
--- a/src/engine/abstract/geary-abstract-folder.vala
+++ b/src/engine/abstract/geary-abstract-folder.vala
@@ -5,6 +5,14 @@
  */
 
 public abstract class Geary.AbstractFolder : BaseObject, Geary.Folder {
+    public abstract Geary.Account account { get; }
+    
+    public abstract Geary.FolderProperties properties { get; }
+    
+    public abstract Geary.FolderPath path { get; }
+    
+    public abstract Geary.SpecialFolderType special_folder_type { get; }
+    
     /*
      * notify_* methods for AbstractFolder are marked internal because the SendReplayOperations
      * need access to them to report changes as they occur.
@@ -58,15 +66,16 @@ public abstract class Geary.AbstractFolder : BaseObject, Geary.Folder {
     internal virtual void notify_special_folder_type_changed(Geary.SpecialFolderType old_type,
         Geary.SpecialFolderType new_type) {
         special_folder_type_changed(old_type, new_type);
+        
+        // in default implementation, this may also mean the display name changed; subclasses may
+        // override this behavior, but no way to detect this, so notify
+        if (special_folder_type != Geary.SpecialFolderType.NONE)
+            notify_display_name_changed();
     }
-
-    public abstract Geary.Account account { get; }
-    
-    public abstract Geary.FolderProperties properties { get; }
     
-    public abstract Geary.FolderPath path { get; }
-    
-    public abstract Geary.SpecialFolderType special_folder_type { get; }
+    internal virtual void notify_display_name_changed() {
+        display_name_changed();
+    }
     
     /**
      * Default is to display the basename of the Folder's path.
diff --git a/src/engine/api/geary-folder.vala b/src/engine/api/geary-folder.vala
index a870896..88ed6e0 100644
--- a/src/engine/api/geary-folder.vala
+++ b/src/engine/api/geary-folder.vala
@@ -279,6 +279,13 @@ public interface Geary.Folder : BaseObject {
     public signal void special_folder_type_changed(Geary.SpecialFolderType old_type,
         Geary.SpecialFolderType new_type);
     
+    /**
+     * Fired when the Folder's display name has changed.
+     *
+     * @see get_display_name
+     */
+    public signal void display_name_changed();
+    
     protected abstract void notify_opened(OpenState state, int count);
     
     protected abstract void notify_open_failed(OpenFailed failure, Error? err);
@@ -305,6 +312,8 @@ public interface Geary.Folder : BaseObject {
     protected abstract void notify_special_folder_type_changed(Geary.SpecialFolderType old_type,
         Geary.SpecialFolderType new_type);
     
+    protected abstract void notify_display_name_changed();
+    
     /**
      * Returns a name suitable for displaying to the user.
      */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]