[mlview-list][patch] 'add child node' corrections



Hi,

This should fix this bug :
http://bugzilla.gnome.org/show_bug.cgi?id=132034.
There still is some work to do with user notification on errors, I will
try to do it.

Cheers,

Nicolas Centa
"HappyPeng"
? depcomp
? install-sh
? intltool-modules
? missing
? mkinstalldirs
? test.diff
? schemas/Makefile.in
Index: src/mlview-node-type-picker.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-node-type-picker.c,v
retrieving revision 1.38
diff -a -u -r1.38 mlview-node-type-picker.c
--- src/mlview-node-type-picker.c	26 Dec 2003 21:49:30 -0000	1.38
+++ src/mlview-node-type-picker.c	25 Jan 2004 10:54:57 -0000
@@ -817,11 +817,17 @@
                 }
                 PRIVATE (a_this)->selected_node_type_def = 
                         &gv_xml_node_types[ELEMENT_NODE] ;
+                gtk_widget_show 
+                        (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content));
+                gtk_widget_show 
+                        (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content_label));
                 break;
         case XML_COMMENT_NODE:
                 gtk_label_set_text 
                         (PRIVATE (a_this)->node_name_or_content_label,
                          _("Comment node content"));
+                gtk_widget_show 
+                        (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content_label));
                 if (PRIVATE (a_this)->node_name_or_content) {
                         gtk_list_clear_items
                                 (GTK_LIST
@@ -833,6 +839,9 @@
                                 (GTK_EDITABLE
                                  (PRIVATE (a_this)->node_name_or_content->entry),
                                  0, -1);
+                        
+                        gtk_widget_show 
+                                (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content));
                 }
                 PRIVATE (a_this)->selected_node_type_def = 
                         &gv_xml_node_types[COMMENT_NODE];
@@ -842,7 +851,8 @@
                 gtk_label_set_text
                         (PRIVATE (a_this)->node_name_or_content_label,
                          _("Text node content"));
-
+                gtk_widget_hide
+                        (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content_label));
                 if (PRIVATE (a_this)->node_name_or_content) {
                         gtk_list_clear_items
                                 (GTK_LIST
@@ -854,6 +864,8 @@
                                  (PRIVATE
                                   (a_this)->node_name_or_content->entry), 0,
                                  -1);
+                        gtk_widget_hide 
+                                (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content));
                 }
                 PRIVATE (a_this)->selected_node_type_def = 
                         &gv_xml_node_types[TEXT_NODE] ;
@@ -864,7 +876,8 @@
                         (PRIVATE 
                          (a_this)->node_name_or_content_label,
                          _("PI node name"));
-
+                gtk_widget_show 
+                        (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content_label));
                 if (PRIVATE (a_this)->node_name_or_content) {
                         gtk_list_clear_items
                                 (GTK_LIST
@@ -875,6 +888,8 @@
                                 (GTK_EDITABLE
                                  (PRIVATE (a_this)->node_name_or_content->entry),
                                  0, -1);
+                        gtk_widget_show
+                                (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content));
                 }
                 PRIVATE (a_this)->selected_node_type_def = 
                         &gv_xml_node_types[PI_NODE] ;
@@ -884,7 +899,8 @@
                 gtk_label_set_text
                         (PRIVATE (a_this)->node_name_or_content_label,
                          _("CDATA section node content"));
-
+                gtk_widget_show 
+                        (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content_label));
                 if (PRIVATE (a_this)->node_name_or_content) {
                         gtk_list_clear_items
                                 (GTK_LIST
@@ -896,6 +912,8 @@
                                  (PRIVATE
                                   (a_this)->node_name_or_content->entry), 0,
                                  -1);
+                        gtk_widget_show 
+                                (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content));
                 }
                 PRIVATE (a_this)->selected_node_type_def = 
                         &gv_xml_node_types[CDATA_SECTION_NODE] ;
@@ -943,6 +961,8 @@
                                 ("should not reach this case") ;
                         break ;
                 }
+                gtk_widget_show 
+                        (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content_label));
                 if (PRIVATE (a_this)->node_name_or_content) {
                         gtk_list_clear_items
                                 (GTK_LIST
@@ -954,13 +974,21 @@
                                  (PRIVATE
                                   (a_this)->node_name_or_content->entry), 0,
                                  -1);
+                        gtk_widget_show 
+                                (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content));
                 }
                 break ;
         default:
                 gtk_label_set_text
                         (PRIVATE (a_this)->node_name_or_content_label,
                          _("Element node name"));
