[gedit] Do not remove missing remote files from the recent list
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Do not remove missing remote files from the recent list
- Date: Sat, 12 Apr 2014 13:07:07 +0000 (UTC)
commit e2dac347ead4b675f1b9384dbccc5f8e1d15db87
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Apr 12 14:53:55 2014 +0200
Do not remove missing remote files from the recent list
Failure to load a remote file is often transient so we prefer
to keep such file in the recent list even if load/save fails.
While at it split recent file utils to a separate file: they were
in window because in the past access to the recent manager required
a reference to the current screen.
gedit/Makefile.am | 2 +
gedit/gedit-recent.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++
gedit/gedit-recent.h | 37 ++++++++++++++++++++
gedit/gedit-tab.c | 26 +++-----------
gedit/gedit-window.c | 54 +-----------------------------
gedit/gedit-window.h | 7 ----
6 files changed, 137 insertions(+), 79 deletions(-)
---
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index 2591fa6..71e19f2 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -118,6 +118,7 @@ gedit_NOINST_H_FILES = \
gedit/gedit-preferences-dialog.h \
gedit/gedit-print-job.h \
gedit/gedit-print-preview.h \
+ gedit/gedit-recent.h \
gedit/gedit-replace-dialog.h \
gedit/gedit-settings.h \
gedit/gedit-small-button.h \
@@ -195,6 +196,7 @@ gedit_libgedit_c_files = \
gedit/gedit-print-job.c \
gedit/gedit-print-preview.c \
gedit/gedit-progress-info-bar.c \
+ gedit/gedit-recent.c \
gedit/gedit-replace-dialog.c \
gedit/gedit-settings.c \
gedit/gedit-small-button.c \
diff --git a/gedit/gedit-recent.c b/gedit/gedit-recent.c
new file mode 100644
index 0000000..f94af21
--- /dev/null
+++ b/gedit/gedit-recent.c
@@ -0,0 +1,90 @@
+/*
+ * gedit-window.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2005 - Paolo Maggi
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtk/gtk.h>
+#include <gedit/gedit-document.h>
+#include "gedit-recent.h"
+
+void
+gedit_recent_add_document (GeditDocument *document)
+{
+ GtkRecentManager *recent_manager;
+ GtkRecentData *recent_data;
+ GFile *location;
+ gchar *uri;
+
+ g_return_if_fail (GEDIT_IS_DOCUMENT (document));
+
+ static gchar *groups[2] = {
+ "gedit",
+ NULL
+ };
+
+ location = gedit_document_get_location (document);
+ if (location != NULL)
+ {
+ recent_manager = gtk_recent_manager_get_default ();
+
+ recent_data = g_slice_new (GtkRecentData);
+
+ recent_data->display_name = NULL;
+ recent_data->description = NULL;
+ recent_data->mime_type = gedit_document_get_mime_type (document);
+ recent_data->app_name = (gchar *) g_get_application_name ();
+ recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
+ recent_data->groups = groups;
+ recent_data->is_private = FALSE;
+
+ uri = g_file_get_uri (location);
+ gtk_recent_manager_add_full (recent_manager,
+ uri,
+ recent_data);
+
+ g_free (uri);
+ g_free (recent_data->app_exec);
+ g_free (recent_data->mime_type);
+ g_slice_free (GtkRecentData, recent_data);
+ }
+}
+
+void
+gedit_recent_remove_if_local (GFile *location)
+{
+ g_return_if_fail (G_IS_FILE (location));
+
+ /* If a file is local chances are that if load/save fails the file has
+ * beed removed and the failure is permanent so we remove it from the
+ * list of recent files. For remote files the failure may be just
+ * transitory and we keep the file in the list.
+ */
+ if (g_file_has_uri_scheme (location, "file"))
+ {
+ GtkRecentManager *recent_manager;
+ gchar *uri;
+
+ recent_manager = gtk_recent_manager_get_default ();
+
+ uri = g_file_get_uri (location);
+ gtk_recent_manager_remove_item (recent_manager, uri, NULL);
+ g_free (uri);
+ }
+}
+
+/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-recent.h b/gedit/gedit-recent.h
new file mode 100644
index 0000000..4991e01
--- /dev/null
+++ b/gedit/gedit-recent.h
@@ -0,0 +1,37 @@
+/*
+ * gedit-window.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2005 - Paolo Maggi
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANWINDOWILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GEDIT_RECENT_H__
+#define __GEDIT_RECENT_H__
+
+#include <gtk/gtk.h>
+#include <gedit/gedit-document.h>
+
+G_BEGIN_DECLS
+
+void gedit_recent_add_document (GeditDocument *document);
+
+void gedit_recent_remove_if_local (GFile *location);
+
+G_END_DECLS
+
+#endif /* __GEDIT_RECENT_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 9de8535..71856dc 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -28,6 +28,7 @@
#include "gedit-app.h"
#include "gedit-notebook.h"
#include "gedit-tab.h"
+#include "gedit-recent.h"
#include "gedit-utils.h"
#include "gedit-io-error-info-bar.h"
#include "gedit-print-job.h"
@@ -623,7 +624,7 @@ io_loading_error_info_bar_response (GtkWidget *info_bar,
default:
if (location != NULL)
{
- _gedit_recent_remove (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET
(tab))), location);
+ gedit_recent_remove_if_local (location);
}
remove_tab (tab);
@@ -1024,7 +1025,7 @@ document_loaded (GeditDocument *document,
{
if (location)
{
- _gedit_recent_remove (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET
(tab))), location);
+ gedit_recent_remove_if_local (location);
}
if (tab->priv->state == GEDIT_TAB_STATE_LOADING_ERROR)
@@ -1064,16 +1065,7 @@ document_loaded (GeditDocument *document,
}
else
{
- if (location != NULL)
- {
- gchar *mime;
- mime = gedit_document_get_mime_type (document);
-
- _gedit_recent_add (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))),
- location,
- mime);
- g_free (mime);
- }
+ gedit_recent_add_document (document);
if (error &&
error->domain == GEDIT_DOCUMENT_ERROR &&
@@ -1476,8 +1468,7 @@ document_saved (GeditDocument *document,
error->code != G_IO_ERROR_PARTIAL_INPUT))
{
/* These errors are _NOT_ recoverable */
- _gedit_recent_remove (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))),
- tab->priv->tmp_save_location);
+ gedit_recent_remove_if_local (tab->priv->tmp_save_location);
emsg = gedit_unrecoverable_saving_error_info_bar_new (tab->priv->tmp_save_location,
error);
@@ -1513,12 +1504,7 @@ document_saved (GeditDocument *document,
}
else
{
- gchar *mime = gedit_document_get_mime_type (document);
-
- _gedit_recent_add (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))),
- tab->priv->tmp_save_location,
- mime);
- g_free (mime);
+ gedit_recent_add_document (document);
if (tab->priv->print_preview != NULL)
gedit_tab_set_state (tab, GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW);
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index c1fdcad..645b3a6 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -34,6 +34,7 @@
#include "gedit-window.h"
#include "gedit-window-private.h"
#include "gedit-app.h"
+#include "gedit-recent.h"
#include "gedit-notebook.h"
#include "gedit-notebook-popup-menu.h"
#include "gedit-multi-notebook.h"
@@ -701,57 +702,6 @@ set_sensitivity_according_to_tab (GeditWindow *window,
window);
}
-void
-_gedit_recent_add (GeditWindow *window,
- GFile *location,
- const gchar *mime)
-{
- GtkRecentManager *recent_manager;
- GtkRecentData *recent_data;
- gchar *uri;
-
- static gchar *groups[2] = {
- "gedit",
- NULL
- };
-
- recent_manager = gtk_recent_manager_get_default ();
-
- recent_data = g_slice_new (GtkRecentData);
-
- recent_data->display_name = NULL;
- recent_data->description = NULL;
- recent_data->mime_type = (gchar *) mime;
- recent_data->app_name = (gchar *) g_get_application_name ();
- recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
- recent_data->groups = groups;
- recent_data->is_private = FALSE;
-
- uri = g_file_get_uri (location);
- gtk_recent_manager_add_full (recent_manager,
- uri,
- recent_data);
-
- g_free (uri);
- g_free (recent_data->app_exec);
-
- g_slice_free (GtkRecentData, recent_data);
-}
-
-void
-_gedit_recent_remove (GeditWindow *window,
- GFile *location)
-{
- GtkRecentManager *recent_manager;
- gchar *uri;
-
- recent_manager = gtk_recent_manager_get_default ();
-
- uri = g_file_get_uri (location);
- gtk_recent_manager_remove_item (recent_manager, uri, NULL);
- g_free (uri);
-}
-
static void
recent_chooser_item_activated (GtkRecentChooser *chooser,
GeditWindow *window)
@@ -773,7 +723,7 @@ recent_chooser_item_activated (GtkRecentChooser *chooser,
if (!loaded || loaded->next) /* if it doesn't contain just 1 element */
{
- _gedit_recent_remove (window, location);
+ gedit_recent_remove_if_local (location);
}
g_slist_free (locations);
diff --git a/gedit/gedit-window.h b/gedit/gedit-window.h
index 5f8befb..1ea86da 100644
--- a/gedit/gedit-window.h
+++ b/gedit/gedit-window.h
@@ -166,13 +166,6 @@ GList *_gedit_window_get_all_tabs (GeditWindow *window);
GFile *_gedit_window_pop_last_closed_doc (GeditWindow *window);
-/* these are in gedit-window because of screen safety */
-void _gedit_recent_add (GeditWindow *window,
- GFile *location,
- const gchar *mime);
-void _gedit_recent_remove (GeditWindow *window,
- GFile *location);
-
G_END_DECLS
#endif /* __GEDIT_WINDOW_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]