Author: nick
Date: 2007-10-18 09:47:52 +0000 (Thu, 18 Oct 2007)
New Revision: 26145

Modified:
   mousepad/branches/nick_0_3/ChangeLog
   mousepad/branches/nick_0_3/mousepad/mousepad-document.c
   mousepad/branches/nick_0_3/mousepad/mousepad-document.h
   mousepad/branches/nick_0_3/mousepad/mousepad-file.c
   mousepad/branches/nick_0_3/mousepad/mousepad-file.h
   mousepad/branches/nick_0_3/mousepad/mousepad-view.c
   mousepad/branches/nick_0_3/mousepad/mousepad-window.c
   mousepad/branches/nick_0_3/mousepad/mousepad-window.h
Log:
* 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.


Modified: mousepad/branches/nick_0_3/ChangeLog
===================================================================
--- mousepad/branches/nick_0_3/ChangeLog        2007-10-18 09:04:31 UTC (rev 
26144)
+++ mousepad/branches/nick_0_3/ChangeLog        2007-10-18 09:47:52 UTC (rev 
26145)
@@ -1,4 +1,12 @@
 2007-10-18     Nick Schermer <[EMAIL PROTECTED]>
+       * 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 <[EMAIL PROTECTED]>
        * 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

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-document.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-document.c     2007-10-18 
09:04:31 UTC (rev 26144)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-document.c     2007-10-18 
09:47:52 UTC (rev 26145)
@@ -525,17 +525,6 @@
 
 
 
-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)
 {

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-document.h
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-document.h     2007-10-18 
09:04:31 UTC (rev 26144)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-document.h     2007-10-18 
09:47:52 UTC (rev 26145)
@@ -85,8 +85,6 @@
                                                               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);

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-file.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-file.c 2007-10-18 09:04:31 UTC 
(rev 26144)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-file.c 2007-10-18 09:47:52 UTC 
(rev 26145)
@@ -142,7 +142,7 @@
   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 @@
 
 
 
+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)

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-file.h
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-file.h 2007-10-18 09:04:31 UTC 
(rev 26144)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-file.h 2007-10-18 09:47:52 UTC 
(rev 26145)
@@ -55,6 +55,8 @@
 
 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);
 

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-view.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-view.c 2007-10-18 09:04:31 UTC 
(rev 26144)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-view.c 2007-10-18 09:47:52 UTC 
(rev 26145)
@@ -342,6 +342,8 @@
   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 @@
   /* 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 @@
 
             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);
 
-                /* insert the indent characters */
-                gtk_text_buffer_insert (buffer, &iter, "\n", 1);
-                gtk_text_buffer_insert (buffer, &iter, string, -1);
+                /* 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);
 
-                /* end user action */
-                gtk_text_buffer_end_user_action (buffer);
+                    /* 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);
+
+                    /* 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 @@
       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 @@
       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);

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-window.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-window.c       2007-10-18 
09:04:31 UTC (rev 26144)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-window.c       2007-10-18 
09:47:52 UTC (rev 26145)
@@ -92,6 +92,9 @@
 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 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 @@
         }
 
       /* 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 @@
     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 @@
   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 @@
 
       /* 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 @@
 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 @@
           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 @@
               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
             {

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-window.h
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-window.h       2007-10-18 
09:04:31 UTC (rev 26144)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-window.h       2007-10-18 
09:47:52 UTC (rev 26145)
@@ -51,10 +51,6 @@
 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);

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to