Re: [mlview-list][patch] feasible children/siblings in popup menu



Hi,

	Sorry, I just forgot to attach the patch to the mail. 

Cheers,

Nicolas

Le sam, 01/05/2004 à 20:24 +0200, Dodji Seketeli a écrit :
> Salut Nicola, on dirait que le patch est pas dans le mail ;)

> On Tue, 2004-04-06 at 18:47 +0200, Nicolas Centa wrote:
> > Hi,
> > 
> > 	All is in the title :-)
> > 
> > This screenshot shows how it looks for possible children :
> > http://happypeng.free.fr/screenshots/mlview-completion.png
> > 
> > 	Cheers,
> > 
> > Nicolas Centa
> > 
> > _______________________________________________
> > Mlview-list mailing list
> > Mlview-list gnome org
> > http://mail.gnome.org/mailman/listinfo/mlview-list
> -- 
> Dodji Seketeli <dodji seketeli org>
> 
? popup.diff
? schemas/Makefile.in
Index: schemas/mlview.schemas
===================================================================
RCS file: /cvs/gnome/mlview/schemas/mlview.schemas,v
retrieving revision 1.5.4.1
diff -a -u -r1.5.4.1 mlview.schemas
--- schemas/mlview.schemas	22 Jan 2004 22:10:37 -0000	1.5.4.1
+++ schemas/mlview.schemas	6 Apr 2004 16:39:08 -0000
@@ -26,6 +26,17 @@
       </locale>
     </schema>
     <schema>
+      <key>/schemas/apps/mlview/enable-completion-box</key>
+      <applyto>/apps/mlview/enable-completion-box</applyto>
+      <owner>mlview</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+        <short>The completion box state</short>
+        <long>If set to true, the completion box will be shown.</long>
+      </locale>
+    </schema>
+    <schema>
       <key>/schemas/apps/mlview/colours/xml-element-node</key>
       <applyto>/apps/mlview/colours/xml-element-node</applyto>
       <owner>mlview</owner>
Index: src/mlview-app-context.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-app-context.c,v
retrieving revision 1.31.2.7
diff -a -u -r1.31.2.7 mlview-app-context.c
--- src/mlview-app-context.c	18 Feb 2004 19:23:51 -0000	1.31.2.7
+++ src/mlview-app-context.c	6 Apr 2004 16:39:11 -0000
@@ -51,6 +51,8 @@
 #define DEFAULT_TREE_EXPANSION_DEPTH_KEY "/apps/mlview/default-tree-expansion-depth"
 #define VALIDATION_IS_ON_KEY "/apps/mlview/validation-is-on"
 #define DEFAULT_EDITING_VIEW_TYPE_KEY "/apps/mlview/default-editing-view-type"
