[gedit] tab: extract function from load_cb()



commit 82a6b3043e1ce778ce9ee3bc612331a40edb79f1
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jun 13 20:56:50 2015 +0200

    tab: extract function from load_cb()
    
    So that load_cb() is smaller and clearer.

 gedit/gedit-tab.c |   87 ++++++++++++++++++++++++++++++++--------------------
 1 files changed, 53 insertions(+), 34 deletions(-)
---
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index ec991b3..f2b60ea 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -1751,6 +1751,48 @@ goto_line (GeditTab *tab)
        gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter);
 }
 
+static gboolean
+file_already_opened (GeditDocument *doc,
+                    GFile         *location)
+{
+       GList *all_documents;
+       GList *l;
+       gboolean already_opened = FALSE;
+
+       if (location == NULL)
+       {
+               return FALSE;
+       }
+
+       all_documents = gedit_app_get_documents (GEDIT_APP (g_application_get_default ()));
+
+       for (l = all_documents; l != NULL; l = l->next)
+       {
+               GeditDocument *cur_doc = l->data;
+               GtkSourceFile *cur_file;
+               GFile *cur_location;
+
+               if (cur_doc == doc)
+               {
+                       continue;
+               }
+
+               cur_file = gedit_document_get_file (cur_doc);
+               cur_location = gtk_source_file_get_location (cur_file);
+
+               if (cur_location != NULL &&
+                   g_file_equal (location, cur_location))
+               {
+                       already_opened = TRUE;
+                       break;
+               }
+       }
+
+       g_list_free (all_documents);
+
+       return already_opened;
+}
+
 static void
 load_cb (GtkSourceFileLoader *loader,
         GAsyncResult        *result,
@@ -1914,47 +1956,24 @@ load_cb (GtkSourceFileLoader *loader,
                tab->idle_scroll = g_idle_add ((GSourceFunc)scroll_to_cursor, tab);
        }
 
-       /* If the document is readonly we don't care how many times the document
+       /* If the document is readonly we don't care how many times the file
         * is opened.
         */
-       if (!gtk_source_file_is_readonly (file))
+       if (!gtk_source_file_is_readonly (file) &&
+           file_already_opened (doc, location))
        {
-               GList *all_documents;
-               GList *l;
-
-               all_documents = gedit_app_get_documents (GEDIT_APP (g_application_get_default ()));
-
-               for (l = all_documents; l != NULL; l = g_list_next (l))
-               {
-                       GeditDocument *cur_doc = l->data;
-
-                       if (cur_doc != doc)
-                       {
-                               GtkSourceFile *cur_file = gedit_document_get_file (cur_doc);
-                               GFile *cur_location = gtk_source_file_get_location (cur_file);
-
-                               if (cur_location != NULL && location != NULL &&
-                                   g_file_equal (location, cur_location))
-                               {
-                                       GtkWidget *info_bar;
-
-                                       set_editable (tab, FALSE);
-
-                                       info_bar = gedit_file_already_open_warning_info_bar_new (location);
+               GtkWidget *info_bar;
 
-                                       g_signal_connect (info_bar,
-                                                         "response",
-                                                         G_CALLBACK 
(file_already_open_warning_info_bar_response),
-                                                         tab);
+               set_editable (tab, FALSE);
 
-                                       set_info_bar (tab, info_bar, GTK_RESPONSE_CANCEL);
+               info_bar = gedit_file_already_open_warning_info_bar_new (location);
 
-                                       break;
-                               }
-                       }
-               }
+               g_signal_connect (info_bar,
+                                 "response",
+                                 G_CALLBACK (file_already_open_warning_info_bar_response),
+                                 tab);
 
-               g_list_free (all_documents);
+               set_info_bar (tab, info_bar, GTK_RESPONSE_CANCEL);
        }
 
        if (location == NULL)


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