[Xfce4-commits] <mousepad:master> Cleanup View and Document menus.

Matthew Brush noreply at xfce.org
Sat May 5 21:31:57 CEST 2012


Updating branch refs/heads/master
         to 143b6ba6c2a8e024057bfca7e96deeb6bc3e765f (commit)
       from 5c88d180a1e20cb51737990948bb041529a97357 (commit)

commit 143b6ba6c2a8e024057bfca7e96deeb6bc3e765f
Author: Matthew Brush <matt at xfce.org>
Date:   Fri Oct 7 00:52:59 2011 -0700

    Cleanup View and Document menus.
    
    * Move "Line Numbers" from Document to View menu and apply it to all
      of the currently open textviews.
    * Re-order View and Document menu items, mostly sorted alphabetically.
    * Remove extra separators between related items.
    * Re-arrange action handler functions to be in the same order as their
      items appear in the XML file.

 mousepad/mousepad-window-ui.xml |   27 ++--
 mousepad/mousepad-window.c      |  335 ++++++++++++++++++++-------------------
 2 files changed, 185 insertions(+), 177 deletions(-)

diff --git a/mousepad/mousepad-window-ui.xml b/mousepad/mousepad-window-ui.xml
index f782f96..bf49fd5 100644
--- a/mousepad/mousepad-window-ui.xml
+++ b/mousepad/mousepad-window-ui.xml
@@ -67,11 +67,12 @@
     <menu action="view-menu">
       <menuitem action="font" />
       <separator />
-      <menuitem action="statusbar" />
-      <separator />
       <menu action="color-scheme-menu">
         <placeholder name="placeholder-color-scheme-items" />
       </menu>
+      <menuitem action="line-numbers" />
+      <separator />
+      <menuitem action="statusbar" />
     </menu>
 
     <menu action="text-menu">
@@ -100,27 +101,23 @@
     </menu>
 
     <menu action="document-menu">
-      <menuitem action="line-numbers" />
-      <menuitem action="word-wrap" />
-      <separator />
       <menuitem action="auto-indent" />
-      <separator />
-      <menuitem action="write-bom" />
-      <separator />
-      <menu action="tab-size-menu">
-        <placeholder name="placeholder-tab-items" />
-        <separator />
-        <menuitem action="insert-spaces" />
+      <menu action="language-menu">
+        <placeholder name="placeholder-language-section-items" />
       </menu>
       <menu action="eol-menu">
         <menuitem action="unix" />
         <menuitem action="mac" />
         <menuitem action="dos" />
       </menu>
-      <separator />
-      <menu action="language-menu">
-        <placeholder name="placeholder-language-section-items" />
+      <menu action="tab-size-menu">
+        <placeholder name="placeholder-tab-items" />
+        <separator />
+        <menuitem action="insert-spaces" />
       </menu>
+      <menuitem action="word-wrap" />
+      <separator />
+      <menuitem action="write-bom" />
     </menu>
 
     <menu action="navigation-menu">
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 118e7e9..7524a39 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -281,12 +281,14 @@ static void              mousepad_window_action_replace               (GtkAction
                                                                        MousepadWindow         *window);
 static void              mousepad_window_action_select_font           (GtkAction              *action,
                                                                        MousepadWindow         *window);
+static void              mousepad_window_action_color_scheme          (GtkToggleAction        *action,
+                                                                       MousepadWindow         *window);
+static void              mousepad_window_action_line_numbers          (GtkToggleAction        *action,
+                                                                       MousepadWindow         *window);
 static void              mousepad_window_action_statusbar_overwrite   (MousepadWindow         *window,
                                                                        gboolean                overwrite);
 static void              mousepad_window_action_statusbar             (GtkToggleAction        *action,
                                                                        MousepadWindow         *window);
