[Xfce4-commits] <mousepad:master> * TODO: Update * mousepad/mousepad-{dialogs, window, file}.c: Check for external file modifications before saving. * ChangeLog: Update. * configure.in.in: Remove api version and add support for a nano version.

Nick Schermer noreply at xfce.org
Sat May 5 21:31:12 CEST 2012


Updating branch refs/heads/master
         to 35ea349ad0c4ee3557c3c28bb7b5c30cb9fdfe22 (commit)
       from 2709fd15751d4197f8c260989b7069473dfae65f (commit)

commit 35ea349ad0c4ee3557c3c28bb7b5c30cb9fdfe22
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Jan 15 10:34:47 2008 +0000

    * TODO: Update
    * mousepad/mousepad-{dialogs,window,file}.c: Check for external
      file modifications before saving.
    * ChangeLog: Update.
    * configure.in.in: Remove api version and add support for a nano
      version.
    
    
    (Old svn revision: 26572)

 ChangeLog                   |   33 ++++++++++++
 TODO                        |   37 ++-----------
 configure.in.in             |   10 ++--
 mousepad/mousepad-dialogs.c |   31 +++++++++++-
 mousepad/mousepad-dialogs.h |   36 +++++++------
 mousepad/mousepad-file.c    |   18 ++++--
 mousepad/mousepad-window.c  |  118 +++++++++++++++++++++++++++++-------------
 7 files changed, 186 insertions(+), 97 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9ecd7a6..88a5ec0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2008-01-15	Nick Schermer <nick at xfce.org>
+
+	* TODO: Update
+	* mousepad/mousepad-{dialogs,window,file}.c: Check for external
+	  file modifications before saving.
+	* ChangeLog: Update.
+	* configure.in.in: Remove api version and add support for a nano
+	  version.
+
+
+2008-01-14	Nick Schermer <nick at xfce.org>
+
+	* configure.in.in, mousepad/mousepad-{preferences,print,window}.c,
+	  mousepad/main.c: Drop libxfce4util as a dependency by using
+	  GKeyFile. Binary size increased with only 1K and most likely more
+	  people will use Mousepad when it's a Gtk+ only application.
+	* mousepad/mousepad-{window,dialogs}.c, Mousepad.desktop.in.in: Use
+	  accessories-text-editor as icon name.
+	* icons/{16x16,24x24,scalable}/Makefile.am: Install symlinks from
+	  Mousepad.{png,svg} to ccessories-text-editor.{png,svg}.
+
+
+2008-01-14	Nick Schermer <nick at xfce.org>
+
+	* mousepad/mousepad-*.c: Use G_DEFINE_TYPE for initializing objects.
+	* mousepad/mousepad-*.c: Properly set the emission stage for
+	  all signals.
+	* mousepad/mousepad-*: Cleanup some unneeded code.
+	* mousepad/mousepad-window.c: Fix assert when dropping a file in
+	  the editor window.
+	* mousepad/mousepad-window.c: Fix 2 small typos in the menu tooltips.
+
+
 2007-12-12	Nick Schermer <nick at xfce.org>
 
 	* mousepad/mousepad-window.c: Try to find the file encoding in the
diff --git a/TODO b/TODO
index db96516..8c8887f 100644
--- a/TODO
+++ b/TODO
@@ -3,41 +3,23 @@ be fixed (or ignored when irrelevant) before the nick_0_3 branch
 can move to trunk. When the branch enters trunk, it's important
 we work towards a stable version, so we can release a 0.2.90.1
 (0.3 beta 1) version as soon as possible (if needed, independent
-from the Xfce schedule).
+from the Xfce release schedule).
 
 
 Interface
 =========
-- Tab font color when the file is modified or read only.
 - Test the application with a screen reader and add Atk objects
   where needed.
-- Cleanup the menus and make them consistent. For example: we're
-  using both file and document atm. The name of the Go menu should
-  also be changed to something more descriptive.
-- Make the mnemonic's consistent all over the application and make
-  sure they don't conflict inside a dialog/window.
 - Check the search and replace code for bugs.
 - Add option to disable the search feedback in the replace dialog
   (highlight, count matches, type-ahead). This can slow down mousepad
-  with large text files.
-
-
-Undo
-====
-- Need to fix a couple of issues here. I'm not really satisfied with
-  it right now.
-
-
-Code
-====
-- Check for code duplication and make sure the comments are worth
-  reading.
+  with (multiple) large documents.
+- Transpose words works a bit odd sometimes.
+- Improve replace (all) in selection.
 
 
 Saving and loading
 ==================
-- Save All option.
-- Check if the file is externally modified when switching tabs.
 - Cleanup and improve encoding support and order the encoding types.
 
 
@@ -45,23 +27,16 @@ Other
 =====
 - We need a cool Mousepad logo.
 - Write documentation.
-- Session manager support.
+- Session manager support (waiting for Gtk+ here).
 
 
 Testing and polishing
 =====================
-- Profiling the startup time. We can possibly use Frederico's trick
-  to optimize the startup time:
-  http://primates.ximian.com/~federico/news-2006-03.html#09
 - Profiling loading large files (Gtk/Pango has a problem here). This
   also locks some dialogs.
 - Checking for memory leaks.
-- Make sure objects are unrefed when their parent is destroyed, Gtk+
-  does not always take care of this.
 
 
 Feature
 =======
-- Maybe a plugin based system for syntax highlighting and GtkSpell.
-  We cannot use GtkSourceView with this implementation, because it
-  cannot attach to an existing textview (GtkSpell can).
+- You'll never know. No promisses here...
diff --git a/configure.in.in b/configure.in.in
index 74c44a5..3169336 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -3,13 +3,13 @@ dnl $Id$
 dnl ***************************
 dnl *** Version information ***
 dnl ***************************
-m4_define([mousepad_version_api], [1])
 m4_define([mousepad_version_major], [0])
 m4_define([mousepad_version_minor], [3])
 m4_define([mousepad_version_micro], [0])
+m4_define([mousepad_version_nano], [])
 m4_define([mousepad_version_build], [r at REVISION@])
 m4_define([mousepad_version_tag], [svn])
-m4_define([mousepad_version], [mousepad_version_major().mousepad_version_minor().mousepad_version_micro()ifelse(mousepad_version_tag(), [svn], [mousepad_version_tag()-mousepad_version_build()], [mousepad_version_tag()])])
+m4_define([mousepad_version], [mousepad_version_major().mousepad_version_minor().mousepad_version_micro()ifelse(mousepad_version_nano(), [], [], [.mousepad_version_nano()])ifelse(mousepad_version_tag(), [svn], [mousepad_version_tag()-mousepad_version_build()], [])])
 
 dnl *******************************************
 dnl *** Debugging support for SVN snapshots ***
@@ -19,7 +19,7 @@ m4_define([mousepad_debug_default], [ifelse(mousepad_version_tag(), [svn], [yes]
 dnl ***************************
 dnl *** Initialize autoconf ***
 dnl ***************************
-AC_COPYRIGHT([Copyright (c) 2007
+AC_COPYRIGHT([Copyright (c) 2007-2008
         The Xfce development team. All rights reserved.])
 AC_INIT([Mousepad], [mousepad_version], [http://bugzilla.xfce.org/], [mousepad])
 AC_PREREQ([2.50])
@@ -57,14 +57,14 @@ AC_PROG_LIBTOOL()
 dnl **************************************
 dnl *** Substitute version information ***
 dnl **************************************
-MOUSEPAD_VERSION_API=mousepad_version_api()
 MOUSEPAD_VERSION_MAJOR=mousepad_version_major()
 MOUSEPAD_VERSION_MINOR=mousepad_version_minor()
 MOUSEPAD_VERSION_MICRO=mousepad_version_micro()
-AC_SUBST([MOUSEPAD_VERSION_API])
+MOUSEPAD_VERSION_NANO=mousepad_version_nano()
 AC_SUBST([MOUSEPAD_VERSION_MAJOR])
 AC_SUBST([MOUSEPAD_VERSION_MINOR])
 AC_SUBST([MOUSEPAD_VERSION_MICRO])
+AC_SUBST([MOUSEPAD_VERSION_NANO])
 
 dnl **********************************
 dnl *** Check for standard headers ***
diff --git a/mousepad/mousepad-dialogs.c b/mousepad/mousepad-dialogs.c
index 498b613..faa0c00 100644
--- a/mousepad/mousepad-dialogs.c
+++ b/mousepad/mousepad-dialogs.c
@@ -362,7 +362,7 @@ mousepad_dialogs_save_changes (GtkWindow *parent,
                                    _("Do you want to save the changes before closing?"));
   gtk_window_set_title (GTK_WINDOW (dialog), _("Save Changes"));
   gtk_dialog_add_action_widget (GTK_DIALOG (dialog), mousepad_util_image_button (GTK_STOCK_DELETE, _("_Don't Save")), MOUSEPAD_RESPONSE_DONT_SAVE);
-  gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, MOUSEPAD_RESPONSE_CANCEL, NULL);
+  gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, MOUSEPAD_RESPONSE_CANCEL);
 
   /* we show the save as button instead of save for readonly document */
   if (G_UNLIKELY (readonly))
@@ -397,6 +397,35 @@ mousepad_dialogs_save_changes (GtkWindow *parent,
 
 
 gint
+mousepad_dialogs_externally_modified (GtkWindow *parent)
+{
+  GtkWidget *dialog;
+  gint       response;
+
+  /* create the question dialog */
+  dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                   GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
+                                   _("The document has been externally modified. Do you want to continue saving?"));
+  gtk_window_set_title (GTK_WINDOW (dialog), _("Externally Modified"));
+  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("If you don't save the document, all the external changes will be lost."));
+  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                          GTK_STOCK_CANCEL, MOUSEPAD_RESPONSE_CANCEL,
+                          GTK_STOCK_SAVE_AS, MOUSEPAD_RESPONSE_SAVE_AS,
+                          GTK_STOCK_SAVE, MOUSEPAD_RESPONSE_SAVE, NULL);
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), MOUSEPAD_RESPONSE_CANCEL);
+
+  /* run the dialog */
+  response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+  /* destroy the dialog */
+  gtk_widget_destroy (dialog);
+
+  return response;
+}
+
+
+
+gint
 mousepad_dialogs_revert (GtkWindow *parent)
 {
   GtkWidget *dialog;
diff --git a/mousepad/mousepad-dialogs.h b/mousepad/mousepad-dialogs.h
index de24257..c97820f 100644
--- a/mousepad/mousepad-dialogs.h
+++ b/mousepad/mousepad-dialogs.h
@@ -37,31 +37,33 @@ enum {
   MOUSEPAD_RESPONSE_CHECK_ENTRY
 };
 
-GtkWidget *mousepad_dialogs_image_button   (const gchar   *stock_id,
-                                            const gchar   *label);
+GtkWidget *mousepad_dialogs_image_button        (const gchar   *stock_id,
+                                                 const gchar   *label);
 
-void       mousepad_dialogs_show_about     (GtkWindow     *parent);
+void       mousepad_dialogs_show_about          (GtkWindow     *parent);
 
-void       mousepad_dialogs_show_error     (GtkWindow     *parent,
-                                            const GError  *error,
-                                            const gchar   *message);
+void       mousepad_dialogs_show_error          (GtkWindow     *parent,
+                                                 const GError  *error,
+                                                 const gchar   *message);
 
-void       mousepad_dialogs_show_help      (GtkWindow     *parent,
-                                            const gchar   *page,
-                                            const gchar   *offset);
+void       mousepad_dialogs_show_help           (GtkWindow     *parent,
+                                                 const gchar   *page,
+                                                 const gchar   *offset);
 
-gint       mousepad_dialogs_other_tab_size (GtkWindow     *parent,
-                                            gint           active_size);
+gint       mousepad_dialogs_other_tab_size      (GtkWindow     *parent,
+                                                 gint           active_size);
 
-gboolean   mousepad_dialogs_go_to          (GtkWindow     *parent,
-                                            GtkTextBuffer *buffer;);
+gboolean   mousepad_dialogs_go_to               (GtkWindow     *parent,
+                                                 GtkTextBuffer *buffer;);
 
-gboolean   mousepad_dialogs_clear_recent   (GtkWindow     *parent);
+gboolean   mousepad_dialogs_clear_recent        (GtkWindow     *parent);
 
-gint       mousepad_dialogs_save_changes   (GtkWindow     *parent,
-                                            gboolean       readonly);
+gint       mousepad_dialogs_save_changes        (GtkWindow     *parent,
+                                                 gboolean       readonly);
 
-gint       mousepad_dialogs_revert         (GtkWindow     *parent);
+gint       mousepad_dialogs_externally_modified (GtkWindow     *parent);
+
+gint       mousepad_dialogs_revert              (GtkWindow     *parent);
 
 G_END_DECLS
 
diff --git a/mousepad/mousepad-file.c b/mousepad/mousepad-file.c
index 64ceb3c..d023d2e 100644
--- a/mousepad/mousepad-file.c
+++ b/mousepad/mousepad-file.c
@@ -369,9 +369,15 @@ mousepad_file_open (MousepadFile  *file,
       /* set the cursor to the beginning of the document */
       gtk_text_buffer_place_cursor (file->buffer, &start);
 
-      /* check if we're allowed to write to the file */
-      if (G_LIKELY (g_lstat (file->filename, &statb) == 0) && access (file->filename, W_OK) == 0)
-        file->readonly = !((statb.st_mode & 00222) != 0);
+      /* get file status */
+      if (G_LIKELY (g_lstat (file->filename, &statb) == 0));
+        {
+          /* store the readonly mode */
+          file->readonly = !((statb.st_mode & S_IWUSR) != 0);
+
+          /* store the file modification time */
+          file->mtime = statb.st_mtime;
+        }
 
       failed:
 
@@ -543,10 +549,10 @@ mousepad_file_get_externally_modified (MousepadFile  *file,
                                        GError       **error)
 {
   struct stat statb;
-  gboolean    modified = FALSE;
+  gboolean    modified = TRUE;
 
   _mousepad_return_val_if_fail (MOUSEPAD_IS_FILE (file), FALSE);
-  _mousepad_return_val_if_fail (file->filename == NULL, FALSE);
+  _mousepad_return_val_if_fail (file->filename != NULL, FALSE);
   _mousepad_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
   if (G_LIKELY (g_lstat (file->filename, &statb) == 0))
@@ -554,7 +560,7 @@ mousepad_file_get_externally_modified (MousepadFile  *file,
       /* check if our modification time differs from the current one */
       modified = (file->mtime > 0 && statb.st_mtime != file->mtime);
     }
-  else
+  else if (error != NULL)
     {
       /* failed to stat the file */
       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index f6ceaf7..debca09 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -3302,6 +3302,8 @@ mousepad_window_action_save (GtkAction      *action,
   MousepadDocument *document = window->active;
   GError           *error = NULL;
   gboolean          succeed = FALSE;
+  gboolean          modified;
+  gint              response;
 
   _mousepad_return_val_if_fail (MOUSEPAD_IS_WINDOW (window), FALSE);
   _mousepad_return_val_if_fail (MOUSEPAD_IS_DOCUMENT (window->active), FALSE);
@@ -3309,23 +3311,55 @@ mousepad_window_action_save (GtkAction      *action,
   if (mousepad_file_get_filename (document->file) == NULL)
     {
       /* file has no filename yet, open the save as dialog */
-      mousepad_window_action_save_as (NULL, window);
+      succeed = mousepad_window_action_save_as (NULL, window);
     }
   else
     {
-      /* save the document */
-      succeed = mousepad_file_save (document->file, &error);
+      /* check whether the file is externally modified */
+      modified = mousepad_file_get_externally_modified (document->file, &error);
+      if (G_UNLIKELY (error != NULL))
+        goto showerror;
 
-      /* update the window title */
-      mousepad_window_set_title (window);
+      if (modified)
+        {
+          /* ask the user what to do */
+          response = mousepad_dialogs_externally_modified (GTK_WINDOW (window));
+        }
+      else
+        {
+          /* save */
+          response = MOUSEPAD_RESPONSE_SAVE;
+        }
+
+      switch (response)
+        {
+          case MOUSEPAD_RESPONSE_CANCEL:
+            /* do nothing */
+            return FALSE;
+
+          case MOUSEPAD_RESPONSE_SAVE_AS:
+            /* run save as dialog */
+            succeed = mousepad_window_action_save_as (NULL, window);
+            break;
+
+          case MOUSEPAD_RESPONSE_SAVE:
+            /* save the document */
+            succeed = mousepad_file_save (document->file, &error);
+            break;
+        }
 
       if (G_LIKELY (succeed))
         {
+          /* update the window title */
+          mousepad_window_set_title (window);
+
           /* store the save state in the undo manager */
           mousepad_undo_save_point (document->undo);
         }
-      else
+      else if (error != NULL)
         {
+          showerror:
+
           /* show the error */
           mousepad_dialogs_show_error (GTK_WINDOW (window), error, _("Failed to save the document"));
           g_error_free (error);
@@ -3399,12 +3433,12 @@ static void
 mousepad_window_action_save_all (GtkAction      *action,
                                  MousepadWindow *window)
 {
-  guint      i, current;
-  gint       page_num;
-  GtkWidget *document;
-  GSList    *li, *unnamed = NULL;
-  gboolean   succeed = TRUE;
-  GError    *error = NULL;
+  guint             i, current;
+  gint              page_num;
+  MousepadDocument *document;
+  GSList           *li, *documents = NULL;
+  gboolean          succeed = TRUE;
+  GError           *error = NULL;
 
   _mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
   _mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
@@ -3416,36 +3450,33 @@ mousepad_window_action_save_all (GtkAction      *action,
   for (i = 0; i < gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook)); i++)
     {
       /* get the document */
-      document = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), i);
+      document = MOUSEPAD_DOCUMENT (gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), i));
 
       /* debug check */
       _mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (document));
 
       /* continue if the document is not modified */
-      if (!gtk_text_buffer_get_modified (MOUSEPAD_DOCUMENT (document)->buffer))
+      if (!gtk_text_buffer_get_modified (document->buffer))
         continue;
 
-      if (mousepad_file_get_filename (MOUSEPAD_DOCUMENT (document)->file) == NULL ||
-          mousepad_file_get_read_only ((MOUSEPAD_DOCUMENT (document)->file)))
-        {
-          /* add the document to a queue to bother the user later */
-          unnamed = g_slist_prepend (unnamed, document);
-        }
-      else
+      /* we try to quickly save files, without bothering the user */
+      if (mousepad_file_get_filename (document->file) != NULL
+          && mousepad_file_get_read_only (document->file) == FALSE
+          && mousepad_file_get_externally_modified (document->file, NULL) == FALSE)
         {
-          /* try to save the file */
-          succeed = mousepad_file_save (MOUSEPAD_DOCUMENT (document)->file, &error);
+          /* try to quickly save the file */
+          succeed = mousepad_file_save (document->file, &error);
 
+          /* store save state, break on problems */
           if (G_LIKELY (succeed))
-            {
-              /* store save state */
-              mousepad_undo_save_point (MOUSEPAD_DOCUMENT (document)->undo);
-            }
+            mousepad_undo_save_point (document->undo);
           else
-            {
-              /* break on problems */
-              break;
-            }
+            break;
+        }
+      else
+        {
+          /* add the document to a queue to bother the user later */
+          documents = g_slist_prepend (documents, document);
         }
     }
 
@@ -3456,13 +3487,18 @@ mousepad_window_action_save_all (GtkAction      *action,
 
       /* show the error */
       mousepad_dialogs_show_error (GTK_WINDOW (window), error, _("Failed to save the document"));
-      g_error_free (error);
+
+      /* free error */
+      if (error != NULL)
+        g_error_free (error);
     }
   else
     {
       /* open a save as dialog for all the unnamed files */
-      for (li = unnamed; li != NULL; li = li->next)
+      for (li = documents; li != NULL; li = li->next)
         {
+          document = MOUSEPAD_DOCUMENT (li->data);
+
           /* get the documents page number */
           page_num = gtk_notebook_page_num (GTK_NOTEBOOK (window->notebook), GTK_WIDGET (li->data));
 
@@ -3471,9 +3507,17 @@ mousepad_window_action_save_all (GtkAction      *action,
               /* focus the tab we're going to save */
               gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), page_num);
 
-              /* trigger the save as function, break when something went wrong */
-              if (!mousepad_window_action_save_as (NULL, window))
-                break;
+              if (mousepad_file_get_filename (document->file) == NULL
+                  || mousepad_file_get_read_only (document->file))
+                {
+                  /* trigger the save as function */
+                  mousepad_window_action_save_as (NULL, window);
+                }
+              else
+                {
+                  /* trigger the save function (externally modified document) */
+                  mousepad_window_action_save (NULL, window);
+                }
             }
         }
 
@@ -3483,7 +3527,7 @@ mousepad_window_action_save_all (GtkAction      *action,
     }
 
   /* cleanup */
-  g_slist_free (unnamed);
+  g_slist_free (documents);
 }
 
 


More information about the Xfce4-commits mailing list