+#define ENABLE_COMPLETION_BOX_KEY "/apps/mlview/enable-completion-box"
+
 static const gchar *tree_editors_node_colours_keys[NB_OF_TREE_NODE_COLOURS + 1] = 
 {"/apps/mlview/colours/xml-element-node",
  "/apps/mlview/colours/xml-attribute-node",
@@ -1081,6 +1083,13 @@
                         (value  && value->type == GCONF_VALUE_BOOL) ;
                 settings->general.validation_is_on =
                         gconf_value_get_bool (value) ;
+        } else if (!strcmp (key,
+                            ENABLE_COMPLETION_BOX_KEY)) {
+                value = gconf_entry_get_value (a_entry);
+                g_return_if_fail
+                        (value && value->type == GCONF_VALUE_BOOL);
+                settings->general.enable_completion_box = 
+                        gconf_value_get_bool (value);
         } else if (is_a_gconf_entry_a_tree_editor_node_color
                    (a_entry, &colour_item) == TRUE) {
                 settings->tree_editors.nodes_colours[colour_item] 
@@ -1124,6 +1133,8 @@
                 (DEFAULT_TREE_EXPANSION_DEPTH_KEY) ;
         settings->general.validation_is_on =
                 eel_gconf_get_boolean (VALIDATION_IS_ON_KEY);
+        settings->general.enable_completion_box = 
+                eel_gconf_get_boolean (ENABLE_COMPLETION_BOX_KEY);
         settings->general.default_editing_view_type =
                 eel_gconf_get_string (DEFAULT_EDITING_VIEW_TYPE_KEY) ;
         for (i = 0 ;
Index: src/mlview-app-context.h
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-app-context.h,v
retrieving revision 1.19.4.6
diff -a -u -r1.19.4.6 mlview-app-context.h
--- src/mlview-app-context.h	18 Feb 2004 19:23:51 -0000	1.19.4.6
+++ src/mlview-app-context.h	6 Apr 2004 16:39:11 -0000
@@ -122,6 +122,7 @@
 struct MlViewAppSettings {
         struct {
                 gboolean validation_is_on ;
+                gboolean enable_completion_box;
                 gchar *default_editing_view_type ;
         } general ;
         struct {
Index: src/mlview-tree-editor2.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-tree-editor2.c,v
retrieving revision 1.73.2.5
diff -a -u -r1.73.2.5 mlview-tree-editor2.c
--- src/mlview-tree-editor2.c	21 Feb 2004 15:37:07 -0000	1.73.2.5
+++ src/mlview-tree-editor2.c	6 Apr 2004 16:39:25 -0000
@@ -4003,7 +4003,12 @@
                           "changed",
                           G_CALLBACK (nodeset_selected_cb),
                           a_this);        
+
         scr_win = gtk_scrolled_window_new (NULL, NULL);
+        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr_win),
+                                        GTK_POLICY_AUTOMATIC,
+                                        GTK_POLICY_AUTOMATIC);
+
         gtk_container_add (GTK_CONTAINER (scr_win),
                            GTK_WIDGET (tree_view));
         gtk_box_pack_start (GTK_BOX (a_this), scr_win,
Index: src/mlview-tree-view.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-tree-view.c,v
retrieving revision 1.17.2.11
diff -a -u -r1.17.2.11 mlview-tree-view.c
--- src/mlview-tree-view.c	24 Feb 2004 19:33:19 -0000	1.17.2.11
+++ src/mlview-tree-view.c	6 Apr 2004 16:39:31 -0000
@@ -39,9 +39,6 @@
 struct TreeEditorContextualMenuHandle {
         GtkWidget *menu ;
         /*menuitems*/
-        GtkWidget *add_child_node_mi ;
-        GtkWidget *insert_prev_node_mi ;
-        GtkWidget *insert_next_node_mi ;
         GtkWidget *copy_node_mi ;
         GtkWidget *cut_node_mi ;
         GtkWidget *paste_node_as_child_mi ;
@@ -49,8 +46,28 @@
         GtkWidget *paste_node_as_next_mi ;
         GtkWidget *expand_cur_node_mi ;
         GtkWidget *find_node_mi ;
+        /* add child */
+        GtkWidget *add_child_node_mi; /* menu item */
+        GtkWidget *add_child_node_sep; /* separator */
+        GtkWidget *add_child_node_sub; /* submenu */
+        GList *add_child_node_items; /* completion items */
+        /* add next */
+        GtkWidget *insert_next_node_mi;
+        GtkWidget *insert_next_node_sep;
+        GtkWidget *insert_next_node_sub;
+        GList *insert_next_node_items;
+        /* add prev */
+        GtkWidget *insert_prev_node_mi;
+        GtkWidget *insert_prev_node_sep;
+        GtkWidget *insert_prev_node_sub;
+        GList *insert_prev_node_items;
 } ;
 
+struct CompletionMenuItem {
+        GtkWidget *item;
+        gchar *text;
+        MlViewTreeView *view;
+};
 
 struct _MlViewTreeViewPrivate {
         guchar *name ;
@@ -149,13 +166,17 @@
 static void mlview_tree_view_finalise (GObject *a_this) ;
 
 static enum MlViewStatus mlview_tree_view_handle_contextual_menu_request (MlViewTreeView *a_this,
-                                                                          GtkWidget *a_source_widget,
+                                                                          GtkWidget *a_source_widget,    
                                                                           GdkEvent *a_event) ;
-static gboolean
-contextual_menu_requested_cb (MlViewAppContext *a_ctxt,
-                              GtkWidget *a_source_widget,
-                              GdkEvent *a_event,
-                              gpointer a_user_data) ;
+
+static void destroy_menu_handle (MlViewTreeView *a_this);
+
+static gboolean contextual_menu_requested_cb (MlViewAppContext *a_ctxt,
+                                              GtkWidget *a_source_widget,
+                                              GdkEvent *a_event,
+                                              gpointer a_user_data);
+
+static void clear_completion_popup_submenu (GList **a_list, GtkWidget *a_separator);
 
 static MlViewViewAdapterClass *parent_class = NULL;
 static guint p_signals[SIGNAL_NUM] = { 0 };
@@ -271,6 +292,8 @@
         if (PRIVATE (thiz)->dispose_has_run == TRUE)
                 return ;
 
+        destroy_menu_handle (MLVIEW_TREE_VIEW (a_this));
+
         if (PRIVATE (thiz)->expand_tree_dialog) {
                 gtk_widget_destroy
                         (GTK_WIDGET
@@ -463,6 +486,9 @@
                                 (cur) ? (gchar *) cur->
                                 data : NULL;
                 }
+                
+                g_list_free (children_name_list);
+                children_name_list = NULL;
         }
 }
 
@@ -520,6 +546,9 @@
                                 (cur) ? (gchar *) cur->
                                 data : NULL;
                 }
+
+                g_list_free (children_name_list);
+                children_name_list = NULL;
         }
 }
 
@@ -576,6 +605,9 @@
                                 (cur) ? (gchar *) cur->
                                 data : NULL;
                 }
+
+                g_list_free (children_name_list);
+                children_name_list = NULL;
         }
 }
 
@@ -634,6 +666,9 @@
                                 (cur) ? (gchar *) cur->
                                 data : NULL;
                 }
+
+                g_list_free (children_name_list);
+                children_name_list = NULL;
         }
 }
 
