[gtranslator] Remove the recent files list



commit 036800a02c99ef0119b95be86009a42da99080df
Author: Daniel García Moreno <danigm wadobo com>
Date:   Wed Sep 12 15:04:22 2018 +0200

    Remove the recent files list
    
    Fix #12

 src/gtr-actions-file.c |  15 +++++--
 src/gtr-application.c  |  10 ++---
 src/gtr-notebook.ui    |   5 ++-
 src/gtr-po.c           |  13 +++---
 src/gtr-po.h           |   2 +-
 src/gtr-projects.c     | 114 -------------------------------------------------
 src/gtr-projects.ui    |  32 +++++++++-----
 src/gtr-window.c       |  14 +++---
 src/gtr-window.h       |   4 +-
 9 files changed, 59 insertions(+), 150 deletions(-)
---
diff --git a/src/gtr-actions-file.c b/src/gtr-actions-file.c
index c23a0d79..1285160f 100644
--- a/src/gtr-actions-file.c
+++ b/src/gtr-actions-file.c
@@ -66,16 +66,22 @@ gtr_open (GFile * location, GtrWindow * window, GError ** error)
    * If the filename can't be opened, pass the error back to the caller
    * to handle.
    */
+
   po = gtr_po_new ();
-  gtr_po_parse (po, location, error);
+  if (!gtr_po_parse (po, location, error)) {
+    gtr_window_show_projects (window);
+    // TODO: show error message
+    return FALSE;
+  }
 
   if ((*error != NULL)
-      && (((GError *) * error)->code != GTR_PO_ERROR_RECOVERY))
+      && (((GError *) * error)->code != GTR_PO_ERROR_RECOVERY)) {
+    gtr_window_show_projects (window);
     return FALSE;
+  }
 
   header = gtr_po_get_header (po);
   project_id = gtr_header_get_prj_id_version (header);
-  _gtr_recent_add (window, location, (gchar *)project_id);
 
   /*
    * Create a page to add to our list of open files
@@ -412,6 +418,9 @@ load_file_list (GtrWindow * window, const GSList * locations)
 
   g_return_if_fail ((locations != NULL) && (locations->data != NULL));
 
+  // removing other tabs, for now on, we'll using single tab and multiples windows
+  gtr_window_remove_all_pages (window);
+
   /* Remove the uris corresponding to documents already open
    * in "window" and remove duplicates from "uris" list */
   l = locations;
diff --git a/src/gtr-application.c b/src/gtr-application.c
index 35ab495f..14d48b44 100644
--- a/src/gtr-application.c
+++ b/src/gtr-application.c
@@ -297,13 +297,13 @@ save_activated (GSimpleAction *action,
 }
 
 static void
-projects_activated (GSimpleAction *action,
-                    GVariant      *parameter,
-                    gpointer       user_data)
+open_activated (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       user_data)
 {
   GtrApplication *app = GTR_APPLICATION (user_data);
   GtrApplicationPrivate *priv = gtr_application_get_instance_private (app);
-  gtr_window_show_projects (priv->active_window);
+  gtr_open_file_dialog (NULL, priv->active_window);
 }
 
 static void
