[gtranslator: 1/2] Add the Open from Damned Lies(DL) button



commit 8d9b94b9a83c97b928735660bf62311b27d9823f
Author: Shafack Amanda <shafack likhene gmail com>
Date:   Mon Oct 28 17:00:34 2019 +0000

    Add the Open from Damned Lies(DL) button
    
    A user can view two buttons in the main window when no file is opened.
    These buttons are namely: Open & Open from DL.
    
    However, if a file is opened, the user can view only the Open button.
    Thus, a user cannot load files from Damned Lies.
    
    To fix this make the Open from DL button visible when a file is opened.
    Prompt a user to save an edited file before the open button is opened.
    
    Closes #65

 src/gtr-application.c | 35 +++++++++++++++++++++++++++++++
 src/gtr-notebook.ui   | 58 +++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 87 insertions(+), 6 deletions(-)
---
diff --git a/src/gtr-application.c b/src/gtr-application.c
index de899a8c..929b1a1f 100644
--- a/src/gtr-application.c
+++ b/src/gtr-application.c
@@ -384,6 +384,38 @@ open_activated (GSimpleAction *action,
   gtr_open_file_dialog (NULL, priv->active_window);
 }
 
+static void
+dl_activated (GSimpleAction *action,
+              GVariant      *parameter,
+              gpointer       user_data)
+{
+  GtrApplication *app = GTR_APPLICATION (user_data);
+  GtrApplicationPrivate *priv = gtr_application_get_instance_private (app);
+
+  GtrTab *active_tab = gtr_window_get_active_tab (priv->active_window);
+  GtrPoState state = gtr_po_get_state (gtr_tab_get_po (active_tab));
+
+  if (state == GTR_PO_STATE_MODIFIED)
+    {
+      GtkWidget *dialog;
+      gint res;
+
+      dialog = gtk_message_dialog_new (GTK_WINDOW (priv->active_window),
+            GTK_DIALOG_DESTROY_WITH_PARENT,
+            GTK_MESSAGE_QUESTION,
+            GTK_BUTTONS_YES_NO,
+            _("Do you want to save the changes?"));
+      gtk_window_set_title (GTK_WINDOW (dialog), _("Warning"));
+      res = gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      if (res == GTK_RESPONSE_YES)
+        gtr_save_current_file_dialog (NULL, priv->active_window);
+    }
+
+  gtr_window_show_dlteams (priv->active_window);
+}
+
 static void
 undo_activated (GSimpleAction *action,
                 GVariant      *parameter,
@@ -503,7 +535,9 @@ sort_by_activated (GSimpleAction *action,
 static GActionEntry app_entries[] = {
   { "save", save_activated, NULL, NULL, NULL },
   { "saveas", saveas_activated, NULL, NULL, NULL },
+
   { "open", open_activated, NULL, NULL, NULL },
+  { "dl", dl_activated, NULL, NULL, NULL },
 
   { "undo", undo_activated, NULL, NULL, NULL },
   { "redo", redo_activated, NULL, NULL, NULL },
@@ -576,6 +610,7 @@ gtr_application_startup (GApplication *application)
 
   // keybindings
   set_kb (application, "app.open", "<Ctrl>o");
+  set_kb (application, "app.dl", "<Ctrl>d");
   set_kb (application, "app.save", "<Ctrl>s");
   set_kb (application, "app.saveas", "<Ctrl><Shift>s");
   set_kb (application, "app.preferences", "<Ctrl>p");
diff --git a/src/gtr-notebook.ui b/src/gtr-notebook.ui
index 8a950c11..769ec3c0 100644
--- a/src/gtr-notebook.ui
+++ b/src/gtr-notebook.ui
@@ -307,19 +307,64 @@
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">Translation Editor</property>
     <property name="show_close_button">True</property>
+
     <child>
-      <object class="GtkButton" id="open">
-        <property name="label" translatable="yes">Open…</property>
+       <object class="GtkButtonBox">
         <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="receives_default">True</property>
-        <property name="tooltip_text" translatable="yes">Open a new file (&lt;Ctrl&gt;o)</property>
-        <property name="action_name">app.open</property>
+        <property name="can_focus">False</property>
+        <property name="layout_style">start</property>
+        <child>
+          <object class="GtkButton" id="open_button">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="tooltip_text" translatable="yes">Open a new file (&lt;Ctrl&gt;o)</property>
+            <property name="action_name">app.open</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">document-open-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>
+        <child>
+          <object class="GtkButton" id="dl_button">
+            <property name="visible">True</property>
+            <property name="tooltip_text" translatable="yes">Open from Damned Lies (&lt;Ctrl&gt;d)</property>
+            <property name="action_name">app.dl</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="icon_name">folder-download-symbolic</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">F</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">1</property>
       </packing>
     </child>
+
     <child>
       <object class="GtkSeparator">
         <property name="visible">True</property>
@@ -596,3 +641,4 @@
 
 
 
+


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