[gedit] Add an utility to get the list of windows



commit 4fb1d6b79023392349104cbf945c7f562185d2de
Author: Paolo Borelli <pborelli gnome org>
Date:   Fri Feb 7 22:54:39 2014 +0100

    Add an utility to get the list of windows
    
    Now that we also register the preferences dialog as a GtkApplication
    window we need to be more careful when looping through all the windows

 gedit/gedit-app.c                                |   41 ++++++++++++++++++++--
 gedit/gedit-app.h                                |    4 +-
 gedit/gedit-commands-file.c                      |   13 +++----
 gedit/gedit-settings.c                           |    5 ++-
 plugins/externaltools/tools/windowactivatable.py |    2 +-
 5 files changed, 50 insertions(+), 15 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index ed0d17f..0c56adc 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -1376,6 +1376,37 @@ gedit_app_create_window (GeditApp  *app,
 }
 
 /**
+ * gedit_app_get_main_windows:
+ * @app: the #GeditApp
+ *
+ * Returns all #GeditWindows currently open in #GeditApp.
+ * This differs from gtk_application_get_windows() since it does not
+ * include the preferences dialog and other auxiliary windows.
+ *
+ * Return value: (element-type Gedit.Window) (transfer container):
+ * a newly allocated list of #GeditWindow objects
+ */
+GList *
+gedit_app_get_main_windows (GeditApp *app)
+{
+       GList *res = NULL;
+       GList *windows, *l;
+
+       g_return_val_if_fail (GEDIT_IS_APP (app), NULL);
+
+       windows = gtk_application_get_windows (GTK_APPLICATION (app));
+       for (l = windows; l != NULL; l = g_list_next (l))
+       {
+               if (GEDIT_IS_WINDOW (l->data))
+               {
+                       res = g_list_prepend (res, l->data);
+               }
+       }
+
+       return g_list_reverse (res);
+}
+
+/**
  * gedit_app_get_documents:
  * @app: the #GeditApp
  *
@@ -1490,7 +1521,6 @@ gedit_app_process_window_event (GeditApp    *app,
     return FALSE;
 }
 
-
 static GMenuModel *
 find_extension_point_section (GMenuModel  *model,
                               const gchar *extension_point)
@@ -1524,8 +1554,13 @@ app_lockdown_changed (GeditApp *app)
        windows = gtk_application_get_windows (GTK_APPLICATION (app));
        for (l = windows; l != NULL; l = g_list_next (l))
        {
-               _gedit_window_set_lockdown (GEDIT_WINDOW (l->data),
-                                           app->priv->lockdown);
+               GtkWindow *window = l->data;
+
+               if (GEDIT_IS_WINDOW (window))
+               {
+                       _gedit_window_set_lockdown (GEDIT_WINDOW (window),
+                                                   app->priv->lockdown);
+               }
        }
 
        g_object_notify (G_OBJECT (app), "lockdown");
diff --git a/gedit/gedit-app.h b/gedit/gedit-app.h
index d59a1fd..a44ea79 100644
--- a/gedit/gedit-app.h
+++ b/gedit/gedit-app.h
@@ -91,10 +91,10 @@ GType                gedit_app_get_type                     (void) G_GNUC_CONST;
 GeditWindow    *gedit_app_create_window                (GeditApp    *app,
                                                         GdkScreen   *screen);
 
-/* Returns a newly allocated list with all the documents */
+GList          *gedit_app_get_main_windows             (GeditApp    *app);
+
 GList          *gedit_app_get_documents                (GeditApp    *app);
 
-/* Returns a newly allocated list with all the views */
 GList          *gedit_app_get_views                    (GeditApp    *app);
 
 /* Lockdown state */
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index 2cceeef..4f6c240 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -1904,23 +1904,20 @@ static void
 quit_all (void)
 {
        GList *windows;
-       GList *item;
-       GeditApp *app;
+       GList *l;
 
-       app = GEDIT_APP (g_application_get_default ());
-       windows = g_list_copy (gtk_application_get_windows (GTK_APPLICATION (app)));
+       windows = gedit_app_get_main_windows (GEDIT_APP (g_application_get_default ()));
 
-       for (item = windows; item; item = g_list_next (item))
+       for (l = windows; l != NULL; l = g_list_next (l))
        {
-               GeditWindow *window = GEDIT_WINDOW (item->data);
+               GeditWindow *window = l->data;
 
                g_object_set_data (G_OBJECT (window),
                                   GEDIT_IS_QUITTING_ALL,
                                   GINT_TO_POINTER (TRUE));
 
                if (!(gedit_window_get_state (window) &
-                                   (GEDIT_WINDOW_STATE_SAVING |
-                                    GEDIT_WINDOW_STATE_PRINTING)))
+                     (GEDIT_WINDOW_STATE_SAVING | GEDIT_WINDOW_STATE_PRINTING)))
                {
                        file_close_all (window, TRUE);
                }
diff --git a/gedit/gedit-settings.c b/gedit/gedit-settings.c
index 133008e..e7fd829 100644
--- a/gedit/gedit-settings.c
+++ b/gedit/gedit-settings.c
@@ -321,7 +321,8 @@ on_syntax_highlighting_changed (GSettings     *settings,
        g_list_free (docs);
 
        /* update the sensitivity of the Higlight Mode menu item */
-       windows = gtk_application_get_windows (GTK_APPLICATION (g_application_get_default ()));
+       windows = gedit_app_get_main_windows (GEDIT_APP (g_application_get_default ()));
+
        for (l = windows; l != NULL; l = g_list_next (l))
        {
                GAction *action;
@@ -329,6 +330,8 @@ on_syntax_highlighting_changed (GSettings     *settings,
                action = g_action_map_lookup_action (G_ACTION_MAP (l->data), "highlight-mode");
                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enable);
        }
+
+       g_list_free (windows);
 }
 
 static void
diff --git a/plugins/externaltools/tools/windowactivatable.py 
b/plugins/externaltools/tools/windowactivatable.py
index 9aa89c8..b82899a 100644
--- a/plugins/externaltools/tools/windowactivatable.py
+++ b/plugins/externaltools/tools/windowactivatable.py
@@ -159,7 +159,7 @@ class WindowActivatable(GObject.Object, Gedit.WindowActivatable):
         self._manager = None
 
     def on_manager_tools_updated(self, manager):
-        for window in Gio.Application.get_default().get_windows():
+        for window in Gio.Application.get_default().get_main_windows():
             window._external_tools_window_activatable.actions.update()
 
 # ex:ts=4:et:


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