@@ -1151,6 +1186,33 @@
         g_return_if_fail (app_menu_bar) ;
 }
 
+static void
+destroy_menu_handle (MlViewTreeView *a_this)
+{
+        g_return_if_fail (a_this && MLVIEW_IS_TREE_VIEW (a_this)
+                          && PRIVATE (a_this));
+
+        if (PRIVATE (a_this)->contextual_menu_handle) {
+                if (PRIVATE (a_this)->contextual_menu_handle->menu) {
+                        clear_completion_popup_submenu 
+                                (&(PRIVATE (a_this)->contextual_menu_handle->add_child_node_items),
+                                 PRIVATE (a_this)->contextual_menu_handle->add_child_node_sep);
+                        clear_completion_popup_submenu
+                                (&(PRIVATE (a_this)->contextual_menu_handle->insert_next_node_items),
+                                 PRIVATE (a_this)->contextual_menu_handle->insert_next_node_sep);
+                        clear_completion_popup_submenu
+                                (&(PRIVATE (a_this)->contextual_menu_handle->insert_prev_node_items),
+                                 PRIVATE (a_this)->contextual_menu_handle->insert_prev_node_sep);
+ 
+                        gtk_widget_destroy
+                                (PRIVATE 
+                                 (a_this)->contextual_menu_handle->menu) ;
+                        PRIVATE (a_this)->contextual_menu_handle->menu = NULL ;
+                }
+                g_free (PRIVATE (a_this)->contextual_menu_handle) ;
+                PRIVATE (a_this)->contextual_menu_handle = NULL ;
+        }
+}
 
 /**
  *Creates a contextual menu that allows
@@ -1164,7 +1226,7 @@
 {
         struct TreeEditorContextualMenuHandle *menu_handle = NULL ;
 
-        GtkWidget *menu = NULL, *menuitem = NULL;
+        GtkWidget *menu = NULL, *menuitem = NULL, *submenu = NULL;
 
         g_return_val_if_fail (a_this
                               && MLVIEW_IS_TREE_VIEW (a_this),
@@ -1180,44 +1242,104 @@
                 sizeof (struct TreeEditorContextualMenuHandle) ) ;
         menu_handle->menu = gtk_menu_new () ;
         menu = menu_handle->menu ;
+
+        menu_handle->add_child_node_items = NULL;
+
         menu_handle->add_child_node_mi = 
-                gtk_menu_item_new_with_label (_("Add child node")) ;
-        menuitem = menu_handle->add_child_node_mi ;
-        gtk_menu_shell_append (GTK_MENU_SHELL (menu),
-                               menuitem) ;
-        gtk_widget_show (menuitem) ;
+                gtk_menu_item_new_with_label (_("Add child node...")) ;
+        
+        submenu = gtk_menu_new ();
+
+        menuitem = gtk_menu_item_new_with_label (_("Other..."));
+        gtk_menu_shell_append (GTK_MENU_SHELL (submenu),
+                               menuitem);
+        gtk_widget_show (menuitem);
+
         g_signal_connect (G_OBJECT (menuitem),
                           "activate",
                           G_CALLBACK 
                           (add_child_node_menuitem_activated_cb),
-                          a_this) ;
+                          a_this);
+
+        menu_handle->add_child_node_sub = submenu;
+
+        menuitem = gtk_separator_menu_item_new ();
+        gtk_menu_shell_append (GTK_MENU_SHELL (submenu),
+                               menuitem);
+
+        menu_handle->add_child_node_sep = menuitem;
+
+        menuitem = menu_handle->add_child_node_mi;
+
+        gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
+
+        gtk_menu_shell_append (GTK_MENU_SHELL (menu),
+                               menuitem);
+
+        gtk_widget_show (menuitem);
 
         menu_handle->insert_next_node_mi = 
                 gtk_menu_item_new_with_label 
-                 (_("Insert next node")) ;
-        menuitem = menu_handle->insert_next_node_mi ;
-        gtk_menu_shell_append (GTK_MENU_SHELL (menu),
-                               menuitem) ;
-        gtk_widget_show (menuitem) ;
+                 (_("Insert next node...")) ;
+        
+        submenu = gtk_menu_new ();
+        menuitem = gtk_menu_item_new_with_label (_("Other..."));
+        gtk_menu_shell_append (GTK_MENU_SHELL (submenu),
+                               menuitem);
+        gtk_widget_show (menuitem);
+
         g_signal_connect (G_OBJECT (menuitem),
                           "activate",
                           G_CALLBACK 
                           (insert_next_node_menuitem_activated_cb),
                           a_this) ;
 
-        menu_handle->insert_prev_node_mi = 
-                gtk_menu_item_new_with_label 
-                (_("Insert previous node")) ;
-        menuitem = menu_handle->insert_prev_node_mi ;
+        menu_handle->insert_next_node_sub = submenu;
+
+        menuitem = gtk_separator_menu_item_new ();
+        gtk_menu_shell_append (GTK_MENU_SHELL (submenu),
+                               menuitem);
+
+        menu_handle->insert_next_node_sep = menuitem;
+        
+        menuitem = menu_handle->insert_next_node_mi ;
+        gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem),
+                                   submenu);
         gtk_menu_shell_append (GTK_MENU_SHELL (menu),
                                menuitem) ;
         gtk_widget_show (menuitem) ;
+       
+        menu_handle->insert_prev_node_mi = 
+                gtk_menu_item_new_with_label 
+                (_("Insert previous node...")) ;
+        
+        submenu = gtk_menu_new ();
+        menuitem = gtk_menu_item_new_with_label (_("Other..."));
+        gtk_menu_shell_append (GTK_MENU_SHELL (submenu),
+                               menuitem);
+        gtk_widget_show (menuitem);
+
         g_signal_connect (G_OBJECT (menuitem),
                           "activate",
                           G_CALLBACK 
                           (insert_previous_node_menuitem_activated_cb),
                           a_this) ;
 
+        menu_handle->insert_prev_node_sub = submenu;
+
+        menuitem = gtk_separator_menu_item_new ();
+        gtk_menu_shell_append (GTK_MENU_SHELL (submenu),
+                               menuitem);
+
+        menu_handle->insert_prev_node_sep = menuitem;
+        
+        menuitem = menu_handle->insert_prev_node_mi ;
+        gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem),
+                                   submenu);
+        gtk_menu_shell_append (GTK_MENU_SHELL (menu),
+                               menuitem) ;
+        gtk_widget_show (menuitem) ;
+
         menuitem = gtk_separator_menu_item_new () ;
         gtk_menu_shell_append (GTK_MENU_SHELL (menu),
                                menuitem) ;
@@ -1320,16 +1442,8 @@
                           a_this) ;
         gtk_widget_show (menuitem) ;
 
-        if (PRIVATE (a_this)->contextual_menu_handle) {
-                if (PRIVATE (a_this)->contextual_menu_handle->menu) {
-                        gtk_widget_destroy
-                                (PRIVATE 
-                                 (a_this)->contextual_menu_handle->menu) ;
-                        PRIVATE (a_this)->contextual_menu_handle->menu = NULL ;
-                }
-                g_free (PRIVATE (a_this)->contextual_menu_handle) ;
-                PRIVATE (a_this)->contextual_menu_handle = NULL ;
-        }
+        destroy_menu_handle (a_this);
+
         PRIVATE (a_this)->contextual_menu_handle = menu_handle ;
 
         return MLVIEW_OK ;
@@ -1519,10 +1633,219 @@
         return MLVIEW_OK ;
 }
 
+void
+completion_menu_item_destroy (struct CompletionMenuItem *a_item)
+{
+        g_return_if_fail (a_item);
+
+        gtk_widget_destroy (a_item->item);
+
+        g_free (a_item);
+}
+
+static void
+clear_completion_popup_submenu (GList **a_list, GtkWidget *a_separator)
+{
+        GList *w_list = NULL;
+
+        g_return_if_fail (a_list);
+
+        w_list = *a_list;
+
+        if (w_list) {
+                g_list_foreach (w_list, (GFunc)completion_menu_item_destroy,
+                                NULL);
+                g_list_free (w_list);
+                w_list = NULL;
+        }
+
+        *a_list = w_list;
+
+        gtk_widget_hide (a_separator);
+}
+
+void
+insert_next_node_menu_item_activate_cb (GtkWidget *a_menu_item,
+                                        struct CompletionMenuItem *a_completion_item)
+{
+        GtkTreeIter cur_sel_start = { 0 };
+        gint ret_code = 0;
+        enum MlViewStatus status = MLVIEW_OK;
+        xmlNode *new_node = NULL;
+
+        g_return_if_fail (a_completion_item && a_completion_item->text);
+        g_return_if_fail (a_completion_item->view &&
+                          MLVIEW_IS_TREE_VIEW (a_completion_item->view) &&
+                          PRIVATE (a_completion_item->view));
+        g_return_if_fail (PRIVATE (a_completion_item->view)->tree_editor);
+
+        status = mlview_tree_editor2_get_cur_sel_start_iter
+                (PRIVATE (a_completion_item->view)->tree_editor,
+                 &cur_sel_start);
+        
+        g_return_if_fail (status == MLVIEW_OK) ;
+        
+        if (strcmp (a_completion_item->text, "#PCDATA") == 0) {
+                new_node = xmlNewNode (NULL, "text");
+                new_node->type = XML_TEXT_NODE;
+        } else 
+                new_node =
+                        xmlNewNode (NULL, a_completion_item->text);
+        
+        g_return_if_fail (new_node);
+                
+        mlview_tree_editor2_insert_sibling_node 
+                (PRIVATE (a_completion_item->view)->tree_editor,
+                 &cur_sel_start, new_node, FALSE) ;
+}
+
+void
+insert_prev_node_menu_item_activate_cb (GtkWidget *a_menu_item,
+                                        struct CompletionMenuItem *a_completion_item)
+{
+        GtkTreeIter cur_sel_start = { 0 };
+        gint ret_code = 0;
+        enum MlViewStatus status = MLVIEW_OK;
+        xmlNode *new_node = NULL;
+
+        g_return_if_fail (a_completion_item && a_completion_item->text);
+        g_return_if_fail (a_completion_item->view &&
+                          MLVIEW_IS_TREE_VIEW (a_completion_item->view) &&
+                          PRIVATE (a_completion_item->view));
+        g_return_if_fail (PRIVATE (a_completion_item->view)->tree_editor);
+
+        status = mlview_tree_editor2_get_cur_sel_start_iter
+                (PRIVATE (a_completion_item->view)->tree_editor,
+                 &cur_sel_start);
+        
+        g_return_if_fail (status == MLVIEW_OK) ;
+        
+        if (strcmp (a_completion_item->text, "#PCDATA") == 0) {
+                new_node = xmlNewNode (NULL, "text");
+                new_node->type = XML_TEXT_NODE;
+        } else 
+                new_node =
+                        xmlNewNode (NULL, a_completion_item->text);
+        
+        g_return_if_fail (new_node);
+                
+        mlview_tree_editor2_insert_sibling_node 
+                (PRIVATE (a_completion_item->view)->tree_editor,
+                 &cur_sel_start, new_node, TRUE) ;
+}
+
+void
+add_child_node_menu_item_activate_cb (GtkWidget *a_menu_item,
+                                      struct CompletionMenuItem *a_completion_item)
+{
+        GtkTreeIter cur_sel_start = { 0 };
+        gint ret_code = 0;
+        enum MlViewStatus status = MLVIEW_OK;
+        xmlNode *new_node = NULL;
+
+        g_return_if_fail (a_completion_item && a_completion_item->text);
+        g_return_if_fail (a_completion_item->view &&
+                          MLVIEW_IS_TREE_VIEW (a_completion_item->view) &&
+                          PRIVATE (a_completion_item->view));
+        g_return_if_fail (PRIVATE (a_completion_item->view)->tree_editor);
+
+        status = mlview_tree_editor2_get_cur_sel_start_iter
+                (PRIVATE (a_completion_item->view)->tree_editor,
+                 &cur_sel_start);
+        
+        g_return_if_fail (status == MLVIEW_OK) ;
+        
+        if (strcmp (a_completion_item->text, "#PCDATA") == 0) {
+                new_node = xmlNewNode (NULL, "text");
+                new_node->type = XML_TEXT_NODE;
+        } else 
+                new_node =
+                        xmlNewNode (NULL, a_completion_item->text);
+        
+        g_return_if_fail (new_node);
+                
+        mlview_tree_editor2_add_child_node 
+                (PRIVATE (a_completion_item->view)->tree_editor,
+                 &cur_sel_start, new_node) ;
+}
+
+static void
+update_completion_popup_submenu (MlViewAppContext *a_context, xmlNodePtr a_node,
+                                 MlViewTreeView *a_this, 
+                                 enum NODE_INSERTION_SCHEME a_insertion_scheme,
+                                 GtkWidget *a_separator, GtkWidget *a_menu,
+                                 GList **a_list, GCallback a_cb)
+{
+        GList *children_name_list = NULL, *w_list = NULL;
+        gint nb_of_names = 0;
+        GtkWidget *menuitem = NULL;
+
+        g_return_if_fail (a_list);
+
+        g_return_if_fail (a_context && 
+                          MLVIEW_IS_APP_CONTEXT (a_context) &&
+                          a_node->doc->extSubset);
+        g_return_if_fail (a_this && MLVIEW_IS_TREE_VIEW (a_this)
+                          && PRIVATE (a_this));
+        g_return_if_fail (a_separator && a_menu);
+
+        clear_completion_popup_submenu (a_list, a_separator);
+
+        w_list = *a_list;
+        
+        nb_of_names =
+                mlview_parsing_utils_build_element_name_completion_list
+                (a_context,
+                 a_insertion_scheme,
+                 a_node, &children_name_list);
+        
+        if (nb_of_names > 0) {
+                gchar *cur_name =
+                        (gchar *) children_name_list->data;
+                GList *cur = children_name_list;
+                struct CompletionMenuItem *completion_item = NULL;
+
+                gtk_widget_show (a_separator);
+                
+                while (cur_name) {
+                        menuitem = gtk_menu_item_new_with_label
+                                (cur_name);
+
+                        completion_item = g_try_malloc (sizeof (struct CompletionMenuItem));
+
+                        g_return_if_fail (completion_item);
+                        
+                        completion_item->item = menuitem;
+                        completion_item->text = cur_name;
+                        completion_item->view = a_this;
+
+                        g_signal_connect (menuitem, "activate",
+                                          a_cb, completion_item);
+                        
+                        w_list = g_list_append (w_list,
+                                                completion_item);
+                        
+                        gtk_menu_shell_append
+                                (GTK_MENU_SHELL (a_menu),
+                                 menuitem);
+                        
+                        gtk_widget_show (menuitem);
+                        
+                        cur = (cur->next) ? cur->next : NULL;
+                        cur_name =
+                                (cur) ? (gchar *) cur->
+                                data : NULL;
+                }
+        }
+
+        *a_list = w_list;
+}
+
 static enum MlViewStatus
 activate_or_deactivate_proper_menu_items (MlViewTreeView *a_this)
 {
         struct TreeEditorContextualMenuHandle *menu_handle = NULL ;
+        struct MlViewAppSettings *settings = NULL;
         xmlNode *cur_node = NULL ;
 
         g_return_val_if_fail (a_this 
@@ -1530,7 +1853,14 @@
                               && PRIVATE (a_this)
                               && PRIVATE (a_this)->tree_editor,
                               MLVIEW_BAD_PARAM_ERROR) ;
-        
+
+        g_return_val_if_fail (PRIVATE (a_this)->app_context, MLVIEW_ERROR);
+
+        settings = mlview_app_context_get_settings 
+                (PRIVATE (a_this)->app_context);
+
+        g_return_val_if_fail (settings, MLVIEW_ERROR);
+
         cur_node = mlview_tree_editor2_get_cur_sel_xml_node 
                 (PRIVATE (a_this)->tree_editor) ;
         if (!cur_node)
@@ -1538,6 +1868,41 @@
         menu_handle = PRIVATE (a_this)->contextual_menu_handle ;
         g_return_val_if_fail (menu_handle, MLVIEW_ERROR) ;
         g_return_val_if_fail (cur_node, MLVIEW_ERROR) ;
+
+        if (cur_node->type == XML_ELEMENT_NODE &&
+            settings->general.validation_is_on &&
+            cur_node->doc->extSubset) {
+                update_completion_popup_submenu (PRIVATE (a_this)->app_context,
+                                                 cur_node, a_this,
+                                                 ADD_CHILD, 
+                                                 menu_handle->add_child_node_sep,
+                                                 menu_handle->add_child_node_sub,
+                                                 &(menu_handle->add_child_node_items),
+                                                 G_CALLBACK (add_child_node_menu_item_activate_cb));
+                update_completion_popup_submenu (PRIVATE (a_this)->app_context,
+                                                 cur_node, a_this, 
+                                                 INSERT_AFTER,
+                                                 menu_handle->insert_next_node_sep,
+                                                 menu_handle->insert_next_node_sub,
+                                                 &(menu_handle->insert_next_node_items),
+                                                 G_CALLBACK (insert_next_node_menu_item_activate_cb));
+                update_completion_popup_submenu (PRIVATE (a_this)->app_context,
+                                                 cur_node, a_this, 
+                                                 INSERT_BEFORE,
+                                                 menu_handle->insert_prev_node_sep,
+                                                 menu_handle->insert_prev_node_sub,
+                                                 &(menu_handle->insert_prev_node_items),
+                                                 G_CALLBACK (insert_prev_node_menu_item_activate_cb));
+        }
+        else {
+                clear_completion_popup_submenu (&(menu_handle->add_child_node_items),
+                                                menu_handle->add_child_node_sep);
+                clear_completion_popup_submenu (&(menu_handle->insert_next_node_items),
+                                                menu_handle->insert_next_node_sep);
+                clear_completion_popup_submenu (&(menu_handle->insert_prev_node_items),
+                                                menu_handle->insert_prev_node_sep);
+        }
+        
         switch (cur_node->type) {
         case XML_DOCUMENT_NODE:
                 gtk_widget_set_sensitive (menu_handle->cut_node_mi,
@@ -1772,6 +2137,7 @@
         MlViewTreeEditor2 *elements = NULL;
         gint i, nb_pages;
         MlViewTreeEditor2 *tree_editor;
+        struct MlViewAppSettings *settings = NULL;
     
         enum MLVIEW_VIEW_ADAPTER_STATUS status = NOK;
         const gchar *feasible_children_titles[1] =
@@ -1797,6 +2163,10 @@
                  a_mlview_xml_doc);
         g_return_if_fail (status == MLVIEW_VIEW_ADAPTER_OK);
 
+        settings = mlview_app_context_get_settings (a_app_context);
+
+        g_return_if_fail (settings);
+
         /*The main vpaned of the view */
         PRIVATE (a_this)->main_paned =
                 GTK_PANED (gtk_vpaned_new ());