-static void              mousepad_window_action_color_scheme          (GtkToggleAction        *action,
-                                                                       MousepadWindow         *window);
 static void              mousepad_window_action_lowercase             (GtkAction              *action,
                                                                        MousepadWindow         *window);
 static void              mousepad_window_action_uppercase             (GtkAction              *action,
@@ -313,22 +315,20 @@ static void              mousepad_window_action_increase_indent       (GtkAction
                                                                        MousepadWindow         *window);
 static void              mousepad_window_action_decrease_indent       (GtkAction              *action,
                                                                        MousepadWindow         *window);
-static void              mousepad_window_action_line_numbers          (GtkToggleAction        *action,
-                                                                       MousepadWindow         *window);
-static void              mousepad_window_action_word_wrap             (GtkToggleAction        *action,
+static void              mousepad_window_action_auto_indent           (GtkToggleAction        *action,
                                                                        MousepadWindow         *window);
-static void              mousepad_window_action_write_bom             (GtkToggleAction        *action,
+static void              mousepad_window_action_language              (GtkToggleAction        *action,
                                                                        MousepadWindow         *window);
-static void              mousepad_window_action_auto_indent           (GtkToggleAction        *action,
+static void              mousepad_window_action_line_ending           (GtkRadioAction         *action,
+                                                                       GtkRadioAction         *current,
                                                                        MousepadWindow         *window);
 static void              mousepad_window_action_tab_size              (GtkToggleAction        *action,
                                                                        MousepadWindow         *window);
-static void              mousepad_window_action_insert_spaces         (GtkToggleAction        *action,
+static void              mousepad_window_action_word_wrap             (GtkToggleAction        *action,
                                                                        MousepadWindow         *window);
-static void              mousepad_window_action_line_ending           (GtkRadioAction         *action,
-                                                                       GtkRadioAction         *current,
+static void              mousepad_window_action_write_bom             (GtkToggleAction        *action,
                                                                        MousepadWindow         *window);
-static void              mousepad_window_action_language              (GtkToggleAction        *action,
+static void              mousepad_window_action_insert_spaces         (GtkToggleAction        *action,
                                                                        MousepadWindow         *window);
 static void              mousepad_window_action_prev_tab              (GtkAction              *action,
                                                                        MousepadWindow         *window);
@@ -4373,65 +4373,6 @@ mousepad_window_action_select_font (GtkAction      *action,
 
 
 static void
-mousepad_window_action_statusbar_overwrite (MousepadWindow *window,
-                                            gboolean        overwrite)
-{
-  mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
-  mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
-
-  /* set the new overwrite mode */
-  mousepad_document_set_overwrite (window->active, overwrite);
-}
-
-
-
-static void
-mousepad_window_action_statusbar (GtkToggleAction *action,
-                                  MousepadWindow  *window)
-{
-  gboolean show_statusbar;
-
-  mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
-
-  /* whether we show the statusbar */
-  show_statusbar = gtk_toggle_action_get_active (action);
-
-  /* check if we should drop the statusbar */
-  if (!show_statusbar && window->statusbar != NULL)
-    {
-      /* destroy the statusbar */
-      gtk_widget_destroy (window->statusbar);
-      window->statusbar = NULL;
-    }
-  else if (show_statusbar && window->statusbar == NULL)
-    {
-      /* setup a new statusbar */
-      window->statusbar = mousepad_statusbar_new ();
-      gtk_box_pack_end (GTK_BOX (window->box), window->statusbar, FALSE, FALSE, 0);
-      gtk_widget_show (window->statusbar);
-
-      /* overwrite toggle signal */
-      g_signal_connect_swapped (G_OBJECT (window->statusbar), "enable-overwrite",
-                                G_CALLBACK (mousepad_window_action_statusbar_overwrite), window);
-
-      /* update the statusbar items */
-      if (window->active)
-        {
-          /* debug check */
-          mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
-
-          /* ask document to resend the cursor status signals */
-          mousepad_document_send_signals (window->active);
-        }
-    }
-
-  /* remember the setting */
-  g_object_set (G_OBJECT (window->preferences), "window-statusbar-visible", show_statusbar, NULL);
-}
-
-
-
-static void
 mousepad_window_action_color_scheme (GtkToggleAction *action,
                                      MousepadWindow  *window)
 {
@@ -4492,6 +4433,101 @@ mousepad_window_action_color_scheme (GtkToggleAction *action,
 
 
 static void
+mousepad_window_action_line_numbers (GtkToggleAction *action,
+                                     MousepadWindow  *window)
+{
+  gint              page_num = 0;
+  gboolean          active;
+  GtkWidget        *page;
+  MousepadDocument *document;
+
+  mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
+  mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
+
+  /* leave when menu updates are locked */
+  if (lock_menu_updates == 0)
+    {
+      /* get the current state */
+      active = gtk_toggle_action_get_active (action);
+
+      /* save as the last used line number setting */
+      g_object_set (G_OBJECT (window->preferences), "view-line-numbers", active, NULL);
+
+      /* apply line numbers setting to all open textviews */
+      while ((page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), page_num)))
+        {
+          if (G_LIKELY (MOUSEPAD_IS_DOCUMENT (page)))
+            {
+              document = MOUSEPAD_DOCUMENT (page);
+              mousepad_view_set_line_numbers (document->textview, active);
+            }
+          page_num++;
+        }
+    }
+}
+
+
+
+static void
+mousepad_window_action_statusbar_overwrite (MousepadWindow *window,
+                                            gboolean        overwrite)
+{
+  mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
+  mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
+
+  /* set the new overwrite mode */
+  mousepad_document_set_overwrite (window->active, overwrite);
+}
+
+
+
+static void
+mousepad_window_action_statusbar (GtkToggleAction *action,
+                                  MousepadWindow  *window)
+{
+  gboolean show_statusbar;
+
+  mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
+
+  /* whether we show the statusbar */
+  show_statusbar = gtk_toggle_action_get_active (action);
+
+  /* check if we should drop the statusbar */
+  if (!show_statusbar && window->statusbar != NULL)
+    {
+      /* destroy the statusbar */
+      gtk_widget_destroy (window->statusbar);
+      window->statusbar = NULL;
+    }
+  else if (show_statusbar && window->statusbar == NULL)
+    {
+      /* setup a new statusbar */
+      window->statusbar = mousepad_statusbar_new ();
+      gtk_box_pack_end (GTK_BOX (window->box), window->statusbar, FALSE, FALSE, 0);
+      gtk_widget_show (window->statusbar);
+
+      /* overwrite toggle signal */
+      g_signal_connect_swapped (G_OBJECT (window->statusbar), "enable-overwrite",
+                                G_CALLBACK (mousepad_window_action_statusbar_overwrite), window);
+
+      /* update the statusbar items */
+      if (window->active)
+        {
+          /* debug check */
+          mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
+
+          /* ask document to resend the cursor status signals */
+          mousepad_document_send_signals (window->active);
+        }
+    }
+
+  /* remember the setting */
+  g_object_set (G_OBJECT (window->preferences), "window-statusbar-visible", show_statusbar, NULL);
+}
+
+
+
+static void
 mousepad_window_action_lowercase (GtkAction      *action,
                                   MousepadWindow *window)
 {
@@ -4661,8 +4697,8 @@ mousepad_window_action_decrease_indent (GtkAction      *action,
 
 
 static void
-mousepad_window_action_line_numbers (GtkToggleAction *action,
-                                     MousepadWindow  *window)
+mousepad_window_action_auto_indent (GtkToggleAction *action,
+                                    MousepadWindow  *window)
 {
   gboolean active;
 
@@ -4675,86 +4711,75 @@ mousepad_window_action_line_numbers (GtkToggleAction *action,
       /* get the current state */
       active = gtk_toggle_action_get_active (action);
 
-      /* save as the last used line number setting */
-      g_object_set (G_OBJECT (window->preferences), "view-line-numbers", active, NULL);
+      /* save as the last auto indent mode */
+      g_object_set (G_OBJECT (window->preferences), "view-auto-indent", active, NULL);
 
       /* update the active document */
-      mousepad_view_set_line_numbers (window->active->textview, active);
+      mousepad_view_set_auto_indent (window->active->textview, active);
     }
 }
 
 
 
 static void
-mousepad_window_action_word_wrap (GtkToggleAction *action,
-                                  MousepadWindow  *window)
+mousepad_window_action_language (GtkToggleAction *action,
+                                 MousepadWindow  *window)
 {
-  gboolean active;
+  guint                     lang_hash;
+  const gchar *const       *lang_id;
+  GtkSourceLanguage        *language;
+  GtkSourceLanguageManager *manager;
+  GtkSourceBuffer          *buffer;
 
-  mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
-  mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
+  lang_hash = (guint) gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
+  buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (window->active->textview)));
 
-  /* leave when menu updates are locked */
-  if (lock_menu_updates == 0)
+  if (lang_hash == g_str_hash ("none"))
     {
-      /* get the current state */
-      active = gtk_toggle_action_get_active (action);
-
-      /* store this as the last used wrap mode */
-      g_object_set (G_OBJECT (window->preferences), "view-word-wrap", active, NULL);
-
-      /* set the wrapping mode of the current document */
-      mousepad_document_set_word_wrap (window->active, active);
+      gtk_source_buffer_set_language (buffer, NULL);
+      return;
     }
-}
-
 
+  manager = gtk_source_language_manager_get_default ();
+  lang_id = gtk_source_language_manager_get_language_ids (manager);
 
-static void
-mousepad_window_action_write_bom (GtkToggleAction *action,
-                                  MousepadWindow  *window)
-{
-  gboolean active;
-
-  mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
-  mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
-
-  /* leave when menu updates are locked */
-  if (lock_menu_updates == 0)
+  while (*lang_id)
     {
-      /* get the current state */
-      active = gtk_toggle_action_get_active (action);
-
-      /* set new value */
-      mousepad_file_set_write_bom (window->active->file, active);
-
-      /* make buffer as modified to show the user the change is not saved */
-      gtk_text_buffer_set_modified (window->active->buffer, TRUE);
+      if (g_str_hash (*lang_id) == lang_hash)
+        {
+          language = gtk_source_language_manager_get_language (manager, *lang_id);
+          gtk_source_buffer_set_language (buffer, language);
+          break;
+        }
+      lang_id++;
     }
 }
 
 
 
 static void
-mousepad_window_action_auto_indent (GtkToggleAction *action,
-                                    MousepadWindow  *window)
+mousepad_window_action_line_ending (GtkRadioAction *action,
+                                    GtkRadioAction *current,
+                                    MousepadWindow *window)
 {
-  gboolean active;
+  MousepadLineEnding eol;
 
   mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
   mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
+  mousepad_return_if_fail (MOUSEPAD_IS_FILE (window->active->file));
+  mousepad_return_if_fail (GTK_IS_TEXT_BUFFER (window->active->buffer));
 
   /* leave when menu updates are locked */
   if (lock_menu_updates == 0)
     {
-      /* get the current state */
-      active = gtk_toggle_action_get_active (action);
+      /* get selected line ending */
+      eol = gtk_radio_action_get_current_value (current);
 
-      /* save as the last auto indent mode */
-      g_object_set (G_OBJECT (window->preferences), "view-auto-indent", active, NULL);
+      /* set the new line ending on the file */
+      mousepad_file_set_line_ending (window->active->file, eol);
 
-      /* update the active document */
-      mousepad_view_set_auto_indent (window->active->textview, active);
+      /* make buffer as modified to show the user the change is not saved */
+      gtk_text_buffer_set_modified (window->active->buffer, TRUE);
     }
 }
 
@@ -4800,10 +4825,10 @@ mousepad_window_action_tab_size (GtkToggleAction *action,
 
 
 static void
-mousepad_window_action_insert_spaces (GtkToggleAction *action,
-                                      MousepadWindow  *window)
+mousepad_window_action_word_wrap (GtkToggleAction *action,
+                                  MousepadWindow  *window)
 {
-  gboolean insert_spaces;
+  gboolean active;
 
   mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
   mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
@@ -4812,38 +4837,35 @@ mousepad_window_action_insert_spaces (GtkToggleAction *action,
   if (lock_menu_updates == 0)
     {
       /* get the current state */
-      insert_spaces = gtk_toggle_action_get_active (action);
+      active = gtk_toggle_action_get_active (action);
 
-      /* save as the last auto indent mode */
-      g_object_set (G_OBJECT (window->preferences), "view-insert-spaces", insert_spaces, NULL);
+      /* store this as the last used wrap mode */
+      g_object_set (G_OBJECT (window->preferences), "view-word-wrap", active, NULL);
 
-      /* update the active document */
-      mousepad_view_set_insert_spaces (window->active->textview, insert_spaces);
+      /* set the wrapping mode of the current document */
+      mousepad_document_set_word_wrap (window->active, active);
     }
 }
 
 
 
 static void
-mousepad_window_action_line_ending (GtkRadioAction *action,
-                                    GtkRadioAction *current,
-                                    MousepadWindow *window)
+mousepad_window_action_write_bom (GtkToggleAction *action,
+                                  MousepadWindow  *window)
 {
-  MousepadLineEnding eol;
+  gboolean active;
 
   mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
   mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
-  mousepad_return_if_fail (MOUSEPAD_IS_FILE (window->active->file));
-  mousepad_return_if_fail (GTK_IS_TEXT_BUFFER (window->active->buffer));
 
   /* leave when menu updates are locked */
   if (lock_menu_updates == 0)
     {
-      /* get selected line ending */
-      eol = gtk_radio_action_get_current_value (current);
+      /* get the current state */
+      active = gtk_toggle_action_get_active (action);
 
-      /* set the new line ending on the file */
-      mousepad_file_set_line_ending (window->active->file, eol);
+      /* set new value */
+      mousepad_file_set_write_bom (window->active->file, active);
 
       /* make buffer as modified to show the user the change is not saved */
       gtk_text_buffer_set_modified (window->active->buffer, TRUE);
@@ -4853,36 +4875,25 @@ mousepad_window_action_line_ending (GtkRadioAction *action,
 
 
 static void
-mousepad_window_action_language (GtkToggleAction *action,
-                                 MousepadWindow  *window)
+mousepad_window_action_insert_spaces (GtkToggleAction *action,
+                                      MousepadWindow  *window)
 {
-  guint                     lang_hash;
-  const gchar *const       *lang_id;
-  GtkSourceLanguage        *language;
-  GtkSourceLanguageManager *manager;
-  GtkSourceBuffer          *buffer;
+  gboolean insert_spaces;
 
-  lang_hash = (guint) gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
-  buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (window->active->textview)));
+  mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
+  mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (window->active));
 
-  if (lang_hash == g_str_hash ("none"))
+  /* leave when menu updates are locked */
+  if (lock_menu_updates == 0)
     {
-      gtk_source_buffer_set_language (buffer, NULL);
-      return;
-    }
+      /* get the current state */
+      insert_spaces = gtk_toggle_action_get_active (action);
 
-  manager = gtk_source_language_manager_get_default ();
-  lang_id = gtk_source_language_manager_get_language_ids (manager);
+      /* save as the last auto indent mode */
+      g_object_set (G_OBJECT (window->preferences), "view-insert-spaces", insert_spaces, NULL);
 
-  while (*lang_id)
-    {
-      if (g_str_hash (*lang_id) == lang_hash)
-        {
-          language = gtk_source_language_manager_get_language (manager, *lang_id);
-          gtk_source_buffer_set_language (buffer, language);
-          break;
-        }
-      lang_id++;
+      /* update the active document */
+      mousepad_view_set_insert_spaces (window->active->textview, insert_spaces);
     }
 }
 


More information about the Xfce4-commits mailing list