1
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8-*- */
3
/*This file is part of MlView
5
*MlView is free software; you can redistribute
6
*it and/or modify it under the terms of
7
*the GNU General Public License as
8
*published by the Free Software Foundation; either version 2,
9
*or (at your option) any later version.
11
*MlView is distributed in the hope that
12
*it will be useful, but WITHOUT ANY WARRANTY;
13
*without even the implied warranty of
14
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*See the GNU General Public License for more details.
17
*You should have received a copy of the
18
*GNU General Public License along with MlView;
19
*see the file COPYING. If not, write to the
20
*Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
*Boston, MA 02111-1307, USA.
23
*See COPYRIGHT file for copyright information.
26
#include <libxml/parser.h>
27
#include <libxml/valid.h>
28
#include <libxml/tree.h>
30
#include "mlview-attribute-picker.h"
31
#include "mlview-parsing-utils.h"
32
#include "mlview-utils.h"
36
*The definition of the class #MlViewAttributePicker.
37
*This class is a business widget. It lets the user enter the name/value of
38
*an attribute. It can for example perform an attribute name completion given
39
*the xmlNode on which the attribute is to be defined.
44
*The private instance members of #MlViewAttributePicker.
45
*Theses member should not be accessed directly. They
46
*must only be accessed through the available accessors.
48
struct _MlViewAttributePickerPrivate {
49
/**the entry used to edit attribute name*/
50
GtkCombo *name_edit_entry;
52
/**the entry used to edit attribute type*/
53
GtkCombo *type_edit_entry;
55
/**the entry used to edit the attribute value*/
56
GtkEntry *value_edit_entry;
58
/**The attribute values list*/
61
/**used to set attr value to the selected attr val*/
62
GtkButton *set_value_button;
64
/**adding a string to the attr value*/
65
GtkButton *add_to_value_button;
67
GtkTable *value_list_table;
69
/**the list of possible attr names*/
70
GList *names_completion_list;
72
/**the list of possible attribute values*/
73
GList *values_completion_list;
75
/**the current xml node*/
76
xmlNode *cur_xml_node;
78
/**the current selected attribute value*/
79
gchar *current_attribute_value;
81
/**The app context passed to this object at creation time*/
82
MlViewAppContext *app_context;
85
#define PRIVATE(object) (object)->private
87
/*a pointer to the parent class. Necessary for the gtk typing system framework*/
88
static GtkDialogClass *parent_class = NULL;
90
static gboolean gv_attributes_completion = TRUE;
92
static void mlview_attribute_picker_destroy (GtkObject *
95
mlview_attribute_picker_init_class (MlViewAttributePickerClass *
97
static void mlview_attribute_picker_init (MlViewAttributePicker *
101
mlview_attribute_picker_show_attr_values (MlViewAttributePicker *
104
mlview_attribute_picker_hide_attr_values (MlViewAttributePicker *
106
static xmlAttributeType
107
mlview_attribute_picker_parse_attr_type (const gchar * a_string);
109
static void attribute_name_changed_cb (GtkEditable *
112
static void add_to_value_button_cb (GtkButton * a_button,
114
static void set_value_button_cb (GtkButton * a_button,
116
static void attribute_value_selected_cb (GtkList *
117
a_attribute_values_list,
118
GtkWidget * a_list_item,
120
static void attribute_type_changed_cb (GtkEditable *
124
/*----------------------------------------------------
126
*----------------------------------------------------*/
129
*The class structure initialyzer.
130
*@param a_klass the current vtable.
133
mlview_attribute_picker_init_class (MlViewAttributePickerClass *
136
GtkObjectClass *object_class;
138
g_return_if_fail (a_klass != NULL);
140
parent_class = g_type_class_peek_parent (a_klass);
141
g_return_if_fail (GTK_IS_DIALOG_CLASS (a_klass));
142
object_class = GTK_OBJECT_CLASS (a_klass);
143
object_class->destroy = mlview_attribute_picker_destroy;
148
*The allocator of the instances of #MlViewAttributePicker.
149
*Allocates memory for the members (and initialyzes them)
150
*of MlViewAttributePicker.
152
*@param a_this the current instance of #MlViewAttributePicker.
155
mlview_attribute_picker_init (MlViewAttributePicker * a_this)
157
GtkWidget *label = NULL,
162
g_return_if_fail (a_this != NULL);
163
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
165
gtk_dialog_add_buttons (GTK_DIALOG (a_this),
169
GTK_RESPONSE_REJECT, NULL);
171
gtk_window_set_modal (GTK_WINDOW (a_this), TRUE);
173
PRIVATE (a_this) = g_try_malloc
174
(sizeof (MlViewAttributePickerPrivate));
175
if (!PRIVATE (a_this)) {
176
g_warning ("System may be out of memory");
180
memset (PRIVATE (a_this), 0,
181
sizeof (MlViewAttributePickerPrivate));
183
label = gtk_label_new (_("attribute name"));
184
PRIVATE (a_this)->name_edit_entry =
185
GTK_COMBO (gtk_combo_new ());
187
g_signal_connect (G_OBJECT
188
(PRIVATE (a_this)->name_edit_entry->
190
G_CALLBACK (attribute_name_changed_cb),
193
table = gtk_table_new (1, 2, TRUE);
194
gtk_table_attach_defaults (GTK_TABLE (table), label,
196
gtk_table_attach_defaults (GTK_TABLE (table),
201
gtk_box_pack_start (GTK_BOX
202
(GTK_DIALOG (a_this)->vbox), table,
204
gtk_widget_show_all (table);
206
label = gtk_label_new (_("attribute type"));
207
PRIVATE (a_this)->type_edit_entry =
208
GTK_COMBO (gtk_combo_new ());
210
g_signal_connect (G_OBJECT
211
(PRIVATE (a_this)->type_edit_entry->
213
G_CALLBACK (attribute_type_changed_cb),
216
table = gtk_table_new (1, 2, TRUE);
217
gtk_table_attach_defaults (GTK_TABLE (table), label,
219
gtk_table_attach_defaults (GTK_TABLE (table),
224
gtk_box_pack_start (GTK_BOX
225
(GTK_DIALOG (a_this)->vbox), table,
227
gtk_widget_show_all (table);
229
separator = gtk_hseparator_new ();
230
gtk_box_pack_start (GTK_BOX
231
(GTK_DIALOG (a_this)->vbox),
232
separator, FALSE, TRUE, 0);
233
gtk_widget_show (separator);
235
label = gtk_label_new (_("attribute value:"));
236
PRIVATE (a_this)->value_edit_entry =
237
GTK_ENTRY (gtk_entry_new ());
238
table = gtk_table_new (1, 2, FALSE);
239
gtk_table_attach_defaults (GTK_TABLE (table), label,
241
gtk_table_attach_defaults (GTK_TABLE (table),
246
gtk_box_pack_start (GTK_BOX
247
(GTK_DIALOG (a_this)->vbox), table,
249
gtk_widget_show_all (table);
252
PRIVATE (a_this)->values_list =
253
GTK_LIST (gtk_list_new ());
254
g_signal_connect (G_OBJECT
255
(PRIVATE (a_this)->values_list),
258
(attribute_value_selected_cb),
260
PRIVATE (a_this)->set_value_button =
261
GTK_BUTTON (gtk_button_new_with_label
263
PRIVATE (a_this)->add_to_value_button =
264
GTK_BUTTON (gtk_button_new_with_label
265
(_("add to value")));
266
g_signal_connect (G_OBJECT
267
(PRIVATE (a_this)->set_value_button),
269
G_CALLBACK (set_value_button_cb),
271
g_signal_connect (G_OBJECT
273
add_to_value_button), "clicked",
274
G_CALLBACK (add_to_value_button_cb),
277
vbox = gtk_vbox_new (FALSE, 0);
278
gtk_box_pack_start (GTK_BOX (vbox),
279
GTK_WIDGET (PRIVATE (a_this)->
280
set_value_button), FALSE,
282
gtk_box_pack_start (GTK_BOX (vbox),
283
GTK_WIDGET (PRIVATE (a_this)->
284
add_to_value_button),
286
PRIVATE (a_this)->value_list_table =
287
GTK_TABLE (gtk_table_new (1, 2, FALSE));
289
gtk_table_attach_defaults (PRIVATE (a_this)->
295
gtk_table_attach_defaults (PRIVATE (a_this)->
296
value_list_table, vbox, 1, 2,
299
gtk_widget_ref (GTK_WIDGET
300
(PRIVATE (a_this)->value_list_table));
306
*@param a_object the instance of #MlViewAttributePicker to
310
mlview_attribute_picker_destroy (GtkObject * a_object)
312
MlViewAttributePicker *picker;
314
g_return_if_fail (a_object != NULL);
315
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_object));
317
picker = MLVIEW_ATTRIBUTE_PICKER (a_object);
319
if (PRIVATE (picker) == NULL)
322
gtk_widget_unref (GTK_WIDGET
323
(PRIVATE (picker)->value_list_table));
325
if (PRIVATE (picker)->names_completion_list) {
326
g_list_free (PRIVATE (picker)->
327
names_completion_list);
328
PRIVATE (picker)->names_completion_list = NULL;
331
if (PRIVATE (picker)->values_completion_list) {
332
g_list_free (PRIVATE (picker)->
333
values_completion_list);
334
PRIVATE (picker)->values_completion_list = NULL;
337
if (PRIVATE (picker)) {
338
g_free (PRIVATE (picker));
339
PRIVATE (picker) = NULL;
342
if (GTK_OBJECT_CLASS (parent_class)->destroy) {
343
GTK_OBJECT_CLASS (parent_class)->
351
*Converts the xmlAttributeType into a string that can be displayed
353
*@param a_attribute_type the xmlAttributeType to convert into a string.
354
*@return the converted string or NULL if the conversion could not be made.
357
mlview_attribute_picker_attr_type_to_str (xmlAttributeType
360
gchar *result = NULL;
362
switch (a_attribute_type) {
363
case XML_ATTRIBUTE_CDATA:
364
result = g_strdup ("CDATA");
366
case XML_ATTRIBUTE_ID:
367
result = g_strdup ("ID");
369
case XML_ATTRIBUTE_IDREF:
370
result = g_strdup ("IDREF");
372
case XML_ATTRIBUTE_IDREFS:
373
result = g_strdup ("IDREFS");
375
case XML_ATTRIBUTE_ENTITY:
376
result = g_strdup ("ENTITY");
378
case XML_ATTRIBUTE_ENTITIES:
379
result = g_strdup ("ENTITIES");
381
case XML_ATTRIBUTE_NMTOKEN:
382
result = g_strdup ("NMTOKEN");
384
case XML_ATTRIBUTE_NMTOKENS:
385
result = g_strdup ("NMTOKENS");
387
case XML_ATTRIBUTE_ENUMERATION:
388
result = g_strdup ("ENUMERATION");
390
case XML_ATTRIBUTE_NOTATION:
391
result = g_strdup ("NOTATION");
400
*Parses the string a_string and return the matching xmlAttributeType.
401
*@param a_string the string to parse.
402
*@return the matching xmlAttributeType. Note that if
403
*the string could not be parsed, this function returns the xmlAttributeType
404
*XML_ATTRIBUTE_CDATA.
406
static xmlAttributeType
407
mlview_attribute_picker_parse_attr_type (const gchar * a_string)
410
|| mlview_utils_is_white_string (a_string))
411
return XML_ATTRIBUTE_CDATA;
413
if (!strcmp (a_string, "CDATA"))
414
return XML_ATTRIBUTE_CDATA;
415
if (!strcmp (a_string, "ID"))
416
return XML_ATTRIBUTE_ID;
417
if (!strcmp (a_string, "IDREF"))
418
return XML_ATTRIBUTE_IDREF;
419
if (!strcmp (a_string, "IDREFS"))
420
return XML_ATTRIBUTE_IDREFS;
421
if (!strcmp (a_string, "ENTITY"))
422
return XML_ATTRIBUTE_ENTITY;
423
if (!strcmp (a_string, "ENTITIES"))
424
return XML_ATTRIBUTE_ENTITIES;
425
if (!strcmp (a_string, "NMTOKEN"))
426
return XML_ATTRIBUTE_NMTOKEN;
427
if (!strcmp (a_string, "NMTOKENS"))
428
return XML_ATTRIBUTE_NMTOKENS;
429
if (!strcmp (a_string, "ENUMERATION"))
430
return XML_ATTRIBUTE_ENUMERATION;
431
if (!strcmp (a_string, "NOTATION"))
432
return XML_ATTRIBUTE_NOTATION;
434
return XML_ATTRIBUTE_CDATA;
439
*Shows the attribute values list that has been build and cached into
441
*@param a_this the current instance of #MlViewAttributePicker.
444
mlview_attribute_picker_show_attr_values (MlViewAttributePicker *a_this)
446
g_return_if_fail (a_this != NULL);
447
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
448
g_return_if_fail (PRIVATE (a_this) != NULL);
450
/*make sure the attribute list table is not there already... */
451
if (GTK_WIDGET (PRIVATE (a_this)->value_list_table)->
452
parent == GTK_WIDGET (GTK_DIALOG (a_this)->vbox))
453
gtk_container_remove (GTK_CONTAINER
454
(GTK_DIALOG (a_this)->
460
/*now, pack the attr list table */
461
gtk_box_pack_start (GTK_BOX
462
(GTK_DIALOG (a_this)->vbox),
463
GTK_WIDGET (PRIVATE (a_this)->
464
value_list_table), FALSE,
467
gtk_widget_show_all (GTK_WIDGET
470
gtk_widget_show_all (GTK_WIDGET
471
(GTK_DIALOG (a_this)->vbox));
476
*Hides the attribute values list that has been build and shown.
477
*@param a_this the current instance of #MlViewAttributePicker.
480
mlview_attribute_picker_hide_attr_values (MlViewAttributePicker *
483
g_return_if_fail (a_this != NULL);
484
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
485
g_return_if_fail (PRIVATE (a_this) != NULL);
487
/*Make sure the value_list_table is packed in the dialog vbox */
488
if (GTK_WIDGET (PRIVATE (a_this)->value_list_table)->
489
parent == GTK_WIDGET (GTK_DIALOG (a_this)->vbox)) {
490
gtk_container_remove (GTK_CONTAINER
491
(GTK_DIALOG (a_this)->
496
gtk_widget_show_all (GTK_WIDGET
497
(GTK_DIALOG (a_this)->
503
/*----------------------------------------------------
504
*Private function callbacks.
505
*----------------------------------------------------*/
509
*Callback function invoked when the attribute name
510
*changes. It actually sets the type of the attribute,
511
*computes the attribute value and displays that choice list if necessary.
515
attribute_name_changed_cb (GtkEditable * a_text_entry,
518
gchar *content = NULL;
519
MlViewAttributePicker *picker = NULL;
521
g_return_if_fail (a_text_entry != NULL);
522
g_return_if_fail (GTK_IS_EDITABLE (a_text_entry));
523
g_return_if_fail (a_this != NULL);
524
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
526
picker = MLVIEW_ATTRIBUTE_PICKER (a_this);
528
if (gv_attributes_completion == FALSE) {
532
gtk_entry_set_text (PRIVATE (picker)->value_edit_entry,
535
content = gtk_editable_get_chars (a_text_entry, 0, -1);
538
mlview_attribute_picker_hide_attr_values
543
if (PRIVATE (picker)->cur_xml_node
544
&& PRIVATE (picker)->cur_xml_node->name) {
545
xmlAttribute *attr_desc = NULL;
547
/*test if the current attr is a defined attribute */
548
if (PRIVATE (picker)->cur_xml_node->doc->
551
xmlGetDtdAttrDesc (PRIVATE
562
if (attr_desc == NULL
563
&& PRIVATE (picker)->cur_xml_node->doc->
566
xmlGetDtdAttrDesc (PRIVATE
577
if (attr_desc == NULL) { /*attribute is unknown by the dtd */
578
gchar *attr_type = NULL;
580
mlview_attribute_picker_hide_attr_values
583
mlview_attribute_picker_attr_type_to_str
584
(XML_ATTRIBUTE_CDATA);
586
gtk_entry_set_text (GTK_ENTRY
595
} else { /*set the the attribute type and the attribute list */
596
GList *attr_vals = NULL;
597
gchar *attr_type = NULL;
599
mlview_app_context_get_last_id_ptr
600
(PRIVATE (picker)->app_context);
602
g_return_if_fail (last_id_ptr != NULL);
605
mlview_attribute_picker_attr_type_to_str
611
type_edit_entry->entry),
620
mlview_parsing_utils_build_graphical_attr_values
621
(PRIVATE (picker)->app_context,
622
attr_desc, last_id_ptr);
624
if (attr_vals != NULL) {
630
gtk_list_append_items
632
values_list, attr_vals);
634
mlview_attribute_picker_show_attr_values
638
mlview_attribute_picker_hide_attr_values
648
*Callback invoked when the attribute type changes. It just enable/disable the
649
*add to value button when necessary. Actually, if the type of the attribute
650
*is either "IDREFS" or "ENTITIES", this function enable the "add to value" button.
654
attribute_type_changed_cb (GtkEditable * a_text_entry,
657
gchar *content = NULL;
658
MlViewAttributePicker *picker = a_this;
660
g_return_if_fail (a_text_entry != NULL);
661
g_return_if_fail (GTK_IS_EDITABLE (a_text_entry));
662
g_return_if_fail (a_this != NULL);
663
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
666
gtk_editable_get_chars (GTK_EDITABLE
667
(a_text_entry), 0, -1);
669
if (!strcmp (content, "IDRREFS")
670
|| !strcmp (content, "ENTITIES")) {
671
gtk_widget_set_sensitive (GTK_WIDGET
673
add_to_value_button),
676
gtk_widget_set_sensitive
678
(PRIVATE (picker)->add_to_value_button),
685
*The callback executed when the user clicks on the "add to value" button.
689
add_to_value_button_cb (GtkButton * a_button, gpointer a_this)
691
MlViewAttributePicker *picker =
692
(MlViewAttributePicker *) a_this;
694
g_return_if_fail (a_button != NULL);
695
g_return_if_fail (GTK_IS_BUTTON (a_button));
696
g_return_if_fail (a_this != NULL);
697
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (picker));
698
g_return_if_fail (PRIVATE (picker) != NULL);
700
if (PRIVATE (picker)->current_attribute_value) {
703
str = gtk_editable_get_chars
705
(PRIVATE (picker)->value_edit_entry), 0,
707
str = g_strconcat (str, " ",
709
current_attribute_value,
711
gtk_entry_set_text (PRIVATE (picker)->
712
value_edit_entry, str);
722
*Callback called when the user clicks on the "set value" button to set
723
*the attribute value to the currently selected value.
727
set_value_button_cb (GtkButton * a_button, gpointer a_this)
729
MlViewAttributePicker *picker =
730
(MlViewAttributePicker *) a_this;
732
g_return_if_fail (a_button != NULL);
733
g_return_if_fail (GTK_IS_BUTTON (a_button));
734
g_return_if_fail (picker != NULL);
735
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (picker));
736
g_return_if_fail (PRIVATE (picker) != NULL);
738
if (PRIVATE (picker)->current_attribute_value) {
739
gtk_entry_set_text (PRIVATE (picker)->
742
current_attribute_value);
751
attribute_value_selected_cb (GtkList * a_attribute_values_list,
752
GtkWidget * a_list_item,
755
MlViewAttributePicker *picker =
756
(MlViewAttributePicker *) a_this;
759
g_return_if_fail (a_attribute_values_list != NULL);
760
g_return_if_fail (a_list_item != NULL);
761
g_return_if_fail (picker != NULL);
762
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (picker));
763
g_return_if_fail (PRIVATE (picker) != NULL);
765
/*get the label contained in the GtkItem */
766
list = gtk_container_children (GTK_CONTAINER
769
if (list && list->data && GTK_IS_LABEL (list->data)) {
770
GtkLabel *label = NULL;
772
label = GTK_LABEL (list->data);
773
gtk_label_get (label,
775
current_attribute_value);
778
PRIVATE (picker)->current_attribute_value = NULL;
783
/*----------------------------------------------------
785
*----------------------------------------------------*/
790
*@return the id of the type MlViewAttribute.
793
mlview_attribute_picker_get_type (void)
795
static gint type = 0;
798
static const GTypeInfo type_info = {
799
sizeof (MlViewAttributePickerClass),
800
NULL, /* base_init */
801
NULL, /* base_finalize */
803
mlview_attribute_picker_init_class,
804
NULL, /* class_finalize */
805
NULL, /* class_data */
806
sizeof (MlViewAttributePicker),
809
mlview_attribute_picker_init
812
type = g_type_register_static (GTK_TYPE_DIALOG,
813
"MlViewAttributePicker",
820
*Builds a brand new attribute picker.
821
*@param a_title the title the window of the attribute picker.
822
*@param a_app_context the current application context.
823
*@return the widget of the attribute picker.
826
mlview_attribute_picker_new (gchar * a_title,
827
MlViewAppContext * a_app_context)
829
MlViewAttributePicker *result = NULL;
831
result = gtk_type_new (MLVIEW_TYPE_ATTRIBUTE_PICKER);
832
mlview_attribute_picker_set_app_context (result,
834
gtk_window_set_title (GTK_WINDOW (result), a_title);
836
return GTK_WIDGET (result);
841
*Sets a new app context.
842
*@param a_this the current instance of #MlViewAttributePicker.
843
*@param a_app_context the new application context.
846
mlview_attribute_picker_set_app_context (MlViewAttributePicker *a_this,
847
MlViewAppContext *a_app_context)
849
g_return_if_fail (a_this != NULL);
850
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
851
g_return_if_fail (PRIVATE (a_this));
853
PRIVATE (a_this)->app_context = a_app_context;
858
*Sets the focus to the name entry of
859
*#MlViewAttributePicker widget.
860
*@param a_this the current instance of #MlViewAttributePicker.
863
mlview_attribute_picker_grab_focus_to_name_entry (MlViewAttributePicker * a_this)
865
g_return_if_fail (a_this != NULL);
866
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
867
g_return_if_fail (PRIVATE (a_this) != NULL);
869
if (PRIVATE (a_this)->name_edit_entry)
870
gtk_widget_grab_focus (PRIVATE (a_this)->
871
name_edit_entry->entry);
876
*Sets the focus to the value entry of
877
*#MlViewAttributePicker widget.
878
*@param a_this the current instance
879
*of #MlViewAttributePicker.
882
mlview_attribute_picker_grab_focus_to_value_entry (MlViewAttributePicker * a_this)
884
g_return_if_fail (a_this != NULL);
885
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
886
g_return_if_fail (PRIVATE (a_this) != NULL);
888
if (PRIVATE (a_this)->value_edit_entry)
889
gtk_widget_grab_focus (GTK_WIDGET
896
*Gets the content of the name entry of attribute picker.
897
*@param a_this the current instance of #MlViewAttributePicker.
898
*@return a pointer to the name entry of attribute picker.
899
*DO NOT FREE THIS POINTER or you will hang the process.
902
mlview_attribute_picker_get_attribute_name (MlViewAttributePicker* a_this)
904
g_return_val_if_fail (a_this != NULL, NULL);
905
g_return_val_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER
907
g_return_val_if_fail (PRIVATE (a_this) != NULL, NULL);
909
if (PRIVATE (a_this)->name_edit_entry
910
&& PRIVATE (a_this)->name_edit_entry->entry)
911
return (guchar *) gtk_entry_get_text
914
(a_this)->name_edit_entry->entry));
920
*Gets the content of the value entry of the attribute picker.
921
*@param a_this the current instance of #MlViewAttributePicker.
922
*@return a pointer to the content of the value entry of the #MlViewAttributePicker widget.
925
mlview_attribute_picker_get_attribute_value (MlViewAttributePicker * a_this)
927
g_return_val_if_fail (a_this != NULL, NULL);
928
g_return_val_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER
930
g_return_val_if_fail (PRIVATE (a_this) != NULL, NULL);
932
if (PRIVATE (a_this)->value_edit_entry)
933
return (guchar *) gtk_entry_get_text
934
(PRIVATE (a_this)->value_edit_entry);
940
*Gets the type of the last attribute the user has entered in the picker.
941
*@param a_this the current instance of #MlViewAttributePicker.
942
*@return the type of the last attribute entered by the user in the picker a_this.
945
mlview_attribute_picker_get_attribute_type (MlViewAttributePicker* a_this)
947
gchar *type_str = NULL;
949
g_return_val_if_fail (a_this != NULL,
950
XML_ATTRIBUTE_CDATA);
951
g_return_val_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER
952
(a_this), XML_ATTRIBUTE_CDATA);
953
g_return_val_if_fail (PRIVATE (a_this) != NULL,
954
XML_ATTRIBUTE_CDATA);
956
if (PRIVATE (a_this)->type_edit_entry
957
&& PRIVATE (a_this)->type_edit_entry->entry)
958
type_str = (guchar *) gtk_entry_get_text
961
(a_this)->type_edit_entry->entry));
964
&& mlview_utils_is_white_string (type_str) ==
966
return mlview_attribute_picker_parse_attr_type
969
return XML_ATTRIBUTE_CDATA;
974
*Graphically selects all the content of the name entry of the #MlViewAttributePicker widget.
975
*@param a_this the current instance of #MlViewAttributePicker.
978
mlview_attribute_picker_select_attribute_name (MlViewAttributePicker * a_this)
980
g_return_if_fail (a_this != NULL);
981
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
982
g_return_if_fail (PRIVATE (a_this) != NULL);
984
if (PRIVATE (a_this)->name_edit_entry
985
&& PRIVATE (a_this)->name_edit_entry->entry)
986
gtk_entry_select_region (GTK_ENTRY
993
*Graphically selects all the content of
994
*the value entry of the #MlViewAttributePicker
996
*@param a_this the current instance of #MlViewAttributePicker.
999
mlview_attribute_picker_select_attribute_value (MlViewAttributePicker * a_this)
1001
g_return_if_fail (a_this != NULL);
1002
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
1003
g_return_if_fail (PRIVATE (a_this) != NULL);
1005
if (PRIVATE (a_this)->value_edit_entry)
1006
gtk_entry_select_region (PRIVATE (a_this)->
1007
value_edit_entry, 0,
1012
*Associates an xml node to this picker.
1013
*That xml node is used for example to build the attribute name
1014
*completion list if needed.
1016
*@param a_this the current instance of #MlViewAttributePicker.
1017
*@param a_xml_node the xmlNode to associate to the current node.
1020
mlview_attribute_picker_set_current_xml_node (MlViewAttributePicker * a_this,
1021
xmlNode * a_xml_node)
1023
g_return_if_fail (a_this != NULL);
1024
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
1025
g_return_if_fail (PRIVATE (a_this) != NULL);
1027
PRIVATE (a_this)->cur_xml_node = a_xml_node;
1032
*Sets the attribute completion on/off.
1033
*All the instances of #MlViewAttributePicker of the current process
1034
*will be affected by this method.
1036
*@param a_completion_on wether to set the completion on or not.
1039
mlview_attribute_picker_set_attribute_completion (gboolean a_completion_on)
1041
gv_attributes_completion = a_completion_on;
1046
*Builds the attribute name completion list.
1047
*The list is built, cached in the current instance of #MlViewAttributePicker, and displayed to the user
1048
*whenever she clicks in the attribute names completion list.
1049
*This function uses mlview_parsing_utils_build_attribute_name_completion_list() to
1050
*actually build the completion list.
1051
*@param a_this the current instance of #MlViewAttributePicker.
1052
*@param a_xml_node the xmlNode used to build the attribute name completion list.
1056
mlview_attribute_picker_build_attribute_name_choice_list (MlViewAttributePicker * a_this,
1057
xmlNode * a_xml_node)
1059
gint nb_of_attribute_names = 0;
1061
g_return_if_fail (a_this != NULL);
1062
g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_this));
1063
g_return_if_fail (PRIVATE (a_this) != NULL);
1065
gtk_list_clear_items (GTK_LIST
1066
(PRIVATE (a_this)->values_list),
1068
gtk_list_clear_items (GTK_LIST
1070
name_edit_entry->list), 0, -1);
1071
gtk_list_clear_items (GTK_LIST
1073
type_edit_entry->list), 0, -1);
1074
/*FIXME: clear the two GktEntry widgets too. This is a bug. */
1076
if (a_xml_node == NULL || a_xml_node->doc == NULL
1077
|| gv_attributes_completion == FALSE) {
1081
nb_of_attribute_names =
1082
mlview_parsing_utils_build_attribute_name_completion_list
1083
(PRIVATE (a_this)->app_context, a_xml_node,
1084
&PRIVATE (a_this)->names_completion_list,
1086
/*get all the attributes, even the optional */
1089
if (nb_of_attribute_names > 0) {
1090
if (PRIVATE (a_this)->names_completion_list)
1091
gtk_combo_set_popdown_strings
1095
names_completion_list);