[gtranslator] message-table: Show msg status inline



commit a8eb2ac61a633870624f92309da1dd26e382b3f3
Author: Daniel GarcĂ­a Moreno <danigm wadobo com>
Date:   Wed Oct 10 18:08:07 2018 +0200

    message-table: Show msg status inline
    
    I've removed the STATUS and the ID columns and to show the message
    status now we use text colors so fuzzy will be orange and untranslated
    red. These two colors are getted from the theme so this should work in
    the dark mode and other themes should work correctly too.
    
    Fix #25

 src/gtr-message-table-model.c | 20 ---------
 src/gtr-message-table-model.h |  1 -
 src/gtr-message-table.c       | 96 ++++++++++++++++++++++++++++++++-----------
 src/gtr-tab.c                 | 10 +++++
 src/gtr-tab.ui                | 39 ++++++++++++++----
 src/styles.css                |  5 +++
 6 files changed, 118 insertions(+), 53 deletions(-)
---
diff --git a/src/gtr-message-table-model.c b/src/gtr-message-table-model.c
index 186a67bb..eb70a7c9 100644
--- a/src/gtr-message-table-model.c
+++ b/src/gtr-message-table-model.c
@@ -30,10 +30,6 @@
 
 #define G_LIST(x) ((GList *) x)
 