+                gtk_widget_show 
+                        (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content_label));
                 PRIVATE (a_this)->selected_node_type_def = NULL ;
+                if (PRIVATE (a_this)->node_name_or_content) {
+                        gtk_widget_show 
+                                (GTK_WIDGET (PRIVATE (a_this)->node_name_or_content));
+                }
                 break;
         }
 }
Index: src/mlview-tree-editor2.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-tree-editor2.c,v
retrieving revision 1.73
diff -a -u -r1.73 mlview-tree-editor2.c
--- src/mlview-tree-editor2.c	26 Dec 2003 21:49:30 -0000	1.73
+++ src/mlview-tree-editor2.c	25 Jan 2004 10:54:58 -0000
@@ -1709,81 +1709,102 @@
         node_name_or_content =
                 mlview_node_type_picker_get_node_name_or_content
                 (picker);
-        if (node_name_or_content != NULL
-            && !mlview_utils_is_white_string (node_name_or_content)) {
-                node_type_def =
-                        mlview_node_type_picker_get_selected_node_type
-                        (picker);
-                g_return_if_fail (node_type_def) ;
-                xml_doc =
-                        mlview_tree_editor2_get_mlview_xml_doc
-                        (a_this);
-                g_return_if_fail (xml_doc) ;
-                native_doc = mlview_xml_document_get_xml_document 
-                        (xml_doc);
-                g_return_if_fail (native_doc) ;
-                xml_node =
-                        new_xml_node (node_type_def, xml_doc);
 
-                switch (node_type_def->node_type) {
-                case XML_ELEMENT_NODE:
-                case XML_PI_NODE:                
-                case XML_DTD_NODE:
-                        mlview_utils_parse_full_name
-                                (xml_node, node_name_or_content,
-                                 &ns, &local_name);
-                        if (local_name != NULL) {
-                                mlview_xml_document_set_node_name
-                                        (xml_doc, xml_node,
-                                         local_name, UTF8, TRUE);
-                                g_free (local_name);
-                                local_name = NULL;
-                        }
-                        break;
-                case XML_ENTITY_DECL:
-                        mlview_utils_parse_full_name
-                                (xml_node, node_name_or_content,
-                                 &ns, &local_name);
-                        if (local_name != NULL) {
-                                mlview_xml_document_set_entity_node_name
-                                        (xml_doc, (xmlEntity*)xml_node,
-                                         native_doc->intSubset,
-                                         local_name, TRUE);
-                                g_free (local_name);
-                                local_name = NULL;
-                        }
-                        break ;
-                default:
-                        mlview_xml_document_set_node_content
-                                (xml_doc, xml_node,
-                                 node_name_or_content, UTF8,
-                                 FALSE);
-                        break;
-                }
-                status = mlview_tree_editor2_get_cur_sel_start_iter 
-                        (a_this, &iter) ;
-                g_return_if_fail (status == MLVIEW_OK) ;
-                node_addion_status =
-                        mlview_tree_editor2_add_child_node (a_this,
-                                                            &iter, 
-                                                            xml_node);
-                if (!node_addion_status
-                    && (node_type_def->entity_type == XML_ELEMENT_NODE
-                        || node_type_def->node_type == XML_PI_NODE)) {
-                        mlview_utils_parse_full_name
-                                (xml_node, node_name_or_content,
-                                 &ns, &local_name);
-                        if (ns) {
-                                xmlSetNs (xml_node, ns);
-                        } else {
-                                xml_node->ns = NULL;
-                        }
-                        if (local_name) {
-                                g_free (local_name);
-                                local_name = NULL;
-                        }
-                }
-        }
+         node_type_def =
+                 mlview_node_type_picker_get_selected_node_type
+                 (picker);
+         g_return_if_fail (node_type_def) ;
+         xml_doc =
+                 mlview_tree_editor2_get_mlview_xml_doc
+                 (a_this);
+         g_return_if_fail (xml_doc) ;
+         status = mlview_tree_editor2_get_cur_sel_start_iter 
+                 (a_this, &iter) ;
+         g_return_if_fail (status == MLVIEW_OK) ;
+         
+         if (node_name_or_content != NULL
+             && !mlview_utils_is_white_string (node_name_or_content)) {
+                 xml_node =
+                         new_xml_node (node_type_def, xml_doc);
+
+                 native_doc = mlview_xml_document_get_xml_document 
+                         (xml_doc);
+                 g_return_if_fail (native_doc) ;
+                 
+                 switch (node_type_def->node_type) {
+                 case XML_ELEMENT_NODE:
+                 case XML_PI_NODE:                
+                 case XML_DTD_NODE:
+                         mlview_utils_parse_full_name
+                                 (xml_node, node_name_or_content,
+                                  &ns, &local_name);
+                         if (local_name != NULL) {
+                                 mlview_xml_document_set_node_name
+                                         (xml_doc, xml_node,
+                                          local_name, UTF8, TRUE);
+                                 g_free (local_name);
+                                 local_name = NULL;
+                         }
+                         break;
+                 case XML_ENTITY_DECL:
+                         mlview_utils_parse_full_name
+                                 (xml_node, node_name_or_content,
+                                  &ns, &local_name);
+                         if (local_name != NULL) {
+                                 mlview_xml_document_set_entity_node_name
+                                         (xml_doc, (xmlEntity*)xml_node,
+                                          native_doc->intSubset,
+                                          local_name, TRUE);
+                                 g_free (local_name);
+                                 local_name = NULL;
+                         }
+                         break ;
+                 default:
+                         mlview_xml_document_set_node_content
+                                 (xml_doc, xml_node,
+                                  node_name_or_content, UTF8,
+                                  FALSE);
+                         break;
+                 }
+         }
+         else if (node_type_def->node_type == XML_TEXT_NODE &&
+                  mlview_utils_is_white_string (node_name_or_content)) {
+                 xml_node =
+                         new_xml_node (node_type_def, xml_doc);
+                 
+                 mlview_xml_document_set_node_content
+                         (xml_doc, xml_node,
+                          "", UTF8,
+                          FALSE);
+         }
+         else {
+                 mlview_app_context_error
+                         (PRIVATE (a_this)->app_context,
+                          _("Nodes of the selected type cannot have an empty content."));
+         }
+         
+         if (xml_node) {
+                 node_addion_status =
+                         mlview_tree_editor2_add_child_node (a_this,
+                                                             &iter, 
+                                                             xml_node);
+                 if (!node_addion_status
+                     && (node_type_def->entity_type == XML_ELEMENT_NODE
+                         || node_type_def->node_type == XML_PI_NODE)) {
+                         mlview_utils_parse_full_name
+                                 (xml_node, node_name_or_content,
+                                  &ns, &local_name);
+                         if (ns) {
+                                 xmlSetNs (xml_node, ns);
+                         } else {
+                                 xml_node->ns = NULL;
+                         }
+                         if (local_name) {
+                                 g_free (local_name);
+                                 local_name = NULL;
+                         }
+                 }
+         }
 }
 
 /**
@@ -4316,6 +4337,13 @@
                         return MLVIEW_BAD_NODE_PARENT ;
                 }
         }
+        else if (parent_xml_node->type == XML_DTD_NODE &&
+                 a_node->type != XML_ENTITY_DECL) {
+                mlview_app_context_error 
+                        (PRIVATE (a_this)->app_context,
+                         _("Nodes of the selected type cannot be a DTD node's children."));
+                return MLVIEW_BAD_NODE_PARENT;
+        }
         added_node = mlview_xml_document_add_child_node
                 (PRIVATE (a_this)->mlview_xml_doc,
                  parent_xml_node, a_node, TRUE,
@@ -4345,8 +4373,13 @@
         g_return_if_fail (cur_node) ;
         /*only an element node should have children*/
         if (cur_node->type != XML_ELEMENT_NODE 
-            && cur_node->type != XML_DTD_NODE)
-                return ;
+            && cur_node->type != XML_DTD_NODE) {
+                mlview_app_context_error 
+                        (PRIVATE (a_this)->app_context,
+                         _("The currently selected node cannot have children."));
+
+                        return ;
+        }
         picker = mlview_tree_editor2_get_node_type_picker (a_this) ;
         g_return_if_fail (picker) ;
         mlview_node_type_picker_set_title (picker, 


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