[Xfce4-commits] [apps/mousepad] 34/45: Add a basic toolbar

noreply at xfce.org noreply at xfce.org
Fri Jul 11 13:03:39 CEST 2014


This is an automated email from the git hooks/post-receive script.

mbrush pushed a commit to branch master
in repository apps/mousepad.

commit 2b5155971e93df04e85419fd56966eb01f15971a
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Thu Jul 10 01:19:09 2014 -0700

    Add a basic toolbar
    
    And a preference to control whether it's visible, default to off.
    
    TODO:
    * See if the layout is optimal
    * Show tooltip in statusbar on mouse hover like main menu items
    * Allow customization? (using GtkUiManager)
---
 mousepad/mousepad-settings.h           |    1 +
 mousepad/mousepad-window-ui.xml        |   22 +++++++++++++
 mousepad/mousepad-window.c             |   54 +++++++++++++++++++++++++++-----
 mousepad/org.xfce.Mousepad.gschema.xml |    7 +++++
 4 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/mousepad/mousepad-settings.h b/mousepad/mousepad-settings.h
index 7d8fb6b..9ddabc0 100644
--- a/mousepad/mousepad-settings.h
+++ b/mousepad/mousepad-settings.h
@@ -23,6 +23,7 @@ G_BEGIN_DECLS
 #define MOUSEPAD_SETTING_TAB_WIDTH                  "/preferences/view/tab-width"
 #define MOUSEPAD_SETTING_WORD_WRAP                  "/preferences/view/word-wrap"
 #define MOUSEPAD_SETTING_COLOR_SCHEME               "/preferences/view/color-scheme"
+#define MOUSEPAD_SETTING_TOOLBAR_VISIBLE            "/preferences/window/toolbar-visible"
 #define MOUSEPAD_SETTING_STATUSBAR_VISIBLE          "/preferences/window/statusbar-visible"
 #define MOUSEPAD_SETTING_ALWAYS_SHOW_TABS           "/preferences/window/always-show-tabs"
 #define MOUSEPAD_SETTING_CYCLE_TABS                 "/preferences/window/cycle-tabs"
diff --git a/mousepad/mousepad-window-ui.xml b/mousepad/mousepad-window-ui.xml
index eabfe38..494b5b1 100644
--- a/mousepad/mousepad-window-ui.xml
+++ b/mousepad/mousepad-window-ui.xml
@@ -99,6 +99,7 @@
       </menu>
       <menuitem action="line-numbers" />
       <separator />
+      <menuitem action="toolbar" />
       <menuitem action="statusbar" />
     </menu>
 
@@ -133,6 +134,27 @@
     </menu>
   </menubar>
 
+  <toolbar action="main-toolbar">
+      <toolitem action="new" />
+      <toolitem action="open" />
+      <toolitem action="save" />
+      <toolitem action="save-as" />
+      <toolitem action="revert" />
+      <toolitem action="close" />
+      <separator />
+      <toolitem action="undo" />
+      <toolitem action="redo" />
+      <toolitem action="cut" />
+      <toolitem action="copy" />
+      <toolitem action="paste" />
+      <separator />
+      <toolitem action="find" />
+      <toolitem action="replace" />
+      <toolitem action="go-to" />
+      <separator />
+      <toolitem action="close-window" />
+  </toolbar>
+
   <popup action="tab-menu">
     <menuitem action="save" />
     <menuitem action="save-as" />
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index d9793e2..40fc9ee 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -324,6 +324,8 @@ static void              mousepad_window_action_color_scheme          (GtkToggle
                                                                        MousepadWindow         *window);
 static void              mousepad_window_action_line_numbers          (GtkToggleAction        *action,
                                                                        MousepadWindow         *window);
