[Xfce4-commits] r26460 - in mousepad/branches/nick_0_3: . mousepad
Nick Schermer
nick at xfce.org
Wed Dec 12 10:29:50 CET 2007
Author: nick
Date: 2007-12-12 09:29:50 +0000 (Wed, 12 Dec 2007)
New Revision: 26460
Modified:
mousepad/branches/nick_0_3/ChangeLog
mousepad/branches/nick_0_3/mousepad/mousepad-window.c
Log:
* mousepad/mousepad-window.c: Try to find the file encoding in the
recent history, when opening a document that didn't pass the
UTF-8 check.
Modified: mousepad/branches/nick_0_3/ChangeLog
===================================================================
--- mousepad/branches/nick_0_3/ChangeLog 2007-12-11 22:14:12 UTC (rev 26459)
+++ mousepad/branches/nick_0_3/ChangeLog 2007-12-12 09:29:50 UTC (rev 26460)
@@ -1,3 +1,10 @@
+2007-12-12 Nick Schermer <nick at xfce.org>
+
+ * mousepad/mousepad-window.c: Try to find the file encoding in the
+ recent history, when opening a document that didn't pass the
+ UTF-8 check.
+
+
2007-12-10 Nick Schermer <nick at xfce.org>
* mousepad/mousepad-undo.c: Remove testing messages.
Modified: mousepad/branches/nick_0_3/mousepad/mousepad-window.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-window.c 2007-12-11 22:14:12 UTC (rev 26459)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-window.c 2007-12-12 09:29:50 UTC (rev 26460)
@@ -184,6 +184,7 @@
static gboolean mousepad_window_recent_menu_idle (gpointer user_data);
static void mousepad_window_recent_menu_idle_destroy (gpointer user_data);
static void mousepad_window_recent_menu (MousepadWindow *window);
+static const gchar *mousepad_window_recent_get_encoding (GtkRecentInfo *info);
static void mousepad_window_recent_clear (MousepadWindow *window);
/* dnd */
@@ -957,9 +958,12 @@
gboolean succeed = FALSE;
gint npages = 0, i;
gint response;
+ const gchar *opened_filename;
const gchar *new_encoding;
- const gchar *opened_filename;
GtkWidget *dialog;
+ gboolean encoding_from_recent = FALSE;
+ gchar *uri;
+ GtkRecentInfo *info;
_mousepad_return_val_if_fail (MOUSEPAD_IS_WINDOW (window), FALSE);
_mousepad_return_val_if_fail (filename != NULL && *filename != '\0', FALSE);
@@ -1023,6 +1027,43 @@
/* clear the error */
g_clear_error (&error);
+ /* try to lookup the encoding from the recent history */
+ if (encoding_from_recent == FALSE)
+ {
+ /* don't try this again */
+ encoding_from_recent = TRUE;
+
+ /* build uri */
+ uri = g_filename_to_uri (filename, NULL, NULL);
+ if (G_LIKELY (uri != NULL))
+ {
+ /* try to lookup the recent item */
+ info = gtk_recent_manager_lookup_item (window->recent_manager, uri, NULL);
+
+ /* cleanup */
+ g_free (uri);
+
+ if (info)
+ {
+ /* try to find the encoding */
+ new_encoding = mousepad_window_recent_get_encoding (info);
+
+ /* release */
+ gtk_recent_info_unref (info);
+
+ /* try again if the encoding looks usefull, else
+ * fall-trough and open encoding dialog */
+ if (G_LIKELY (new_encoding != NULL))
+ {
+ /* set encoding */
+ mousepad_file_set_encoding (document->file, new_encoding);
+
+ goto try_open_again;
+ }
+ }
+ }
+ }
+
/* run the encoding dialog */
dialog = mousepad_encoding_dialog_new (GTK_WINDOW (window), document->file);
@@ -1031,10 +1072,10 @@
if (response == GTK_RESPONSE_OK)
{
- /* get the selected encoding */
+ /* set the new encoding */
new_encoding = mousepad_encoding_dialog_get_encoding (MOUSEPAD_ENCODING_DIALOG (dialog));
- /* set the document encoding */
+ /* set encoding */
mousepad_file_set_encoding (document->file, new_encoding);
}
@@ -2475,6 +2516,30 @@
+static const gchar *
+mousepad_window_recent_get_encoding (GtkRecentInfo *info)
+{
+ const gchar *description;
+ const gchar *encoding = NULL;
+ gint offset;
+
+ /* get the description */
+ description = gtk_recent_info_get_description (info);
+ if (G_LIKELY (description))
+ {
+ /* get the offset length: 'Encoding: ' */
+ offset = strlen (_("Encoding")) + 2;
+
+ /* check if the encoding string looks valid, if so, set it */
+ if (G_LIKELY (strlen (description) > offset))
+ encoding = description + offset;
+ }
+
+ return encoding;
+}
+
+
+
static void
mousepad_window_recent_clear (MousepadWindow *window)
{
@@ -3169,10 +3234,9 @@
mousepad_window_action_open_recent (GtkAction *action,
MousepadWindow *window)
{
- const gchar *uri, *description;
- const gchar *encoding = NULL;
+ const gchar *uri;
+ const gchar *encoding;
GError *error = NULL;
- gint offset;
gchar *filename;
gboolean succeed = FALSE;
GtkRecentInfo *info;
@@ -3196,18 +3260,9 @@
/* open the file in a new tab if it exists */
if (g_file_test (filename, G_FILE_TEST_EXISTS))
{
- /* check if we set the encoding in the recent description */
- description = gtk_recent_info_get_description (info);
- if (G_LIKELY (description))
- {
- /* get the offset length */
- offset = strlen (_("Encoding")) + 2;
+ /* try to get the encoding from the recent description */
+ encoding = mousepad_window_recent_get_encoding (info);
- /* check if the encoding string looks valid and set it */
- if (G_LIKELY (strlen (description) > offset))
- encoding = description + offset;
- }
-
/* try to open the file */
succeed = mousepad_window_open_file (window, filename, encoding);
}
More information about the Xfce4-commits
mailing list