@@ -1841,96 +2211,98 @@
                                   gtk_label_new (_("Raw XML")));
 
         /*the table with the feasible children, siblings and attributes */
-        PRIVATE (a_this)->feasible_children =
-                GTK_CLIST (gtk_clist_new_with_titles
-                           (1, (gchar**)feasible_children_titles));
-
-        g_signal_connect (G_OBJECT
-                          (PRIVATE (a_this)->
-                           feasible_children), "select-row",
-                          G_CALLBACK
-                          (selected_a_possible_child_cb),
-                          a_this);
-
-        PRIVATE (a_this)->feasible_prev_siblings =
-                GTK_CLIST (gtk_clist_new_with_titles
-                           (1, (gchar**)feasible_prev_siblings_titles));
-
-        g_signal_connect (G_OBJECT
-                          (PRIVATE (a_this)->
-                           feasible_prev_siblings), "select-row",
-                          G_CALLBACK
-                          (selected_a_possible_prev_sibling_cb),
-                          a_this);
-
-        PRIVATE (a_this)->feasible_next_siblings =
-                GTK_CLIST (gtk_clist_new_with_titles
-                           (1, (gchar**) feasible_next_siblings_titles));
-
-        g_signal_connect (G_OBJECT
-                          (PRIVATE (a_this)->
-                           feasible_next_siblings), "select-row",
-                          G_CALLBACK
-                          (selected_a_possible_next_sibling_cb),
-                          a_this);
-
-        PRIVATE (a_this)->feasible_attributes =
-                GTK_CLIST
-                (gtk_clist_new_with_titles
-                 (1, (gchar**)feasible_attributes_titles));
-
-        g_signal_connect (G_OBJECT
-                          (PRIVATE (a_this)->
-                           feasible_attributes), "select-row",
-                          GTK_SIGNAL_FUNC
-                          (selected_a_possible_attribute_cb),
-                          a_this);
-
-        table = gtk_table_new (2, 2, TRUE);
-
-        scrolled = gtk_scrolled_window_new (NULL, NULL);
-
-        gtk_container_add
-                (GTK_CONTAINER (scrolled),
-                 GTK_WIDGET (PRIVATE (a_this)->
-                             feasible_children));
-
-        gtk_table_attach_defaults (GTK_TABLE (table), scrolled,
-                                   0, 1, 0, 1);
-
-        scrolled = gtk_scrolled_window_new (NULL, NULL);
-
-        gtk_container_add (GTK_CONTAINER (scrolled),
-                           GTK_WIDGET
-                           (PRIVATE (a_this)->
-                            feasible_prev_siblings));
-
-        gtk_table_attach_defaults (GTK_TABLE (table), scrolled,
-                                   1, 2, 0, 1);
-
-        scrolled = gtk_scrolled_window_new (NULL, NULL);
-
-        gtk_container_add (GTK_CONTAINER (scrolled),
-                           GTK_WIDGET
-                           (PRIVATE (a_this)->
-                            feasible_next_siblings));
-
-        gtk_table_attach_defaults (GTK_TABLE (table), scrolled,
-                                   1, 2, 1, 2);
-
-        scrolled = gtk_scrolled_window_new (NULL, NULL);
-
-        gtk_container_add (GTK_CONTAINER (scrolled),
-                           GTK_WIDGET
-                           (PRIVATE (a_this)->
-                            feasible_attributes));
-
-        gtk_table_attach_defaults (GTK_TABLE (table), scrolled,
-                                   0, 1, 1, 2);
-
-        gtk_paned_pack2 (GTK_PANED
-                         (PRIVATE (a_this)->upper_paned1),
-                         table, FALSE, TRUE);
+        if (settings->general.enable_completion_box) {
+                PRIVATE (a_this)->feasible_children =
+                        GTK_CLIST (gtk_clist_new_with_titles
+                                   (1, (gchar**)feasible_children_titles));
+                
+                g_signal_connect (G_OBJECT
+                                  (PRIVATE (a_this)->
+                                   feasible_children), "select-row",
+                                  G_CALLBACK
+                                  (selected_a_possible_child_cb),
+                                  a_this);
+                
+                PRIVATE (a_this)->feasible_prev_siblings =
+                        GTK_CLIST (gtk_clist_new_with_titles
+                                   (1, (gchar**)feasible_prev_siblings_titles));
+                
+                g_signal_connect (G_OBJECT
+                                  (PRIVATE (a_this)->
+                                   feasible_prev_siblings), "select-row",
+                                  G_CALLBACK
+                                  (selected_a_possible_prev_sibling_cb),
+                                  a_this);
+                
+                PRIVATE (a_this)->feasible_next_siblings =
+                        GTK_CLIST (gtk_clist_new_with_titles
+                                   (1, (gchar**) feasible_next_siblings_titles));
+                
+                g_signal_connect (G_OBJECT
+                                  (PRIVATE (a_this)->
+                                   feasible_next_siblings), "select-row",
+                                  G_CALLBACK
+                                  (selected_a_possible_next_sibling_cb),
+                                  a_this);
+                
+                PRIVATE (a_this)->feasible_attributes =
+                        GTK_CLIST
+                        (gtk_clist_new_with_titles
+                         (1, (gchar**)feasible_attributes_titles));
+                
+                g_signal_connect (G_OBJECT
+                                  (PRIVATE (a_this)->
+                                   feasible_attributes), "select-row",
+                                  GTK_SIGNAL_FUNC
+                                  (selected_a_possible_attribute_cb),
+                                  a_this);
+                
+                table = gtk_table_new (2, 2, TRUE);
+                
+                scrolled = gtk_scrolled_window_new (NULL, NULL);
+                
+                gtk_container_add
+                        (GTK_CONTAINER (scrolled),
+                         GTK_WIDGET (PRIVATE (a_this)->
+                                     feasible_children));
+                
+                gtk_table_attach_defaults (GTK_TABLE (table), scrolled,
+                                           0, 1, 0, 1);
+                
+                scrolled = gtk_scrolled_window_new (NULL, NULL);
+                
+                gtk_container_add (GTK_CONTAINER (scrolled),
+                                   GTK_WIDGET
+                                   (PRIVATE (a_this)->
+                                    feasible_prev_siblings));
+                
+                gtk_table_attach_defaults (GTK_TABLE (table), scrolled,
+                                           1, 2, 0, 1);
+                
+                scrolled = gtk_scrolled_window_new (NULL, NULL);
+                
+                gtk_container_add (GTK_CONTAINER (scrolled),
+                                   GTK_WIDGET
+                                   (PRIVATE (a_this)->
+                                    feasible_next_siblings));
+                
+                gtk_table_attach_defaults (GTK_TABLE (table), scrolled,
+                                           1, 2, 1, 2);
+                
+                scrolled = gtk_scrolled_window_new (NULL, NULL);
+                
+                gtk_container_add (GTK_CONTAINER (scrolled),
+                                   GTK_WIDGET
+                                   (PRIVATE (a_this)->
+                                    feasible_attributes));
+                
+                gtk_table_attach_defaults (GTK_TABLE (table), scrolled,
+                                           0, 1, 1, 2);
+                
+                gtk_paned_pack2 (GTK_PANED
+                                 (PRIVATE (a_this)->upper_paned1),
+                                 table, FALSE, TRUE);
+        }
 
         /*The node editor */
         PRIVATE (a_this)->node_editor =