+static void              mousepad_window_action_toolbar               (GtkToggleAction        *action,
+                                                                       MousepadWindow         *window);
 static void              mousepad_window_action_statusbar_overwrite   (MousepadWindow         *window,
                                                                        gboolean                overwrite);
 static void              mousepad_window_action_statusbar             (GtkToggleAction        *action,
@@ -474,6 +476,7 @@ static const GtkActionEntry action_entries[] =
 static const GtkToggleActionEntry toggle_action_entries[] =
 {
   { "line-numbers", NULL, N_("Line N_umbers"), NULL, N_("Show line numbers"), G_CALLBACK (mousepad_window_action_line_numbers), FALSE, },
+  { "toolbar", NULL, N_("_Toolbar"), NULL, N_("Change the visibility of the toolbar"), G_CALLBACK (mousepad_window_action_toolbar), FALSE, },
   { "statusbar", NULL, N_("St_atusbar"), NULL, N_("Change the visibility of the statusbar"), G_CALLBACK (mousepad_window_action_statusbar), FALSE, },
   { "auto-indent", NULL, N_("_Auto Indent"), NULL, N_("Auto indent a new line"), G_CALLBACK (mousepad_window_action_auto_indent), FALSE, },
   { "insert-spaces", NULL, N_("Insert _Spaces"), NULL, N_("Insert spaces when the tab button is pressed"), G_CALLBACK (mousepad_window_action_insert_spaces), FALSE, },
@@ -601,11 +604,14 @@ mousepad_window_init (MousepadWindow *window)
 {
   GtkAccelGroup *accel_group;
   GtkWidget     *menubar;
+  GtkWidget     *toolbar;
   GtkWidget     *label;
   GtkWidget     *separator;
   GtkWidget     *ebox;
   GtkWidget     *item;
+  GtkAction     *action;
   gint           width, height;
+  gboolean       active;
 
   /* initialize stuff */
   window->save_geometry_timer_id = 0;
@@ -682,6 +688,17 @@ mousepad_window_init (MousepadWindow *window)
   menubar = gtk_ui_manager_get_widget (window->ui_manager, "/main-menu");
   gtk_box_pack_start (GTK_BOX (window->box), menubar, FALSE, FALSE, 0);
   gtk_widget_show (menubar);
+  
+  toolbar = gtk_ui_manager_get_widget (window->ui_manager, "/main-toolbar");
+  gtk_box_pack_start (GTK_BOX (window->box), toolbar, FALSE, FALSE, 0);
+
+  /* sync the toolbar visibility and action state to the setting */
+  action = gtk_action_group_get_action (window->action_group, "toolbar");
+  active = MOUSEPAD_SETTING_GET_BOOLEAN (TOOLBAR_VISIBLE);
+  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);
+
+  /* update the toolbar visibility with the setting */
+  MOUSEPAD_SETTING_BIND (TOOLBAR_VISIBLE, toolbar, "visible", G_SETTINGS_BIND_DEFAULT);
 
   /* check if we need to add the root warning */
   if (G_UNLIKELY (geteuid () == 0))
@@ -878,12 +895,15 @@ mousepad_window_connect_proxy (GtkUIManager   *manager,
                                MousepadWindow *window)
 {
   mousepad_return_if_fail (GTK_IS_ACTION (action));
-  mousepad_return_if_fail (GTK_IS_MENU_ITEM (proxy));
+  mousepad_return_if_fail (GTK_IS_MENU_ITEM (proxy) || GTK_IS_TOOL_ITEM (proxy));
   mousepad_return_if_fail (GTK_IS_UI_MANAGER (manager));
 
-  /* we want to get informed when the user hovers a menu item */
-  g_signal_connect_closure (G_OBJECT (proxy), "select", window->menu_item_selected_closure, FALSE);
-  g_signal_connect_closure (G_OBJECT (proxy), "deselect", window->menu_item_deselected_closure, FALSE);
+  if (GTK_IS_MENU_ITEM (proxy))
+    {
+      /* we want to get informed when the user hovers a menu item */
+      g_signal_connect_closure (G_OBJECT (proxy), "select", window->menu_item_selected_closure, FALSE);
+      g_signal_connect_closure (G_OBJECT (proxy), "deselect", window->menu_item_deselected_closure, FALSE);
+    }
 }
 
 
@@ -895,12 +915,15 @@ mousepad_window_disconnect_proxy (GtkUIManager   *manager,
                                   MousepadWindow *window)
 {
   mousepad_return_if_fail (GTK_IS_ACTION (action));
-  mousepad_return_if_fail (GTK_IS_MENU_ITEM (proxy));
+  mousepad_return_if_fail (GTK_IS_MENU_ITEM (proxy) || GTK_IS_TOOL_ITEM (proxy));
   mousepad_return_if_fail (GTK_IS_UI_MANAGER (manager));
 
-  /* disconnect the signal from mousepad_window_connect_proxy() */
-  g_signal_handlers_disconnect_matched (G_OBJECT (proxy), G_SIGNAL_MATCH_CLOSURE, 0, 0, window->menu_item_selected_closure, NULL, NULL);
-  g_signal_handlers_disconnect_matched (G_OBJECT (proxy), G_SIGNAL_MATCH_CLOSURE, 0, 0, window->menu_item_deselected_closure, NULL, NULL);
+  if (GTK_IS_MENU_ITEM (proxy))
+    {
+      /* disconnect the signal from mousepad_window_connect_proxy() */
+      g_signal_handlers_disconnect_matched (G_OBJECT (proxy), G_SIGNAL_MATCH_CLOSURE, 0, 0, window->menu_item_selected_closure, NULL, NULL);
+      g_signal_handlers_disconnect_matched (G_OBJECT (proxy), G_SIGNAL_MATCH_CLOSURE, 0, 0, window->menu_item_deselected_closure, NULL, NULL);
+    }
 }
 
 
@@ -4795,6 +4818,21 @@ mousepad_window_action_line_numbers (GtkToggleAction *action,
 
 
 static void
+mousepad_window_action_toolbar (GtkToggleAction *action,
+                                MousepadWindow  *window)
+{
+  gboolean active;
+
+  mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
+
+  active = gtk_toggle_action_get_active (action);
+
+  MOUSEPAD_SETTING_SET_BOOLEAN (TOOLBAR_VISIBLE, active);
+}
+
+
+
+static void
 mousepad_window_action_statusbar_overwrite (MousepadWindow *window,
                                             gboolean        overwrite)
 {
diff --git a/mousepad/org.xfce.Mousepad.gschema.xml b/mousepad/org.xfce.Mousepad.gschema.xml
index bf93dac..bd013f8 100644
--- a/mousepad/org.xfce.Mousepad.gschema.xml
+++ b/mousepad/org.xfce.Mousepad.gschema.xml
@@ -152,6 +152,13 @@
 
   <!-- window preferences -->
   <schema id="org.xfce.mousepad.preferences.window" path="/org/xfce/mousepad/preferences/window/" gettext-domain="mousepad">
+    <key name="toolbar-visible" type="b">
+      <default>false</default>
+      <summary>Toolbar visible</summary>
+      <description>
+        When true the toolbar is visible, when false it is not visible.
+      </description>
+    </key>
     <key name="statusbar-visible" type="b">
       <default>true</default>
       <summary>Statusbar visible</summary>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list