[gedit/wip/loader-saver] tab: more file loading post-processing
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/loader-saver] tab: more file loading post-processing
- Date: Wed, 25 Jun 2014 14:08:08 +0000 (UTC)
commit c2c52b732a7b50d798a4f3505840c47fe3c6da20
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Jun 25 00:22:45 2014 +0200
tab: more file loading post-processing
gedit/gedit-io-error-info-bar.c | 6 +-
gedit/gedit-tab.c | 373 ++++++++++++++++++---------------------
2 files changed, 179 insertions(+), 200 deletions(-)
---
diff --git a/gedit/gedit-io-error-info-bar.c b/gedit/gedit-io-error-info-bar.c
index ce0d02a..be36644 100644
--- a/gedit/gedit-io-error-info-bar.c
+++ b/gedit/gedit-io-error-info-bar.c
@@ -598,9 +598,9 @@ gedit_io_loading_error_info_bar_new (GFile *location,
gboolean convert_error = FALSE;
g_return_val_if_fail (error != NULL, NULL);
- g_return_val_if_fail ((error->domain == G_CONVERT_ERROR) ||
- (error->domain == GEDIT_DOCUMENT_ERROR) ||
- (error->domain == G_IO_ERROR), NULL);
+ g_return_val_if_fail (error->domain == GTK_SOURCE_FILE_LOADER_ERROR ||
+ error->domain == G_IO_ERROR ||
+ error->domain == G_CONVERT_ERROR, NULL);
if (location)
{
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 48da20d..831420f 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -925,193 +925,6 @@ scroll_to_cursor (GeditTab *tab)
}
static void
-document_loaded (GeditDocument *document,
- const GError *error,
- GeditTab *tab)
-{
- GFile *location;
-
- g_return_if_fail ((tab->priv->state == GEDIT_TAB_STATE_LOADING) ||
- (tab->priv->state == GEDIT_TAB_STATE_REVERTING));
-
- if (tab->priv->timer != NULL)
- {
- g_timer_destroy (tab->priv->timer);
- tab->priv->timer = NULL;
- }
-
- set_info_bar (tab, NULL, GTK_RESPONSE_NONE);
-
- location = gedit_document_get_location (document);
-
- /* if the error is CONVERSION FALLBACK don't treat it as a normal error */
- if (error != NULL &&
- (error->domain != GEDIT_DOCUMENT_ERROR || error->code !=
GEDIT_DOCUMENT_ERROR_CONVERSION_FALLBACK))
- {
- if (tab->priv->state == GEDIT_TAB_STATE_LOADING)
- {
- 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 the tab, but in an idle handler, since
- * we are in the handler of doc loaded and we
- * don't want doc and tab to be finalized now.
- */
- g_idle_add ((GSourceFunc) remove_tab_idle, tab);
-
- goto end;
- }
- else
- {
- GtkWidget *info_bar;
-
- if (location != NULL)
- {
- gedit_recent_remove_if_local (location);
- }
-
- if (tab->priv->state == GEDIT_TAB_STATE_LOADING_ERROR)
- {
- info_bar = gedit_io_loading_error_info_bar_new (location,
- tab->priv->tmp_encoding,
- error);
- g_signal_connect (info_bar,
- "response",
- G_CALLBACK (io_loading_error_info_bar_response),
- tab);
- }
- else
- {
- g_return_if_fail (tab->priv->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);
- }
-
- if (location)
- {
- g_object_unref (location);
- }
-
- return;
- }
-
- gedit_recent_add_document (document);
-
- if (error != NULL &&
- error->domain == GEDIT_DOCUMENT_ERROR &&
- error->code == GEDIT_DOCUMENT_ERROR_CONVERSION_FALLBACK)
- {
- GtkWidget *info_bar;
-
- /* Set the tab as not editable as we have an error, the
- user can decide to make it editable again */
- tab->priv->editable = FALSE;
-
- info_bar = gedit_io_loading_error_info_bar_new (location,
- tab->priv->tmp_encoding,
- error);
-
- g_signal_connect (info_bar,
- "response",
- G_CALLBACK (io_loading_error_info_bar_response),
- tab);
-
- set_info_bar (tab, info_bar, GTK_RESPONSE_CANCEL);
- }
-
- /* 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->priv->idle_scroll == 0)
- {
- tab->priv->idle_scroll = g_idle_add ((GSourceFunc)scroll_to_cursor, tab);
- }
-
- /* if the document is readonly we don't care how many times the document
- is opened */
- if (!gedit_document_get_readonly (document))
- {
- 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 != document)
- {
- GFile *cur_location;
-
- cur_location = gedit_document_get_location (cur_doc);
-
- if (cur_location != NULL && location != NULL &&
- g_file_equal (location, cur_location))
- {
- GtkWidget *info_bar;
-
- tab->priv->editable = 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);
-
- g_object_unref (cur_location);
- break;
- }
-
- if (cur_location != NULL)
- {
- g_object_unref (cur_location);
- }
- }
- }
-
- g_list_free (all_documents);
- }
-
- gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
-
- if (location == NULL)
- {
- /* FIXME: hackish */
- gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (document), TRUE);
- }
-
- tab->priv->ask_if_externally_modified = TRUE;
-
-end:
- if (location != NULL)
- {
- g_object_unref (location);
- }
-
- tab->priv->tmp_line_pos = 0;
- tab->priv->tmp_encoding = NULL;
-}
-
-static void
document_saving (GeditDocument *document,
goffset size,
goffset total_size,
@@ -1629,11 +1442,6 @@ gedit_tab_init (GeditTab *tab)
tab);
g_signal_connect (doc,
- "loaded",
- G_CALLBACK (document_loaded),
- tab);
-
- g_signal_connect (doc,
"saving",
G_CALLBACK (document_saving),
tab);
@@ -2033,14 +1841,24 @@ load_cb (GtkSourceFileLoader *loader,
GFile *location = gtk_source_file_loader_get_location (loader);
GError *error = NULL;
+ g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_LOADING ||
+ tab->priv->state == GEDIT_TAB_STATE_REVERTING);
+
gtk_source_file_loader_load_finish (loader, result, &error);
if (error != NULL)
{
g_warning ("File loading error: %s", error->message);
- g_error_free (error);
}
+ if (tab->priv->timer != NULL)
+ {
+ g_timer_destroy (tab->priv->timer);
+ tab->priv->timer = NULL;
+ }
+
+ set_info_bar (tab, NULL, GTK_RESPONSE_NONE);
+
/* Load was successful. */
if (error == NULL ||
(error->domain == GTK_SOURCE_FILE_LOADER_ERROR &&
@@ -2069,14 +1887,175 @@ load_cb (GtkSourceFileLoader *loader,
error = NULL;
}
- g_clear_object (&tab->priv->loader);
- g_clear_object (&tab->priv->cancellable);
- tab->priv->load_create = FALSE;
+ /* 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 (tab->priv->state == GEDIT_TAB_STATE_LOADING)
+ {
+ gedit_tab_set_state (tab, GEDIT_TAB_STATE_LOADING_ERROR);
+ }
+ else
+ {
+ gedit_tab_set_state (tab, GEDIT_TAB_STATE_REVERTING_ERROR);
+ }
- g_signal_emit_by_name (doc, "loaded", NULL);
+ if (error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_CANCELLED)
+ {
+ /* remove the tab, but in an idle handler, since
+ * we are in the handler of doc loaded and we
+ * don't want doc and tab to be finalized now.
+ */
+ /* FIXME idle still needed? */
+ /* FIXME if an idle is still needed, it's safer to
+ * remove the idle source during dispose().
+ */
+ g_idle_add ((GSourceFunc) remove_tab_idle, tab);
+ }
+ else
+ {
+ GtkWidget *info_bar;
+
+ if (location != NULL)
+ {
+ gedit_recent_remove_if_local (location);
+ }
+
+ if (tab->priv->state == GEDIT_TAB_STATE_LOADING_ERROR)
+ {
+ info_bar = gedit_io_loading_error_info_bar_new (location,
+ tab->priv->tmp_encoding,
+ error);
+ g_signal_connect (info_bar,
+ "response",
+ G_CALLBACK (io_loading_error_info_bar_response),
+ tab);
+ }
+ else
+ {
+ g_return_if_fail (tab->priv->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;
+ }
+
+ gedit_recent_add_document (doc);
+
+ if (error != NULL &&
+ error->domain == GTK_SOURCE_FILE_LOADER_ERROR &&
+ error->code == GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK)
+ {
+ GtkWidget *info_bar;
+ const GtkSourceEncoding *encoding;
+
+ /* Set the tab as not editable as we have an error, the user can
+ * decide to make it editable again.
+ */
+ tab->priv->editable = FALSE;
+
+ 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);
+
+ set_info_bar (tab, info_bar, GTK_RESPONSE_CANCEL);
+ }
+
+ /* 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->priv->idle_scroll == 0)
+ {
+ tab->priv->idle_scroll = g_idle_add ((GSourceFunc)scroll_to_cursor, tab);
+ }
+
+ /* If the document is readonly we don't care how many times the document
+ * is opened.
+ */
+ if (!gedit_document_get_readonly (doc))
+ {
+ 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)
+ {
+ GFile *cur_location;
+
+ cur_location = gedit_document_get_location (cur_doc);
+
+ if (cur_location != NULL && location != NULL &&
+ g_file_equal (location, cur_location))
+ {
+ GtkWidget *info_bar;
+
+ tab->priv->editable = 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);
+
+ g_object_unref (cur_location);
+ break;
+ }
+
+ if (cur_location != NULL)
+ {
+ g_object_unref (cur_location);
+ }
+ }
+ }
+
+ g_list_free (all_documents);
+ }
gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
+ if (location == NULL)
+ {
+ /* FIXME: hackish */
+ gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), TRUE);
+ }
+
+ tab->priv->ask_if_externally_modified = TRUE;
+
+ if (error == NULL)
+ {
+ g_clear_object (&tab->priv->loader);
+ g_clear_object (&tab->priv->cancellable);
+ tab->priv->load_create = FALSE;
+
+ g_signal_emit_by_name (doc, "loaded", NULL);
+ }
+
+end:
/* Async operation finished. */
g_object_unref (tab);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]