[Xfce4-commits] r25404 - in mousepad/branches/nick_0_3: . mousepad
Nick Schermer
nick at xfce.org
Fri Apr 6 18:36:12 CEST 2007
Author: nick
Date: 2007-04-06 16:36:12 +0000 (Fri, 06 Apr 2007)
New Revision: 25404
Modified:
mousepad/branches/nick_0_3/ChangeLog
mousepad/branches/nick_0_3/mousepad/mousepad-document.c
mousepad/branches/nick_0_3/mousepad/mousepad-file.c
mousepad/branches/nick_0_3/mousepad/mousepad-window.c
Log:
* 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.
Modified: mousepad/branches/nick_0_3/ChangeLog
===================================================================
--- mousepad/branches/nick_0_3/ChangeLog 2007-04-06 15:50:49 UTC (rev 25403)
+++ mousepad/branches/nick_0_3/ChangeLog 2007-04-06 16:36:12 UTC (rev 25404)
@@ -1,4 +1,10 @@
2007-04-06 Nick Schermer <nick at 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 <nick at 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
Modified: mousepad/branches/nick_0_3/mousepad/mousepad-document.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-document.c 2007-04-06 15:50:49 UTC (rev 25403)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-document.c 2007-04-06 16:36:12 UTC (rev 25404)
@@ -70,9 +70,7 @@
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 @@
/* 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 @@
/* 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 @@
mousepad_document_get_tab_label (MousepadDocument *document)
{
GtkWidget *hbox;
- GtkWidget *ebox;
GtkWidget *button, *image;
/* create the box */
@@ -1042,21 +1043,19 @@
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 @@
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);
}
Modified: mousepad/branches/nick_0_3/mousepad/mousepad-file.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-file.c 2007-04-06 15:50:49 UTC (rev 25403)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-file.c 2007-04-06 16:36:12 UTC (rev 25404)
@@ -246,18 +246,16 @@
_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 @@
/* 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)
Modified: mousepad/branches/nick_0_3/mousepad/mousepad-window.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-window.c 2007-04-06 15:50:49 UTC (rev 25403)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-window.c 2007-04-06 16:36:12 UTC (rev 25404)
@@ -107,9 +107,6 @@
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 @@
/* 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 @@
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 @@
* 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_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_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 @@
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 @@
MousepadWindow *window)
{
const gchar *uri;
+ GError *error = NULL;
gchar *filename;
gboolean succeed = FALSE;
GtkRecentInfo *info;
@@ -1856,10 +1846,21 @@
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);
- /* update the recent history */
+ /* show the warning and cleanup */
+ mousepad_dialogs_show_error (GTK_WINDOW (window), error, _("Failed to open file"));
+ g_error_free (error);
+ }
+
+ /* 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 @@
/* 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 */
More information about the Xfce4-commits
mailing list