[gtranslator/open-dl-button] Add the Open from Damned Lies(DL) button



commit 0dcd9661e5fa4da07586a2a34174fd6556151876
Author: Shafack Amanda <shafack likhene gmail com>
Date:   Fri Oct 18 07:09:33 2019 +0100

    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 +++++++++++++++++++++++++++++++++++++++++++++------
 src/gtr-projects.c    |  3 ---
 3 files changed, 87 insertions(+), 9 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 @@
 
 
 
+
diff --git a/src/gtr-projects.c b/src/gtr-projects.c
index d04b3446..0e5334d3 100644
--- a/src/gtr-projects.c
+++ b/src/gtr-projects.c
@@ -42,7 +42,6 @@ struct _GtrProjects
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtrProjects, gtr_projects, GTK_TYPE_BIN)
 
-
 static void project_add_cb (GtkButton *btn, GtrProjects *self);
 static void switch_to_dl (GtkButton *btn, GtrProjects *self);
 
@@ -82,7 +81,6 @@ gtr_projects_init (GtrProjects *self)
 {
   GtrProjectsPrivate *priv = gtr_projects_get_instance_private (self);
   gtk_widget_init_template (GTK_WIDGET (self));
-
   priv->main_window = NULL;
 
   g_signal_connect (priv->open_button,
@@ -131,4 +129,3 @@ switch_to_dl (GtkButton   *btn,
   GtrWindow *window = GTR_WINDOW (priv->main_window);
   gtr_window_show_dlteams (window);
 }
-


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