[gtranslator] Functional app with *modern* interface
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator] Functional app with *modern* interface
- Date: Wed, 12 Sep 2018 11:55:56 +0000 (UTC)
commit 2c32c87d02aaa73c0a0f0afc205987e599b6ec8d
Author: Daniel GarcĂa Moreno <danigm wadobo com>
Date: Thu Sep 6 21:48:23 2018 +0200
Functional app with *modern* interface
This patch tries to leave the app functional so it can be used meantime
we continue working in the UI.
First a *Project* selection is showed, showing recent files so you can
open files from there. This view will be updated soon to a
GtrProjectSelector widget, that will manage more information than only a
.po file, but for now, a *project* is a single po file.
Once a file is opened the NoteBook is showed using the old interface.
The toolbar and status bar are removed so we need to show that
information in other places, following the gnome HIG.
Menu actions are moved to the headerbar or to the hamburger menu.
.gitignore | 1 +
src/gtr-tab.c | 4 ++
src/gtr-tab.ui | 1 +
src/gtr-window.c | 130 ++++++++++++++++++++++++++++++++++++++
src/gtr-window.ui | 183 +++++++++++++++++++++++++++++++++---------------------
5 files changed, 247 insertions(+), 72 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 682da155..d587d7f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
_build/
*.swp
+*~
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index dd47b116..0bca8941 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -766,6 +766,10 @@ gtr_tab_class_init (GtrTabClass * klass)
gtk_widget_class_bind_template_child_private (widget_class, GtrTab, msgstr_label);
gtk_widget_class_bind_template_child_private (widget_class, GtrTab, trans_notebook);
gtk_widget_class_bind_template_child_private (widget_class, GtrTab, context);
+
+ g_type_ensure (gtr_view_get_type ());
+ g_type_ensure (gtr_context_panel_get_type ());
+ g_type_ensure (gtr_message_table_get_type ());
}
/***************************** Public funcs ***********************************/
diff --git a/src/gtr-tab.ui b/src/gtr-tab.ui
index b92b2463..ca2f81a9 100644
--- a/src/gtr-tab.ui
+++ b/src/gtr-tab.ui
@@ -153,3 +153,4 @@
</child>
</template>
</interface>
+
diff --git a/src/gtr-window.c b/src/gtr-window.c
index 7c911c94..0694fe78 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -58,10 +58,16 @@
typedef struct
{
+ GtkRecentManager *recent_manager;
GSettings *state_settings;
GtkWidget *header_bar;
GtkWidget *main_box;
+ GtkWidget *stack;
+
+ GtkWidget *project_add;
+ GtkWidget *project_list;
+ GtkWidget *project_remove;
GtkWidget *notebook;
GtrTab *active_tab;
@@ -184,6 +190,54 @@ get_drop_window (GtkWidget * widget)
return GTR_WINDOW (target_window);
}
+static void
+show_notebook (GtrWindow *window) {
+ GtrWindowPrivate *priv = gtr_window_get_instance_private(window);
+ gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "notebook");
+}
+
+static void
+file_open_cb (GtkListBox *box,
+ GtkListBoxRow *row,
+ gpointer data)
+{
+ gint index = gtk_list_box_row_get_index (row);
+ GtrWindow *window = GTR_WINDOW (data);
+ GtrWindowPrivate *priv = gtr_window_get_instance_private(window);
+ 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, window, &error)) {
+ g_error_free (error);
+ goto out;
+ }
+
+ show_notebook (window);
+
+out:
+ g_object_unref (file);
+ g_list_free_full (recents, (GDestroyNotify)gtk_recent_info_unref);
+}
+
+static void
+project_add_cb (GtkButton *btn,
+ gpointer data)
+{
+ GtrWindow *window = GTR_WINDOW (data);
+ gtr_open_file_dialog (NULL, window);
+}
+
+static void
+project_remove_cb (GtkButton *btn,
+ gpointer data)
+{
+ printf ("PROJECT REMOVE\n");
+}
+
/* Handle drops on the GtrWindow */
static void
drag_data_received_cb (GtkWidget * widget,
@@ -353,6 +407,16 @@ notebook_page_removed (GtkNotebook * notebook,
gtk_widget_hide (priv->profile_combo);
}
+static void
+notebook_tab_close_request (GtrNotebook * notebook,
+ GtrTab * tab, GtrWindow * window)
+{
+ /* Note: we are destroying the tab before the default handler
+ * seems to be ok, but we need to keep an eye on this. */
+ gtr_close_tab (tab, window);
+}
+
+
static void
notebook_tab_added (GtkNotebook * notebook,
GtkWidget * child, guint page_num, GtrWindow * window)
@@ -452,6 +516,37 @@ fill_profile_combo (GtrWindow *window)
}
}
+static void
+init_recent (GtrWindow *window)
+{
+ GtrWindowPrivate *priv = gtr_window_get_instance_private(window);
+ GtkListBox *list = GTK_LIST_BOX (priv->project_list);
+
+ GList *recents = gtk_recent_manager_get_items (priv->recent_manager);
+ GList *it = g_list_first (recents);
+ 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_signal_connect (list,
+ "row-activated",
+ G_CALLBACK (file_open_cb), window);
+
+
+ g_list_free_full (recents, (GDestroyNotify)gtk_recent_info_unref);
+}
+
static void
init_statusbar (GtrWindow *window)
{
@@ -605,6 +700,7 @@ gtr_window_init (GtrWindow *window)
GtrWindowPrivate *priv = gtr_window_get_instance_private(window);
priv->state_settings = g_settings_new ("org.gnome.gtranslator.state.window");
+ priv->recent_manager = gtk_recent_manager_get_default ();
gtk_widget_init_template (GTK_WIDGET (window));
@@ -623,6 +719,26 @@ gtr_window_init (GtrWindow *window)
/* statusbar & progress bar */
init_statusbar (window);
+ /* init recent projects */
+ init_recent (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);
+ g_signal_connect (priv->notebook, "page-added",
+ G_CALLBACK (notebook_tab_added), window);
+ g_signal_connect (priv->notebook, "page-removed",
+ G_CALLBACK (notebook_page_removed), window);
+ g_signal_connect (priv->notebook,
+ "tab_close_request",
+ G_CALLBACK (notebook_tab_close_request), window);
+
+ gtk_stack_add_named (GTK_STACK (priv->stack),
+ priv->notebook,
+ "notebook");
+
/* Drag and drop support, set targets to NULL because we add the
default uri_targets below */
gtk_drag_dest_set (GTK_WIDGET (window),
@@ -646,6 +762,15 @@ gtr_window_init (GtrWindow *window)
g_signal_connect (window,
"drag_data_received",
G_CALLBACK (drag_data_received_cb), NULL);
+
+ g_signal_connect (priv->project_add,
+ "clicked",
+ G_CALLBACK (project_add_cb),
+ (gpointer)window);
+ g_signal_connect (priv->project_remove,
+ "clicked",
+ G_CALLBACK (project_remove_cb),
+ (gpointer)window);
}
static void
@@ -714,6 +839,11 @@ gtr_window_class_init (GtrWindowClass *klass)
/* Main layout widgets */
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GtrWindow, header_bar);
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GtrWindow, main_box);
+ gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GtrWindow, stack);
+
+ gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GtrWindow, project_list);
+ gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GtrWindow, project_add);
+ gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GtrWindow, project_remove);
}
/***************************** Public funcs ***********************************/
diff --git a/src/gtr-window.ui b/src/gtr-window.ui
index df56d232..759c16db 100644
--- a/src/gtr-window.ui
+++ b/src/gtr-window.ui
@@ -1,26 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.14"/>
+ <object class="GtkImage" id="add_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">list-add-symbolic</property>
+ </object>
+ <object class="GtkImage" id="menu_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">open-menu-symbolic</property>
+ </object>
+ <object class="GtkImage" id="remove_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">list-remove-symbolic</property>
+ </object>
<template class="GtrWindow" parent="GtkApplicationWindow">
- <property name="can-focus">False</property>
- <property name="default-width">800</property>
- <property name="default-height">600</property>
- <property name="height-request">600</property>
- <property name="show-menubar">False</property>
+ <property name="height_request">600</property>
+ <property name="can_focus">False</property>
+ <property name="default_width">800</property>
+ <property name="default_height">600</property>
+ <property name="show_menubar">False</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="header_bar">
<property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="show-close-button">True</property>
+ <property name="can_focus">False</property>
<property name="title" translatable="yes">Projects</property>
+ <property name="show_close_button">True</property>
<child>
<object class="GtkMenuButton" id="menu_button">
<property name="visible">True</property>
- <property name="use-popover">True</property>
+ <property name="can_focus">False</property>
+ <property name="receives_default">False</property>
<property name="image">menu_image</property>
</object>
<packing>
- <property name="pack-type">end</property>
+ <property name="pack_type">end</property>
</packing>
</child>
</object>
@@ -28,93 +45,115 @@
<child>
<object class="GtkBox" id="main_box">
<property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="margin-start">134</property>
- <property name="margin-end">134</property>
- <property name="margin-top">24</property>
- <property name="margin-bottom">24</property>
+ <property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkFrame" id="project_frame">
- <property name="visible">True</property>
- <property name="can-focus">False</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>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkToolbar" id="project_toolbar">
+ <object class="GtkStack" id="stack">
<property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="toolbar-style">icons</property>
- <property name="show-arrow">False</property>
- <property name="icon-size">1</property>
- <style>
- <class name="inline-toolbar"/>
- </style>
+ <property name="can_focus">False</property>
+ <property name="vexpand">True</property>
<child>
- <object class="GtkToolItem" id="project_add_remove_item">
+ <object class="GtkBox" id="projects">
+ <property name="margin_start">134</property>
+ <property name="margin_end">134</property>
<property name="visible">True</property>
- <property name="can-focus">False</property>
+ <property name="can_focus">False</property>
+ <property name="margin_top">24</property>
+ <property name="margin_bottom">24</property>
+ <property name="vexpand">False</property>
+ <property name="orientation">vertical</property>
<child>
- <object class="GtkBox" id="project_add_remove_box">
+ <object class="GtkFrame" id="project_frame">
<property name="visible">True</property>
- <property name="can-focus">False</property>
+ <property name="can_focus">False</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">in</property>
<child>
- <object class="GtkButton" id="project_add">
+ <object class="GtkListBox" id="project_list">
<property name="visible">True</property>
- <property name="can-focus">True</property>
- <property name="receives-default">True</property>
- <property name="image">add_image</property>
- <child internal-child="accessible">
- <object class="AtkObject">
- <property name="accessible-name" translatable="yes">Add project</property>
- </object>
- </child>
+ <property name="can_focus">True</property>
</object>
</child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToolbar" id="project_toolbar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="toolbar_style">icons</property>
+ <property name="show_arrow">False</property>
+ <property name="icon_size">1</property>
<child>
- <object class="GtkButton" id="project_remove">
+ <object class="GtkToolItem" id="project_add_remove_item">
<property name="visible">True</property>
- <property name="can-focus">True</property>
- <property name="receives-default">True</property>
- <property name="image">remove_image</property>
- <child internal-child="accessible">
- <object class="AtkObject">
- <property name="accessible-name" translatable="yes">Remove project</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkBox" id="project_add_remove_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkButton" id="project_add">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="image">add_image</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="project_remove">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="image">remove_image</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
</child>
</object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">False</property>
+ </packing>
</child>
+ <style>
+ <class name="inline-toolbar"/>
+ </style>
</object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
</child>
</object>
+ <packing>
+ <property name="name">projects</property>
+ <property name="title" translatable="yes">Projects</property>
+ </packing>
</child>
</object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
</child>
</object>
</child>
</template>
- <object class="GtkImage" id="add_image">
- <property name="visible">True</property>
- <property name="icon-name">list-add-symbolic</property>
- </object>
- <object class="GtkImage" id="menu_image">
- <property name="visible">True</property>
- <property name="icon-name">open-menu-symbolic</property>
- </object>
- <object class="GtkImage" id="remove_image">
- <property name="visible">True</property>
- <property name="icon-name">list-remove-symbolic</property>
- </object>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]