Updating branch refs/heads/master to 7b33a930bf6efc2c879dbb304e6ee0fd4adb2b5a (commit) from 46e78d17d7e5fc5ae16f9e9ee6ae8103e683af53 (commit)
commit 7b33a930bf6efc2c879dbb304e6ee0fd4adb2b5a Author: Nick Schermer <n...@xfce.org> Date: Fri Apr 6 16:36:12 2007 +0000 * mousepad/mousepad-window.c: Fix opening recent files that do not exist. * mousepad/mousepad-window.c, mousepad/mousepad-document.c: Update the window title correctly and remove the unused notify::title signals. (Old svn revision: 25404) ChangeLog | 6 +++++ mousepad/mousepad-document.c | 29 ++++++++++++--------------- mousepad/mousepad-file.c | 9 ++++--- mousepad/mousepad-window.c | 43 +++++++++++++++++++++-------------------- 4 files changed, 46 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3c70f4a..6102442 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ 2007-04-06 Nick Schermer <n...@xfce.org> + * mousepad/mousepad-window.c: Fix opening recent files that do not exist. + * mousepad/mousepad-window.c, mousepad/mousepad-document.c: Update the window + title correctly and remove the unused notify::title signals. + + +2007-04-06 Nick Schermer <n...@xfce.org> * mousepad/mousepad-document.c: Because we don't use invisible characters in the text buffer, I was able to write a custom iter search function that can search in both directions, can be case insensitive, no string duplications diff --git a/mousepad/mousepad-document.c b/mousepad/mousepad-document.c index 8310f09..f64d418 100644 --- a/mousepad/mousepad-document.c +++ b/mousepad/mousepad-document.c @@ -70,9 +70,7 @@ static gboolean mousepad_document_iter_search (const GtkTextIter GtkTextIter *match_end, const GtkTextIter *limit, gboolean forward_search); -static void mousepad_document_update_tab (MousepadDocument *document, - GParamSpec *pspec, - GtkWidget *ebox); +static void mousepad_document_update_tab (MousepadDocument *document); static void mousepad_document_tab_button_clicked (GtkWidget *widget, MousepadDocument *document); @@ -104,7 +102,8 @@ struct _MousepadDocument /* the highlight tag */ GtkTextTag *tag; - /* the tab label */ + /* the tab label and ebox */ + GtkWidget *ebox; GtkWidget *label; /* absolute path of the file */ @@ -472,6 +471,9 @@ mousepad_document_set_filename (MousepadDocument *document, /* create the new names */ document->filename = g_strdup (filename); document->display_name = g_filename_display_basename (filename); + + /* update the tab label and tooltip */ + mousepad_document_update_tab (document); } @@ -1034,7 +1036,6 @@ GtkWidget * mousepad_document_get_tab_label (MousepadDocument *document) { GtkWidget *hbox; - GtkWidget *ebox; GtkWidget *button, *image; /* create the box */ @@ -1042,21 +1043,19 @@ mousepad_document_get_tab_label (MousepadDocument *document) gtk_widget_show (hbox); /* the ebox */ - ebox = g_object_new (GTK_TYPE_EVENT_BOX, "border-width", 2, NULL); - gtk_box_pack_start (GTK_BOX (hbox), ebox, TRUE, TRUE, 0); - gtk_widget_show (ebox); + document->ebox = g_object_new (GTK_TYPE_EVENT_BOX, "border-width", 2, NULL); + gtk_box_pack_start (GTK_BOX (hbox), document->ebox, TRUE, TRUE, 0); + gtk_widget_show (document->ebox); /* create the label */ document->label = g_object_new (GTK_TYPE_LABEL, "selectable", FALSE, "xalign", 0.0, NULL); - gtk_container_add (GTK_CONTAINER (ebox), document->label); + gtk_container_add (GTK_CONTAINER (document->ebox), document->label); gtk_widget_show (document->label); /* update the tab and add signal to the ebox for a title update */ - mousepad_document_update_tab (document, NULL, ebox); - g_signal_connect (G_OBJECT (document), "notify::title", - G_CALLBACK (mousepad_document_update_tab), ebox); + mousepad_document_update_tab (document); /* create the button */ button = g_object_new (GTK_TYPE_BUTTON, @@ -1082,16 +1081,14 @@ mousepad_document_get_tab_label (MousepadDocument *document) static void -mousepad_document_update_tab (MousepadDocument *document, - GParamSpec *pspec, - GtkWidget *ebox) +mousepad_document_update_tab (MousepadDocument *document) { /* set the tab label */ gtk_label_set_text (GTK_LABEL (document->label), mousepad_document_get_title (document, FALSE)); /* set the tab tooltip */ - mousepad_gtk_set_tooltip (ebox, document->filename); + mousepad_gtk_set_tooltip (document->ebox, document->filename); } diff --git a/mousepad/mousepad-file.c b/mousepad/mousepad-file.c index e0d6a17..8dc18a6 100644 --- a/mousepad/mousepad-file.c +++ b/mousepad/mousepad-file.c @@ -246,18 +246,16 @@ mousepad_file_read_to_buffer (const gchar *filename, _mousepad_return_val_if_fail (error == NULL || *error == NULL, FALSE); _mousepad_return_val_if_fail (filename != NULL, FALSE); - /* get the start point in the buffer */ - gtk_text_buffer_get_start_iter (buffer, &start_iter); - /* open the file for reading */ fd = open (filename, O_RDONLY); if (G_UNLIKELY (fd < 0)) { - /* the file does not exists, so probably the user ran 'mousepad newfile' from the command line */ + /* the file does not exists, so probably the user ran 'mousepad <new-file-name>' from the command line */ if (G_LIKELY (errno == ENOENT)) { /* we can write the new file */ *readonly = FALSE; + return TRUE; } else @@ -283,6 +281,9 @@ mousepad_file_read_to_buffer (const gchar *filename, /* check if we're allowed to write the file */ *readonly = !((statb.st_mode & 00222) != 0 && access (filename, W_OK) == 0); + /* get the start point in the buffer */ + gtk_text_buffer_get_start_iter (buffer, &start_iter); + #ifdef HAVE_MMAP /* try mmap() for files not larger than 8MB */ content = (statb.st_size <= 8 * 1024 * 1024) diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c index b223468..8779309 100644 --- a/mousepad/mousepad-window.c +++ b/mousepad/mousepad-window.c @@ -107,9 +107,6 @@ static gboolean mousepad_window_tab_popup (GtkNotebo MousepadWindow *window); /* document signals */ -static void mousepad_window_notify_title (MousepadDocument *document, - GParamSpec *pspec, - MousepadWindow *window); static void mousepad_window_modified_changed (MousepadDocument *document, MousepadWindow *window); static void mousepad_window_cursor_changed (MousepadDocument *document, @@ -877,6 +874,9 @@ mousepad_window_save (MousepadWindow *window, /* set the filename */ mousepad_document_set_filename (document, new_filename); + /* update the window title */ + mousepad_window_set_title (window, document); + /* add the new document to the recent menu */ mousepad_window_recent_add (window, new_filename); @@ -953,7 +953,6 @@ mousepad_window_add (MousepadWindow *window, g_signal_connect (G_OBJECT (document), "modified-changed", G_CALLBACK (mousepad_window_modified_changed), window); g_signal_connect (G_OBJECT (document), "cursor-changed", G_CALLBACK (mousepad_window_cursor_changed), window); g_signal_connect (G_OBJECT (document), "overwrite-changed", G_CALLBACK (mousepad_window_overwrite_changed), window); - g_signal_connect (G_OBJECT (document), "notify::title", G_CALLBACK (mousepad_window_notify_title), window); /* insert the page right from the active tab */ page = gtk_notebook_get_current_page (GTK_NOTEBOOK (window->notebook)); @@ -1234,16 +1233,6 @@ mousepad_window_tab_popup (GtkNotebook *notebook, * Document Signals Functions **/ static void -mousepad_window_notify_title (MousepadDocument *document, - GParamSpec *pspec, - MousepadWindow *window) -{ - mousepad_window_set_title (window, document); -} - - - -static void mousepad_window_modified_changed (MousepadDocument *document, MousepadWindow *window) { @@ -1265,7 +1254,7 @@ mousepad_window_cursor_changed (MousepadDocument *document, _mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (document)); /* set the new statusbar position */ - if (G_LIKELY (window->statusbar)) + if (window->statusbar) mousepad_statusbar_set_cursor_position (MOUSEPAD_STATUSBAR (window->statusbar), line, column); } @@ -1280,7 +1269,7 @@ mousepad_window_overwrite_changed (MousepadDocument *document, _mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (document)); /* set the new overwrite mode in the statusbar */ - if (G_LIKELY (window->statusbar)) + if (window->statusbar) mousepad_statusbar_set_overwrite (MOUSEPAD_STATUSBAR (window->statusbar), overwrite); } @@ -1735,7 +1724,7 @@ mousepad_window_recent_clear (MousepadWindow *window) if (G_UNLIKELY (error != NULL)) { mousepad_dialogs_show_error (GTK_WINDOW (window), error, - _("Failed to remove an item from the recent history")); + _("Failed to remove an item from the document history")); g_error_free (error); } } @@ -1839,6 +1828,7 @@ mousepad_window_action_open_recent (GtkAction *action, MousepadWindow *window) { const gchar *uri; + GError *error = NULL; gchar *filename; gboolean succeed = FALSE; GtkRecentInfo *info; @@ -1856,10 +1846,21 @@ mousepad_window_action_open_recent (GtkAction *action, if (G_LIKELY (filename != NULL)) { - /* open a new tab */ - succeed = mousepad_window_open_tab (window, filename); + /* open the file in a new tab if it exists */ + if (g_file_test (filename, G_FILE_TEST_EXISTS)) + succeed = mousepad_window_open_tab (window, filename); + else + { + /* create a warning */ + g_set_error (&error, G_FILE_ERROR, G_FILE_ERROR_IO, + _("Failed to open \"%s\" for reading. It will be removed from the document history"), filename); + + /* show the warning and cleanup */ + mousepad_dialogs_show_error (GTK_WINDOW (window), error, _("Failed to open file")); + g_error_free (error); + } - /* update the recent history */ + /* update the document history */ if (G_LIKELY (succeed)) /* update the recent manager count and time */ gtk_recent_manager_add_item (window->recent_manager, uri); @@ -1885,7 +1886,7 @@ mousepad_window_action_clear_recent (GtkAction *action, /* avoid updating the menu */ lock_menu_updates = TRUE; - /* clear the recent history */ + /* clear the document history */ mousepad_window_recent_clear (window); /* allow menu updates again */ _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits