[Xfce4-commits] <mousepad:master> * mousepad/mousepad-view.c: Respect input methods and don't insert text when the textview is not editable. * mousepad/mousepad-{file, document, window}.c: Properly handle read-only files. A file is now always readonly unless proven otherwise.

Nick Schermer noreply at xfce.org
Sat May 5 21:30:48 CEST 2012


Updating branch refs/heads/master
         to 1f30cae6c6774f25728d5c7254e772281762abd6 (commit)
       from b01842db991e385a4a2373da1eaac1191197d9af (commit)

commit 1f30cae6c6774f25728d5c7254e772281762abd6
Author: Nick Schermer <nick at xfce.org>
Date:   Thu Oct 18 09:47:52 2007 +0000

    * mousepad/mousepad-view.c: Respect input methods and don't insert
      text when the textview is not editable.
    * mousepad/mousepad-{file,document,window}.c: Properly handle
      read-only files. A file is now always readonly unless proven
      otherwise.
    
    
    (Old svn revision: 26145)

 ChangeLog                    |    8 +++++++
 mousepad/mousepad-document.c |   11 ----------
 mousepad/mousepad-document.h |    2 -
 mousepad/mousepad-file.c     |   12 ++++++++++-
 mousepad/mousepad-file.h     |    2 +
 mousepad/mousepad-view.c     |   44 ++++++++++++++++++++++++++---------------
 mousepad/mousepad-window.c   |   25 +++++++++++++----------
 mousepad/mousepad-window.h   |    4 ---
 8 files changed, 63 insertions(+), 45 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9ea6287..88904b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,12 @@
 2007-10-18	Nick Schermer <nick at xfce.org>
+	* mousepad/mousepad-view.c: Respect input methods and don't insert
+	  text when the textview is not editable.
+	* mousepad/mousepad-{file,document,window}.c: Properly handle
+	  read-only files. A file is now always readonly unless proven
+	  otherwise.
+
+
+2007-10-18	Nick Schermer <nick at xfce.org>
 	* mousepad/mousepad-utils.{c,h}: Add iter function to move the iter
 	  in front of text. Code used from one of the indentation functions.
 	* mousepad/mousepad-view.c: Add code for a smart home button: when
