Re: [mlview-list][patch] Completion widget - UI fixes
- From: Nicolas Centa <nicolas centa free fr>
- To: mlview-list gnome org
- Subject: Re: [mlview-list][patch] Completion widget - UI fixes
- Date: Sat, 17 Jan 2004 21:06:56 +0100
The same patch, now corrected : no completion on invalid nodes.
Nicolas Centa
? completion.diff
Index: src/mlview-completion-table.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-completion-table.c,v
retrieving revision 1.1
diff -a -u -r1.1 mlview-completion-table.c
--- src/mlview-completion-table.c 11 Jan 2004 20:48:21 -0000 1.1
+++ src/mlview-completion-table.c 17 Jan 2004 16:20:37 -0000
@@ -286,13 +286,15 @@
}
}
-
static void
mlview_completion_table_init (MlViewCompletionTable *a_this)
{
GtkWidget *scrolled = NULL;
GtkCellRenderer *renderer = NULL;
GtkTreeSelection *selection = NULL;
+
+ gtk_table_set_col_spacings (GTK_TABLE (a_this), 3);
+ gtk_table_set_row_spacings (GTK_TABLE (a_this), 3);
if (PRIVATE (a_this) == NULL) {
PRIVATE (a_this) = g_try_malloc (sizeof (MlViewCompletionTablePrivate));
@@ -363,18 +365,26 @@
gtk_table_resize (GTK_TABLE (a_this), 2, 2);
scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (scrolled), PRIVATE (a_this)->widgets.feasible_children);
gtk_table_attach_defaults (GTK_TABLE (a_this), scrolled, 0, 1, 0, 1);
scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (scrolled), PRIVATE (a_this)->widgets.feasible_prev_siblings);
gtk_table_attach_defaults (GTK_TABLE (a_this), scrolled, 1, 2, 0, 1);
scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (scrolled), PRIVATE (a_this)->widgets.feasible_next_siblings);
gtk_table_attach_defaults (GTK_TABLE (a_this), scrolled, 1, 2, 1, 2);
scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (scrolled), PRIVATE (a_this)->widgets.feasible_attributes);
gtk_table_attach_defaults (GTK_TABLE (a_this), scrolled, 0, 1, 1, 2);
}
@@ -427,7 +437,9 @@
app_context = mlview_xml_document_get_app_context (PRIVATE (a_widget)->xml_doc);
- if (a_node_found->type == XML_ELEMENT_NODE) {
+ if (a_node_found->type == XML_ELEMENT_NODE &&
+ mlview_xml_document_is_node_valid (PRIVATE (a_widget)->xml_doc,
+ a_node_found)) {
mlview_parsing_utils_build_element_name_completion_list
(app_context,
ADD_CHILD,
@@ -457,6 +469,8 @@
list = NULL;
PRIVATE (a_widget)->cur_node = a_node_found;
+
+ gtk_widget_set_sensitive (GTK_WIDGET (a_widget), TRUE);
}
else {
update_list_store (PRIVATE (a_widget)->models.feasible_children, NULL);
@@ -465,6 +479,8 @@
update_list_store (PRIVATE (a_widget)->models.feasible_attributes, NULL);
PRIVATE (a_widget)->cur_node = NULL;
+
+ gtk_widget_set_sensitive (GTK_WIDGET (a_widget), FALSE);
}
}
Index: src/mlview-tree-view.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-tree-view.c,v
retrieving revision 1.18
diff -a -u -r1.18 mlview-tree-view.c
--- src/mlview-tree-view.c 11 Jan 2004 20:48:21 -0000 1.18
+++ src/mlview-tree-view.c 17 Jan 2004 16:20:37 -0000
@@ -799,6 +799,45 @@
}
}
+static void
+document_dtd_associated_cb (MlViewXMLDocument *a_xml_doc,
+ MlViewExtSubsDef * a_ext_subs_def,
+ gpointer a_user_data)
+{
+ GtkWidget *table = NULL;
+
+ g_return_if_fail (a_xml_doc && MLVIEW_IS_XML_DOCUMENT (a_xml_doc));
+ g_return_if_fail (a_ext_subs_def);
+ g_return_if_fail (a_user_data && MLVIEW_IS_COMPLETION_TABLE (a_user_data));
+
+ table = GTK_WIDGET (a_user_data);
+
+ if (mlview_xml_document_is_completion_possible_global (a_xml_doc))
+ gtk_widget_show (table);
+}
+
+static gboolean
+completion_widget_mapped_cb (GtkWidget *a_widget,
+ gpointer a_user_data)
+{
+ MlViewTreeView *tree_view = NULL ;
+
+ g_return_val_if_fail (a_user_data
+ && MLVIEW_IS_TREE_VIEW (a_user_data),
+ FALSE) ;
+
+ tree_view = MLVIEW_TREE_VIEW (a_user_data) ;
+
+ g_return_val_if_fail (a_widget, FALSE) ;
+
+ if (!mlview_xml_document_is_completion_possible_global
+ (PRIVATE (tree_view)->xml_doc))
+ gtk_widget_hide (a_widget);
+
+ return FALSE ;
+}
+
+
/**
*Instance initialyzer of the #MlViewTreeView class.
*Should be called by the constructor.
@@ -879,7 +918,7 @@
/* The element name completion widget*/
compl = mlview_completion_table_new (a_mlview_xml_doc);
-
+
g_signal_connect (a_mlview_xml_doc, "node-selected",
(GCallback)update_completion_widget_cb, compl);
@@ -911,7 +950,7 @@
gtk_widget_show_all (GTK_WIDGET
(PRIVATE (a_this)->
main_paned));
-
+
PRIVATE (a_this)->app_context = a_app_context ;
/* Build trees */
@@ -922,11 +961,22 @@
mlview_tree_editor2_edit_xml_doc
(tree_editor, a_mlview_xml_doc, NULL);
}
+
g_signal_connect (G_OBJECT (a_mlview_xml_doc),
"file-path-changed",
G_CALLBACK
(doc_path_changed_cb),
a_this) ;
+ g_signal_connect (G_OBJECT
+ (compl),
+ "map",
+ G_CALLBACK (completion_widget_mapped_cb),
+ a_this) ;
+ g_signal_connect (G_OBJECT
+ (PRIVATE (a_this)->xml_doc),
+ "dtd-associated",
+ G_CALLBACK (document_dtd_associated_cb),
+ compl);
}
/**
Index: src/mlview-xml-document.c
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-xml-document.c,v
retrieving revision 1.72
diff -a -u -r1.72 mlview-xml-document.c
--- src/mlview-xml-document.c 11 Jan 2004 22:15:47 -0000 1.72
+++ src/mlview-xml-document.c 17 Jan 2004 16:20:37 -0000
@@ -101,6 +101,7 @@
ENTITY_NODE_CONTENT_CHANGED,
ENTITY_NODE_PUBLIC_ID_CHANGED,
ENTITY_NODE_SYSTEM_ID_CHANGED,
+ DTD_ASSOCIATED,
NUMBER_OF_SIGNALS
};
@@ -554,6 +555,17 @@
mlview_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER) ;
+ gv_signals [DTD_ASSOCIATED] =
+ g_signal_new ("dtd-associated",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET
+ (MlViewXMLDocumentClass,
+ dtd_associated),
+ NULL, NULL,
+ mlview_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
+
a_klass->document_changed = NULL;
a_klass->node_cut = NULL;
a_klass->child_node_added = NULL;
@@ -1141,6 +1153,11 @@
PRIVATE (a_doc)->xml_doc->standalone = 0;
+ g_signal_emit
+ (G_OBJECT (a_doc),
+ gv_signals [DTD_ASSOCIATED], 0,
+ a_ext_subs_def);
+
return 0; /*dtd parsing OK, association OK */
}
@@ -3023,4 +3040,76 @@
*a_found) ;
}
return MLVIEW_OK ;
+}
+
+/**
+ *Determines if completion can be possible on some valid elements
+ *of the documents (if validation is ON and if the document has an
+ *associated DTD, currently).
+ * param a_this the current instance of #MlViewXMLDocument.
+ * return TRUE if completion is possible for valid elements in this document, or FALSE.
+ */
+gboolean
+mlview_xml_document_is_completion_possible_global (MlViewXMLDocument *a_this)
+{
+ MlViewAppContext *app_context = NULL;
+ struct MlViewAppSettings *settings;
+
+ g_return_if_fail (a_this && MLVIEW_IS_XML_DOCUMENT (a_this));
+
+ app_context = mlview_xml_document_get_app_context (a_this);
+
+ g_return_if_fail (app_context && MLVIEW_IS_APP_CONTEXT (app_context));
+
+ settings = mlview_app_context_get_settings (app_context);
+
+ g_return_if_fail (settings);
+
+ if (settings->general.validation_is_on &&
+ mlview_xml_document_get_xml_document (a_this)->extSubset)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+/**
+ *Determines if a node is valid according to the DTD (if validation is ON,
+ *if the document has an associated DTD and if the node is valid).
+ * param a_this the current instance of #MlViewXMLDocument.
+ * param a_node the current node.
+ * return TRUE if the specified node is valid, or FALSE.
+ */
+gboolean
+mlview_xml_document_is_node_valid (MlViewXMLDocument *a_this,
+ xmlNode *a_node)
+{
+ MlViewAppContext *app_context = NULL;
+ struct MlViewAppSettings *settings;
+ xmlValidCtxt vctxt;
+ xmlDoc *xml_doc = NULL;
+
+ g_return_if_fail (a_this && MLVIEW_IS_XML_DOCUMENT (a_this));
+ g_return_if_fail (a_node);
+
+ app_context = mlview_xml_document_get_app_context (a_this);
+
+ g_return_if_fail (app_context && MLVIEW_IS_APP_CONTEXT (app_context));
+
+ settings = mlview_app_context_get_settings (app_context);
+
+ g_return_if_fail (settings);
+
+ memset (&vctxt, 0, sizeof (xmlValidCtxt));
+ xml_doc = mlview_xml_document_get_xml_document (a_this);
+
+ g_return_if_fail (xml_doc);
+
+ if (settings->general.validation_is_on &&
+ xml_doc->extSubset &&
+ xmlValidateOneElement (&vctxt,
+ xml_doc,
+ a_node))
+ return TRUE;
+ else
+ return FALSE;
}
Index: src/mlview-xml-document.h
===================================================================
RCS file: /cvs/gnome/mlview/src/mlview-xml-document.h,v
retrieving revision 1.44
diff -a -u -r1.44 mlview-xml-document.h
--- src/mlview-xml-document.h 21 Dec 2003 21:46:56 -0000 1.44
+++ src/mlview-xml-document.h 17 Jan 2004 16:20:38 -0000
@@ -190,6 +190,10 @@
void (*entity_node_system_id_changed) (MlViewXMLDocument *a_this,
xmlEntity *a_entity_node,
gpointer *a_user_data) ;
+
+ void (*dtd_associated) (MlViewXMLDocument *a_this,
+ MlViewExtSubsDef *a_ext_subs_def,
+ gpointer a_user_data);
};
guint mlview_xml_document_get_type (void);
@@ -407,5 +411,11 @@
xmlNode *a_from,
xmlNode **a_found,
gboolean a_emit_signal);
+
+gboolean mlview_xml_document_is_completion_possible_global (MlViewXMLDocument *a_this);
+
+gboolean mlview_xml_document_is_node_valid (MlViewXMLDocument *a_this,
+ xmlNode *a_node);
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]