@@ -1966,33 +2338,34 @@
                         (gtk_notebook_get_nth_page (PRIVATE (a_this)->trees, i));
                 mlview_tree_editor2_edit_xml_doc
                         (tree_editor, a_mlview_xml_doc, NULL);
-
-                g_signal_connect (G_OBJECT
-                                  (tree_editor),
-                                  "node-selected",
-                                  G_CALLBACK
-                                  (update_feasible_children_list_cb),
-                                  a_this);
-
-                g_signal_connect (G_OBJECT
-                                  (tree_editor),
-                                  "node-selected",
-                                  G_CALLBACK
-                                  (update_feasible_prev_siblings_list_cb),
-                                  a_this);
-                g_signal_connect (G_OBJECT
-                                  (tree_editor),
-                                  "node-selected",
-                                  G_CALLBACK
-                                  (update_feasible_next_siblings_list_cb),
-                                  a_this);
-                g_signal_connect (GTK_OBJECT
-                                  (tree_editor),
-                                  "node-selected",
-                                  G_CALLBACK
-                                  (update_feasible_attributes_list_cb),
-                                  a_this);
                 
+                if (settings->general.enable_completion_box) {
+                        g_signal_connect (G_OBJECT
+                                          (tree_editor),
+                                          "node-selected",
+                                          G_CALLBACK
+                                          (update_feasible_children_list_cb),
+                                          a_this);
+                        
+                        g_signal_connect (G_OBJECT
+                                          (tree_editor),
+                                          "node-selected",
+                                          G_CALLBACK
+                                          (update_feasible_prev_siblings_list_cb),
+                                          a_this);
+                        g_signal_connect (G_OBJECT
+                                          (tree_editor),
+                                          "node-selected",
+                                          G_CALLBACK
+                                          (update_feasible_next_siblings_list_cb),
+                                          a_this);
+                        g_signal_connect (GTK_OBJECT
+                                          (tree_editor),
+                                          "node-selected",
+                                          G_CALLBACK
+                                          (update_feasible_attributes_list_cb),
+                                          a_this);
+                }
         }
         g_signal_connect (G_OBJECT (a_mlview_xml_doc),
                           "file-path-changed",
Index: src/mlview-view-adapter.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-view-adapter.c,v
retrieving revision 1.8.4.1
diff -a -u -r1.8.4.1 mlview-view-adapter.c
--- src/mlview-view-adapter.c	21 Feb 2004 15:37:07 -0000	1.8.4.1
+++ src/mlview-view-adapter.c	6 Apr 2004 16:39:33 -0000
@@ -64,7 +64,7 @@
 static void mlview_view_adapter_init (MlViewViewAdapter * a_mlview_xml_doc);
 
 static enum MLVIEW_VIEW_ADAPTER_STATUS mlview_view_adapter_connect_to_document (MlViewViewAdapter * a_tree_view,
-                                                                                          MlViewXMLDocument * a_xml_doc);
+                                                                                MlViewXMLDocument * a_xml_doc);
 
 static enum MLVIEW_VIEW_ADAPTER_STATUS mlview_view_adapter_disconnect_from_document (MlViewViewAdapter * a_this,
                                                                                                MlViewXMLDocument * a_xml_doc);
@@ -414,7 +414,7 @@
  * param a_xml_doc the document which signals are to be connected to.
  * return the status.
  */
-static enum MlViewStatus 
+static  enum MLVIEW_VIEW_ADAPTER_STATUS
 mlview_view_adapter_connect_to_document (MlViewViewAdapter * a_this,
                                          MlViewXMLDocument * a_xml_doc) 
 {


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