[gedit/wip/tab-cleanup] tab: extract successful_load() function from load_cb()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/tab-cleanup] tab: extract successful_load() function from load_cb()
- Date: Sat, 13 Jun 2015 19:22:58 +0000 (UTC)
commit a09f38ed6ead8cabd29acedb3c9f5bedf8a8e768
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Jun 13 21:20:47 2015 +0200
tab: extract successful_load() function from load_cb()
So that load_cb() is smaller.
gedit/gedit-tab.c | 156 +++++++++++++++++++++++++++++------------------------
1 files changed, 85 insertions(+), 71 deletions(-)
---
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index f2b60ea..2117fb6 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -1794,6 +1794,81 @@ file_already_opened (GeditDocument *doc,
}
static void
+successful_load (GeditTab *tab,
+ gboolean create_named_new_doc)
+{
+ GeditDocument *doc;
+ GFile *file;
+ GFile *location;
+
+ doc = gedit_tab_get_document (tab);
+ file = gedit_document_get_file (doc);
+
+ if (tab->user_requested_encoding)
+ {
+ const GtkSourceEncoding *encoding = gtk_source_file_loader_get_encoding (tab->loader);
+ const gchar *charset = gtk_source_encoding_get_charset (encoding);
+
+ gedit_document_set_metadata (doc,
+ GEDIT_METADATA_ATTRIBUTE_ENCODING, charset,
+ NULL);
+ }
+
+ if (!create_named_new_doc)
+ {
+ gedit_recent_add_document (doc);
+ }
+
+ goto_line (tab);
+
+ /* Scroll to the cursor when the document is loaded, we need to do it in
+ * an idle as after the document is loaded the textview is still
+ * redrawing and relocating its internals.
+ */
+ if (tab->idle_scroll == 0)
+ {
+ tab->idle_scroll = g_idle_add ((GSourceFunc)scroll_to_cursor, tab);
+ }
+
+ location = gtk_source_file_loader_get_location (tab->loader);
+
+ /* If the document is readonly we don't care how many times the file
+ * is opened.
+ */
+ if (!gtk_source_file_is_readonly (file) &&
+ file_already_opened (doc, location))
+ {
+ GtkWidget *info_bar;
+
+ set_editable (tab, FALSE);
+
+ info_bar = gedit_file_already_open_warning_info_bar_new (location);
+
+ g_signal_connect (info_bar,
+ "response",
+ G_CALLBACK (file_already_open_warning_info_bar_response),
+ tab);
+
+ set_info_bar (tab, info_bar, GTK_RESPONSE_CANCEL);
+ }
+
+ if (location == NULL)
+ {
+ /* FIXME: hackish */
+ gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), TRUE);
+ }
+
+ tab->ask_if_externally_modified = TRUE;
+
+ if (error == NULL)
+ {
+ clear_loading (tab);
+ }
+
+ g_signal_emit_by_name (doc, "loaded");
+}
+
+static void
load_cb (GtkSourceFileLoader *loader,
GAsyncResult *result,
GeditTab *tab)
@@ -1822,24 +1897,6 @@ load_cb (GtkSourceFileLoader *loader,
set_info_bar (tab, NULL, GTK_RESPONSE_NONE);
- /* Load was successful. */
- if (error == NULL ||
- (error->domain == GTK_SOURCE_FILE_LOADER_ERROR &&
- error->code == GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK))
- {
- if (tab->user_requested_encoding)
- {
- const GtkSourceEncoding *encoding = gtk_source_file_loader_get_encoding (loader);
- const gchar *charset = gtk_source_encoding_get_charset (encoding);
-
- gedit_document_set_metadata (doc,
- GEDIT_METADATA_ATTRIBUTE_ENCODING, charset,
- NULL);
- }
-
- goto_line (tab);
- }
-
/* Special case creating a named new doc. */
create_named_new_doc = (_gedit_document_get_create (doc) &&
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) &&
@@ -1889,8 +1946,15 @@ load_cb (GtkSourceFileLoader *loader,
{
gedit_tab_set_state (tab, GEDIT_TAB_STATE_REVERTING_ERROR);
}
+
+ /* The loading was successful, despite some invalid characters.
+ * The document can be edited.
+ */
+ successful_load (tab, create_named_new_doc);
+ goto end;
}
- else if (error != NULL)
+
+ if (error != NULL)
{
GtkWidget *info_bar;
@@ -1937,59 +2001,9 @@ load_cb (GtkSourceFileLoader *loader,
set_info_bar (tab, info_bar, GTK_RESPONSE_CANCEL);
goto end;
}
- else
- {
- gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
- }
- if (!create_named_new_doc)
- {
- gedit_recent_add_document (doc);
- }
-
- /* Scroll to the cursor when the document is loaded, we need to do it in
- * an idle as after the document is loaded the textview is still
- * redrawing and relocating its internals.
- */
- if (tab->idle_scroll == 0)
- {
- tab->idle_scroll = g_idle_add ((GSourceFunc)scroll_to_cursor, tab);
- }
-
- /* If the document is readonly we don't care how many times the file
- * is opened.
- */
- if (!gtk_source_file_is_readonly (file) &&
- file_already_opened (doc, location))
- {
- GtkWidget *info_bar;
-
- set_editable (tab, FALSE);
-
- info_bar = gedit_file_already_open_warning_info_bar_new (location);
-
- g_signal_connect (info_bar,
- "response",
- G_CALLBACK (file_already_open_warning_info_bar_response),
- tab);
-
- set_info_bar (tab, info_bar, GTK_RESPONSE_CANCEL);
- }
-
- if (location == NULL)
- {
- /* FIXME: hackish */
- gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), TRUE);
- }
-
- tab->ask_if_externally_modified = TRUE;
-
- if (error == NULL)
- {
- clear_loading (tab);
- }
-
- g_signal_emit_by_name (doc, "loaded");
+ gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
+ successful_load (tab, create_named_new_doc);
end:
/* Async operation finished. */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]