[gedit] tab: reorganize a bit load_cb()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] tab: reorganize a bit load_cb()
- Date: Sat, 13 Jun 2015 18:59:25 +0000 (UTC)
commit 488ca485786713e5a567064a4652b0daa07fbc05
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Jun 13 20:44:26 2015 +0200
tab: reorganize a bit load_cb()
And use g_error_matches().
gedit/gedit-tab.c | 125 ++++++++++++++++++++++++----------------------------
1 files changed, 58 insertions(+), 67 deletions(-)
---
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index aa9c538..ec991b3 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -1800,9 +1800,7 @@ load_cb (GtkSourceFileLoader *loader,
/* Special case creating a named new doc. */
create_named_new_doc = (_gedit_document_get_create (doc) &&
- error != NULL &&
- error->domain == G_IO_ERROR &&
- error->code == G_IO_ERROR_NOT_FOUND &&
+ g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) &&
g_file_has_uri_scheme (location, "file"));
if (create_named_new_doc)
@@ -1811,74 +1809,15 @@ load_cb (GtkSourceFileLoader *loader,
error = NULL;
}
- /* If the error is CONVERSION FALLBACK don't treat it as a normal error. */
- if (error != NULL &&
- (error->domain != GTK_SOURCE_FILE_LOADER_ERROR ||
- error->code != GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK))
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
- if (tab->state == GEDIT_TAB_STATE_LOADING)
- {
- gtk_widget_hide (GTK_WIDGET (tab->frame));
- gedit_tab_set_state (tab, GEDIT_TAB_STATE_LOADING_ERROR);
- }
- else
- {
- gedit_tab_set_state (tab, GEDIT_TAB_STATE_REVERTING_ERROR);
- }
-
- if (error->domain == G_IO_ERROR &&
- error->code == G_IO_ERROR_CANCELLED)
- {
- remove_tab (tab);
- }
- else
- {
- GtkWidget *info_bar;
-
- if (location != NULL)
- {
- gedit_recent_remove_if_local (location);
- }
-
- if (tab->state == GEDIT_TAB_STATE_LOADING_ERROR)
- {
- const GtkSourceEncoding *encoding;
-
- encoding = gtk_source_file_loader_get_encoding (loader);
-
- info_bar = gedit_io_loading_error_info_bar_new (location, encoding, error);
-
- g_signal_connect (info_bar,
- "response",
- G_CALLBACK (io_loading_error_info_bar_response),
- tab);
- }
- else
- {
- g_return_if_fail (tab->state == GEDIT_TAB_STATE_REVERTING_ERROR);
-
- info_bar = gedit_unrecoverable_reverting_error_info_bar_new (location, error);
-
- g_signal_connect (info_bar,
- "response",
- G_CALLBACK
(unrecoverable_reverting_error_info_bar_response),
- tab);
- }
-
- set_info_bar (tab, info_bar, GTK_RESPONSE_CANCEL);
- }
-
+ remove_tab (tab);
goto end;
}
- if (!create_named_new_doc)
- {
- gedit_recent_add_document (doc);
- }
-
- if (error != NULL &&
- error->domain == GTK_SOURCE_FILE_LOADER_ERROR &&
- error->code == GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK)
+ if (g_error_matches (error,
+ GTK_SOURCE_FILE_LOADER_ERROR,
+ GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK))
{
GtkWidget *info_bar;
const GtkSourceEncoding *encoding;
@@ -1909,11 +1848,63 @@ load_cb (GtkSourceFileLoader *loader,
gedit_tab_set_state (tab, GEDIT_TAB_STATE_REVERTING_ERROR);
}
}
+ else if (error != NULL)
+ {
+ GtkWidget *info_bar;
+
+ if (tab->state == GEDIT_TAB_STATE_LOADING)
+ {
+ gtk_widget_hide (GTK_WIDGET (tab->frame));
+ gedit_tab_set_state (tab, GEDIT_TAB_STATE_LOADING_ERROR);
+ }
+ else
+ {
+ gedit_tab_set_state (tab, GEDIT_TAB_STATE_REVERTING_ERROR);
+ }
+
+ if (location != NULL)
+ {
+ gedit_recent_remove_if_local (location);
+ }
+
+ if (tab->state == GEDIT_TAB_STATE_LOADING_ERROR)
+ {
+ const GtkSourceEncoding *encoding;
+
+ encoding = gtk_source_file_loader_get_encoding (loader);
+
+ info_bar = gedit_io_loading_error_info_bar_new (location, encoding, error);
+
+ g_signal_connect (info_bar,
+ "response",
+ G_CALLBACK (io_loading_error_info_bar_response),
+ tab);
+ }
+ else
+ {
+ g_return_if_fail (tab->state == GEDIT_TAB_STATE_REVERTING_ERROR);
+
+ info_bar = gedit_unrecoverable_reverting_error_info_bar_new (location, error);
+
+ g_signal_connect (info_bar,
+ "response",
+ G_CALLBACK (unrecoverable_reverting_error_info_bar_response),
+ tab);
+ }
+
+ 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.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]