[gtranslator] Build translation memory dialog from menu
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator] Build translation memory dialog from menu
- Date: Wed, 12 Sep 2018 11:56:12 +0000 (UTC)
commit df7f377b0c0e9b47b29fb96221d0b9139e6e8782
Author: Daniel GarcĂa Moreno <danigm wadobo com>
Date: Mon Sep 10 19:26:11 2018 +0200
Build translation memory dialog from menu
src/gtr-application.c | 19 +++++++++++++++----
src/gtr-context.c | 39 +++++++++++++++------------------------
src/gtr-context.h | 3 +++
src/gtr-notebook.c | 1 -
src/gtr-notebook.ui | 22 ++++++++++++++++++----
src/gtr-tab.c | 7 ++++++-
src/gtr-tab.h | 2 +-
src/gtr-window.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
src/gtr-window.h | 6 ++++--
9 files changed, 111 insertions(+), 39 deletions(-)
---
diff --git a/src/gtr-application.c b/src/gtr-application.c
index 0c9f976f..696f18a4 100644
--- a/src/gtr-application.c
+++ b/src/gtr-application.c
@@ -373,8 +373,8 @@ next_activated (GSimpleAction *action,
static void
prev_no_activated (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
GtrApplication *app = GTR_APPLICATION (user_data);
gtr_message_go_to_prev_fuzzy_or_untranslated (NULL, app->priv->active_window);
@@ -382,13 +382,23 @@ prev_no_activated (GSimpleAction *action,
static void
next_no_activated (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ 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 void
+build_tm_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtrApplication *app = GTR_APPLICATION (user_data);
+ GtrWindow *w = GTR_WINDOW (app->priv->active_window);
+ gtr_window_show_tm_dialog (w);
+}
+
static GActionEntry app_entries[] = {
{ "save", save_activated, NULL, NULL, NULL },
{ "saveas", saveas_activated, NULL, NULL, NULL },
@@ -403,6 +413,7 @@ static GActionEntry app_entries[] = {
{ "prev_no", prev_no_activated, NULL, NULL, NULL },
{ "next_no", next_no_activated, NULL, NULL, NULL },
+ { "build_tm", build_tm_activated, NULL, NULL, NULL },
{ "new_window", new_window_activated, NULL, NULL, NULL },
{ "preferences", preferences_activated, NULL, NULL, NULL },
{ "help", help_activated, NULL, NULL, NULL },
diff --git a/src/gtr-context.c b/src/gtr-context.c
index b08f9193..a38f08c9 100644
--- a/src/gtr-context.c
+++ b/src/gtr-context.c
@@ -22,9 +22,7 @@
#include "gtr-context.h"
#include "gtr-tab.h"
#include "gtr-debug.h"
-#include "translation-memory/gtr-translation-memory.h"
#include "translation-memory/gtr-translation-memory-ui.h"
-#include "translation-memory/gda/gtr-gda.h"
#include <glib.h>
#include <glib/gi18n.h>
@@ -47,8 +45,6 @@ typedef struct
GtrMsg *current_msg;
// translation memory
- GSettings *tm_settings;
- GtrTranslationMemory *translation_memory;
GtkWidget *translation_memory_ui;
} GtrContextPanelPrivate;
@@ -388,24 +384,6 @@ gtr_context_panel_init (GtrContextPanel *panel)
g_signal_connect (priv->button, "clicked",
G_CALLBACK (on_done_button_clicked), panel);
- priv->tm_settings = g_settings_new ("org.gnome.gtranslator.plugins.translation-memory");
- priv->translation_memory = GTR_TRANSLATION_MEMORY (gtr_gda_new());
- gtr_translation_memory_set_max_omits (priv->translation_memory,
- g_settings_get_int (priv->tm_settings,
- "max-missing-words"));
- gtr_translation_memory_set_max_delta (priv->translation_memory,
- g_settings_get_int (priv->tm_settings,
- "max-length-diff"));
- gtr_translation_memory_set_max_items (priv->translation_memory, 10);
-
- priv->translation_memory_ui = gtr_translation_memory_ui_new (GTK_WIDGET (priv->tab),
- priv->translation_memory);
- gtk_widget_show (priv->translation_memory_ui);
- gtk_widget_set_size_request (priv->translation_memory_ui, 300, 400);
- gtk_box_pack_start (GTK_BOX (priv->translation_memory_box),
- priv->translation_memory_ui,
- FALSE, FALSE, 0);
-
gtk_widget_hide (priv->button_box);
}
@@ -484,8 +462,6 @@ gtr_context_panel_dispose (GObject *object)
g_clear_object (&priv->hand_cursor);
g_clear_object (&priv->regular_cursor);
- g_clear_object (&priv->translation_memory);
- g_clear_object (&priv->tm_settings);
G_OBJECT_CLASS (gtr_context_panel_parent_class)->dispose (object);
}
@@ -560,3 +536,18 @@ gtr_context_panel_get_context_text_view (GtrContextPanel * panel)
priv = gtr_context_panel_get_instance_private(panel);
return GTK_TEXT_VIEW (priv->context);
}
+
+void
+gtr_context_init_tm (GtrContextPanel *panel,
+ GtrTranslationMemory *tm)
+{
+ GtrContextPanelPrivate *priv = gtr_context_panel_get_instance_private(panel);
+ priv->translation_memory_ui = gtr_translation_memory_ui_new (GTK_WIDGET (priv->tab),
+ tm);
+ gtk_widget_show (priv->translation_memory_ui);
+ gtk_widget_set_size_request (priv->translation_memory_ui, 300, 400);
+ gtk_box_pack_start (GTK_BOX (priv->translation_memory_box),
+ priv->translation_memory_ui,
+ FALSE, FALSE, 0);
+}
+
diff --git a/src/gtr-context.h b/src/gtr-context.h
index b3f92d99..eb6e0014 100644
--- a/src/gtr-context.h
+++ b/src/gtr-context.h
@@ -23,6 +23,7 @@
#include <gtk/gtk.h>
#include "gtr-msg.h"
+#include "translation-memory/gtr-translation-memory.h"
G_BEGIN_DECLS
/*
@@ -67,5 +68,7 @@ GtkWidget *gtr_context_panel_new (void);
GtkTextView *gtr_context_panel_get_context_text_view (GtrContextPanel *panel);
+void gtr_context_init_tm (GtrContextPanel *panel, GtrTranslationMemory *tm);
+
G_END_DECLS
#endif /* __CONTEXT_PANEL_H__ */
diff --git a/src/gtr-notebook.c b/src/gtr-notebook.c
index 72ac58a0..18d40940 100644
--- a/src/gtr-notebook.c
+++ b/src/gtr-notebook.c
@@ -245,4 +245,3 @@ gtr_notebook_get_header (GtrNotebook *notebook)
GtrNotebookPrivate *priv = gtr_notebook_get_instance_private (notebook);
return priv->titlebar;
}
-
diff --git a/src/gtr-notebook.ui b/src/gtr-notebook.ui
index 8b228138..40fa4208 100644
--- a/src/gtr-notebook.ui
+++ b/src/gtr-notebook.ui
@@ -17,6 +17,20 @@
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="orientation">vertical</property>
+ <child>
+ <object class="GtkModelButton" id="translation_memory">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="action_name">app.build_tm</property>
+ <property name="text" translatable="yes">Build translation memory</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
<child>
<object class="GtkModelButton" id="pref_button1">
<property name="visible">True</property>
@@ -28,7 +42,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">0</property>
+ <property name="position">1</property>
</packing>
</child>
<child>
@@ -41,7 +55,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
<child>
@@ -55,7 +69,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">3</property>
</packing>
</child>
<child>
@@ -69,7 +83,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">3</property>
+ <property name="position">4</property>
</packing>
</child>
</object>
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index 0bca8941..7e7a2529 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -44,6 +44,7 @@
#include "gtr-view.h"
#include "gtr-dirs.h"
#include "gtr-debug.h"
+#include "gtr-window.h"
#include <glib.h>
#include <glib-object.h>
@@ -777,13 +778,15 @@ gtr_tab_class_init (GtrTabClass * klass)
/**
* gtr_tab_new:
* @po: a #GtrPo
+ * @window: a #GtkWindow
*
* Creates a new #GtrTab.
*
* Return value: a new #GtrTab object
**/
GtrTab *
-gtr_tab_new (GtrPo * po)
+gtr_tab_new (GtrPo * po,
+ GtkWindow *window)
{
GtrTab *tab;
GtrTabPrivate *priv;
@@ -793,6 +796,8 @@ gtr_tab_new (GtrPo * po)
tab = g_object_new (GTR_TYPE_TAB, NULL);
priv = gtr_tab_get_instance_private (tab);
+ gtr_context_init_tm (GTR_CONTEXT_PANEL (priv->context),
+ gtr_window_get_tm (GTR_WINDOW (window)));
/* FIXME: make the po a property */
priv->po = po;
diff --git a/src/gtr-tab.h b/src/gtr-tab.h
index d19ca3a7..63d59e92 100644
--- a/src/gtr-tab.h
+++ b/src/gtr-tab.h
@@ -91,7 +91,7 @@ typedef enum
*/
GType gtr_tab_get_type (void) G_GNUC_CONST;
-GtrTab *gtr_tab_new (GtrPo * po);
+GtrTab *gtr_tab_new (GtrPo * po, GtkWindow *window);
GtrPo *gtr_tab_get_po (GtrTab * tab);
diff --git a/src/gtr-window.c b/src/gtr-window.c
index 2c9bd065..633277e2 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -42,6 +42,10 @@
#include "gtr-profile-manager.h"
#include "gtr-status-combo-box.h"
+#include "translation-memory/gtr-translation-memory.h"
+#include "translation-memory/gtr-translation-memory-dialog.h"
+#include "translation-memory/gda/gtr-gda.h"
+
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n.h>
@@ -60,6 +64,8 @@
typedef struct
{
GSettings *state_settings;
+ GSettings *tm_settings;
+ GtrTranslationMemory *translation_memory;
GtkWidget *header_bar;
GtkWidget *main_box;
@@ -671,7 +677,7 @@ gtr_window_init (GtrWindow *window)
*/
// poeditor
- priv->notebook = GTK_WIDGET (gtr_notebook_new (window));
+ priv->notebook = GTK_WIDGET (gtr_notebook_new ());
gtk_widget_show (priv->notebook);
g_signal_connect (priv->notebook, "switch-page",
G_CALLBACK (notebook_switch_page), window);
@@ -697,6 +703,17 @@ gtr_window_init (GtrWindow *window)
gtk_widget_show_all (priv->stack);
+ // translation memory
+ priv->translation_memory = GTR_TRANSLATION_MEMORY (gtr_gda_new());
+ priv->tm_settings = g_settings_new ("org.gnome.gtranslator.plugins.translation-memory");
+ gtr_translation_memory_set_max_omits (priv->translation_memory,
+ g_settings_get_int (priv->tm_settings,
+ "max-missing-words"));
+ gtr_translation_memory_set_max_delta (priv->translation_memory,
+ g_settings_get_int (priv->tm_settings,
+ "max-length-diff"));
+ gtr_translation_memory_set_max_items (priv->translation_memory, 10);
+
gtr_window_show_projects (window);
}
@@ -726,6 +743,8 @@ gtr_window_dispose (GObject * object)
g_clear_object (&priv->state_settings);
g_clear_object (&priv->prof_manager);
+ g_clear_object (&priv->translation_memory);
+ g_clear_object (&priv->tm_settings);
G_OBJECT_CLASS (gtr_window_parent_class)->dispose (object);
}
@@ -788,7 +807,7 @@ gtr_window_create_tab (GtrWindow * window, GtrPo * po)
GtrWindowPrivate *priv = gtr_window_get_instance_private(window);
GtrTab *tab;
- tab = gtr_tab_new (po);
+ tab = gtr_tab_new (po, GTK_WINDOW (window));
gtk_widget_show (GTK_WIDGET (tab));
gtr_notebook_add_page (GTR_NOTEBOOK (priv->notebook), tab);
@@ -1082,3 +1101,31 @@ gtr_window_show_poeditor (GtrWindow *window)
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "poeditor");
}
+void
+gtr_window_show_tm_dialog (GtrWindow *window)
+{
+ GtrWindowPrivate *priv = gtr_window_get_instance_private(window);
+ static GtkWidget *dlg = NULL;
+
+ if (dlg == NULL)
+ {
+ dlg = gtr_translation_memory_dialog_new (priv->translation_memory);
+ g_signal_connect (dlg, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &dlg);
+ gtk_widget_show_all (dlg);
+ }
+
+ if (GTK_WINDOW (window) != gtk_window_get_transient_for (GTK_WINDOW (dlg)))
+ {
+ gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (window));
+ }
+
+ gtk_window_present (GTK_WINDOW (dlg));
+}
+
+GtrTranslationMemory *
+gtr_window_get_tm (GtrWindow *window) {
+ GtrWindowPrivate *priv = gtr_window_get_instance_private (window);
+ return priv->translation_memory;
+}
+
diff --git a/src/gtr-window.h b/src/gtr-window.h
index 9e6e5302..73a758bd 100644
--- a/src/gtr-window.h
+++ b/src/gtr-window.h
@@ -81,8 +81,10 @@ 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);
+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);
/** stack app states **/
void gtr_window_show_projects (GtrWindow *window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]