[gtranslator] Tool buttons in headerbar with keybindings



commit f78a0c9b13c61bf22bad2a80f14ed70e3914d713
Author: Daniel García Moreno <danigm wadobo com>
Date:   Mon Sep 10 18:36:46 2018 +0200

    Tool buttons in headerbar with keybindings

 src/gtr-application.c |  96 ++++++++++++-
 src/gtr-context.c     |   2 +
 src/gtr-notebook.ui   | 365 ++++++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 404 insertions(+), 59 deletions(-)
---
diff --git a/src/gtr-application.c b/src/gtr-application.c
index c09a56c5..0c9f976f 100644
--- a/src/gtr-application.c
+++ b/src/gtr-application.c
@@ -309,7 +309,7 @@ quit_activated (GSimpleAction *action,
 }
 
 static void
-save_activated (GSimpleAction *action,
+saveas_activated (GSimpleAction *action,
                 GVariant      *parameter,
                 gpointer       user_data)
 {
@@ -317,6 +317,15 @@ save_activated (GSimpleAction *action,
   gtr_save_file_as_dialog (NULL, app->priv->active_window);
 }
 
+static void
+save_activated (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       user_data)
+{
+  GtrApplication *app = GTR_APPLICATION (user_data);
+  gtr_save_current_file_dialog (NULL, app->priv->active_window);
+}
+
 static void
 projects_activated (GSimpleAction *action,
                     GVariant      *parameter,
@@ -326,10 +335,74 @@ projects_activated (GSimpleAction *action,
   gtr_window_show_projects (app->priv->active_window);
 }
 
+static void
+undo_activated (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       user_data)
+{
+  GtrApplication *app = GTR_APPLICATION (user_data);
+  gtr_actions_edit_undo (NULL, app->priv->active_window);
+}
+
+static void
+redo_activated (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       user_data)
+{
+  GtrApplication *app = GTR_APPLICATION (user_data);
+  gtr_actions_edit_redo (NULL, app->priv->active_window);
+}
+
+static void
+prev_activated (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       user_data)
+{
+  GtrApplication *app = GTR_APPLICATION (user_data);
+  gtr_message_go_to_previous (NULL, app->priv->active_window);
+}
+
+static void
+next_activated (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       user_data)
+{
+  GtrApplication *app = GTR_APPLICATION (user_data);
+  gtr_message_go_to_next (NULL, app->priv->active_window);
+}
+
+static void
+prev_no_activated (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       user_data)
+{
+  GtrApplication *app = GTR_APPLICATION (user_data);
+  gtr_message_go_to_prev_fuzzy_or_untranslated (NULL, app->priv->active_window);
+}
+
+static void
+next_no_activated (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       user_data)
+{
+  GtrApplication *app = GTR_APPLICATION (user_data);
+  gtr_message_go_to_next_fuzzy_or_untranslated (NULL, app->priv->active_window);
+}
+
 static GActionEntry app_entries[] = {
   { "save", save_activated, NULL, NULL, NULL },
+  { "saveas", saveas_activated, NULL, NULL, NULL },
   { "projects", projects_activated, NULL, NULL, NULL },
 
+  { "undo", undo_activated, NULL, NULL, NULL },
+  { "redo", redo_activated, NULL, NULL, NULL },
+
+  { "prev", prev_activated, NULL, NULL, NULL },
+  { "next", next_activated, NULL, NULL, NULL },
+
+  { "prev_no", prev_no_activated, NULL, NULL, NULL },
+  { "next_no", next_no_activated, NULL, NULL, NULL },
+
   { "new_window", new_window_activated, NULL, NULL, NULL },
   { "preferences", preferences_activated, NULL, NULL, NULL },
   { "help", help_activated, NULL, NULL, NULL },
@@ -337,6 +410,13 @@ static GActionEntry app_entries[] = {
   { "quit", quit_activated, NULL, NULL, NULL }
 };
 
+static void
+set_kb (GApplication *app, gchar *action, gchar *accel)
+{
+  const gchar *keys[] = {accel, NULL};
+  gtk_application_set_accels_for_action(GTK_APPLICATION (app), action, keys);
+}
+
 static void
 gtr_application_startup (GApplication *application)
 {
@@ -354,6 +434,20 @@ gtr_application_startup (GApplication *application)
   g_action_map_add_action_entries (G_ACTION_MAP (application), app_entries,
                                    G_N_ELEMENTS (app_entries), application);
 
+  // keybindings
+  set_kb (application, "app.projects", "<Ctrl>o");
+  set_kb (application, "app.save", "<Ctrl>s");
+  set_kb (application, "app.saveas", "<Ctrl><Shift>s");
+  set_kb (application, "app.preferences", "<Ctrl>p");
+
+  set_kb (application, "app.undo", "<Ctrl>z");
+  set_kb (application, "app.redo", "<Ctrl><Shift>z");
+
+  set_kb (application, "app.prev", "<Alt>Left");
+  set_kb (application, "app.next", "<Alt>Right");
+  set_kb (application, "app.prev_no", "<Alt>Page_Up");
+  set_kb (application, "app.next_no", "<Alt>Page_Down");
+
   builder = gtk_builder_new ();
   gtk_builder_add_from_resource (builder, "/org/gnome/translator/gtranslator-menu.ui", NULL);
   gtk_application_set_app_menu (GTK_APPLICATION (application),
diff --git a/src/gtr-context.c b/src/gtr-context.c
index 519621c6..b08f9193 100644
--- a/src/gtr-context.c
+++ b/src/gtr-context.c
@@ -405,6 +405,8 @@ gtr_context_panel_init (GtrContextPanel *panel)
   gtk_box_pack_start (GTK_BOX (priv->translation_memory_box),
                       priv->translation_memory_ui,
                       FALSE, FALSE, 0);
+
+  gtk_widget_hide (priv->button_box);
 }
 
 static void
diff --git a/src/gtr-notebook.ui b/src/gtr-notebook.ui
index fdb599d5..8b228138 100644
--- a/src/gtr-notebook.ui
+++ b/src/gtr-notebook.ui
@@ -1,124 +1,373 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.15.3 on Mon Sep  2 16:45:01 2013 -->
+<!-- Generated with glade 3.22.1 -->
 <interface domain="gtranslator">
-  <!-- interface-requires gtk+ 3.10 -->
+  <requires lib="gtk+" version="3.20"/>
   <template class="GtrNotebook" parent="GtkNotebook">
     <property name="visible">True</property>
     <property name="can_focus">True</property>
   </template>
-
-  <!-- Header bar -->
+  <object class="GtkPopoverMenu" id="main_menu_popover">
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_left">6</property>
+        <property name="margin_right">6</property>
+        <property name="margin_top">6</property>
+        <property name="margin_bottom">6</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkModelButton" id="pref_button1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="action_name">app.preferences</property>
+            <property name="text" translatable="yes">Preferences</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkSeparator">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_top">3</property>
+            <property name="margin_bottom">3</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="pref_button">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="action_name">app.keybinding</property>
+            <property name="text" translatable="yes">Keybindings</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="about_button">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="action_name">app.about</property>
+            <property name="text" translatable="yes">About</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="submenu">main</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+  </object>
   <object class="GtkHeaderBar" id="titlebar">
-    <property name="visible">true</property>
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
     <property name="title" translatable="yes">Editing PO file</property>
     <property name="show_close_button">True</property>
-    <style>
-      <class name="titlebar"/>
-    </style>
     <child>
-      <object class="GtkMenuButton" id="main_menu">
+      <object class="GtkButton" id="open">
+        <property name="label" translatable="yes">Open</property>
         <property name="visible">True</property>
         <property name="can_focus">True</property>
         <property name="receives_default">True</property>
-        <property name="popover">main_menu_popover</property>
+        <property name="tooltip_text" translatable="yes">Open a new file (&lt;Ctrl&gt;o)</property>
+        <property name="action_name">app.projects</property>
+      </object>
+      <packing>
+        <property name="position">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkSeparator">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+      </object>
+      <packing>
+        <property name="position">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButtonBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="layout_style">start</property>
         <child>
-          <object class="GtkImage">
+          <object class="GtkButton" id="undo">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="icon_name">open-menu-symbolic</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="tooltip_text" translatable="yes">Undo (&lt;Ctrl&gt;z)</property>
+            <property name="action_name">app.undo</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">edit-undo-symbolic</property>
+              </object>
+            </child>
           </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+            <property name="non_homogeneous">True</property>
+          </packing>
         </child>
-        <accessibility>
-        </accessibility>
-        <child internal-child="accessible">
-          <object class="AtkObject" id="a11y-room_menu_button">
-            <property name="AtkObject::accessible_name" translatable="yes">Room Menu</property>
+        <child>
+          <object class="GtkButton" id="redo">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="tooltip_text" translatable="yes">Redo (&lt;Ctrl&gt;&lt;Shift&gt;z)</property>
+            <property name="action_name">app.redo</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">edit-redo-symbolic</property>
+              </object>
+            </child>
           </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+            <property name="non_homogeneous">True</property>
+          </packing>
         </child>
+        <style>
+          <class name="linked"/>
+          <class name="horizontal"/>
+        </style>
       </object>
       <packing>
-        <property name="pack-type">end</property>
-        <property name="position">0</property>
+        <property name="position">3</property>
       </packing>
     </child>
-  </object>
-
-  <!-- Menu -->
-  <object class="GtkPopoverMenu" id="main_menu_popover">
-    <property name="can_focus">False</property>
     <child>
-      <object class="GtkBox">
+      <object class="GtkSeparator">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="margin_left">6</property>
-        <property name="margin_right">6</property>
-        <property name="margin_top">6</property>
-        <property name="margin_bottom">6</property>
-        <property name="orientation">vertical</property>
+      </object>
+      <packing>
+        <property name="position">4</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButtonBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="layout_style">start</property>
         <child>
-          <object class="GtkModelButton" id="save_button">
+          <object class="GtkButton" id="prev">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="action_name">app.save</property>
-            <property name="text" translatable="yes">Save</property>
+            <property name="receives_default">True</property>
+            <property name="tooltip_text" translatable="yes">Previous message (&lt;Alt&gt;🡄)</property>
+            <property name="action_name">app.prev</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">go-previous-symbolic</property>
+              </object>
+            </child>
           </object>
           <packing>
-            <property name="expand">False</property>
+            <property name="expand">True</property>
             <property name="fill">True</property>
             <property name="position">0</property>
+            <property name="non_homogeneous">True</property>
           </packing>
         </child>
         <child>
-          <object class="GtkModelButton" id="pref_button">
+          <object class="GtkButton" id="next">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="action_name">app.preferences</property>
-            <property name="text" translatable="yes">Preferences</property>
+            <property name="receives_default">True</property>
+            <property name="tooltip_text" translatable="yes">Next message (&lt;Alt&gt;🡆)</property>
+            <property name="action_name">app.next</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">go-next-symbolic</property>
+              </object>
+            </child>
           </object>
           <packing>
-            <property name="expand">False</property>
+            <property name="expand">True</property>
             <property name="fill">True</property>
             <property name="position">1</property>
+            <property name="non_homogeneous">True</property>
           </packing>
         </child>
-
+        <style>
+          <class name="linked"/>
+          <class name="horizontal"/>
+        </style>
+      </object>
+      <packing>
+        <property name="position">5</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButtonBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="layout_style">start</property>
         <child>
-          <object class="GtkSeparator">
+          <object class="GtkButton" id="prev_untranslated">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="margin_top">3</property>
-            <property name="margin_bottom">3</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="tooltip_text" translatable="yes">Previous message without translation 
(&lt;Alt&gt;&lt;Page Up&gt;)</property>
+            <property name="action_name">app.prev_no</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">go-up-symbolic</property>
+              </object>
+            </child>
           </object>
           <packing>
-            <property name="expand">False</property>
+            <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">2</property>
+            <property name="position">0</property>
+            <property name="non_homogeneous">True</property>
           </packing>
         </child>
         <child>
-          <object class="GtkModelButton" id="open_button">
+          <object class="GtkButton" id="next_untranslated">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="action_name">app.projects</property>
-            <property name="text" translatable="yes">Open</property>
+            <property name="receives_default">True</property>
+            <property name="tooltip_text" translatable="yes">Next message without translation 
(&lt;Alt&gt;&lt;Page Down&gt;)</property>
+            <property name="action_name">app.next_no</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">go-down-symbolic</property>
+              </object>
+            </child>
           </object>
           <packing>
-            <property name="expand">False</property>
+            <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">3</property>
+            <property name="position">1</property>
+            <property name="non_homogeneous">True</property>
           </packing>
         </child>
+        <style>
+          <class name="linked"/>
+          <class name="horizontal"/>
+        </style>
       </object>
       <packing>
-        <property name="submenu">main</property>
+        <property name="position">6</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkMenuButton" id="main_menu">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <property name="popover">main_menu_popover</property>
+        <child>
+          <object class="GtkImage">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="icon_name">open-menu-symbolic</property>
+          </object>
+        </child>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="main_menu-atkobject">
+            <property name="AtkObject::accessible-name" translatable="yes">Room Menu</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="pack_type">end</property>
         <property name="position">1</property>
       </packing>
     </child>
+    <child>
+      <object class="GtkButtonBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="layout_style">start</property>
+        <child>
+          <object class="GtkButton" id="save">
+            <property name="label" translatable="yes">Save</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="tooltip_text" translatable="yes">Save the current file (&lt;Ctrl&gt;s)</property>
+            <property name="action_name">app.save</property>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+            <property name="non_homogeneous">True</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="tooltip_text" translatable="yes">Save as (&lt;Ctrl&gt;&lt;Shift&gt;s)</property>
+            <property name="action_name">app.saveas</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">document-save-as-symbolic</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+            <property name="non_homogeneous">True</property>
+          </packing>
+        </child>
+        <style>
+          <class name="horizontal"/>
+          <class name="linked"/>
+        </style>
+      </object>
+      <packing>
+        <property name="pack_type">end</property>
+        <property name="position">6</property>
+      </packing>
+    </child>
+    <style>
+      <class name="titlebar"/>
+    </style>
   </object>
-
 </interface>
-
-


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]