diff --git a/mousepad/mousepad-document.c b/mousepad/mousepad-document.c
index 782568a..6104dda 100644
--- a/mousepad/mousepad-document.c
+++ b/mousepad/mousepad-document.c
@@ -525,17 +525,6 @@ mousepad_document_line_numbers (MousepadDocument *document,
 
 
 
-gboolean
-mousepad_document_get_readonly (MousepadDocument *document)
-{
-  _mousepad_return_val_if_fail (MOUSEPAD_IS_DOCUMENT (document), FALSE);
-  _mousepad_return_val_if_fail (GTK_IS_TEXT_VIEW (document->textview), FALSE);
-
-  return !gtk_text_view_get_editable (GTK_TEXT_VIEW (document->textview));
-}
-
-
-
 GtkWidget *
 mousepad_document_get_tab_label (MousepadDocument *document)
 {
diff --git a/mousepad/mousepad-document.h b/mousepad/mousepad-document.h
index d9af13d..550cab1 100644
--- a/mousepad/mousepad-document.h
+++ b/mousepad/mousepad-document.h
@@ -85,8 +85,6 @@ void              mousepad_document_line_numbers             (MousepadDocument
                                                               gint                  *current_line,
                                                               gint                  *last_line);
 
-gboolean          mousepad_document_get_readonly             (MousepadDocument      *document);
-
 GtkWidget        *mousepad_document_get_tab_label            (MousepadDocument      *document);
 
 const gchar      *mousepad_document_get_basename             (MousepadDocument      *document);
diff --git a/mousepad/mousepad-file.c b/mousepad/mousepad-file.c
index 1388985..a02e28e 100644
--- a/mousepad/mousepad-file.c
+++ b/mousepad/mousepad-file.c
@@ -142,7 +142,7 @@ mousepad_file_init (MousepadFile *file)
   file->filename    = NULL;
   file->encoding    = NULL;
   file->line_ending = MOUSEPAD_LINE_END_NONE;
-  file->readonly    = FALSE;
+  file->readonly    = TRUE;
   file->mtime       = 0;
 }
 
@@ -245,6 +245,16 @@ mousepad_file_get_encoding (MousepadFile *file)
 
 
 
+gboolean
+mousepad_file_get_read_only (MousepadFile *file)
+{
+  _mousepad_return_val_if_fail (MOUSEPAD_IS_FILE (file), FALSE);
+
+  return file->filename ? file->readonly : FALSE;
+}
+
+
+
 void
 mousepad_file_set_line_ending (MousepadFile       *file,
                                MousepadLineEnding  line_ending)
diff --git a/mousepad/mousepad-file.h b/mousepad/mousepad-file.h
index d76ac4a..034216c 100644
--- a/mousepad/mousepad-file.h
+++ b/mousepad/mousepad-file.h
@@ -55,6 +55,8 @@ void                mousepad_file_set_encoding             (MousepadFile
 
 const gchar        *mousepad_file_get_encoding             (MousepadFile        *file);
 
+gboolean            mousepad_file_get_read_only            (MousepadFile        *file);
+
 void                mousepad_file_set_line_ending          (MousepadFile        *file,
                                                             MousepadLineEnding   line_ending);
 
diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c
index 5b79429..42d64da 100644
--- a/mousepad/mousepad-view.c
+++ b/mousepad/mousepad-view.c
@@ -342,6 +342,8 @@ mousepad_view_key_press_event (GtkWidget   *widget,
   GtkTextMark   *cursor;
   guint          modifiers;
   gchar         *string;
+  gboolean       im_handled;
+  gboolean       is_editable;
 
   /* get the modifiers state */
   modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
@@ -349,12 +351,15 @@ mousepad_view_key_press_event (GtkWidget   *widget,
   /* get the textview buffer */
   buffer = mousepad_view_get_buffer (view);
 
+  /* whether the textview is editable */
+  is_editable = GTK_TEXT_VIEW (view)->editable;
+
   /* handle the key event */
   switch (event->keyval)
     {
       case GDK_Return:
       case GDK_KP_Enter:
-        if (!(event->state & GDK_SHIFT_MASK) && view->auto_indent)
+        if (!(event->state & GDK_SHIFT_MASK) && view->auto_indent && is_editable)
           {
             /* get the iter position of the cursor */
             cursor = gtk_text_buffer_get_insert (buffer);
@@ -365,24 +370,31 @@ mousepad_view_key_press_event (GtkWidget   *widget,
 
             if (string != NULL)
               {
-                /* begin a user action */
-                gtk_text_buffer_begin_user_action (buffer);
+                /* check if the input method emitted this event */
+                im_handled = gtk_im_context_filter_keypress (GTK_TEXT_VIEW (view)->im_context, event);
+
+                /* check if we're allowed to handle this event */
+                if (G_LIKELY (im_handled == FALSE))
+                  {
+                    /* begin a user action */
+                    gtk_text_buffer_begin_user_action (buffer);
 
-                /* insert the indent characters */
-                gtk_text_buffer_insert (buffer, &iter, "\n", 1);
-                gtk_text_buffer_insert (buffer, &iter, string, -1);
+                    /* insert the indent characters */
+                    gtk_text_buffer_insert (buffer, &iter, "\n", 1);
+                    gtk_text_buffer_insert (buffer, &iter, string, -1);
 
-                /* end user action */
-                gtk_text_buffer_end_user_action (buffer);
+                    /* end user action */
+                    gtk_text_buffer_end_user_action (buffer);
+
+                    /* make sure the new string is visible for the user */
+                    mousepad_view_put_cursor_on_screen (view);
+                  }
 
                 /* cleanup */
                 g_free (string);
 
-                /* make sure the new string is visible for the user */
-                mousepad_view_put_cursor_on_screen (view);
-
-                /* we've inserted the new line, nothing to do for gtk */
-                return TRUE;
+                /* return */
+                return (im_handled == FALSE);
               }
           }
         break;
@@ -441,14 +453,14 @@ mousepad_view_key_press_event (GtkWidget   *widget,
       case GDK_Tab:
       case GDK_KP_Tab:
       case GDK_ISO_Left_Tab:
-        if (mousepad_view_get_has_selection (view))
+        if (mousepad_view_get_has_selection (view) && is_editable)
           {
             /* indent the selection */
             mousepad_view_indent_selection (view, (modifiers != GDK_SHIFT_MASK), TRUE);
 
             return TRUE;
           }
-        else if (view->insert_spaces)
+        else if (view->insert_spaces && is_editable)
           {
             /* get the iter position of the cursor */
             cursor = gtk_text_buffer_get_insert (buffer);
@@ -463,7 +475,7 @@ mousepad_view_key_press_event (GtkWidget   *widget,
       case GDK_BackSpace:
       case GDK_space:
         /* indent on Space unindent on Backspace or Tab */
-        if (modifiers == GDK_SHIFT_MASK && mousepad_view_get_has_selection (view))
+        if (modifiers == GDK_SHIFT_MASK && mousepad_view_get_has_selection (view) && is_editable)
           {
             /* indent the selection */
             mousepad_view_indent_selection (view, (event->keyval == GDK_space), FALSE);
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 72a3ee2..c943a3a 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -92,6 +92,9 @@ static gboolean          mousepad_window_save_geometry_timer          (gpointer
 static void              mousepad_window_save_geometry_timer_destroy  (gpointer                user_data);
 
 /* window functions */
+static gboolean          mousepad_window_open_file                    (MousepadWindow         *window,
+                                                                       const gchar            *filename,
+                                                                       const gchar            *encoding);
 static gboolean          mousepad_window_close_document               (MousepadWindow         *window,
                                                                        MousepadDocument       *document);
 static void              mousepad_window_set_title                    (MousepadWindow         *window);
@@ -815,10 +818,10 @@ mousepad_window_save_geometry_timer_destroy (gpointer user_data)
 /**
  * Mousepad Window Functions
  **/
-gboolean
-mousepad_window_open_tab (MousepadWindow *window,
-                          const gchar    *filename,
-                          const gchar    *encoding)
+static gboolean
+mousepad_window_open_file (MousepadWindow *window,
+                           const gchar    *filename,
+                           const gchar    *encoding)
 {
   MousepadDocument *document;
   GError           *error = NULL;
@@ -974,7 +977,7 @@ mousepad_window_open_files (MousepadWindow  *window,
         }
 
       /* open a new tab with the file */
-      mousepad_window_open_tab (window, filename ? filename : filenames[n], NULL);
+      mousepad_window_open_file (window, filename ? filename : filenames[n], NULL);
 
       /* cleanup */
       g_free (filename);
@@ -1113,7 +1116,7 @@ mousepad_window_set_title (MousepadWindow *window)
     title = mousepad_document_get_basename (document);
 
   /* build the title */
-  if (G_UNLIKELY (mousepad_document_get_readonly (document)))
+  if (G_UNLIKELY (mousepad_file_get_read_only (document->file)))
     string = g_strdup_printf ("%s [%s] - %s", title, _("Read Only"), PACKAGE_NAME);
   else
     string = g_strdup_printf ("%s%s - %s", gtk_text_buffer_get_modified (document->buffer) ? "*" : "", title, PACKAGE_NAME);
@@ -1355,7 +1358,7 @@ mousepad_window_notebook_button_press_event (GtkNotebook    *notebook,
   else if (event->type == GDK_2BUTTON_PRESS && event->button == 1)
     {
       /* open a new tab */
-      mousepad_window_open_tab (window, NULL, NULL);
+      mousepad_window_open_file (window, NULL, NULL);
 
       /* we succeed */
       return TRUE;
@@ -1533,7 +1536,7 @@ mousepad_window_update_actions (MousepadWindow *window)
 
       /* set the reload, detach and save sensitivity */
       action = gtk_action_group_get_action (window->action_group, "save-file");
-      gtk_action_set_sensitive (action, !mousepad_document_get_readonly (document));
+      gtk_action_set_sensitive (action, !mousepad_file_get_read_only (document->file));
 
       action = gtk_action_group_get_action (window->action_group, "detach-tab");
       gtk_action_set_sensitive (action, (n_pages > 1));
@@ -2150,7 +2153,7 @@ static void
 mousepad_window_action_open_new_tab (GtkAction      *action,
                                      MousepadWindow *window)
 {
-  mousepad_window_open_tab (window, NULL, NULL);
+  mousepad_window_open_file (window, NULL, NULL);
 }
 
 
@@ -2215,7 +2218,7 @@ mousepad_window_action_open_file (GtkAction      *action,
           filename = li->data;
 
           /* open the file in a new tab */
-          mousepad_window_open_tab (window, filename, NULL);
+          mousepad_window_open_file (window, filename, NULL);
 
           /* cleanup */
           g_free (filename);
@@ -2274,7 +2277,7 @@ mousepad_window_action_open_recent (GtkAction      *action,
               if (G_LIKELY (description && strlen (description) > offset))
                 encoding = description + offset;
 
-              succeed = mousepad_window_open_tab (window, filename, encoding);
+              succeed = mousepad_window_open_file (window, filename, encoding);
             }
           else
             {
diff --git a/mousepad/mousepad-window.h b/mousepad/mousepad-window.h
index 8bf4ff6..9a7204d 100644
--- a/mousepad/mousepad-window.h
+++ b/mousepad/mousepad-window.h
@@ -51,10 +51,6 @@ GtkWidget      *mousepad_window_new              (void);
 void            mousepad_window_add              (MousepadWindow   *window,
                                                   MousepadDocument *document);
 
-gboolean        mousepad_window_open_tab         (MousepadWindow  *window,
-                                                  const gchar     *filename,
-                                                  const gchar     *encoding);
-
 gboolean        mousepad_window_open_files       (MousepadWindow  *window,
                                                   const gchar     *working_directory,
                                                   gchar          **filenames);


More information about the Xfce4-commits mailing list