[nautilus/gnome-3-18] toolbar: avoid empty operations popover



commit e5163bab0c95e4490a0d90618093f483d34a299c
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Nov 12 16:32:28 2015 +0100

    toolbar: avoid empty operations popover
    
    We need to check that all windows have the popover hidden
    to remove the operations, if not, what happens is that if
    one of the windows has it hidden it removes its operations
    and all the other popovers become empty.
    
    The code is not very beautiful since we have to access all
    the toolbars of all the windows, which is kind of breaking
    the design, but well... creating a "operations toolbar manager"
    just for this looks overkill.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=756560

 src/nautilus-toolbar.c |   38 +++++++++++++++++++++++++++++++++++---
 src/nautilus-toolbar.h |    2 ++
 2 files changed, 37 insertions(+), 3 deletions(-)
---
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 2f02e74..20a2045 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -30,6 +30,7 @@
 #include "nautilus-pathbar.h"
 #include "nautilus-window.h"
 #include "nautilus-progress-info-widget.h"
+#include "nautilus-application.h"
 
 #include <libnautilus-private/nautilus-global-preferences.h>
 #include <libnautilus-private/nautilus-ui-utilities.h>
@@ -473,13 +474,38 @@ add_operations_button_attention_style (NautilusToolbar *self)
                                                                             self);
 }
 
+/* It's not the most beautiful solution, but we need to check wheter all windows
+ * have it's button inactive, so the toolbar can schedule to remove the operations
+ * only in that case to avoid other windows to show an empty popover in the oposite
+ * case */
+static gboolean
+is_all_windows_operations_buttons_inactive ()
+{
+        GApplication *application;
+        GList *windows;
+        GList *l;
+        GtkWidget *toolbar;
+
+        application = g_application_get_default ();
+        windows = nautilus_application_get_windows (NAUTILUS_APPLICATION (application));
+
+        for (l = windows; l != NULL; l = l->next) {
+                toolbar = nautilus_window_get_toolbar (NAUTILUS_WINDOW (l->data));
+                if (nautilus_toolbar_is_operations_button_active (NAUTILUS_TOOLBAR (toolbar))) {
+                          return FALSE;
+                }
+        }
+
+        return TRUE;
+}
+
 static void
 on_progress_info_cancelled (NautilusToolbar *self)
 {
         /* Update the pie chart progress */
         gtk_widget_queue_draw (self->priv->operations_icon);
 
-        if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->operations_button))) {
+        if (is_all_windows_operations_buttons_inactive ()) {
                 schedule_remove_finished_operations (self);
         }
 }
@@ -501,7 +527,7 @@ on_progress_info_finished (NautilusToolbar      *self,
         /* Update the pie chart progress */
         gtk_widget_queue_draw (self->priv->operations_icon);
 
-        if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->operations_button))) {
+        if (is_all_windows_operations_buttons_inactive ()){
                 schedule_remove_finished_operations (self);
         }
 
@@ -720,7 +746,7 @@ static void
 on_operations_button_toggled (NautilusToolbar *self)
 {
         unschedule_remove_finished_operations (self);
-        if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->operations_button))) {
+        if (is_all_windows_operations_buttons_inactive ()) {
                 schedule_remove_finished_operations (self);
         } else {
                 update_operations (self);
@@ -988,3 +1014,9 @@ nautilus_toolbar_set_active_slot (NautilusToolbar    *toolbar,
 
         }
 }
+
+gboolean
+nautilus_toolbar_is_operations_button_active (NautilusToolbar *self)
+{
+        return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->operations_button));
+}
diff --git a/src/nautilus-toolbar.h b/src/nautilus-toolbar.h
index c66ef91..3e0266f 100644
--- a/src/nautilus-toolbar.h
+++ b/src/nautilus-toolbar.h
@@ -75,4 +75,6 @@ void nautilus_toolbar_set_show_location_entry (NautilusToolbar *self,
 void       nautilus_toolbar_set_active_slot    (NautilusToolbar    *toolbar,
                                                 NautilusWindowSlot *slot);
 
+gboolean   nautilus_toolbar_is_operations_button_active (NautilusToolbar *toolbar);
+
 #endif /* __NAUTILUS_TOOLBAR_H__ */


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