-#define TABLE_FUZZY_ICON "dialog-warning-symbolic"
-#define TABLE_UNTRANSLATED_ICON "dialog-error-symbolic"
-#define TABLE_TRANSLATED_ICON NULL
-
 enum {
   PROP_0,
   PROP_CONTAINER
@@ -65,7 +61,6 @@ gtr_message_table_model_get_column_type (GtkTreeModel * self, gint column)
 
   switch (column)
     {
-    case GTR_MESSAGE_TABLE_MODEL_ICON_COLUMN:
     case GTR_MESSAGE_TABLE_MODEL_ORIGINAL_COLUMN:
     case GTR_MESSAGE_TABLE_MODEL_TRANSLATION_COLUMN:
       retval = G_TYPE_STRING;
@@ -149,21 +144,6 @@ gtr_message_table_model_get_value (GtkTreeModel * self,
 
   switch (column)
     {
-    case GTR_MESSAGE_TABLE_MODEL_ICON_COLUMN:
-      g_value_init (value, G_TYPE_STRING);
-
-      status = gtr_msg_get_status (msg);
-
-      if (status == GTR_MSG_STATUS_UNTRANSLATED)
-        text = TABLE_UNTRANSLATED_ICON;
-      else if (status == GTR_MSG_STATUS_FUZZY)
-        text = TABLE_FUZZY_ICON;
-      else
-        text = TABLE_TRANSLATED_ICON;
-
-      g_value_set_string (value, text);
-      break;
-
     case GTR_MESSAGE_TABLE_MODEL_ID_COLUMN:
       g_value_init (value, G_TYPE_INT);
 
diff --git a/src/gtr-message-table-model.h b/src/gtr-message-table-model.h
index 59cdc6d6..0e2817d5 100644
--- a/src/gtr-message-table-model.h
+++ b/src/gtr-message-table-model.h
@@ -56,7 +56,6 @@ typedef enum _GtrMessageTableModelColumn GtrMessageTableModelColumn;
 
 enum _GtrMessageTableModelColumn
 {
-  GTR_MESSAGE_TABLE_MODEL_ICON_COLUMN,
   GTR_MESSAGE_TABLE_MODEL_ID_COLUMN,
   GTR_MESSAGE_TABLE_MODEL_ORIGINAL_COLUMN,
   GTR_MESSAGE_TABLE_MODEL_TRANSLATION_COLUMN,
diff --git a/src/gtr-message-table.c b/src/gtr-message-table.c
index ea266ced..b94086b0 100644
--- a/src/gtr-message-table.c
+++ b/src/gtr-message-table.c
@@ -55,6 +55,55 @@ typedef struct
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtrMessageTable, gtr_message_table, GTK_TYPE_BOX)
 
+typedef struct
+{
+  GdkRGBA *fuzzy;
+  GdkRGBA *untranslated;
+  GdkRGBA *translated;
+} GtrMessageColors;
+
+static void
+gtr_message_color_destroy (GtrMessageColors *colors)
+{
+  gdk_rgba_free (colors->fuzzy);
+  gdk_rgba_free (colors->untranslated);
+  gdk_rgba_free (colors->translated);
+  g_free (colors);
+}
+
+static GtrMessageColors *
+gtr_message_color_copy (GtrMessageColors *colors)
+{
+  GtrMessageColors *copy = g_malloc0 (sizeof(GtrMessageColors));
+  copy->fuzzy = gdk_rgba_copy (colors->fuzzy);
+  copy->translated = gdk_rgba_copy (colors->translated);
+  copy->untranslated = gdk_rgba_copy (colors->untranslated);
+
+  return copy;
+}
+
+static void
+colorize_cell (GtkTreeViewColumn *tree_column,
+               GtkCellRenderer *cell,
+               GtkTreeModel *tree_model,
+               GtkTreeIter *iter,
+               gpointer data)
+{
+  GtrMsg *msg;
+  GtrMessageColors *colors = (GtrMessageColors*)data;
+
+  gtk_tree_model_get (tree_model, iter,
+                      GTR_MESSAGE_TABLE_MODEL_POINTER_COLUMN, &msg,
+                      -1);
+
+  if (gtr_msg_is_fuzzy (msg))
+    g_object_set (cell, "foreground-rgba", colors->fuzzy, NULL);
+  else if (gtr_msg_is_translated (msg))
+    g_object_set (cell, "foreground-rgba", colors->translated, NULL);
+  else
+    g_object_set (cell, "foreground-rgba", colors->untranslated, NULL);
+}
+
 static void
 showed_message_cb (GtrTab * tab, GtrMsg * msg, GtrMessageTable * table)
 {
@@ -163,36 +212,27 @@ gtr_message_table_init (GtrMessageTable * table)
   GtkTreeSelection *selection;
   GtrMessageTablePrivate *priv;
 
-  priv = gtr_message_table_get_instance_private (table);
+  GdkRGBA translated, fuzzy, untranslated;
+  GtkStyleContext *style_context;
+  GtrMessageColors *colors;
 
-  gtk_orientable_set_orientation (GTK_ORIENTABLE (table),
-                                  GTK_ORIENTATION_VERTICAL);
+  colors = g_malloc0 (sizeof(GtrMessageColors));
 
-  gtk_widget_init_template (GTK_WIDGET (table));
+  style_context = gtk_widget_get_style_context (GTK_WIDGET (table));
+  gtk_style_context_lookup_color (style_context, "fg_color", &translated);
+  gtk_style_context_lookup_color (style_context, "warning_color", &fuzzy);
+  gtk_style_context_lookup_color (style_context, "error_color", &untranslated);
 
-  renderer = gtk_cell_renderer_pixbuf_new ();
-  column = gtk_tree_view_column_new_with_attributes (_("Status"),
-                                                     renderer,
-                                                     "icon-name",
-                                                     GTR_MESSAGE_TABLE_MODEL_ICON_COLUMN,
-                                                     NULL);
+  colors->fuzzy = gdk_rgba_copy (&fuzzy);
+  colors->translated = gdk_rgba_copy (&translated);
+  colors->untranslated = gdk_rgba_copy (&untranslated);
 
-  gtk_tree_view_column_set_sort_column_id (column,
-                                           GTR_MESSAGE_TABLE_MODEL_STATUS_COLUMN);
-  gtk_tree_view_column_set_resizable (column, FALSE);
-  gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview), column);
+  priv = gtr_message_table_get_instance_private (table);
 
-  renderer = gtk_cell_renderer_text_new ();
-  column = gtk_tree_view_column_new_with_attributes (_("ID"),
-                                                     renderer,
-                                                     "text",
-                                                     GTR_MESSAGE_TABLE_MODEL_ID_COLUMN,
-                                                     NULL);
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (table),
+                                  GTK_ORIENTATION_VERTICAL);
 
-  gtk_tree_view_column_set_sort_column_id (column,
-                                           GTR_MESSAGE_TABLE_MODEL_ID_COLUMN);
-  gtk_tree_view_column_set_resizable (column, FALSE);
-  gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview), column);
+  gtk_widget_init_template (GTK_WIDGET (table));
 
   renderer = gtk_cell_renderer_text_new ();
   g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
@@ -204,6 +244,10 @@ gtr_message_table_init (GtrMessageTable * table)
                                                      GTR_MESSAGE_TABLE_MODEL_ORIGINAL_COLUMN,
                                                      NULL);
 
+  gtk_tree_view_column_set_cell_data_func (column, renderer, colorize_cell,
+                                           colors,
+                                           (GDestroyNotify)gtr_message_color_destroy);
+
   gtk_tree_view_column_set_sort_column_id (column,
                                            GTR_MESSAGE_TABLE_MODEL_ORIGINAL_COLUMN);
   gtk_tree_view_column_set_expand (column, TRUE);
@@ -219,6 +263,10 @@ gtr_message_table_init (GtrMessageTable * table)
                                                      GTR_MESSAGE_TABLE_MODEL_TRANSLATION_COLUMN,
                                                      NULL);
 
