Re: [Gtranslator-devel] e-tree vs e-table and status grouping
- From: Kevin Vandersloot <kfv101 psu edu>
- To: Fatih Demir <kabalak gtranslator org>
- Cc: gtranslator devel <gtranslator-devel lists sourceforge net>
- Subject: Re: [Gtranslator-devel] e-tree vs e-table and status grouping
- Date: Sun Sep 16 15:27:02 2001
Patch attached. I apologize if it doesn't pass Werror. This wouldn't be
the final patch but at least gives you the idea of how it will work.
There is also a crash when closing files that I haven't really looked
into.
Kevin
On Sun, 2001-09-16 at 10:34, Fatih Demir wrote:
> On Sat, 2001-09-15 at 23:03, Kevin Vandersloot wrote:
> Hello everyone.
>
> Hi.
>
> I spent my afternoon porting gtranslator to e-table
> instead of e-tree considering that e-tree will not support grouping for
> the near future. I've attached screenshots with the grouping enabled.
>
> Hm, ok. Could you put up a diff of this somewhere or send it to me/list? Let me patch the current sources and let me try it.
>
> The one big problem is that it groups alphabetically ie. Fuzzy first,
> Translated second, and Untranslated third (of course different for other
> langs). One way around that is to put a number before the status as in
> "1 Untranslated".
>
> Uhm, shouldn't be this way: I haven't researched enough but there's surely a way to handle this better via ETableSortInfo etc.
> Maybe via replacing the ordering function for the grouping (surely a *cmp variant) with a custom one which assorts the status strings in the right order and leaves everything other as it is?!
>
> Besides this I found it quite good to have the count of fuzzy, missing
> strings in the table/tree -- via auto-grouping this is quite hopeless
> and non-given.
>
> This does remove a lot of hacks to do the present grouping a simplifies
> a lot of code. Let me know if you think this is better than the old way
> using e-tree and hackery.
>
> Yes, it will make the code much easier and will base upon GAL's logic
> (eh, if this is something good to do is another point ,-)).
Index: messages-table.c
===================================================================
RCS file: /cvs/gnome/gtranslator/src/messages-table.c,v
retrieving revision 1.52
diff -u -5 -r1.52 messages-table.c
--- messages-table.c 2001/09/08 17:05:53 1.52
+++ messages-table.c 2001/09/16 22:22:47
@@ -43,14 +43,14 @@
#include <gal/e-table/e-cell-combo.h>
#include <gal/e-table/e-cell-number.h>
#include <gal/e-table/e-cell-text.h>
#include <gal/e-table/e-cell-tree.h>
#include <gal/e-table/e-table-extras.h>
-#include <gal/e-table/e-tree-model.h>
-#include <gal/e-table/e-tree-memory.h>
-#include <gal/e-table/e-tree-scrolled.h>
-#include <gal/e-table/e-tree-memory-callbacks.h>
+#include <gal/e-table/e-table.h>
+#include <gal/e-table/e-table-memory.h>
+#include <gal/e-table/e-table-memory-callbacks.h>
+#include <gal/e-table/e-table-scrolled.h>
/*
* Create the ETableExtras for our messages table.
*/
static ETableExtras *table_extras_new(void);
@@ -58,30 +58,29 @@
/*
* Internal ETableModel functions: the names should be self-explanatory.
*
* Prototypes:
*/
-static GdkPixbuf *icon_at_function (ETreeModel *model, ETreePath path, void *data);
-static gint column_count_function(ETreeModel *model, void *data);
+static gint column_count_function(ETableModel *model, void *data);
-static gboolean is_cell_editable_function(ETreeModel *model, ETreePath path,
- int column, void *data);
-static gboolean is_empty_function(ETreeModel *model, int column,
+static gboolean is_cell_editable_function(ETableModel *model, int column, int row,
+ void *data);
+static gboolean is_empty_function(ETableModel *model, int column,
const void *value, void *data);
-static void free_value_function(ETreeModel *model, int column,
+static void free_value_function(ETableModel *model, int column,
void *value, void *data);
-static void set_value_at_function(ETreeModel *model, ETreePath path, int col,
+static void set_value_at_function(ETableModel *model, int col, int row,
const void *value, void *data);
-static void *duplicate_value_function(ETreeModel *model, int column,
+static void *duplicate_value_function(ETableModel *model, int column,
const void *value, void *data);
-static void *initialize_value_function(ETreeModel *model, int column, void *data);
-static void *value_at_function(ETreeModel *model, ETreePath path, int column,
+static void *initialize_value_function(ETableModel *model, int column, void *data);
+static void *value_at_function(ETableModel *model, int column, int row,
void *data);
-static gchar *return_string_for_value_function(ETreeModel *model, int column,
+static gchar *return_string_for_value_function(ETableModel *model, int column,
const void *value, void *data);
/*
* Simply sets up/frees the generally used messages table colors.
*/
@@ -99,18 +98,14 @@
} GtrMessagesTableColors;
/*
* Global variables
*/
-GtkWidget *tree;
-ETreeModel *tree_model;
-ETreeMemory *tree_memory;
-ETreePath root_node = NULL;
-ETreePath translated_node = NULL;
-ETreePath fuzzy_node = NULL;
-ETreePath unknown_node = NULL;
-ETableExtras *tree_extras;
+GtkWidget *table;
+ETableModel *table_model;
+ETableMemory *table_memory;
+ETableExtras *table_extras;
GtrMessagesTableColors *messages_table_colors;
/*
* hash table to associate an ETreePath with each message. Used
@@ -197,28 +192,29 @@
}
/*
* Functions:
*/
+#if 0
static GdkPixbuf *
icon_at_function (ETreeModel *model, ETreePath path, void *data)
{
return NULL;
}
+#endif
-static gint column_count_function(ETreeModel *model, void *data)
+static gint column_count_function(ETableModel *model, void *data)
{
return 6;
}
-static gboolean is_cell_editable_function(ETreeModel *model, ETreePath path,
- int column, void *data)
+static gboolean is_cell_editable_function(ETableModel *model, int column, int row, void *data)
{
return FALSE;
}
-static gboolean is_empty_function(ETreeModel *model, int column,
+static gboolean is_empty_function(ETableModel *model, int column,
const void *value, void *data)
{
switch (column) {
case COL_NUMBER:
@@ -234,11 +230,11 @@
g_assert_not_reached ();
return FALSE;
}
}
-static void free_value_function(ETreeModel *model, int column,
+static void free_value_function(ETableModel *model, int column,
void *value, void *data)
{
switch (column) {
case COL_ORIGINAL:
case COL_TRANSLATION:
@@ -254,16 +250,16 @@
default:
g_assert_not_reached ();
}
}
-static void set_value_at_function(ETreeModel *model, ETreePath path, int col,
+static void set_value_at_function(ETableModel *model, int col, int row,
const void *value, void *data)
{
}
-static void *duplicate_value_function(ETreeModel *model, int column,
+static void *duplicate_value_function(ETableModel *model, int column,
const void *value, void *data)
{
switch (column) {
case COL_ORIGINAL:
case COL_TRANSLATION:
@@ -280,11 +276,11 @@
g_assert_not_reached ();
return NULL;
}
}
-static void *initialize_value_function(ETreeModel *model, int column, void *data)
+static void *initialize_value_function(ETableModel *model, int column, void *data)
{
switch (column) {
case COL_ORIGINAL:
case COL_TRANSLATION:
@@ -301,89 +297,16 @@
g_assert_not_reached ();
return NULL;
}
}
-static void *value_at_function(ETreeModel *model, ETreePath path, int column,
+static void *value_at_function(ETableModel *model, int column, int row,
void *data)
{
GtrMsg *message;
-
- if (path == unknown_node)
- {
- if (column == COL_ORIGINAL)
- {
- gchar *display_string;
- gint untranslated_messages=0;
-
- /*
- * Get the number of missing entries/translations.
- */
- untranslated_messages=po->length - po->translated;
-
- if(untranslated_messages >= 1)
- {
- /*
- * The `%i' format stands for the number of
- * untranslated messages left over.
- */
- display_string=g_strdup_printf(_("Untranslated (%i)"),
- untranslated_messages);
- }
- else
- {
- display_string=g_strdup(_("Untranslated"));
- }
-
- return e_utf8_from_locale_string(display_string);
- GTR_FREE(display_string);
- }
- else if (column == COL_BOLD)
- return GINT_TO_POINTER (1);
- else
- return NULL;
- }
- if (path == fuzzy_node)
- {
- if (column == COL_ORIGINAL)
- {
- gchar *display_string;
-
- if(po->fuzzy >= 1)
- {
- /*
- * The '%i' format stands for the number
- * of fuzzy entries/messages left over.
- */
- display_string=g_strdup_printf(_("Fuzzy (%i)"),
- po->fuzzy);
- }
- else
- {
- display_string=g_strdup(_("Fuzzy"));
- }
-
- return e_utf8_from_locale_string(display_string);
- GTR_FREE(display_string);
- }
- else if (column == COL_BOLD)
- return GINT_TO_POINTER (1);
- else
- return NULL;
- }
- if (path == translated_node)
- {
- if (column == COL_ORIGINAL)
- return e_utf8_from_locale_string(_("Translated"));
- else if (column == COL_BOLD)
- return GINT_TO_POINTER (1);
- else
- return NULL;
- }
-
-
- message = e_tree_memory_node_get_data (tree_memory, path);
+
+ message = e_table_memory_get_data (table_memory, row);
g_return_val_if_fail(message!=NULL, NULL);
switch (column) {
case COL_ORIGINAL:
return message->msgid;
@@ -402,22 +325,22 @@
return message->comment->pure_comment;
break;
case COL_STATUS:
switch(message->status) {
case GTR_MSG_STATUS_UNKNOWN:
- return e_utf8_from_locale_string(_("Untranslated"));
+ return e_utf8_from_locale_string(_("1 Untranslated"));
break;
case GTR_MSG_STATUS_TRANSLATED:
- return e_utf8_from_locale_string(_("Translated"));
+ return e_utf8_from_locale_string(_("3 Translated"));
break;
case GTR_MSG_STATUS_STICK:
return e_utf8_from_locale_string(_("Sticky"));
break;
case GTR_MSG_STATUS_FUZZY:
default:
- return e_utf8_from_locale_string(_("Fuzzy"));
- }
+ return e_utf8_from_locale_string(_("2 Fuzzy"));
+ }
break;
case COL_NUMBER:
return GINT_TO_POINTER(message->no);
break;
case COL_LINE:
@@ -437,17 +360,19 @@
}
else
{
return messages_table_colors->untranslated;
}
+ break;
default:
g_assert_not_reached ();
return NULL;
}
+
}
-static gchar *return_string_for_value_function(ETreeModel *model, int column,
+static gchar *return_string_for_value_function(ETableModel *model, int column,
const void *value, void *data)
{
switch (column) {
case COL_ORIGINAL:
case COL_TRANSLATION:
@@ -463,21 +388,21 @@
default:
g_assert_not_reached ();
return NULL;
}
}
-
+#if 1
static void
-row_selected (ETree *et, int row, ETreePath node, int column, gpointer data)
+row_selected (ETable *et, int row, gpointer data)
{
GtrMsg *message, *old_message;
gint model_row;
- if (!node)
+ if (row < 0)
return;
- message=e_tree_memory_node_get_data (tree_memory, node);
+ message=e_table_memory_get_data (table_memory, row);
old_message = po->current->data;
if (message != NULL && message != old_message)
{
model_row=message->no - 1;
@@ -485,10 +410,11 @@
if (model_row<0)
return;
gtranslator_message_go_to(g_list_nth(po->messages, model_row));
}
}
+#endif
/*
* Creates all the nice and nifty stuff for the ETable.
*/
static ETableExtras *table_extras_new()
@@ -526,11 +452,11 @@
gtk_object_set (GTK_OBJECT (cell),
"bold_column", COL_BOLD,
"color_column", COL_COLOR,
NULL);
e_table_extras_add_cell(extras, list_parts[count],
- e_cell_tree_new(NULL, NULL, FALSE, cell));
+ cell);
count++;
while(list_parts[count]!=NULL)
{
cell=e_cell_text_new(NULL, GTK_JUSTIFY_LEFT);
@@ -550,78 +476,56 @@
* Create the new ETable with all the stuff needed for
* gal/gtranslator.
*/
GtkWidget *gtranslator_messages_table_new()
{
- GtkWidget *messages_tree;
+ GtkWidget *messages_table;
- tree_extras=table_extras_new();
+ table_extras=table_extras_new();
- tree_model=e_tree_memory_callbacks_new(
- icon_at_function,
+ table_model=e_table_memory_callbacks_new(
column_count_function,
- NULL,
- NULL,
- NULL,
- NULL,
value_at_function,
set_value_at_function,
is_cell_editable_function,
duplicate_value_function,
free_value_function,
initialize_value_function,
is_empty_function,
return_string_for_value_function,
NULL);
- e_tree_memory_set_expanded_default(E_TREE_MEMORY(tree_model), TRUE);
-
- tree_memory=E_TREE_MEMORY(tree_model);
-
- /* Calling gtk_widget_new here is to work around a bug in gal
- ** where e_tree_scrolled_new_from_spec is broken */
- messages_tree=gtk_widget_new(e_tree_scrolled_get_type (),
- "hadjustment", NULL,
- "vadjustment", NULL,
- NULL);
-
- messages_tree = GTK_WIDGET(
- e_tree_scrolled_construct_from_spec_file(
- E_TREE_SCROLLED(messages_tree),
- tree_model,
- tree_extras,
+
+ table_memory=E_TABLE_MEMORY(table_model);
+
+ messages_table = GTK_WIDGET(
+ e_table_scrolled_new_from_spec_file (
+ table_model,
+ table_extras,
ETSPECS_DIR "/messages-table.etspec",
gtranslator_runtime_config->table_state_filename)
);
- tree = GTK_WIDGET(e_tree_scrolled_get_tree (E_TREE_SCROLLED (messages_tree)));
+ table = GTK_WIDGET(e_table_scrolled_get_table (E_TABLE_SCROLLED (messages_table)));
- gtk_signal_connect(GTK_OBJECT(tree), "cursor_activated",
+ gtk_signal_connect(GTK_OBJECT(table), "cursor_activated",
GTK_SIGNAL_FUNC(row_selected), NULL);
- return messages_tree;
+ return messages_table;
}
/*
* Clear the table
*/
void gtranslator_messages_table_clear(void)
{
- if(root_node)
- {
- e_tree_memory_node_remove(tree_memory, root_node);
- /* sadly we seem to need to create a root_node or else mayhem results */
- root_node=e_tree_memory_node_insert (tree_memory, NULL, 0, NULL);
- }
+ return;
+#if 1
+ e_table_memory_clear (table_memory);
- if(hash_table)
- {
- g_hash_table_destroy(hash_table);
- hash_table=NULL;
- }
-
free_messages_table_colors();
+#endif
}
/*
* Populate with the messages
*/
@@ -633,115 +537,65 @@
if(!file_opened)
return;
list=po->messages;
+#if 1
/* messages-list already exists so clear it */
- if (hash_table)
- gtranslator_messages_table_clear();
-
- if (!root_node)
- root_node = e_tree_memory_node_insert (tree_memory, NULL, 0, NULL);
- e_tree_root_node_set_visible (E_TREE(tree), FALSE);
+ /*if (hash_table)
+ gtranslator_messages_table_clear();*/
read_messages_table_colors();
- hash_table=g_hash_table_new(g_direct_hash, g_direct_equal);
- unknown_node = e_tree_memory_node_insert (tree_memory, root_node, 0, NULL);
- fuzzy_node = e_tree_memory_node_insert (tree_memory, root_node, 1, NULL);
- translated_node = e_tree_memory_node_insert (tree_memory, root_node, 2, NULL);
-
- /*
- * Collapse all translated entries according to the user's preference.
- */
- e_tree_node_set_expanded_recurse(E_TREE(tree), translated_node,
- !GtrPreferences.collapse_translated);
-
while(list)
{
GtrMsg *message=list->data;
- ETreePath *node;
- switch (message->status){
- case GTR_MSG_STATUS_UNKNOWN:
- node=e_tree_memory_node_insert(tree_memory, unknown_node,
- 0, message);
- break;
- case GTR_MSG_STATUS_TRANSLATED:
- node=e_tree_memory_node_insert(tree_memory, translated_node,
- 0, message);
- break;
- case GTR_MSG_STATUS_STICK:
- node=NULL;
- break;
- case GTR_MSG_STATUS_FUZZY:
- default:
- node=e_tree_memory_node_insert(tree_memory, fuzzy_node,
- 0, message);
- }
- /*node=e_tree_memory_node_insert(tree_memory, root_node,
- i, message);*/
- if (node)
- g_hash_table_insert(hash_table, message, node);
+ if (message->status != GTR_MSG_STATUS_STICK)
+ e_table_memory_insert (table_memory, i, message);
list = g_list_next(list);
i++;
}
+#endif
}
/*
* Update the data in a single row
*/
void gtranslator_messages_table_update_row(GtrMsg *message)
{
- ETreePath node=NULL;
-
+
g_return_if_fail(message!=NULL);
- node=g_hash_table_lookup(hash_table, message);
-
- if(node)
- {
- e_tree_model_node_data_changed (tree_model, node);
- }
+
+ e_table_model_row_changed (table_model, message->no - 1);
}
/*
* Select given message
*/
void gtranslator_messages_table_select_row(GtrMsg *message)
{
- ETreePath node=NULL;
g_return_if_fail(message!=NULL);
+
- node=g_hash_table_lookup(hash_table, message);
+#if 1
+ e_table_set_cursor_row (E_TABLE (table), message->no - 1);
- if(node)
- {
- /*
- * Expand the node if we're calling a translated entry in a
- * translated entry collapsing tree region.
- */
- if((message->status & GTR_MSG_STATUS_TRANSLATED) &&
- GtrPreferences.collapse_translated)
- {
- e_tree_node_set_expanded_recurse(E_TREE(tree),
- translated_node, TRUE);
- }
-
- e_tree_set_cursor(E_TREE(tree), node);
- }
+
+#endif
}
/*
* Update the status grouping of a message
*/
void gtranslator_messages_table_update_message_status(GtrMsg *message)
{
- ETreePath old_node=NULL, new_node=NULL;
g_return_if_fail(message!=NULL);
-
+ return;
+#if 0
old_node=g_hash_table_lookup(hash_table, message);
g_return_if_fail (old_node!=NULL);
g_hash_table_remove (hash_table, message);
e_tree_memory_node_remove(tree_memory, old_node);
@@ -762,16 +616,18 @@
0, message);
}
if (new_node)
g_hash_table_insert(hash_table, message, new_node);
-
+#endif
}
/*
* Save the e-tree state
*/
void gtranslator_messages_table_save_state()
{
- e_tree_save_state (E_TREE (tree),
+
+ e_table_save_state (E_TABLE (table),
gtranslator_runtime_config->table_state_filename);
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]