[Patch] New tree !
Nicolas Centa <[email protected]> Sat, 25 Oct 2003 22:34:16 +0200
| Newsgroups | gmane.editors.mlview.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello, This patch countains the new tree, with icons. Screenshot : http://happypeng.free.fr/mlview-icons.png Enjoy ! :-) Nicolas Centa "HappyPeng" (The pixmaps.tar.gz countains the icons.)
new-tree.diff
(application/octet-stream, 65.7 KB)
Les fichiers binaires orig/mlview/pixmaps/blockdevice.png et mlview/pixmaps/blockdevice.png sont différents.
Les fichiers binaires orig/mlview/pixmaps/folder_violet.png et mlview/pixmaps/folder_violet.png sont différents.
diff -ruN orig/mlview/pixmaps/Makefile.am mlview/pixmaps/Makefile.am
--- orig/mlview/pixmaps/Makefile.am 2003-10-25 22:07:34.000000000 +0200
+++ mlview/pixmaps/Makefile.am 2003-10-25 22:08:44.000000000 +0200
@@ -4,6 +4,11 @@
xml-element-node.xpm \
xml-text-node.xpm \
mlview-app-icon.xpm \
- control-center2.png
+ control-center2.png \
+ folder_violet.png \
+ misc_doc.png \
+ txt.png \
+ unknown.png \
+ blockdevice.png
EXTRA_DIST = $(pixmaps_DATA)
Les fichiers binaires orig/mlview/pixmaps/misc_doc.png et mlview/pixmaps/misc_doc.png sont différents.
Les fichiers binaires orig/mlview/pixmaps/txt.png et mlview/pixmaps/txt.png sont différents.
Les fichiers binaires orig/mlview/pixmaps/unknown.png et mlview/pixmaps/unknown.png sont différents.
diff -ruN orig/mlview/src/Makefile.am mlview/src/Makefile.am
--- orig/mlview/src/Makefile.am 2003-10-25 22:07:34.000000000 +0200
+++ mlview/src/Makefile.am 2003-10-25 22:08:55.000000000 +0200
@@ -52,7 +52,9 @@
mlview-preferences.c \
mlview-preferences.h \
mlview-ns-editor.c \
- mlview-ns-editor.h
+ mlview-ns-editor.h \
+ mlview-icon-tree.c \
+ mlview-icon-tree.h
bin_PROGRAMS = mlv
diff -ruN orig/mlview/src/mlview-icon-tree.c mlview/src/mlview-icon-tree.c
--- orig/mlview/src/mlview-icon-tree.c 1970-01-01 01:00:00.000000000 +0100
+++ mlview/src/mlview-icon-tree.c 2003-10-25 22:09:01.000000000 +0200
@@ -0,0 +1,877 @@
+#include "mlview-icon-tree.h"
+
+enum MlViewIconTreeColumns {
+ /*hidden column, where the xml node is stored.*/
+ XML_NODE_COLUMN = 0,
+ /*
+ *contains a boolean that says
+ *if the column is editable or not.
+ */
+ IS_EDITABLE_COLUMN,
+ ARE_ATTRIBUTES_EDITABLE_COLUMN,
+ /*the first visible column, etc.*/
+ ICON_COLUMN,
+ NODE_COLUMN,
+ ATTRIBUTES_COLUMN,
+ /*
+ *This must be the last element
+ *of the enum.
+ */
+ NB_COLUMNS
+};
+
+static guchar *node_to_string_tag (xmlNode * a_node);
+static enum MlViewStatus build_tree_model_from_xml_tree (MlViewTreeEditor2 * a_this,
+ const xmlNode * a_node,
+ GtkTreeIter * a_ref_iter,
+ enum MlViewTreeInsertType a_type,
+ GtkTreeModel ** a_model);
+static void mlview_icon_tree_load_icons (MlViewIconTreeClass *a_klass);
+
+static enum MlViewStatus
+update_visual_node (MlViewTreeEditor2 *a_this, GtkTreeIter *a_iter)
+{
+ guchar *start_tag_str = NULL, *attr_str;
+ GtkTreeModel *model = NULL;
+ xmlNode *xml_node = NULL;
+
+ g_return_val_if_fail (a_this
+ && MLVIEW_IS_TREE_EDITOR2 (a_this)
+ && a_iter, MLVIEW_BAD_PARAM_ERROR);
+
+ model = mlview_tree_editor2_get_model (a_this);
+ g_return_val_if_fail (model, MLVIEW_ERROR);
+ gtk_tree_model_get (model, a_iter, XML_NODE_COLUMN,
+ &xml_node, -1);
+
+ start_tag_str = node_to_string_tag (xml_node);
+ attr_str = mlview_tree_editor2_build_attrs_list_str (xml_node);
+
+ g_return_val_if_fail (start_tag_str, MLVIEW_ERROR);
+
+ gtk_tree_store_set (GTK_TREE_STORE (model),
+ a_iter, NODE_COLUMN,
+ start_tag_str, ATTRIBUTES_COLUMN,
+ attr_str, -1);
+
+ if (start_tag_str) {
+ g_free (start_tag_str) ;
+ start_tag_str = NULL ;
+ }
+
+ if (attr_str) {
+ g_free (attr_str);
+ attr_str = NULL;
+ }
+
+ return MLVIEW_OK;
+}
+
+static enum MlViewStatus
+build_tree_model_from_xml_doc (MlViewTreeEditor2 * a_this,
+ const xmlDoc * a_doc,
+ GtkTreeModel ** a_model)
+{
+ GtkTreeIter iter = { 0 };
+ GtkTreeStore *model = NULL;
+ GtkTreeRowReference *row_ref = NULL;
+ GtkTreePath *tree_path = NULL;
+ xmlNode *xml_tree = NULL;
+ enum MlViewStatus status = MLVIEW_OK;
+
+ g_return_val_if_fail (a_this
+ && MLVIEW_IS_TREE_EDITOR2 (a_this)
+ && a_doc && a_model
+ && *a_model == NULL,
+ MLVIEW_BAD_PARAM_ERROR);
+
+ if (!a_this->nodes_rows_hash) {
+ a_this->nodes_rows_hash =
+ g_hash_table_new (g_direct_hash,
+ g_direct_equal);
+ if (!a_this->nodes_rows_hash) {
+ mlview_utils_trace_info
+ ("The system may be out of memory");
+ return MLVIEW_ERROR;
+ }
+ }
+ model = gtk_tree_store_new (NB_COLUMNS,
+ G_TYPE_POINTER,
+ G_TYPE_BOOLEAN,
+ G_TYPE_BOOLEAN,
+ GDK_TYPE_PIXBUF,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+ g_return_val_if_fail (model, MLVIEW_BAD_PARAM_ERROR);
+ *a_model = GTK_TREE_MODEL (model);
+ g_return_val_if_fail (model, MLVIEW_BAD_PARAM_ERROR);
+
+ gtk_tree_store_append (model, &iter, NULL);
+ tree_path =
+ gtk_tree_model_get_path (GTK_TREE_MODEL (model),
+ &iter);
+ g_return_val_if_fail (tree_path, MLVIEW_BAD_PARAM_ERROR);
+ row_ref = gtk_tree_row_reference_new
+ (GTK_TREE_MODEL (model), tree_path);
+ if (!row_ref) {
+ mlview_utils_trace_info ("!row_ref failed") ;
+ goto cleanup ;
+ }
+ g_hash_table_insert (a_this->nodes_rows_hash,
+ (gpointer) a_doc, row_ref);
+ gtk_tree_store_set (model, &iter, XML_NODE_COLUMN, a_doc, -1);
+ gtk_tree_store_set (model, &iter, NODE_COLUMN,
+ "<span foreground=\"#bbbb00\">XML Document Root</span>", -1);
+ gtk_tree_store_set (model, &iter, ICON_COLUMN,
+ MLVIEW_ICON_TREE_CLASS
+ (G_OBJECT_GET_CLASS (a_this))->icons.root,
+ ARE_ATTRIBUTES_EDITABLE_COLUMN, FALSE, -1);
+ xml_tree = a_doc->children;
+ status = build_tree_model_from_xml_tree
+ (a_this, xml_tree,
+ &iter, INSERT_TYPE_ADD_CHILD,
+ (GtkTreeModel **) & model);
+ cleanup:
+ if (tree_path) {
+ gtk_tree_path_free (tree_path) ;
+ tree_path = NULL ;
+ }
+ return status;
+}
+
+static enum MlViewStatus
+build_tree_model_from_xml_tree (MlViewTreeEditor2 * a_this,
+ const xmlNode * a_node,
+ GtkTreeIter * a_ref_iter,
+ enum MlViewTreeInsertType a_type,
+ GtkTreeModel ** a_model)
+{
+ GtkTreeStore *model = NULL;
+ GtkTreeIter iter = {0} ;
+ GtkTreeIter parent_iter = {0} ;
+ GtkTreePath *tree_path = NULL;
+ xmlNode *cur_node = NULL,
+ *parent_node = NULL;
+ gchar *start_tag = NULL;
+ enum MlViewStatus status = MLVIEW_OK;
+
+ g_return_val_if_fail (a_this
+ && MLVIEW_IS_TREE_EDITOR2 (a_this)
+ && a_node && a_model && *a_model,
+ MLVIEW_BAD_PARAM_ERROR);
+
+ model = GTK_TREE_STORE (*a_model);
+ g_return_val_if_fail (model, MLVIEW_BAD_PARAM_ERROR);
+
+ if (!a_this->nodes_rows_hash) {
+ a_this->nodes_rows_hash =
+ g_hash_table_new (g_direct_hash,
+ g_direct_equal);
+ if (!a_this->nodes_rows_hash) {
+ mlview_utils_trace_info
+ ("The system may be out of memory");
+ return MLVIEW_ERROR;
+ }
+ }
+
+ for (cur_node = (xmlNode *) a_node;
+ cur_node; cur_node = cur_node->next) {
+ GtkTreeRowReference *row_ref = NULL;
+
+ start_tag = node_to_string_tag (cur_node);
+ switch (a_type) {
+ case INSERT_TYPE_ADD_CHILD:
+ gtk_tree_store_append (model, &iter,
+ a_ref_iter);
+ break;
+ case INSERT_TYPE_INSERT_BEFORE:
+ case INSERT_TYPE_INSERT_AFTER:
+ parent_node = cur_node->parent;
+ if (!parent_node) {
+ mlview_utils_trace_info
+ ("parent_node failed") ;
+ status = MLVIEW_ERROR ;
+ goto cleanup ;
+
+ }
+ status = mlview_tree_editor2_get_iter
+ (a_this, parent_node,
+ &parent_iter);
+ if (status != MLVIEW_OK) {
+ mlview_utils_trace_info
+ ("status == MLVIEW_OK failed") ;
+ status = MLVIEW_ERROR ;
+ goto cleanup ;
+ }
+ model = GTK_TREE_STORE
+ (mlview_tree_editor2_get_model
+ (a_this));
+ if (!model) {
+ mlview_utils_trace_info
+ ("model failed") ;
+ status = MLVIEW_ERROR ;
+ goto cleanup ;
+ }
+ if (a_type == INSERT_TYPE_INSERT_BEFORE)
+ gtk_tree_store_insert_before
+ (model, &iter,
+ &parent_iter,
+ a_ref_iter);
+ else
+ gtk_tree_store_insert_after
+ (model, &iter,
+ &parent_iter,
+ a_ref_iter);
+ break;
+ default:
+ break;
+ }
+ tree_path = gtk_tree_model_get_path
+ (GTK_TREE_MODEL (model), &iter);
+ if (!tree_path) {
+ mlview_utils_trace_info ("tree_path failed") ;
+ status = MLVIEW_ERROR ;
+ goto cleanup ;
+ }
+ row_ref = gtk_tree_row_reference_new
+ (GTK_TREE_MODEL (model), tree_path);
+ if (!row_ref) {
+ mlview_utils_trace_info ("row_ref failed") ;
+ status = MLVIEW_ERROR ;
+ goto cleanup ;
+ }
+ g_hash_table_insert
+ (a_this->nodes_rows_hash,
+ cur_node, row_ref);
+ gtk_tree_store_set (model, &iter,
+ XML_NODE_COLUMN, cur_node, -1);
+ gtk_tree_store_set (model, &iter,
+ NODE_COLUMN, start_tag, -1);
+ if (cur_node->type == XML_ELEMENT_NODE) {
+ gtk_tree_store_set (model, &iter,
+ IS_EDITABLE_COLUMN,
+ TRUE, ICON_COLUMN,
+ MLVIEW_ICON_TREE_CLASS
+ (G_OBJECT_GET_CLASS (a_this))->icons.element,
+ ATTRIBUTES_COLUMN,
+ mlview_tree_editor2_build_attrs_list_str (cur_node),
+ ARE_ATTRIBUTES_EDITABLE_COLUMN,
+ TRUE,
+ -1);
+
+ if (cur_node->children) {
+ build_tree_model_from_xml_tree
+ (a_this,
+ cur_node->children,
+ &iter,
+ INSERT_TYPE_ADD_CHILD,
+ a_model);
+ }
+ } else if (cur_node->type == XML_TEXT_NODE) {
+ gtk_tree_store_set (model, &iter,
+ IS_EDITABLE_COLUMN,
+ TRUE, ICON_COLUMN,
+ MLVIEW_ICON_TREE_CLASS
+ (G_OBJECT_GET_CLASS (a_this))->icons.text,
+ ARE_ATTRIBUTES_EDITABLE_COLUMN,
+ FALSE,
+ -1);
+ } else if (cur_node->type == XML_COMMENT_NODE) {
+ gtk_tree_store_set (model, &iter,
+ IS_EDITABLE_COLUMN,
+ FALSE,
+ ICON_COLUMN,
+ MLVIEW_ICON_TREE_CLASS
+ (G_OBJECT_GET_CLASS (a_this))->icons.comment,
+ ARE_ATTRIBUTES_EDITABLE_COLUMN,
+ FALSE,
+ -1);
+ } else if (cur_node->type == XML_PI_NODE) {
+ gtk_tree_store_set (model, &iter,
+ IS_EDITABLE_COLUMN,
+ FALSE,
+ ICON_COLUMN,
+ MLVIEW_ICON_TREE_CLASS
+ (G_OBJECT_GET_CLASS (a_this))->icons.pi,
+ ARE_ATTRIBUTES_EDITABLE_COLUMN,
+ FALSE,
+ -1);
+ } else {
+ mlview_utils_trace_info ("unknown node");
+ }
+ if (start_tag) {
+ g_free (start_tag) ;
+ start_tag = NULL ;
+ }
+ if (tree_path) {
+ gtk_tree_path_free (tree_path) ;
+ tree_path = NULL ;
+ }
+ if (a_type == INSERT_TYPE_INSERT_BEFORE
+ || a_type == INSERT_TYPE_INSERT_AFTER) {
+ /*
+ *we are building a tree model which root
+ *node is cur_node so we should not
+ *visit cur_node->next.
+ */
+ break ;
+ }
+ }
+ if (*a_model) {
+ g_object_set_data (G_OBJECT (*a_model),
+ "MlViewTreeEditor2",
+ a_this) ;
+ }
+ cleanup:
+ if (tree_path) {
+ gtk_tree_path_free (tree_path) ;
+ tree_path = NULL ;
+ }
+ if (start_tag) {
+ g_free (start_tag) ;
+ start_tag = NULL ;
+ }
+ return status ;
+}
+
+static guchar *
+node_to_string_tag (xmlNode * a_node)
+{
+ guchar *result = NULL,
+ *content = NULL;
+
+ g_return_val_if_fail (a_node != NULL, NULL);
+
+ const gchar *colour_str = mlview_tree_editor2_get_colour_string (a_node->type);
+
+ if (a_node->type == XML_ELEMENT_NODE) {
+ guchar *ns_prefix = NULL,
+ *name = NULL;
+
+ if (a_node->ns != NULL && a_node->ns->prefix) {
+ ns_prefix = g_strdup_printf ("%s:", a_node->ns->prefix);
+ } else {
+ ns_prefix = NULL;
+ }
+
+ if (ns_prefix) {
+ name = g_strconcat (ns_prefix, a_node->name, NULL);
+ } else
+ name = g_strdup (a_node->name);
+
+ if (ns_prefix) {
+ g_free (ns_prefix);
+ ns_prefix = NULL;
+ }
+
+ result = g_strdup_printf ("<span foreground=\"%s\">%s</span>",
+ colour_str, name);
+
+ if (name) {
+ g_free (name);
+ name = NULL;
+ }
+
+ } else if (xmlNodeIsText (a_node)) {
+ content = xmlNodeGetContent (a_node);
+ if (content == NULL) {
+ xmlNodeSetContent (a_node, "text");
+ content = xmlNodeGetContent (a_node); }
+
+ result = g_strdup_printf ("<span foreground=\"%s\">%s</span>",
+ colour_str, content);
+
+ xmlFree (content);
+ } else if (a_node->type == XML_COMMENT_NODE) {
+ content = xmlNodeGetContent (a_node);
+ if (content == NULL) {
+ xmlNodeSetContent (a_node, "<!--comment-->");
+ content = xmlNodeGetContent (a_node); }
+
+ result = g_strdup_printf ("<span foreground=\"%s\">%s</span>",
+ colour_str, content);
+
+ xmlFree (content);
+ } else if (a_node->type == XML_PI_NODE) {
+ content = xmlNodeGetContent (a_node);
+ if (content == NULL) {
+ xmlNodeSetContent
+ (a_node, "processing instruction node");
+ content = xmlNodeGetContent (a_node); }
+
+ result = g_strdup_printf ("<span foreground=\"%s\">%s %s</span>",
+ colour_str, a_node->name, content);
+
+ xmlFree (content);
+ }
+
+ return result;
+}
+
+static guchar *
+build_xml_attrs_list_str (xmlAttrPtr attr_iter)
+{
+ guchar *result = NULL, *attribute, *tmp;
+
+ while (attr_iter)
+ {
+ attribute = g_strdup_printf ("%s=\"%s\"", attr_iter->name,
+ attr_iter->children->content);
+ if (result)
+ {
+ tmp = g_strdup_printf ("%s %s", result, attribute);
+ g_free (result);
+ result = tmp;
+ }
+ else
+ result = attribute;
+
+ attr_iter = attr_iter->next;
+ }
+
+ return result;
+}
+
+static guchar *
+node_to_xml_tag_w_attr (const xmlChar *node_name, xmlElementType type, xmlNode *children, xmlNs *ns,
+ xmlChar *content, gchar *attributes)
+{
+ guchar *result = NULL;
+
+ if (type == XML_ELEMENT_NODE) {
+ guchar *ns_prefix = NULL,
+ *attr_str = NULL,
+ *name = NULL;
+
+ if (attributes)
+ attr_str = strlen (attributes) > 0 ? attributes : NULL;
+
+ if (ns != NULL && ns->prefix) {
+ ns_prefix = g_strconcat (ns->prefix,
+ ":", NULL);
+ } else {
+ ns_prefix = NULL;
+ }
+
+ if (ns_prefix) {
+ name = g_strconcat (ns_prefix,
+ node_name, NULL);
+ } else {
+ name = g_strdup (node_name);
+ }
+ if (ns_prefix) {
+ g_free (ns_prefix);
+ ns_prefix = NULL;
+ }
+
+ if (children != NULL) {
+ if (attr_str)
+ result = g_strconcat
+ ("<", name, " ", attr_str, ">", NULL);
+ else
+ result = g_strconcat
+ ("<", name, ">", NULL);
+ } else { /*empty tag */
+ if (attr_str)
+ result = g_strconcat
+ ("<", name, " ", attr_str, " />", NULL);
+ else
+ result = g_strconcat
+ ("<", name, " />", NULL);
+
+ if (name) {
+ g_free (name);
+ name = NULL;
+ }
+ }
+ } else if (type == XML_TEXT_NODE) {
+ result = g_strdup (content);
+
+ } else if (type == XML_COMMENT_NODE) {
+ result = g_strconcat
+ ("<!--", content, "-->", NULL);
+ } else if (type == XML_PI_NODE) {
+ result = g_strconcat
+ ("<?", node_name, " ", content, ">", NULL);
+ }
+
+ return result;
+}
+
+static guchar *
+node_to_xml_tag (const xmlChar *node_name, xmlElementType type, xmlNode *children, xmlNs *ns,
+ xmlChar *content, xmlAttrPtr attributes)
+{
+ guchar *attr, *result;
+
+ attr = build_xml_attrs_list_str (attributes);
+ result = node_to_xml_tag_w_attr (node_name, type, children, ns, content, attr);
+
+ if (attr)
+ g_free (attr);
+
+ return result;
+}
+
+static guchar *
+build_attrs_list_str_from_nv_pairs (GList *list)
+{
+ guchar *result = NULL, *tmp;
+ struct NameValuePair *pair;
+ const gchar *attval_col = "#00FF00",
+ *attname_col = mlview_tree_editor2_get_colour_string (XML_ATTRIBUTE_NODE);
+
+ while (list)
+ {
+ pair = list->data;
+
+ if (result)
+ {
+ tmp = g_strdup_printf
+ ("%s <span foreground=\"%s\">%s</span>=<span foreground=\"%s\">\"%s\"</span>",
+ result, attname_col, pair->name->str, attval_col, pair->value->str);
+ g_free (result);
+ result = tmp;
+ }
+ else
+ result = g_strdup_printf
+ ("<span foreground=\"%s\">%s</span>=<span foreground=\"%s\">\"%s\"</span>",
+ attname_col, pair->name->str, attval_col, pair->value->str);
+
+ list = g_list_next (list);
+ }
+
+ return result;
+}
+
+static void
+node_attributes_edited_cb (GtkCellRendererText *a_renderer,
+ gchar *a_cell_path,
+ gchar *a_new_text,
+ gpointer a_data)
+{
+ MlViewTreeEditor2 *tree_editor = NULL ;
+ GtkTreePath *tree_path = NULL ;
+ GtkTreeIter iter = {0} ;
+ GtkTreeModel *model = NULL ;
+ MlViewXMLDocument *mlview_xml_doc = NULL ;
+ enum MlViewStatus status = MLVIEW_OK ;
+ GString *element_name = NULL ;
+ GList *nv_pair_list = NULL ;
+ xmlNode *cur_node = NULL ;
+ guchar *start_tag = NULL ;
+
+ g_return_if_fail (a_renderer && a_data && a_cell_path) ;
+ g_return_if_fail (MLVIEW_IS_TREE_EDITOR2 (a_data)
+ && GTK_IS_CELL_RENDERER_TEXT (a_renderer)) ;
+ tree_editor = a_data ;
+ model = mlview_tree_editor2_get_model (tree_editor) ;
+ g_return_if_fail (model) ;
+ tree_path = gtk_tree_path_new_from_string (a_cell_path) ;
+ g_return_if_fail (tree_path) ;
+ status = mlview_tree_editor2_get_cur_sel_start_iter
+ (tree_editor, &iter) ;
+ g_return_if_fail (status == MLVIEW_OK) ;
+ cur_node = mlview_tree_editor2_get_cur_sel_xml_node (tree_editor) ;
+ if (!cur_node) {
+ mlview_utils_trace_info ("cur_node failed") ;
+ goto cleanup ;
+ }
+ mlview_xml_doc = mlview_tree_editor2_get_mlview_xml_doc (tree_editor);
+ if (!mlview_xml_doc) {
+ mlview_utils_trace_info
+ ("mlview_xml_doc failed") ;
+ goto cleanup ;
+ }
+
+ start_tag = node_to_xml_tag_w_attr (cur_node->name, cur_node->type, cur_node->children,
+ cur_node->ns, cur_node->content, a_new_text);
+
+ status = mlview_utils_parse_start_tag
+ (start_tag, &element_name, &nv_pair_list);
+
+ if (status == MLVIEW_OK)
+ if (nv_pair_list)
+ mlview_xml_document_synch_attributes (mlview_xml_doc, cur_node, nv_pair_list);
+
+ cleanup:
+ if (start_tag) {
+ g_free (start_tag) ;
+ start_tag = NULL ;
+ }
+ if (element_name) {
+ g_string_free (element_name, TRUE) ;
+ element_name = NULL ;
+ }
+ if (nv_pair_list) {
+ GList *cur_item = NULL;
+ for (cur_item = nv_pair_list; cur_item ;
+ cur_item = cur_item->next) {
+ if (cur_item->data) {
+ mlview_utils_name_value_pair_free
+ (cur_item->data, TRUE) ;
+ }
+ }
+ g_list_free (nv_pair_list) ;
+ nv_pair_list = NULL ;
+ }
+ if (tree_path) {
+ gtk_tree_path_free (tree_path) ;
+ tree_path = NULL ;
+ }
+}
+
+static void
+node_cell_edited_cb (GtkCellRendererText *a_renderer,
+ gchar *a_cell_path,
+ gchar *a_new_text,
+ gpointer a_data)
+{
+ MlViewTreeEditor2 *tree_editor = NULL ;
+ GtkTreePath *tree_path = NULL ;
+ GtkTreeIter iter = {0} ;
+ GtkTreeModel *model = NULL ;
+ MlViewXMLDocument *mlview_xml_doc = NULL ;
+ enum MlViewStatus status = MLVIEW_OK ;
+ GString *element_name = NULL ;
+ GList *nv_pair_list = NULL ;
+ xmlNode *cur_node = NULL ;
+ guchar *start_tag = NULL ;
+
+ g_return_if_fail (a_renderer && a_data && a_cell_path) ;
+ g_return_if_fail (MLVIEW_IS_TREE_EDITOR2 (a_data)
+ && GTK_IS_CELL_RENDERER_TEXT (a_renderer)) ;
+ tree_editor = a_data ;
+ model = mlview_tree_editor2_get_model (tree_editor) ;
+ g_return_if_fail (model) ;
+ tree_path = gtk_tree_path_new_from_string (a_cell_path) ;
+ g_return_if_fail (tree_path) ;
+ status = mlview_tree_editor2_get_cur_sel_start_iter
+ (tree_editor, &iter) ;
+ g_return_if_fail (status == MLVIEW_OK) ;
+ cur_node = mlview_tree_editor2_get_cur_sel_xml_node (tree_editor) ;
+ if (!cur_node) {
+ mlview_utils_trace_info ("cur_node failed") ;
+ goto cleanup ;
+ }
+ mlview_xml_doc = mlview_tree_editor2_get_mlview_xml_doc (tree_editor);
+ if (!mlview_xml_doc) {
+ mlview_utils_trace_info
+ ("mlview_xml_doc failed") ;
+ goto cleanup ;
+ }
+
+ if (cur_node->type == XML_ELEMENT_NODE) {
+
+ start_tag = node_to_xml_tag (a_new_text, cur_node->type, cur_node->children, cur_node->ns,
+ cur_node->content, cur_node->properties);
+
+ status = mlview_utils_parse_start_tag
+ (start_tag, &element_name, &nv_pair_list) ;
+
+ if (status == MLVIEW_OK)
+ mlview_xml_document_set_node_name (mlview_xml_doc, cur_node, a_new_text, UTF8, TRUE);
+
+ } else if (cur_node->type == XML_TEXT_NODE) {
+ mlview_xml_document_set_node_content
+ (mlview_xml_doc, cur_node, a_new_text, UTF8, TRUE) ;
+ }
+
+ cleanup:
+ if (start_tag) {
+ g_free (start_tag) ;
+ start_tag = NULL ;
+ }
+ if (element_name) {
+ g_string_free (element_name, TRUE) ;
+ element_name = NULL ;
+ }
+ if (nv_pair_list) {
+ GList *cur_item = NULL;
+ for (cur_item = nv_pair_list; cur_item ;
+ cur_item = cur_item->next) {
+ if (cur_item->data) {
+ mlview_utils_name_value_pair_free
+ (cur_item->data, TRUE) ;
+ }
+ }
+ g_list_free (nv_pair_list) ;
+ nv_pair_list = NULL ;
+ }
+ if (tree_path) {
+ gtk_tree_path_free (tree_path) ;
+ tree_path = NULL ;
+ }
+}
+
+static GtkTreeView *
+build_tree_view_from_xml_doc (MlViewTreeEditor2 * a_this,
+ xmlDoc * a_doc)
+{
+ GtkTreeView *tree_view = NULL ;
+ GtkTreeModel *model = NULL ;
+ GtkCellRenderer *renderer = NULL ;
+ GtkTreeIter iter = {0} ;
+ enum MlViewStatus status = MLVIEW_OK ;
+ struct MlViewAppSettings *settings = NULL ;
+ gboolean is_ok = TRUE ;
+
+ g_return_val_if_fail (a_this
+ && MLVIEW_IS_TREE_EDITOR2 (a_this)
+ && a_this->app_context,
+ NULL);
+
+ settings = mlview_app_context_get_settings
+ (a_this->app_context) ;
+
+ g_return_val_if_fail (settings, NULL) ;
+
+ status = build_tree_model_from_xml_doc
+ (a_this, a_doc, &model);
+
+ g_return_val_if_fail (model, NULL);
+
+ is_ok = gtk_tree_model_get_iter_first (model, &iter) ;
+
+ g_return_val_if_fail (is_ok == TRUE, NULL) ;
+
+ tree_view = GTK_TREE_VIEW
+ (gtk_tree_view_new_with_model (model));
+
+ g_return_val_if_fail (tree_view, NULL);
+
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ gtk_tree_view_insert_column_with_attributes
+ (tree_view, ICON_COLUMN, "", renderer, "pixbuf", ICON_COLUMN, NULL);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_tree_view_insert_column_with_attributes
+ (tree_view, NODE_COLUMN, _("Element name"),
+ renderer, "markup", NODE_COLUMN,
+ "editable", IS_EDITABLE_COLUMN, NULL);
+ g_signal_connect (G_OBJECT (renderer),
+ "edited", G_CALLBACK (node_cell_edited_cb),
+ a_this) ;
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_tree_view_insert_column_with_attributes
+ (tree_view, ATTRIBUTES_COLUMN, _("Attributes"),
+ renderer, "markup", ATTRIBUTES_COLUMN, "editable",
+ ARE_ATTRIBUTES_EDITABLE_COLUMN, NULL);
+ g_signal_connect (G_OBJECT (renderer),
+ "edited", G_CALLBACK (node_attributes_edited_cb),
+ a_this);
+
+ mlview_utils_gtk_tree_view_expand_row_to_depth2
+ (tree_view, &iter,
+ settings->default_doc_expansion_depth) ;
+
+ return tree_view;
+}
+
+static void
+mlview_icon_tree_load_icons (MlViewIconTreeClass *a_klass)
+{
+ gchar *path;
+
+ path = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_DATADIR,
+ "pixmaps/folder_violet.png", TRUE, NULL);
+ a_klass->icons.element = gdk_pixbuf_new_from_file (path, NULL);
+ g_free (path);
+
+ path = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_DATADIR,
+ "pixmaps/txt.png", TRUE, NULL);
+ a_klass->icons.text = gdk_pixbuf_new_from_file (path, NULL);
+ g_free (path);
+
+ path = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_DATADIR,
+ "pixmaps/blockdevice.png", TRUE, NULL);
+ a_klass->icons.root = gdk_pixbuf_new_from_file (path, NULL);
+ g_free (path);
+
+ path = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_DATADIR,
+ "pixmaps/misc_doc.png", TRUE, NULL);
+ a_klass->icons.comment = gdk_pixbuf_new_from_file (path, NULL);
+ g_free (path);
+
+ path = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_DATADIR,
+ "pixmaps/unknown.png", TRUE, NULL);
+ a_klass->icons.pi = gdk_pixbuf_new_from_file (path, NULL);
+ g_free (path);
+}
+
+static void
+mlview_icon_tree_free_icons (MlViewIconTreeClass *a_klass)
+{
+ g_object_unref (G_OBJECT (a_klass->icons.element));
+ g_object_unref (G_OBJECT (a_klass->icons.text));
+ g_object_unref (G_OBJECT (a_klass->icons.root));
+ g_object_unref (G_OBJECT (a_klass->icons.comment));
+ g_object_unref (G_OBJECT (a_klass->icons.pi));
+}
+
+static void
+mlview_icon_tree_class_init (MlViewIconTreeClass *a_klass)
+{
+ MlViewTreeEditor2Class *p_klass = MLVIEW_TREE_EDITOR2_CLASS (a_klass);
+
+ p_klass->build_tree_view_from_xml_doc = build_tree_view_from_xml_doc;
+ p_klass->update_visual_node = update_visual_node;
+ p_klass->build_tree_model_from_xml_tree = build_tree_model_from_xml_tree;
+
+ a_klass->icons.refcount = 0;
+}
+
+GType
+mlview_icon_tree_get_type (void)
+{
+ static GType type = 0;
+
+ if (!type) {
+ static const GTypeInfo type_info = {
+ sizeof (MlViewIconTreeClass),
+ NULL, NULL,
+ (GClassInitFunc)
+ mlview_icon_tree_class_init,
+ NULL, NULL,
+ sizeof (MlViewTreeEditor2),
+ 0,
+ NULL, NULL
+ };
+ type = g_type_register_static (mlview_tree_editor2_get_type (),
+ "MlViewIconTree",
+ &type_info, 0);
+ }
+
+ return type;
+}
+
+static void
+destroy_cb (MlViewIconTree *tree, MlViewIconTreeClass *klass)
+{
+ klass->icons.refcount--;
+
+ if (!klass->icons.refcount)
+ mlview_icon_tree_free_icons (klass);
+}
+
+GtkWidget *
+mlview_icon_tree_new (MlViewAppContext *a_context)
+{
+ MlViewIconTree *editor;
+ MlViewIconTreeClass *klass;
+
+ editor = g_object_new (mlview_icon_tree_get_type (), NULL);
+
+ mlview_tree_editor2_construct (MLVIEW_TREE_EDITOR2 (editor), a_context);
+
+ klass = MLVIEW_ICON_TREE_CLASS (G_OBJECT_GET_CLASS (editor));
+
+ g_signal_connect (G_OBJECT (editor), "destroy", G_CALLBACK (destroy_cb), klass);
+
+ if (!klass->icons.refcount)
+ mlview_icon_tree_load_icons (klass);
+ klass->icons.refcount++;
+
+ return GTK_WIDGET (editor);
+}
diff -ruN orig/mlview/src/mlview-icon-tree.h mlview/src/mlview-icon-tree.h
--- orig/mlview/src/mlview-icon-tree.h 1970-01-01 01:00:00.000000000 +0100
+++ mlview/src/mlview-icon-tree.h 2003-10-25 22:09:03.000000000 +0200
@@ -0,0 +1,67 @@
+/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
+/*
+ *This file is part of MlView.
+ *
+ *MlView is free software; you can redistribute
+ *it and/or modify it under the terms of
+ *the GNU General Public License as published by the
+ *Free Software Foundation; either version 2,
+ *or (at your option) any later version.
+ *
+ *GNU MlView is distributed in the hope that it will
+ *be useful, but WITHOUT ANY WARRANTY;
+ *without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *See the GNU General Public License for more details.
+ *
+ *You should have received a copy of the
+ *GNU General Public License along with MlView;
+ *see the file COPYING.
+ *If not, write to the Free Software Foundation,
+ *Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *See COPYRIGHT file for copyright information.
+ */
+
+#ifndef __MLVIEW_ICON_TREE_H__
+#define __MLVIEW_ICON_TREE_H__
+
+#include "mlview-tree-editor2.h"
+
+G_BEGIN_DECLS
+
+#define MLVIEW_TYPE_ICON_TREE (mlview_tree_editor2_get_type())
+#define MLVIEW_ICON_TREE(object) (G_TYPE_CHECK_INSTANCE_CAST((object),MLVIEW_TYPE_ICON_TREE,MlViewIconTree))
+#define MLVIEW_ICON_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MLVIEW_TYPE_ICON_TREE,MlViewIconTreeClass))
+#define MLVIEW_IS_ICON_TREE(object) (G_TYPE_CHECK_INSTANCE_TYPE((object),MLVIEW_TYPE_ICON_TREE))
+#define MLVIEW_IS_ICON_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MLVIEW_TYPE_ICON_TREE))
+
+typedef struct _MlViewIconTree MlViewIconTree;
+typedef struct _MlViewIconTreeClass MlViewIconTreeClass;
+typedef struct _MlViewIconTreePrivate MlViewIconTreePrivate;
+
+struct _MlViewIconTree {
+ MlViewTreeEditor2 tree_editor2;
+};
+
+GType mlview_icon_tree_get_type (void);
+GtkWidget *mlview_icon_tree_new (MlViewAppContext *a_app_context);
+
+struct _MlViewIconTreeClass {
+ MlViewTreeEditor2Class parent_class;
+
+ struct
+ {
+ GdkPixbuf *element;
+ GdkPixbuf *text;
+ GdkPixbuf *root;
+ GdkPixbuf *comment;
+ GdkPixbuf *pi;
+
+ guint refcount;
+ } icons;
+};
+
+G_END_DECLS
+
+#endif
diff -ruN orig/mlview/src/mlview-tree-editor2.c mlview/src/mlview-tree-editor2.c
--- orig/mlview/src/mlview-tree-editor2.c 2003-10-25 22:07:34.000000000 +0200
+++ mlview/src/mlview-tree-editor2.c 2003-10-25 22:09:10.000000000 +0200
@@ -50,22 +50,11 @@
#include "mlview-marshal.h"
#include "mlview-utils.h"
-#define SEARCH_IN_NAMES_CHECK_BUTTON "search-in-names-check-box"
-#define SEARCH_IN_ATTRIBUTES_NAMES_CHECK_BUTTON "search-in-attributes-names-check-box"
-#define SEARCH_IN_ATTRIBUTES_VALUES_CHECK_BUTTON "search-in-attributes-values-check-box"
-#define SEARCH_IN_CONTENT_CHECK_BUTTON "search-in-content-check-box"
-#define SEARCHED_TEXT_ENTRY "searched-text-entry"
-
-#define IS_THE_FIND_DIALOG "is-the-find-dialog"
-
-/*================================================================
- *The struct defining the private attributes of
- *MlViewTreeEditor and it associated macros
- *=================================================================*/
+#include "mlview-xml-document.h"
+#include "mlview-node-type-picker.h"
#define PRIVATE(mlview_tree_editor2) ((mlview_tree_editor2)->priv)
-
struct _MlViewTreeEditor2Private {
/*the xml document being edited. FIXME => handle it lifetime !!! */
xmlDocPtr xml_doc;
@@ -74,12 +63,6 @@
/*the viewable tree that matches xml_doc */
GtkTreeView *tree_view;
- /*
- *a cache that contains
- *a list of xmlNode/GtkTreeRowReference
- *pair. This is to speed up searches.
- */
- GHashTable *nodes_rows_hash;
/*
*the menu poped up when the user
@@ -98,7 +81,7 @@
*MlViewTreeEditor does not have to handle it lifetime
*/
MlViewNodeTypePicker *node_type_picker;
- MlViewAppContext *app_context;
+
/*the search dialog*/
GtkDialog *search_dialog ;
gboolean dispose_has_run ;
@@ -106,29 +89,19 @@
gpointer backup_drag_data_received ;
};
-/**
- *The different signals emited
- *by #MlViewTreeEditor2.
- */
-enum {
- TREE_CHANGED = 1,
- MARK_SET_TO_NODE,
- MARK_REMOVED_FROM_NODE,
- NODE_CUT,
- NODE_PASTED,
- NODE_ADDED,
- NODE_SELECTED,
- NODE_UNSELECTED,
- NUMBER_OF_SIGNALS
-};
+#define SEARCH_IN_NAMES_CHECK_BUTTON "search-in-names-check-box"
+#define SEARCH_IN_ATTRIBUTES_NAMES_CHECK_BUTTON "search-in-attributes-names-check-box"
+#define SEARCH_IN_ATTRIBUTES_VALUES_CHECK_BUTTON "search-in-attributes-values-check-box"
+#define SEARCH_IN_CONTENT_CHECK_BUTTON "search-in-content-check-box"
+#define SEARCHED_TEXT_ENTRY "searched-text-entry"
+
+#define IS_THE_FIND_DIALOG "is-the-find-dialog"
+/*================================================================
+ *The struct defining the private attributes of
+ *MlViewTreeEditor and it associated macros
+ *=================================================================*/
-/*static const gchar * p_tree_editor_titles[]=
-{
- N_("the xml document"),
- N_("the xml document tags")
-} ;
-*/
enum MlViewTreeEditorColumns {
/*hidden column, where the xml node is stored.*/
XML_NODE_COLUMN = 0,
@@ -148,15 +121,26 @@
NB_COLUMNS
};
+/**
+ *The different signals emited
+ *by #MlViewTreeEditor2.
+ */
+enum {
+ TREE_CHANGED = 1,
+ MARK_SET_TO_NODE,
+ MARK_REMOVED_FROM_NODE,
+ NODE_CUT,
+ NODE_PASTED,
+ NODE_ADDED,
+ NODE_SELECTED,
+ NODE_UNSELECTED,
+ NUMBER_OF_SIGNALS
+};
+
enum MlViewTreeEditorColumnsOffsets {
START_TAG_COLUMN_OFFSET,
NODE_TYPE_COLUMN_OFFSET
} ;
-enum MlViewTreeInsertType {
- INSERT_TYPE_ADD_CHILD,
- INSERT_TYPE_INSERT_BEFORE,
- INSERT_TYPE_INSERT_AFTER
-};
#define MLVIEW_TREE_EDITOR2_NODE_CLIPBOARD_SIZE 128
static const gint TREE_EDITOR_NUMBER_OF_COLUMNS = 1;
@@ -170,9 +154,6 @@
{(gchar *)"GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0}
} ;
-/* Coloration */
-const gchar *get_colour_string (int type);
-
static void xml_doc_prev_sibling_node_inserted_cb (MlViewXMLDocument *a_this,
xmlNode *a_sibling_node,
xmlNode *a_inserted_node,
@@ -212,6 +193,16 @@
gchar *a_cell_path,
gchar *a_new_text,
gpointer a_data) ;
+
+static GtkTreeView *build_tree_view_from_xml_doc (MlViewTreeEditor2 * a_this,
+ xmlDoc * a_doc);
+static enum MlViewStatus update_visual_node (MlViewTreeEditor2 *a_this, GtkTreeIter *a_iter);
+static enum MlViewStatus build_tree_model_from_xml_tree (MlViewTreeEditor2 * a_this,
+ const xmlNode * a_node,
+ GtkTreeIter * a_ref_iter,
+ enum MlViewTreeInsertType a_type,
+ GtkTreeModel ** a_model);
+
/***************************************************
*private methods required by the GTK typing system
***************************************************/
@@ -347,6 +338,10 @@
a_klass->node_added = NULL;
a_klass->node_pasted = NULL;
a_klass->node_selected = NULL;
+
+ a_klass->build_tree_view_from_xml_doc = build_tree_view_from_xml_doc;
+ a_klass->update_visual_node = update_visual_node;
+ a_klass->build_tree_model_from_xml_tree = build_tree_model_from_xml_tree;
}
/**
@@ -683,33 +678,38 @@
*@return the newly built attribute list string, or NULL if something
*bad happened.
*/
-static guchar *
-build_attrs_list_str (xmlNode * a_node)
+guchar *
+mlview_tree_editor2_build_attrs_list_str (xmlNode * a_node)
{
g_return_val_if_fail (a_node, NULL);
- guchar *result = g_strdup ("");
xmlAttrPtr attr_iter;
const gchar *attval_col = "#00FF00",
- *attname_col = get_colour_string (XML_ATTRIBUTE_NODE);
- gchar *attribute;
+ *attname_col = mlview_tree_editor2_get_colour_string (XML_ATTRIBUTE_NODE);
+ gchar *attribute, *result = NULL, *tmp;
- for (attr_iter = a_node->properties;
- attr_iter; attr_iter=attr_iter->next) {
- attribute = g_strdup_printf
- (" <span foreground=\"%s\">%s=<span foreground=\"%s\">\"%s\"</span></span>",
- attname_col, attr_iter->name,
- attval_col, attr_iter->children->content) ;
- result = g_strconcat (attribute, result, NULL);
- g_free(attribute);
- }
+ attr_iter = a_node->properties;
+ while (attr_iter) {
+ attribute = g_strdup_printf
+ ("<span foreground=\"%s\">%s=<span foreground=\"%s\">\"%s\"</span></span>",
+ attname_col, attr_iter->name, attval_col, attr_iter->children->content);
+ if (result) {
+ tmp = g_strdup_printf ("%s %s", result, attribute);
+ g_free (result);
+ result = tmp;
+ } else {
+ result = attribute;
+ }
+ attr_iter = attr_iter->next;
+ }
+
return result;
}
/* Coloration (from Conglomerate) */
-const gchar*
-get_colour_string (int type)
+gchar*
+mlview_tree_editor2_get_colour_string (int type)
{
switch (type) {
default:
@@ -772,16 +772,16 @@
g_return_val_if_fail (a_node != NULL, NULL);
- const gchar *colour_str = get_colour_string (a_node->type);
+ const gchar *colour_str = mlview_tree_editor2_get_colour_string (a_node->type);
if (a_node->type == XML_ELEMENT_NODE) {
guchar *ns_prefix = NULL,
*attr_str = NULL,
*name = NULL;
- const gchar *attr_colour_str = get_colour_string (XML_ATTRIBUTE_NODE);
+ const gchar *attr_colour_str = mlview_tree_editor2_get_colour_string (XML_ATTRIBUTE_NODE);
- attr_str = build_attrs_list_str (a_node);
+ attr_str = mlview_tree_editor2_build_attrs_list_str (a_node);
if (a_node->ns != NULL && a_node->ns->prefix) {
ns_prefix = g_strconcat (a_node->ns->prefix,
":", NULL);
@@ -819,11 +819,11 @@
("<span foreground=\"", colour_str, "\"><",
name, "</span> <span foreground=\"", attr_colour_str,
"\">", attr_str, "</span><span foreground=\"", colour_str,
- "\">/></span>", NULL);
+ "\"> /></span>", NULL);
else
result = g_strconcat
("<span foreground=\"", colour_str, "\"><", name,
- "/></span>", NULL);
+ " /></span>", NULL);
}
if (name) {
@@ -884,6 +884,18 @@
*@return MLVIEW_OK upon successful completion, an error
*code otherwise.
*/
+enum MlViewStatus
+mlview_tree_editor2_build_tree_model_from_xml_tree (MlViewTreeEditor2 * a_this,
+ const xmlNode * a_node,
+ GtkTreeIter * a_ref_iter,
+ enum MlViewTreeInsertType a_type,
+ GtkTreeModel ** a_model)
+{
+ return MLVIEW_TREE_EDITOR2_CLASS
+ (G_OBJECT_GET_CLASS (a_this))->build_tree_model_from_xml_tree
+ (a_this, a_node, a_ref_iter, a_type, a_model);
+}
+
static enum MlViewStatus
build_tree_model_from_xml_tree (MlViewTreeEditor2 * a_this,
const xmlNode * a_node,
@@ -909,11 +921,11 @@
model = GTK_TREE_STORE (*a_model);
g_return_val_if_fail (model, MLVIEW_BAD_PARAM_ERROR);
- if (!PRIVATE (a_this)->nodes_rows_hash) {
- PRIVATE (a_this)->nodes_rows_hash =
+ if (!a_this->nodes_rows_hash) {
+ a_this->nodes_rows_hash =
g_hash_table_new (g_direct_hash,
g_direct_equal);
- if (!PRIVATE (a_this)->nodes_rows_hash) {
+ if (!a_this->nodes_rows_hash) {
mlview_utils_trace_info
("The system may be out of memory");
return MLVIEW_ERROR;
@@ -987,7 +999,7 @@
goto cleanup ;
}
g_hash_table_insert
- (PRIVATE (a_this)->nodes_rows_hash,
+ (a_this->nodes_rows_hash,
cur_node, row_ref);
gtk_tree_store_set (model, &iter,
XML_NODE_COLUMN, cur_node, -1);
@@ -1000,7 +1012,7 @@
IS_EDITABLE_COLUMN,
TRUE, -1);
if (cur_node->children) {
- build_tree_model_from_xml_tree
+ mlview_tree_editor2_build_tree_model_from_xml_tree
(a_this,
cur_node->children,
&iter,
@@ -1087,11 +1099,11 @@
&& *a_model == NULL,
MLVIEW_BAD_PARAM_ERROR);
- if (!PRIVATE (a_this)->nodes_rows_hash) {
- PRIVATE (a_this)->nodes_rows_hash =
+ if (!a_this->nodes_rows_hash) {
+ a_this->nodes_rows_hash =
g_hash_table_new (g_direct_hash,
g_direct_equal);
- if (!PRIVATE (a_this)->nodes_rows_hash) {
+ if (!a_this->nodes_rows_hash) {
mlview_utils_trace_info
("The system may be out of memory");
return MLVIEW_ERROR;
@@ -1117,14 +1129,14 @@
mlview_utils_trace_info ("!row_ref failed") ;
goto cleanup ;
}
- g_hash_table_insert (PRIVATE (a_this)->nodes_rows_hash,
+ g_hash_table_insert (a_this->nodes_rows_hash,
(gpointer) a_doc, row_ref);
gtk_tree_store_set (model, &iter, XML_NODE_COLUMN, a_doc, -1);
gtk_tree_store_set (model, &iter, START_TAG_COLUMN,
- "XML Document Root", -1);
+ "<span foreground=\"#bbbb00\">XML Document Root</span>", -1);
gtk_tree_store_set (model, &iter, NODE_TYPE_COLUMN, "", -1);
xml_tree = a_doc->children;
- status = build_tree_model_from_xml_tree
+ status = mlview_tree_editor2_build_tree_model_from_xml_tree
(a_this, xml_tree,
&iter, INSERT_TYPE_ADD_CHILD,
(GtkTreeModel **) & model);
@@ -1144,6 +1156,15 @@
*@return the newly built instance of GtkTreeView, or NULL
*if a probleme arose.
*/
+
+GtkTreeView *
+mlview_tree_editor2_build_tree_view_from_xml_doc (MlViewTreeEditor2 * a_this,
+ xmlDoc * a_doc)
+{
+ return MLVIEW_TREE_EDITOR2_CLASS
+ (G_OBJECT_GET_CLASS (a_this))->build_tree_view_from_xml_doc (a_this, a_doc);
+}
+
static GtkTreeView *
build_tree_view_from_xml_doc (MlViewTreeEditor2 * a_this,
xmlDoc * a_doc)
@@ -1159,11 +1180,11 @@
g_return_val_if_fail (a_this
&& MLVIEW_IS_TREE_EDITOR2 (a_this)
&& PRIVATE (a_this)
- && PRIVATE (a_this)->app_context,
+ && a_this->app_context,
NULL);
settings = mlview_app_context_get_settings
- (PRIVATE (a_this)->app_context) ;
+ (a_this->app_context) ;
g_return_val_if_fail (settings, NULL) ;
status = build_tree_model_from_xml_doc
@@ -2018,12 +2039,21 @@
MlViewTreeEditor2 *editor = NULL;
editor = g_object_new (MLVIEW_TYPE_TREE_EDITOR2, NULL);
- PRIVATE (editor)->app_context = a_context;
+
+ mlview_tree_editor2_construct (editor, a_context);
+
+ return GTK_WIDGET (editor);
+}
+
+void
+mlview_tree_editor2_construct (MlViewTreeEditor2 *editor,
+ MlViewAppContext *a_context)
+{
+ editor->app_context = a_context;
g_signal_connect (G_OBJECT (editor),
"button_press_event",
- G_CALLBACK (event_cb), editor);
- return GTK_WIDGET (editor);
+ G_CALLBACK (event_cb), editor);
}
/**
@@ -2041,7 +2071,7 @@
(a_this));
g_return_if_fail (PRIVATE (a_this) != NULL);
- PRIVATE (a_this)->app_context = a_app_context;
+ a_this->app_context = a_app_context;
}
/**
@@ -2095,7 +2125,7 @@
NULL);
g_return_val_if_fail (PRIVATE (a_this) != NULL, NULL);
- return PRIVATE (a_this)->app_context;
+ return a_this->app_context;
}
@@ -2183,7 +2213,7 @@
res = GTK_WIDGET (PRIVATE (a_this)->node_type_picker) ;
if (! res) {
res = mlview_node_type_picker_new
- (PRIVATE (a_this)->app_context) ;
+ (a_this->app_context) ;
g_return_val_if_fail (res, NULL) ;
if (! MLVIEW_IS_NODE_TYPE_PICKER (res))
{
@@ -2245,7 +2275,7 @@
g_return_val_if_fail (a_this
&& MLVIEW_IS_TREE_EDITOR2 (a_this)
&& PRIVATE (a_this)
- && PRIVATE (a_this)->nodes_rows_hash
+ && a_this->nodes_rows_hash
&& a_iter, NULL) ;
model = mlview_tree_editor2_get_model (a_this) ;
@@ -2253,7 +2283,7 @@
&xml_node, -1) ;
g_return_val_if_fail (xml_node, NULL) ;
result = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash,
+ (a_this->nodes_rows_hash,
xml_node) ;
return result ;
}
@@ -2285,14 +2315,14 @@
g_return_val_if_fail (MLVIEW_IS_TREE_EDITOR2 (a_this),
MLVIEW_ERROR);
g_return_val_if_fail (PRIVATE (a_this)
- && PRIVATE (a_this)->app_context,
+ && a_this->app_context,
MLVIEW_ERROR);
g_return_val_if_fail (a_doc != NULL, MLVIEW_ERROR);
g_return_val_if_fail (MLVIEW_IS_XML_DOCUMENT
(a_doc), MLVIEW_ERROR);
settings = mlview_app_context_get_settings
- (PRIVATE (a_this)->app_context) ;
+ (a_this->app_context) ;
g_return_val_if_fail (MLVIEW_ERROR, MLVIEW_ERROR) ;
xml_doc =
mlview_xml_document_get_xml_document
@@ -2300,7 +2330,7 @@
g_return_val_if_fail (xml_doc != NULL, -1);
PRIVATE (a_this)->mlview_xml_doc = a_doc;
- tree_view = build_tree_view_from_xml_doc
+ tree_view = mlview_tree_editor2_build_tree_view_from_xml_doc
(a_this, xml_doc);
g_assert (tree_view != NULL);
@@ -2398,13 +2428,13 @@
a_node) ;
is_ok = gtk_tree_model_get_iter_first (model, &iter) ;
g_return_if_fail (is_ok == TRUE) ;
- status = build_tree_model_from_xml_tree (a_this, a_node, &iter,
- INSERT_TYPE_ADD_CHILD,
- &model) ;
+ status = mlview_tree_editor2_build_tree_model_from_xml_tree (a_this, a_node, &iter,
+ INSERT_TYPE_ADD_CHILD,
+ &model) ;
g_return_if_fail (status == MLVIEW_OK) ;
if (a_emit_signals == TRUE) {
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash, a_node) ;
+ (a_this->nodes_rows_hash, a_node) ;
g_return_if_fail (row_ref) ;
g_signal_emit (G_OBJECT (a_this),
gv_signals[NODE_ADDED],0,
@@ -2443,15 +2473,14 @@
g_return_val_if_fail (a_this
&& MLVIEW_IS_TREE_EDITOR2 (a_this)
&& PRIVATE (a_this)
- && PRIVATE (a_this)->
- nodes_rows_hash
+ && a_this->nodes_rows_hash
&& a_iter, MLVIEW_BAD_PARAM_ERROR);
model = mlview_tree_editor2_get_model (a_this);
g_return_val_if_fail (model, MLVIEW_ERROR);
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash, a_node);
+ (a_this->nodes_rows_hash, a_node);
if (!row_ref)
return MLVIEW_NODE_NOT_FOUND_ERROR;
tree_path = gtk_tree_row_reference_get_path (row_ref);
@@ -2674,7 +2703,7 @@
added_node = mlview_xml_document_add_child_node
(PRIVATE (a_this)->mlview_xml_doc,
parent_xml_node, a_node, TRUE,
- TRUE /*emit signal */ );
+ TRUE);
if (added_node)
return MLVIEW_OK;
return MLVIEW_ERROR;
@@ -2710,7 +2739,7 @@
mlview_node_type_picker_select_node_name_or_content_entry_text
(picker) ;
mlview_app_context_set_window_icon
- (PRIVATE (a_this)->app_context, GTK_WINDOW (picker)) ;
+ (a_this->app_context, GTK_WINDOW (picker)) ;
button = gtk_dialog_run (GTK_DIALOG (picker)) ;
switch (button) {
case GTK_RESPONSE_ACCEPT:
@@ -2761,7 +2790,7 @@
mlview_node_type_picker_build_element_name_choice_list
(picker, INSERT_BEFORE, cur_node) ;
mlview_app_context_set_window_icon
- (PRIVATE (a_this)->app_context,
+ (a_this->app_context,
GTK_WINDOW (picker)) ;
button = gtk_dialog_run (GTK_DIALOG (picker)) ;
switch (button) {
@@ -2814,7 +2843,7 @@
mlview_node_type_picker_build_element_name_choice_list
(picker, INSERT_BEFORE, cur_node) ;
mlview_app_context_set_window_icon
- (PRIVATE (a_this)->app_context,
+ (a_this->app_context,
GTK_WINDOW (picker)) ;
button = gtk_dialog_run (GTK_DIALOG (picker)) ;
switch (button) {
@@ -2855,14 +2884,13 @@
g_return_val_if_fail (a_this
&& MLVIEW_IS_TREE_EDITOR2 (a_this)
&& PRIVATE (a_this)
- && PRIVATE (a_this)->
- nodes_rows_hash && a_node
+ && a_this->nodes_rows_hash && a_node
&& a_ref_iter,
MLVIEW_BAD_PARAM_ERROR);
/*make sure a_node hasn't be drawn already */
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash, a_node);
+ (a_this->nodes_rows_hash, a_node);
g_return_val_if_fail (row_ref == NULL,
MLVIEW_BAD_PARAM_ERROR);
@@ -3127,7 +3155,7 @@
*the visual tree yet. row_ref must be NULL.
*/
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash, a_node);
+ (a_this->nodes_rows_hash, a_node);
if (row_ref)
return MLVIEW_OK;
/*only an element node should have children */
@@ -3143,7 +3171,7 @@
*It must have been drawn already.
*/
parent_row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash, a_parent);
+ (a_this->nodes_rows_hash, a_parent);
g_return_val_if_fail (parent_row_ref,
MLVIEW_NODE_NOT_FOUND_ERROR);
/*get an iterator on the parent node */
@@ -3161,7 +3189,7 @@
*build a GtkTreeModel subtree that matches the a_node
*subtree.
*/
- status = build_tree_model_from_xml_tree
+ status = mlview_tree_editor2_build_tree_model_from_xml_tree
(a_this, a_node,
&iter, INSERT_TYPE_ADD_CHILD, &model);
/*
@@ -3181,7 +3209,7 @@
/*emit the appropriate signals */
if (a_emit_signals == TRUE) {
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash,
+ (a_this->nodes_rows_hash,
a_node);
if (!row_ref) {
mlview_utils_trace_info ("row_ref failed") ;
@@ -3228,12 +3256,12 @@
&& a_node, MLVIEW_BAD_PARAM_ERROR);
/*make sure a_parent_node is drawn */
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash,
+ (a_this->nodes_rows_hash,
a_parent_node);
g_return_val_if_fail (row_ref, MLVIEW_BAD_PARAM_ERROR);
/*make sure a_node is not drawn */
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash, a_node);
+ (a_this->nodes_rows_hash, a_node);
g_return_val_if_fail (row_ref == NULL,
MLVIEW_BAD_PARAM_ERROR);
status = mlview_tree_editor2_update_child_node_added
@@ -3241,7 +3269,7 @@
g_return_val_if_fail (status == MLVIEW_OK, status);
if (a_emit_signals == TRUE) {
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash,
+ (a_this->nodes_rows_hash,
a_node);
g_return_val_if_fail (row_ref, MLVIEW_ERROR);
g_signal_emit (G_OBJECT (a_this),
@@ -3280,18 +3308,17 @@
g_return_val_if_fail (a_this
&& MLVIEW_IS_TREE_EDITOR2 (a_this)
&& PRIVATE (a_this)
- && PRIVATE (a_this)->
- nodes_rows_hash && a_ref_node
+ && a_this->nodes_rows_hash && a_ref_node
&& a_inserted_node,
MLVIEW_BAD_PARAM_ERROR);
/*make sure ref_node has been drawn already */
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash, a_ref_node);
+ (a_this->nodes_rows_hash, a_ref_node);
g_return_val_if_fail (row_ref, MLVIEW_BAD_PARAM_ERROR);
/*make sure a_inserted_node hasn't been drawn already */
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash,
+ (a_this->nodes_rows_hash,
a_inserted_node);
g_return_val_if_fail (row_ref == NULL,
MLVIEW_BAD_PARAM_ERROR);
@@ -3301,12 +3328,12 @@
model = mlview_tree_editor2_get_model (a_this);
g_return_val_if_fail (model, MLVIEW_ERROR);
if (a_previous == TRUE) {
- status = build_tree_model_from_xml_tree
+ status = mlview_tree_editor2_build_tree_model_from_xml_tree
(a_this, a_inserted_node,
&iter, INSERT_TYPE_INSERT_BEFORE,
&model);
} else {
- status = build_tree_model_from_xml_tree
+ status = mlview_tree_editor2_build_tree_model_from_xml_tree
(a_this, a_inserted_node,
&iter, INSERT_TYPE_INSERT_AFTER,
&model);
@@ -3372,7 +3399,7 @@
if (status != MLVIEW_OK)
return status;
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash, a_node_cut);
+ (a_this->nodes_rows_hash, a_node_cut);
g_return_val_if_fail (row_ref, MLVIEW_ERROR) ;
status = mlview_tree_editor2_get_iter
(a_this, a_node_cut, &iter);
@@ -3383,7 +3410,7 @@
is_ok = gtk_tree_store_remove
(GTK_TREE_STORE (model), &iter);
g_hash_table_remove
- (PRIVATE (a_this)->nodes_rows_hash, a_node_cut);
+ (a_this->nodes_rows_hash, a_node_cut);
gtk_tree_row_reference_free (row_ref) ;
row_ref=NULL ;
g_signal_emit (G_OBJECT (a_this),
@@ -3400,9 +3427,8 @@
*@return MLVIEW_OK upon successful completion, an error code
*otherwise.
*/
-enum MlViewStatus
-mlview_tree_editor2_update_visual_node (MlViewTreeEditor2 *a_this,
- GtkTreeIter * a_iter)
+static enum MlViewStatus
+update_visual_node (MlViewTreeEditor2 *a_this, GtkTreeIter *a_iter)
{
guchar *start_tag_str = NULL;
GtkTreeModel *model = NULL;
@@ -3417,7 +3443,9 @@
gtk_tree_model_get (model, a_iter, XML_NODE_COLUMN,
&xml_node, -1);
start_tag_str = node_to_string_tag (xml_node);
+
g_return_val_if_fail (start_tag_str, MLVIEW_ERROR);
+
gtk_tree_store_set (GTK_TREE_STORE (model),
a_iter, START_TAG_COLUMN,
start_tag_str, -1);
@@ -3425,10 +3453,18 @@
g_free (start_tag_str) ;
start_tag_str = NULL ;
}
-
+
return MLVIEW_OK;
}
+enum MlViewStatus
+mlview_tree_editor2_update_visual_node (MlViewTreeEditor2 *a_this,
+ GtkTreeIter * a_iter)
+{
+ return MLVIEW_TREE_EDITOR2_CLASS
+ (G_OBJECT_GET_CLASS (a_this))->update_visual_node (a_this, a_iter);
+}
+
/**
*Update the tag string of a given visual node.
*@param a_this the current instance of #MlViewTreeEditor2.
@@ -3453,7 +3489,7 @@
&& a_node, MLVIEW_BAD_PARAM_ERROR);
row_ref = g_hash_table_lookup
- (PRIVATE (a_this)->nodes_rows_hash, a_node);
+ (a_this->nodes_rows_hash, a_node);
if (!row_ref) {
return MLVIEW_NODE_NOT_FOUND_ERROR;
}
diff -ruN orig/mlview/src/mlview-tree-editor2.h mlview/src/mlview-tree-editor2.h
--- orig/mlview/src/mlview-tree-editor2.h 2003-10-25 22:07:34.000000000 +0200
+++ mlview/src/mlview-tree-editor2.h 2003-10-25 22:09:13.000000000 +0200
@@ -41,6 +41,8 @@
#include "mlview-xml-document.h"
+
+
G_BEGIN_DECLS
/*common macros to comply with the GtkObject typing system.*/
#define MLVIEW_TYPE_TREE_EDITOR2 (mlview_tree_editor2_get_type())
@@ -61,6 +63,15 @@
*===================================================================*/
struct _MlViewTreeEditor2 {
GtkVBox vbox;
+
+ /*
+ *a cache that contains
+ *a list of xmlNode/GtkTreeRowReference
+ *pair. This is to speed up searches.
+ */
+ GHashTable *nodes_rows_hash;
+ MlViewAppContext *app_context;
+
MlViewTreeEditor2Private *priv;
};
@@ -79,6 +90,9 @@
GtkWidget *mlview_tree_editor2_new (MlViewAppContext *
a_app_context);
+void mlview_tree_editor2_construct (MlViewTreeEditor2 *editor,
+ MlViewAppContext *a_context);
+
GtkTreeModel *mlview_tree_editor2_get_model (MlViewTreeEditor2 *a_this);
void mlview_tree_editor2_destroy (GtkObject * a_object);
@@ -221,6 +235,16 @@
enum MlViewStatus mlview_tree_editor2_disconnect_from_doc (MlViewTreeEditor2 *a_this,
MlViewXMLDocument *a_doc) ;
+guchar *mlview_tree_editor2_build_attrs_list_str (xmlNode *a_node);
+
+gchar *mlview_tree_editor2_get_colour_string (int type);
+
+enum MlViewTreeInsertType {
+ INSERT_TYPE_ADD_CHILD,
+ INSERT_TYPE_INSERT_BEFORE,
+ INSERT_TYPE_INSERT_AFTER
+};
+
/*===============================================================
*The structure representing the class of all the MlViewTreeEditor2 objects.
*==============================================================*/
@@ -286,6 +310,18 @@
void (*node_selected) (MlViewTreeEditor2 * a_editor,
GtkTreeRowReference *a_ref,
gpointer a_user_data);
+
+ GtkTreeView * (*build_tree_view_from_xml_doc) (MlViewTreeEditor2 * a_this,
+ xmlDoc * a_doc);
+
+ enum MlViewStatus (*update_visual_node) (MlViewTreeEditor2 *a_this,
+ GtkTreeIter * a_iter);
+
+ enum MlViewStatus (*build_tree_model_from_xml_tree) (MlViewTreeEditor2 * a_this,
+ const xmlNode * a_node,
+ GtkTreeIter * a_ref_iter,
+ enum MlViewTreeInsertType a_type,
+ GtkTreeModel ** a_model);
};
diff -ruN orig/mlview/src/mlview-tree-view.c mlview/src/mlview-tree-view.c
--- orig/mlview/src/mlview-tree-view.c 2003-10-25 22:07:34.000000000 +0200
+++ mlview/src/mlview-tree-view.c 2003-10-25 22:15:36.000000000 +0200
@@ -27,7 +27,7 @@
#include <glade/glade.h>
#include "mlview-tree-view.h"
#include "mlview-tree-editor2.h"
-
+#include "mlview-icon-tree.h"
struct _MlViewTreeViewPrivate {
guchar *name ;
@@ -1223,8 +1223,8 @@
GtkWidget *table = NULL,
*scrolled = NULL;
- MlViewTreeEditor2 *raw_xml_tree;
- /* MlViewTreeEditor2 *test_tree; */
+ MlViewTreeEditor2 *raw_xml;
+ MlViewTreeEditor2 *elements;
gint i, nb_pages;
MlViewTreeEditor2 *tree;
@@ -1284,17 +1284,17 @@
a_this);
/* Trees */
- raw_xml_tree = MLVIEW_TREE_EDITOR2 (mlview_tree_editor2_new (a_app_context));
- /* test_tree = MLVIEW_TREE_EDITOR2 (mlview_tree_editor2_new (a_app_context)); */
+ raw_xml = MLVIEW_TREE_EDITOR2 (mlview_tree_editor2_new (a_app_context));
+ elements = MLVIEW_TREE_EDITOR2 (mlview_icon_tree_new (a_app_context));
- PRIVATE (a_this)->tree_editor = raw_xml_tree;
+ PRIVATE (a_this)->tree_editor = raw_xml;
+ gtk_notebook_append_page (PRIVATE (a_this)->trees,
+ GTK_WIDGET (elements),
+ gtk_label_new (_("Elements")));
gtk_notebook_append_page (PRIVATE (a_this)->trees,
- GTK_WIDGET (raw_xml_tree),
- gtk_label_new (_("Elements")));
- /* gtk_notebook_append_page (PRIVATE (a_this)->trees,
- GTK_WIDGET (test_tree),
- gtk_label_new ("Test")); */
+ GTK_WIDGET (raw_xml),
+ gtk_label_new (_("Raw XML")));
/*the table with the feasible children, siblings and attributes */
PRIVATE (a_this)->feasible_children =
pixmaps.tar.gz
(application/gzip, 3.4 KB) - not displayed