[gtranslator] projects: The open button open and show the file



commit 2f1b4292b20cb142c4b769d5fb9e0376aae4647e
Author: Daniel García Moreno <danigm wadobo com>
Date:   Mon Sep 10 10:37:17 2018 +0200

    projects: The open button open and show the file

 src/gtr-actions-file.c |  8 +++++++
 src/gtr-notebook.ui    |  4 ++++
 src/gtr-projects.c     | 60 ++++++++++++++++++++++++++++++++++++++++++++++----
 src/gtr-projects.h     |  7 ++++--
 src/gtr-projects.ui    |  4 ++++
 src/gtr-window.c       |  9 ++++++++
 src/gtr-window.h       |  3 +++
 7 files changed, 89 insertions(+), 6 deletions(-)
---
diff --git a/src/gtr-actions-file.c b/src/gtr-actions-file.c
index 3bba22bd..4053313a 100644
--- a/src/gtr-actions-file.c
+++ b/src/gtr-actions-file.c
@@ -59,6 +59,8 @@ gtr_open (GFile * location, GtrWindow * window, GError ** error)
   GtrTab *tab;
   GList *current;
   GtrView *active_view;
+  GtrHeader *header;
+  const gchar *project_id;
 
   /*
    * If the filename can't be opened, pass the error back to the caller
@@ -71,6 +73,10 @@ gtr_open (GFile * location, GtrWindow * window, GError ** error)
       && (((GError *) * error)->code != GTR_PO_ERROR_RECOVERY))
     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
    */
@@ -98,6 +104,8 @@ gtr_open (GFile * location, GtrWindow * window, GError ** error)
                                      (gdouble)
                                      gtr_po_get_messages_count (po));
 
+  gtr_window_show_poeditor (window);
+
   return TRUE;
 }
 
diff --git a/src/gtr-notebook.ui b/src/gtr-notebook.ui
index 0a5b8455..fdb599d5 100644
--- a/src/gtr-notebook.ui
+++ b/src/gtr-notebook.ui
@@ -12,6 +12,9 @@
     <property name="visible">true</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">
         <property name="visible">True</property>
@@ -118,3 +121,4 @@
 
 </interface>
 
+
diff --git a/src/gtr-projects.c b/src/gtr-projects.c
index c48b8cab..90f37987 100644
--- a/src/gtr-projects.c
+++ b/src/gtr-projects.c
@@ -23,6 +23,7 @@
 #include "gtr-actions.h"
 #include "gtr-projects.h"
 #include "gtr-window.h"
+#include "gtr-utils.h"
 
 typedef struct
 {
@@ -45,6 +46,7 @@ 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
@@ -82,17 +84,20 @@ 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 ();
 
-  init_recent (self);
-
   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*
@@ -157,6 +162,14 @@ init_recent (GtrProjects *self)
 
   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);
@@ -172,8 +185,47 @@ init_recent (GtrProjects *self)
       it = g_list_next (it);
     }
 
-  g_signal_connect (list, "row-activated", G_CALLBACK (file_open_cb), self);
-
   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.h b/src/gtr-projects.h
index 770608fd..c11f8de0 100644
--- a/src/gtr-projects.h
+++ b/src/gtr-projects.h
@@ -26,8 +26,11 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GtrProjects, gtr_projects, GTR, PROJECTS, GtkBin)
 
-GtrProjects*  gtr_projects_new        ();
-GtkWidget*    gtr_projects_get_header (GtrProjects *self);
+GtrProjects*  gtr_projects_new         ();
+GtkWidget*    gtr_projects_get_header  (GtrProjects *self);
+void          gtr_projects_recent_add  (GtrProjects *self,
+                                        GFile *location,
+                                        gchar *jkkproject_id);
 
 G_END_DECLS
 
diff --git a/src/gtr-projects.ui b/src/gtr-projects.ui
index 069495fb..4af64370 100644
--- a/src/gtr-projects.ui
+++ b/src/gtr-projects.ui
@@ -39,6 +39,9 @@
     <property name="visible">true</property>
     <property name="title" translatable="yes">Select a PO file</property>
     <property name="show_close_button">True</property>
+    <style>
+      <class name="titlebar"/>
+    </style>
     <child>
       <object class="GtkButton" id="open_button">
         <property name="label" translatable="yes">Open…</property>
@@ -52,3 +55,4 @@
   </object>
 
 </interface>
+
diff --git a/src/gtr-window.c b/src/gtr-window.c
index bf63840d..2c9bd065 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -1055,6 +1055,13 @@ _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)
 {
@@ -1062,6 +1069,8 @@ gtr_window_show_projects (GtrWindow *window)
 
   gtk_stack_set_visible_child_name (GTK_STACK (priv->header_stack), "projects");
   gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "projects");
+
+  gtr_notebook_remove_all_pages (GTR_NOTEBOOK (priv->notebook));
 }
 
 void
diff --git a/src/gtr-window.h b/src/gtr-window.h
index 70aa954c..9e6e5302 100644
--- a/src/gtr-window.h
+++ b/src/gtr-window.h
@@ -81,6 +81,9 @@ 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);
+
 /** 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]