[mlview-list][patch] colours
- From: Nicolas Centa <nicolas centa free fr>
- To: mlview-list gnome org
- Subject: [mlview-list][patch] colours
- Date: Fri, 28 Nov 2003 19:32:53 +0100
Hello,
You can apply this patch instead of the previous colours/gconf patch :
this one allows you to change the attributes' values colours (the
flashing green).
Nicolas Centa
"HappyPeng"
? colours.diff
? depcomp
? install-sh
? missing
? mkinstalldirs
? schemas/Makefile.in
Index: schemas/mlview.schemas
===================================================================
RCS file: /cvs/gnome/mlview/schemas/mlview.schemas,v
retrieving revision 1.4
diff -a -u -r1.4 mlview.schemas
--- schemas/mlview.schemas 16 Nov 2003 18:36:04 -0000 1.4
+++ schemas/mlview.schemas 28 Nov 2003 18:28:03 -0000
@@ -25,5 +25,71 @@
feature is activated.</long>
</locale>
</schema>
+ <schema>
+ <key>/schemas/apps/mlview/colours/xml-element-node</key>
+ <applyto>/apps/mlview/colours/xml-element-node</applyto>
+ <owner>mlview</owner>
+ <type>string</type>
+ <default>#0080ff</default>
+ <locale name="C">
+ <short>Element node colour in mlview</short>
+ <long>Element node colour in mlview's trees.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/mlview/colours/xml-text-node</key>
+ <applyto>/apps/mlview/colours/xml-text-node</applyto>
+ <owner>mlview</owner>
+ <type>string</type>
+ <default>#ff0000</default>
+ <locale name="C">
+ <short>Text node colour in mlview</short>
+ <long>Text node colour in mlview's trees.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/mlview/colours/xml-comment-node</key>
+ <applyto>/apps/mlview/colours/xml-comment-node</applyto>
+ <owner>mlview</owner>
+ <type>string</type>
+ <default>#0000FF</default>
+ <locale name="C">
+ <short>Comment node colour in mlview</short>
+ <long>Comment node colour in mlview's trees.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/mlview/colours/xml-document-node</key>
+ <applyto>/apps/mlview/colours/xml-document-node</applyto>
+ <owner>mlview</owner>
+ <type>string</type>
+ <default>#0080ff</default>
+ <locale name="C">
+ <short>Document node colour in mlview</short>
+ <long>Document node colour in mlview's trees.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/mlview/colours/xml-dtd-node</key>
+ <applyto>/apps/mlview/colours/xml-dtd-node</applyto>
+ <owner>mlview</owner>
+ <type>string</type>
+ <default>#ff00ff</default>
+ <locale name="C">
+ <short>DTD node colour in mlview</short>
+ <long>DTD node colour in mlview's trees.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/mlview/colours/xml-attribute-value</key>
+ <applyto>/apps/mlview/colours/xml-attribute-value</applyto>
+ <owner>mlview</owner>
+ <type>string</type>
+ <default>#00ff00</default>
+ <locale name="C">
+ <short>Attribute value colour in mlview</short>
+ <long>Attribute value colour in mlview's trees.</long>
+ </locale>
+ </schema>
</schemalist>
</gconfschemafile>
Index: src/mlview-app-context.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-app-context.c,v
retrieving revision 1.29
diff -a -u -r1.29 mlview-app-context.c
--- src/mlview-app-context.c 24 Nov 2003 22:07:25 -0000 1.29
+++ src/mlview-app-context.c 28 Nov 2003 18:28:03 -0000
@@ -857,6 +857,95 @@
}
}
+/* Some gconf-related utilities to load many keys in only some
+ lines */
+
+#define GCONF_SEPARATOR "/"
+
+void
+mlview_gconf_free_values (GConfValue **values, const gint nb_keys)
+{
+ gint i;
+
+ for (i = 0 ; i < nb_keys ; i++)
+ {
+ gconf_value_free (values [i]);
+ }
+ g_free (values);
+}
+
+void
+mlview_gconf_free_strings (gchar **values, const gint nb_keys)
+{
+ gint i;
+
+ for (i = 0 ; i < nb_keys ; i++)
+ {
+ g_free (values [i]);
+ }
+ g_free (values);
+}
+
+GConfValue **
+mlview_gconf_read_values (GConfClient *client, const gchar *root,
+ const gchar **keys, const gint nb_keys, GError **err)
+{
+ GConfValue **values;
+ gint i;
+ gchar *path;
+ GError *tmp_err = NULL;
+
+ values = g_new (GConfValue*, nb_keys);
+ for (i = 0 ; i < nb_keys ; i++)
+ {
+ path = g_build_path (GCONF_SEPARATOR, root, keys [i], NULL);
+ values [i] = gconf_client_get (client, path, &tmp_err);
+ g_free (path);
+ if (tmp_err != NULL)
+ {
+ g_propagate_error (err, tmp_err);
+ mlview_gconf_free_values (values, i - 1);
+
+ return NULL;
+ }
+ }
+
+ return values;
+}
+
+gchar **
+mlview_gconf_read_strings (GConfClient *client, const gchar *root,
+ const gchar **keys, const gint nb_keys, GError **err)
+{
+ GConfValue **values;
+ gint i;
+ GError *tmp_err = NULL;
+ gchar **ret;
+
+ values = mlview_gconf_read_values (client, root, keys, nb_keys, &tmp_err);
+ if (tmp_err != NULL)
+ {
+ g_propagate_error (err, tmp_err);
+
+ return NULL;
+ }
+ ret = g_new (gchar*, nb_keys);
+ for (i = 0 ; i < nb_keys ; i++)
+ {
+ ret [i] = g_strdup (gconf_value_get_string (values [i]));
+ gconf_value_free (values [i]);
+ }
+ g_free (values);
+
+ return ret;
+}
+
+/* Colours keys */
+
+const gchar *colours_dir = "/apps/mlview/colours";
+const gchar *colours_keys [] = {"xml-element-node", "xml-text-node", "xml-comment-node",
+"xml-document-node", "xml-dtd-node", "xml-attribute-value"};
+
/**
*Loads all the gconf keys defined by the MlView application.
* param a_this the current instance of the #MlViewAppContext.
@@ -912,6 +1001,19 @@
gconf_value_free (value) ;
value = NULL ;
}
+
+ /* Colours */
+ settings->colours = mlview_gconf_read_strings (gconf_client,
+ colours_dir,
+ colours_keys,
+ MLVIEW_COLOURS_NB,
+ NULL);
+ if (!settings->colours) {
+ mlview_utils_trace_info
+ ("inconsistent gconf settings");
+ status = MLVIEW_ERROR;
+ goto cleanup;
+ }
cleanup:
if (value) {
@@ -1160,6 +1262,10 @@
}
if (PRIVATE (ctxt)->settings) {
+ if (PRIVATE (ctxt)->settings->colours) {
+ mlview_gconf_free_strings (PRIVATE (ctxt)->settings->colours,
+ MLVIEW_COLOURS_NB);
+ }
g_free (PRIVATE (ctxt)->settings) ;
PRIVATE (ctxt)->settings = NULL ;
}
Index: src/mlview-app-context.h
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-app-context.h,v
retrieving revision 1.18
diff -a -u -r1.18 mlview-app-context.h
--- src/mlview-app-context.h 24 Nov 2003 22:07:25 -0000 1.18
+++ src/mlview-app-context.h 28 Nov 2003 18:28:03 -0000
@@ -78,15 +78,27 @@
GObjectClass parent_class;
};
+enum {
+ XML_ELEMENT_NODE_COLOUR_KEY,
+ XML_TEXT_NODE_COLOUR_KEY,
+ XML_COMMENT_NODE_COLOUR_KEY,
+ XML_DOCUMENT_NODE_COLOUR_KEY,
+ XML_DTD_NODE_COLOUR_KEY,
+ XML_ATTR_VAL_COLOUR_KEY,
+ MLVIEW_COLOURS_NB
+} MlViewColourKey;
+
/**
*The public application wide settings
*data structure.
*This data structure is readonly the
*applicatoin.
*/
+
struct MlViewAppSettings {
gint default_doc_expansion_depth ;
gboolean validation_is_on ;
+ gchar **colours;
} ;
Index: src/mlview-icon-tree.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-icon-tree.c,v
retrieving revision 1.15
diff -a -u -r1.15 mlview-icon-tree.c
--- src/mlview-icon-tree.c 27 Nov 2003 19:46:21 -0000 1.15
+++ src/mlview-icon-tree.c 28 Nov 2003 18:28:04 -0000
@@ -61,7 +61,7 @@
NB_COLUMNS
};
-static guchar *node_to_string_tag (xmlNode * a_node);
+static guchar *node_to_string_tag (xmlNode * a_node, MlViewAppContext *ctxt);
static enum MlViewStatus build_tree_model_from_xml_tree (MlViewTreeEditor2 * a_this,
const xmlNode * a_node,
GtkTreeIter * a_ref_iter,
@@ -85,8 +85,8 @@
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);
+ start_tag_str = node_to_string_tag (xml_node, a_this->app_context);
+ attr_str = mlview_tree_editor2_build_attrs_list_str (xml_node, a_this->app_context);
if (!start_tag_str)
return MLVIEW_OK ;
@@ -223,7 +223,7 @@
cur_node; cur_node = cur_node->next) {
GtkTreeRowReference *row_ref = NULL;
- start_tag = node_to_string_tag (cur_node);
+ start_tag = node_to_string_tag (cur_node, a_this->app_context);
switch (a_type) {
case INSERT_TYPE_ADD_CHILD:
gtk_tree_store_append (model, &iter,
@@ -302,7 +302,8 @@
MLVIEW_ICON_TREE_CLASS
(G_OBJECT_GET_CLASS (a_this))->icons.open_element,
ATTRIBUTES_COLUMN,
- mlview_tree_editor2_build_attrs_list_str (cur_node),
+ mlview_tree_editor2_build_attrs_list_str (cur_node,
+ a_this->app_context),
ARE_ATTRIBUTES_EDITABLE_COLUMN,
TRUE,
-1);
@@ -395,16 +396,17 @@
*(e.g: <node-name attr0="val0" attr1="val1">)out of
*an instance of xmlNode *
* param a_node the instance of xmlNode * to consider.
+ * param ctxt the application context.
* return the newly built start tag string.
*/
static guchar *
-node_to_string_tag (xmlNode * a_node)
+node_to_string_tag (xmlNode * a_node, MlViewAppContext *ctxt)
{
guchar *result = NULL,
*content = NULL,
*escaped_content = NULL;
const gchar *colour_str =
- mlview_tree_editor2_get_colour_string (a_node->type);
+ mlview_tree_editor2_get_colour_string (a_node->type, ctxt);
g_return_val_if_fail (a_node != NULL, NULL) ;
if (a_node->type == XML_ELEMENT_NODE) {
@@ -521,7 +523,7 @@
guchar *tmp_str = NULL ;
guchar *dtd_color = (guchar*)
mlview_tree_editor2_get_colour_string
- (a_node->type) ;
+ (a_node->type, ctxt) ;
if (!a_node->name) {
mlview_utils_trace_info
("a node of type XML_DTD_NODE must have a ->name field set!!") ;
@@ -751,13 +753,14 @@
return result;
}
+/* UNUSED
static guchar *
-build_attrs_list_str_from_nv_pairs (GList *list)
+build_attrs_list_str_from_nv_pairs (GList *list, MlViewAppContext *ctxt)
{
guchar *result = NULL, *tmp;
struct NameValuePair *pair;
const gchar *attval_col = "#00FF00",
- *attname_col = mlview_tree_editor2_get_colour_string (XML_ATTRIBUTE_NODE);
+ *attname_col = mlview_tree_editor2_get_colour_string (XML_ATTRIBUTE_NODE, ctxt);
while (list)
{
@@ -781,7 +784,8 @@
return result;
}
-
+*/
+
static void
node_attributes_edited_cb (GtkCellRendererText *a_renderer,
gchar *a_cell_path,
Index: src/mlview-tree-editor2.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-tree-editor2.c,v
retrieving revision 1.59
diff -a -u -r1.59 mlview-tree-editor2.c
--- src/mlview-tree-editor2.c 27 Nov 2003 22:47:45 -0000 1.59
+++ src/mlview-tree-editor2.c 28 Nov 2003 18:28:05 -0000
@@ -690,61 +690,38 @@
}
}
-
/**
*Returns the color code of a given type of xml node.
* param a_type the type of xml node to consider.
+ * param ctxt the application context.
* return string representing the color code of the node
*in the form "#006FFF" for example.
*/
+
const gchar*
-mlview_tree_editor2_get_colour_string (xmlElementType a_type)
+mlview_tree_editor2_get_colour_string (xmlElementType a_type,
+ MlViewAppContext *ctxt)
{
- switch (a_type) {
+ struct MlViewAppSettings *settings;
+
+ g_return_val_if_fail (ctxt, "#000000");
+ settings = mlview_app_context_get_settings (ctxt);
+ g_return_val_if_fail (settings && settings->colours, "#000000");
+
+ switch (a_type) {
case XML_ELEMENT_NODE:
- return "#0080ff";
- case XML_ATTRIBUTE_NODE:
- return "#000000";
- case XML_TEXT_NODE:
- return "#ff0000";
- case XML_CDATA_SECTION_NODE:
- return "#000000";
- case XML_ENTITY_REF_NODE:
- return "#000000";
- case XML_ENTITY_NODE:
- return "#000000";
- case XML_PI_NODE:
- return "#000000";
- case XML_COMMENT_NODE:
- return "#0000FF";
- case XML_DOCUMENT_NODE:
- return "#0080ff";
- case XML_DOCUMENT_TYPE_NODE:
- return "#000000";
- case XML_DOCUMENT_FRAG_NODE:
- return "#000000";
- case XML_NOTATION_NODE:
- return "#000000";
- case XML_HTML_DOCUMENT_NODE:
- return "#000000";
- case XML_DTD_NODE:
- return "#FF00FF";
- case XML_ELEMENT_DECL:
- return "#000000";
- case XML_ATTRIBUTE_DECL:
- return "#000000";
- case XML_ENTITY_DECL:
- return "#000000";
- case XML_NAMESPACE_DECL:
- return "#000000";
- case XML_XINCLUDE_START:
- return "#000000";
- case XML_XINCLUDE_END:
- return "#000000";
- default:
- return "#000000" ;
-
- }
+ return settings->colours [XML_ELEMENT_NODE_COLOUR_KEY];
+ case XML_TEXT_NODE:
+ return settings->colours [XML_TEXT_NODE_COLOUR_KEY];
+ case XML_COMMENT_NODE:
+ return settings->colours [XML_COMMENT_NODE_COLOUR_KEY];
+ case XML_DOCUMENT_NODE:
+ return settings->colours [XML_DOCUMENT_NODE_COLOUR_KEY];
+ case XML_DTD_NODE:
+ return settings->colours [XML_DTD_NODE_COLOUR_KEY];
+ default:
+ return "#000000";
+ }
}
/**
@@ -752,15 +729,16 @@
*(e.g: <node-name attr0="val0" attr1="val1">)out of
*an instance of xmlNode *
* param a_node the instance of xmlNode * to consider.
+ * param ctxt the application context.
* return the newly built start tag string.
*/
static guchar *
-node_to_string_tag (xmlNode * a_node)
+node_to_string_tag (xmlNode * a_node, MlViewAppContext *ctxt)
{
guchar *result = NULL,
*content = NULL,
*escaped_content = NULL;
- const gchar *colour_str = mlview_tree_editor2_get_colour_string (a_node->type);
+ const gchar *colour_str = mlview_tree_editor2_get_colour_string (a_node->type, ctxt);
g_return_val_if_fail (a_node != NULL, NULL);
@@ -771,10 +749,10 @@
const gchar *attr_colour_str =
mlview_tree_editor2_get_colour_string
- (XML_ATTRIBUTE_NODE) ;
+ (XML_ATTRIBUTE_NODE, ctxt) ;
attr_str = mlview_tree_editor2_build_attrs_list_str
- (a_node) ;
+ (a_node, ctxt) ;
if (a_node->ns != NULL && a_node->ns->prefix) {
ns_prefix = g_strconcat (a_node->ns->prefix,
":", NULL);
@@ -922,7 +900,7 @@
xmlDtd *node = (xmlDtd*)a_node ;
guchar *tmp_str = NULL ;
guchar *dtd_color = (guchar*)mlview_tree_editor2_get_colour_string
- (a_node->type) ;
+ (a_node->type, ctxt) ;
if (!a_node->name) {
mlview_utils_trace_info
@@ -1100,7 +1078,7 @@
cur_node; cur_node = cur_node->next) {
GtkTreeRowReference *row_ref = NULL;
- start_tag = node_to_string_tag (cur_node);
+ start_tag = node_to_string_tag (cur_node, a_this->app_context);
switch (a_type) {
case INSERT_TYPE_ADD_CHILD:
gtk_tree_store_append (model, &iter,
@@ -1484,7 +1462,7 @@
("mlview_xml_doc failed") ;
goto cleanup ;
}
- start_tag = node_to_string_tag (cur_node) ;
+ start_tag = node_to_string_tag (cur_node, tree_editor->app_context) ;
if (cur_node->type == XML_ELEMENT_NODE) {
status = mlview_utils_parse_start_tag
(a_new_text, &element_name, &nv_pair_list) ;
@@ -2271,21 +2249,31 @@
*construct a string which looks like
*'attrname0="attrval0" attrname1=attrvall'
*where each attrnamei is
- * param a_node the node to build the attribute list from.
+ * param a_node the node to build the attribute list from.
+ * param ctxt the application context.
* return the newly built attribute list string, or NULL if something
*bad happened.
*/
guchar *
-mlview_tree_editor2_build_attrs_list_str (xmlNode * a_node)
+mlview_tree_editor2_build_attrs_list_str (xmlNode * a_node, MlViewAppContext *ctxt)
{
enum MlViewStatus status = MLVIEW_OK ;
xmlAttrPtr attr_iter = NULL ;
- const gchar *attval_col = "#00FF00",
- *attname_col = mlview_tree_editor2_get_colour_string (XML_ATTRIBUTE_NODE);
+ const gchar *attval_col,
+ *attname_col = mlview_tree_editor2_get_colour_string (XML_ATTRIBUTE_NODE, ctxt);
gchar *attribute, *result = NULL, *tmp = NULL ;
guchar *escaped_content = NULL;
guint esc_content_len = 0 ;
+ struct MlViewAppSettings *settings;
+ settings = mlview_app_context_get_settings (ctxt);
+ if (settings && settings->colours) {
+ attval_col = settings->colours [XML_ATTR_VAL_COLOUR_KEY];
+ }
+ else {
+ attval_col = "#000000";
+ }
+
g_return_val_if_fail (a_node, NULL);
for (attr_iter = a_node->properties;
@@ -3767,7 +3755,7 @@
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);
+ start_tag_str = node_to_string_tag (xml_node, a_this->app_context);
if (!start_tag_str) {
return MLVIEW_OK;
}
Index: src/mlview-tree-editor2.h
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-tree-editor2.h,v
retrieving revision 1.22
diff -a -u -r1.22 mlview-tree-editor2.h
--- src/mlview-tree-editor2.h 11 Nov 2003 00:03:12 -0000 1.22
+++ src/mlview-tree-editor2.h 28 Nov 2003 18:28:05 -0000
@@ -245,9 +245,11 @@
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);
+guchar *mlview_tree_editor2_build_attrs_list_str (xmlNode *a_node,
+ MlViewAppContext *ctxt);
-const gchar *mlview_tree_editor2_get_colour_string (xmlElementType a_type);
+const gchar *mlview_tree_editor2_get_colour_string (xmlElementType a_type,
+ MlViewAppContext *ctxt);
enum MlViewTreeInsertType {
INSERT_TYPE_ADD_CHILD,
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]