@@ -380,7 +380,7 @@ build_tm_activated (GSimpleAction *action,
 static GActionEntry app_entries[] = {
   { "save", save_activated, NULL, NULL, NULL },
   { "saveas", saveas_activated, NULL, NULL, NULL },
-  { "projects", projects_activated, NULL, NULL, NULL },
+  { "open", open_activated, NULL, NULL, NULL },
 
   { "undo", undo_activated, NULL, NULL, NULL },
   { "redo", redo_activated, NULL, NULL, NULL },
diff --git a/src/gtr-notebook.ui b/src/gtr-notebook.ui
index 9d6c382e..18ade05e 100644
--- a/src/gtr-notebook.ui
+++ b/src/gtr-notebook.ui
@@ -178,12 +178,12 @@
     <property name="show_close_button">True</property>
     <child>
       <object class="GtkButton" id="open">
-        <property name="label" translatable="yes">Open</property>
+        <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="tooltip_text" translatable="yes">Open a new file (&lt;Ctrl&gt;o)</property>
-        <property name="action_name">app.projects</property>
+        <property name="action_name">app.open</property>
       </object>
       <packing>
         <property name="position">1</property>
@@ -483,3 +483,4 @@
     </style>
   </object>
 </interface>
+
diff --git a/src/gtr-po.c b/src/gtr-po.c
index 7b3e819c..73955075 100644
--- a/src/gtr-po.c
+++ b/src/gtr-po.c
@@ -611,7 +611,7 @@ _gtr_po_load_ensure_utf8 (GtrPo * po, GError ** error)
  * Parses all things related to the #GtrPo and initilizes all neccessary
  * variables.
  **/
-void
+gboolean
 gtr_po_parse (GtrPo * po, GFile * location, GError ** error)
 {
   GtrPoPrivate *priv = po->priv;
@@ -622,8 +622,8 @@ gtr_po_parse (GtrPo * po, GFile * location, GError ** error)
   gint i = 0;
   gint pos = 1;
 
-  g_return_if_fail (GTR_IS_PO (po));
-  g_return_if_fail (location != NULL);
+  g_return_val_if_fail (GTR_IS_PO (po), FALSE);
+  g_return_val_if_fail (location != NULL, FALSE);
 
   if (message_error != NULL)
     {
@@ -639,7 +639,7 @@ gtr_po_parse (GtrPo * po, GFile * location, GError ** error)
   if (!_gtr_po_load_ensure_utf8 (po, error))
     {
       g_object_unref (po);
-      return;
+      return FALSE;
     }
 
   /*
@@ -663,7 +663,7 @@ gtr_po_parse (GtrPo * po, GFile * location, GError ** error)
                    GTR_PO_ERROR_GETTEXT,
                    _("Gettext returned a null message domain list."));
       g_object_unref (po);
-      return;
+      return FALSE;
     }
   while (domains[i])
     {
@@ -708,7 +708,7 @@ gtr_po_parse (GtrPo * po, GFile * location, GError ** error)
                    GTR_PO_ERROR_OTHER,
                    _("No messages obtained from parser."));
       g_object_unref (po);
-      return;
+      return FALSE;
     }
 
   priv->messages = g_list_reverse (priv->messages);
@@ -722,6 +722,7 @@ gtr_po_parse (GtrPo * po, GFile * location, GError ** error)
 
   /* Initialize Tab state */
   po->priv->state = GTR_PO_STATE_SAVED;
+  return TRUE;
 }
 
 /**
diff --git a/src/gtr-po.h b/src/gtr-po.h
index e8c4b396..22cdad82 100644
--- a/src/gtr-po.h
+++ b/src/gtr-po.h
@@ -100,7 +100,7 @@ gtr_po_get_type (void)
 
      GtrPo *gtr_po_new (void);
 
-     void gtr_po_parse (GtrPo * po, GFile * location, GError ** error);
+     gboolean gtr_po_parse (GtrPo * po, GFile * location, GError ** error);
 
      void gtr_po_save_header_in_msg (GtrPo * po, GtrHeader * header);
 
diff --git a/src/gtr-projects.c b/src/gtr-projects.c
index 90f37987..1e408e76 100644
--- a/src/gtr-projects.c
+++ b/src/gtr-projects.c
@@ -27,10 +27,8 @@
 
 typedef struct
 {
-  GtkRecentManager *recent_manager;
   GtkWidget *titlebar;
   GtkWidget *main_box;
-  GtkWidget *project_list;
   GtkWidget *open_button;
 
   GtrWindow *main_window;
@@ -45,8 +43,6 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtrProjects, gtr_projects, GTK_TYPE_BIN)
 
 
 static void project_add_cb (GtkButton *btn, GtrProjects *self);
-static void init_recent (GtrProjects *self);
-static void file_open_cb (GtkListBox *box, GtkListBoxRow *row, gpointer data);
 
 
 static void
@@ -75,7 +71,6 @@ gtr_projects_class_init (GtrProjectsClass *klass)
 
   gtk_widget_class_bind_template_child_private (widget_class, GtrProjects, titlebar);
   gtk_widget_class_bind_template_child_private (widget_class, GtrProjects, main_box);
-  gtk_widget_class_bind_template_child_private (widget_class, GtrProjects, project_list);
 
   gtk_widget_class_bind_template_child_private (widget_class, GtrProjects, open_button);
 }
@@ -84,20 +79,14 @@ static void
 gtr_projects_init (GtrProjects *self)
 {
   GtrProjectsPrivate *priv = gtr_projects_get_instance_private (self);
-  GtkListBox *list;
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  list = GTK_LIST_BOX (priv->project_list);
   priv->main_window = NULL;
-  priv->recent_manager = gtk_recent_manager_get_default ();
 
   g_signal_connect (priv->open_button,
                     "clicked",
                     G_CALLBACK (project_add_cb),
                     self);
-
-  g_signal_connect (list, "row-activated", G_CALLBACK (file_open_cb), self);
-  init_recent (self);
 }
 
 GtrProjects*
@@ -117,34 +106,6 @@ gtr_projects_get_header (GtrProjects *self)
 }
 
 // static functions
-static void
-file_open_cb (GtkListBox *box,
-              GtkListBoxRow *row,
-              gpointer data)
-{
-  gint index = gtk_list_box_row_get_index (row);
-  GtrProjects *self = GTR_PROJECTS (data);
-  GtrProjectsPrivate *priv = gtr_projects_get_instance_private (self);
-
-  GList *recents = gtk_recent_manager_get_items (priv->recent_manager);
-  GtkRecentInfo *info = g_list_nth_data (recents, index);
-
-  GError *error;
-  GFile *file;
-
-  file = g_file_new_for_uri (gtk_recent_info_get_uri (info));
-  if (!gtr_open (file, priv->main_window, &error)) {
-    g_error_free (error);
-    goto out;
-  }
-
-  gtr_window_show_poeditor (priv->main_window);
-
-out:
-  g_object_unref (file);
-  g_list_free_full (recents, (GDestroyNotify)gtk_recent_info_unref);
-}
-
 static void
 project_add_cb (GtkButton   *btn,
                 GtrProjects *self)
@@ -154,78 +115,3 @@ project_add_cb (GtkButton   *btn,
   gtr_open_file_dialog (NULL, window);
 }
 
-static void
-init_recent (GtrProjects *self)
-{
-  GtrProjectsPrivate *priv = gtr_projects_get_instance_private (self);
-  GtkListBox *list = GTK_LIST_BOX (priv->project_list);
-
-  GList *recents = gtk_recent_manager_get_items (priv->recent_manager);
-  GList *it = g_list_first (recents);
-
-  GList *children, *iter;
-
-  children = gtk_container_get_children (GTK_CONTAINER (list));
-  for(iter = children; iter != NULL; iter = g_list_next (iter))
-    gtk_widget_destroy (GTK_WIDGET (iter->data));
-  g_list_free (children);
-
-  while (it)
-    {
-      const gchar *name = gtk_recent_info_get_uri_display (it->data);
-      GtkWidget *label = gtk_label_new (name);
-      GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-
-      gtk_label_set_xalign (GTK_LABEL (label), 0.0);
-      gtk_label_set_yalign (GTK_LABEL (label), 0.5);
-      gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 6);
-
-      gtk_widget_show_all (box);
-      gtk_list_box_insert (list, box, -1);
-      it = g_list_next (it);
-    }
-
-  g_list_free_full (recents, (GDestroyNotify)gtk_recent_info_unref);
-}
-
-void
-gtr_projects_recent_add (GtrProjects *self,
-                         GFile *location,
-                         gchar *project_id)
-{
-  GtrProjectsPrivate *priv = gtr_projects_get_instance_private (self);
-  GtkRecentData *recent_data;
-  gchar *uri;
-  gchar *path;
-  gchar *display_name;
-
-  uri = g_file_get_uri (location);
-  path = g_file_get_path (location);
-  display_name = gtr_utils_reduce_path ((const gchar *) path);
-
-  recent_data = g_slice_new (GtkRecentData);
-
-  recent_data->display_name = display_name;
-  recent_data->description = NULL;
-  recent_data->mime_type = "text/x-gettext-translation";
-  recent_data->app_name = (gchar *) g_get_application_name ();
-  recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
-  recent_data->groups = NULL;
-  recent_data->is_private = FALSE;
-
-  if (!gtk_recent_manager_add_full (priv->recent_manager,
-                                    uri, recent_data))
-    {
-      g_warning ("Unable to add '%s' to the list of recently used documents",
-                 uri);
-    } else {
-      init_recent (self);
-    }
-
-  g_free (uri);
-  g_free (path);
-  g_free (display_name);
-  g_free (recent_data->app_exec);
-  g_slice_free (GtkRecentData, recent_data);
-}
-
diff --git a/src/gtr-projects.ui b/src/gtr-projects.ui
index 4af64370..a6e15aac 100644
--- a/src/gtr-projects.ui
+++ b/src/gtr-projects.ui
@@ -10,26 +10,37 @@
         <property name="margin_top">24</property>
         <property name="margin_bottom">24</property>
         <property name="vexpand">False</property>
+        <property name="valign">center</property>
         <property name="orientation">vertical</property>
+        <property name="spacing">14</property>
+
         <child>
-          <object class="GtkFrame" id="project_frame">
+          <object class="GtkImage">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="label_xalign">0</property>
-            <property name="shadow_type">in</property>
-            <child>
-              <object class="GtkListBox" id="project_list">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-              </object>
-            </child>
+            <property name="pixel_size">80</property>
+            <property name="icon_name">document-new-symbolic</property>
+            <property name="icon_size">6</property>
           </object>
           <packing>
-            <property name="expand">True</property>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Open a new .po file or drag &amp; drop here</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
             <property name="fill">True</property>
             <property name="position">1</property>
           </packing>
         </child>
+
       </object>
     </child>
   </template>
@@ -56,3 +67,4 @@
 
 </interface>
 
+
diff --git a/src/gtr-window.c b/src/gtr-window.c
index 0d7cc047..bd9165c4 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -1097,13 +1097,6 @@ _gtr_window_close_tab (GtrWindow * window, GtrTab * tab)
     }
 }
 
-void
-_gtr_recent_add (GtrWindow *window, GFile *location, gchar *project_id)
-{
-  GtrWindowPrivate *priv = gtr_window_get_instance_private(window);
-  gtr_projects_recent_add (GTR_PROJECTS (priv->projects), location, project_id);
-}
-
 void
 gtr_window_show_projects (GtrWindow *window)
 {
@@ -1124,6 +1117,13 @@ gtr_window_show_poeditor (GtrWindow *window)
   gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "poeditor");
 }
 
+void
+gtr_window_remove_all_pages (GtrWindow *window)
+{
+  GtrWindowPrivate *priv = gtr_window_get_instance_private(window);
+  gtr_notebook_remove_all_pages (GTR_NOTEBOOK (priv->notebook));
+}
+
 void
 gtr_window_show_tm_dialog (GtrWindow *window)
 {
diff --git a/src/gtr-window.h b/src/gtr-window.h
index 73a758bd..8e38b60a 100644
--- a/src/gtr-window.h
+++ b/src/gtr-window.h
@@ -81,11 +81,11 @@ void gtr_window_set_active_tab (GtrWindow * window, GtkWidget * tab);
 
 void _gtr_window_close_tab (GtrWindow * window, GtrTab * tab);
 
-void _gtr_recent_add (GtrWindow * window, GFile * location, gchar * project_id);
-
 GtrTranslationMemory * gtr_window_get_tm (GtrWindow *window);
 void gtr_window_show_tm_dialog (GtrWindow *window);
 
+void gtr_window_remove_all_pages (GtrWindow *window);
+
 /** stack app states **/
 void gtr_window_show_projects (GtrWindow *window);
 void gtr_window_show_poeditor (GtrWindow *window);


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