+  gtk_tree_view_column_set_cell_data_func (column, renderer, colorize_cell,
+                                           gtr_message_color_copy (colors),
+                                           (GDestroyNotify)gtr_message_color_destroy);
+
   gtk_tree_view_column_set_sort_column_id (column,
                                            GTR_MESSAGE_TABLE_MODEL_TRANSLATION_COLUMN);
   gtk_tree_view_column_set_expand (column, TRUE);
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index ea3716fb..8f1809dd 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -77,6 +77,7 @@ typedef struct
   GtkWidget *text_msgid;
   GtkWidget *text_plural_scroll;
   GtkWidget *text_msgid_plural;
+  GtkWidget *msgid_tags;
 
   /*Translated text */
   GtkWidget *msgstr_label;
@@ -403,6 +404,7 @@ gtr_tab_show_message (GtrTab * tab, GtrMsg * msg)
   g_return_if_fail (GTR_IS_TAB (tab));
 
   priv = gtr_tab_get_instance_private (tab);
+  gtk_label_set_text (GTK_LABEL (priv->msgid_tags), "");
 
   po = priv->po;
   gtr_po_update_current_message (po, msg);
@@ -413,6 +415,9 @@ gtr_tab_show_message (GtrTab * tab, GtrMsg * msg)
       gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (buf));
       gtk_text_buffer_set_text (buf, (gchar *) msgid, -1);
       gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (buf));
+
+      if (gtr_msg_is_fuzzy (msg))
+        gtk_label_set_text (GTK_LABEL (priv->msgid_tags), _("fuzzy"));
     }
   msgid_plural = gtr_msg_get_msgid_plural (msg);
   if (!msgid_plural)
@@ -522,6 +527,10 @@ update_status (GtrTab * tab, GtrMsg * msg, gpointer useless)
     }
 
   gtr_msg_set_status (msg, status);
+  if (gtr_msg_is_fuzzy (msg))
+    gtk_label_set_text (GTK_LABEL (priv->msgid_tags), _("fuzzy"));
+  else
+    gtk_label_set_text (GTK_LABEL (priv->msgid_tags), "");
 
   /* We need to update the tab state too if is neccessary */
   if (po_state != GTR_PO_STATE_MODIFIED)
@@ -780,6 +789,7 @@ gtr_tab_class_init (GtrTabClass * klass)
 
   gtk_widget_class_bind_template_child_private (widget_class, GtrTab, message_table);
   gtk_widget_class_bind_template_child_private (widget_class, GtrTab, text_msgid);
+  gtk_widget_class_bind_template_child_private (widget_class, GtrTab, msgid_tags);
   gtk_widget_class_bind_template_child_private (widget_class, GtrTab, text_plural_scroll);
   gtk_widget_class_bind_template_child_private (widget_class, GtrTab, text_msgid_plural);
   gtk_widget_class_bind_template_child_private (widget_class, GtrTab, msgstr_label);
diff --git a/src/gtr-tab.ui b/src/gtr-tab.ui
index f99b53d0..64dde0e5 100644
--- a/src/gtr-tab.ui
+++ b/src/gtr-tab.ui
@@ -40,16 +40,38 @@
                     <property name="can_focus">False</property>
                     <property name="orientation">vertical</property>
                     <child>
-                      <object class="GtkLabel" id="msgid_label">
+                      <object class="GtkBox" id="text_hbox">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
-                        <property name="ypad">5</property>
-                        <property name="label" translatable="yes">_Original Message:</property>
-                        <property name="use_underline">True</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
+                        <property name="orientation">horizontal</property>
+                        <child>
+                          <object class="GtkLabel" id="msgid_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="ypad">5</property>
+                            <property name="label" translatable="yes">_Original Message:</property>
+                            <property name="use_underline">True</property>
+                            <attributes>
+                              <attribute name="weight" value="bold"/>
+                            </attributes>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="msgid_tags">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="ypad">5</property>
+                            <property name="label"></property>
+                            <attributes>
+                              <attribute name="weight" value="bold"/>
+                            </attributes>
+                            <style>
+                              <class name="msgtags"/>
+                            </style>
+                          </object>
+                        </child>
                       </object>
                       <packing>
                         <property name="expand">False</property>
@@ -165,3 +187,4 @@
     </child>
   </template>
 </interface>
+
diff --git a/src/styles.css b/src/styles.css
index b922d85e..65112d9b 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -9,3 +9,8 @@
 .devel .titlebar label {
   color: @theme_fg_color;
 }
+
+.msgtags {
+  margin-left: 10px;
+  color: @warning_color;
+}


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