Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

mlview-attribute-picker.c

Go to the documentation of this file.
00001 /*This file is part of MlView
00002  *
00003  *MlView is free software; you can redistribute it and/or modify it under the terms of 
00004  *the GNU General Public License as published by the Free Software Foundation; either version 2, 
00005  *or (at your option) any later version.
00006  *
00007  *MlView is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
00008  *without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00009  *See the GNU General Public License for more details.
00010  *
00011  *You should have received a copy of the GNU General Public License along with MlView; 
00012  *see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00013  *
00014  *
00015  *Copyright 2001-2002 Dodji Seketeli
00016  */
00017 
00018 #include <libxml/parser.h>
00019 #include <libxml/valid.h>
00020 #include <libxml/tree.h>
00021 
00022 #include "mlview-attribute-picker.h"
00023 #include "mlview-parsing-utils.h"
00024 #include "utils.h"
00025 
00040 struct _MlViewAttributePickerPrivate {
00042         GtkCombo * name_edit_entry ;
00043 
00045         GtkCombo * type_edit_entry ;
00046 
00048         GtkEntry *value_edit_entry ;
00049 
00051         GtkList * values_list ;
00052 
00054         GtkButton * set_value_button ;
00055 
00057         GtkButton * add_to_value_button ;
00058 
00059         GtkTable * value_list_table ;
00060 
00062         GList * names_completion_list ;
00063 
00065         GList * values_completion_list ;
00066 
00068         xmlNode *current_xml_node ;
00069 
00071         gchar * current_attribute_value ;
00072 
00074         MlViewAppContext * app_context ;
00075 } ;
00076 
00077 #define PRIVATE(object) (object)->private
00078 
00079 /*a pointer to the parent class. Necessary for the gtk typing system framework*/
00080 static GnomeDialogClass * parent_class = NULL ;
00081 
00082 static gboolean gv_attributes_completion = TRUE ;
00083 
00084 static void mlview_attribute_picker_destroy (GtkObject * a_object) ;
00085 static void mlview_attribute_picker_init_class (MlViewAttributePickerClass * a_klass) ;
00086 static void mlview_attribute_picker_init (MlViewAttributePicker * a_picker) ;
00087 
00088 static void mlview_attribute_picker_show_attribute_values_list (MlViewAttributePicker *a_picker) ;
00089 static void mlview_attribute_picker_hide_attribute_values_list (MlViewAttributePicker *a_picker) ;
00090 static xmlAttributeType mlview_attribute_picker_parse_attribute_type (const gchar * a_string) ;
00091 
00092 static void attribute_name_changed_cb (GtkEditable * a_text_entry,gpointer a_picker) ;
00093 static void add_to_value_button_cb (GtkButton * a_button,gpointer a_picker) ;
00094 static void set_value_button_cb (GtkButton *a_button,gpointer a_picker) ;
00095 static void attribute_value_selected_cb (GtkList * a_attribute_values_list,GtkWidget *a_list_item,gpointer * a_picker) ;
00096 static void attribute_type_changed_cb (GtkEditable * a_text_entry,gpointer a_picker) ;
00097 
00098 /*----------------------------------------------------
00099  *Private functions
00100  *----------------------------------------------------*/
00101 
00106 static void
00107 mlview_attribute_picker_init_class (MlViewAttributePickerClass * a_klass)
00108 {
00109         GtkObjectClass * object_class ;
00110         g_return_if_fail (a_klass != NULL) ;
00111 
00112         parent_class = gtk_type_class (GNOME_TYPE_DIALOG) ;
00113         object_class = GTK_OBJECT_CLASS (a_klass) ;
00114         
00115         object_class->destroy = mlview_attribute_picker_destroy ;
00116 }
00117 
00118 
00125 static void
00126 mlview_attribute_picker_init (MlViewAttributePicker * a_picker)
00127 {
00128         GtkWidget * label=NULL, *table=NULL, *vbox=NULL, *separator=NULL;
00129         const gchar * buttons[3] = {GNOME_STOCK_BUTTON_OK,
00130                                     GNOME_STOCK_BUTTON_CANCEL,
00131                                     NULL} ;
00132 
00133         g_return_if_fail (a_picker != NULL) ;
00134         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00135 
00136         gnome_dialog_constructv (GNOME_DIALOG (a_picker),"",
00137                                  (const gchar **)buttons) ;
00138 
00139         PRIVATE (a_picker) = g_malloc0 (sizeof (MlViewAttributePickerPrivate)) ;
00140         
00141         label = gtk_label_new (_("attribute name")) ;
00142         PRIVATE (a_picker)->name_edit_entry = GTK_COMBO (gtk_combo_new ()) ;
00143         gtk_signal_connect (GTK_OBJECT (PRIVATE (a_picker)->name_edit_entry->entry),
00144                             "changed",
00145                             GTK_SIGNAL_FUNC (attribute_name_changed_cb),
00146                             a_picker) ;
00147         table = gtk_table_new (1,2,TRUE) ;
00148         gtk_table_attach_defaults (GTK_TABLE(table),label,
00149                                           0,1,0,1) ;
00150         gtk_table_attach_defaults (GTK_TABLE (table), 
00151                                    GTK_WIDGET (PRIVATE (a_picker)->name_edit_entry),
00152                                    1,2,0,1) ;
00153         gtk_box_pack_start( GTK_BOX (GNOME_DIALOG (a_picker)->vbox),
00154                             table,FALSE,TRUE,0) ;
00155         gtk_widget_show_all (table) ;
00156         
00157         label = gtk_label_new (_("attribute type")) ;
00158         PRIVATE (a_picker)->type_edit_entry = GTK_COMBO (gtk_combo_new ()) ;
00159         gtk_signal_connect (GTK_OBJECT (PRIVATE (a_picker)->type_edit_entry->entry),
00160                             "changed",
00161                             GTK_SIGNAL_FUNC (attribute_type_changed_cb),
00162                             a_picker) ;
00163         table = gtk_table_new (1, 2, TRUE) ;
00164         gtk_table_attach_defaults (GTK_TABLE (table),label,
00165                                    0,1,0,1) ;
00166         gtk_table_attach_defaults (GTK_TABLE (table),
00167                                    GTK_WIDGET (PRIVATE (a_picker)->type_edit_entry),
00168                                    1,2,0,1) ;
00169         gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (a_picker)->vbox),
00170                             table, FALSE, TRUE, 0) ;
00171         gtk_widget_show_all (table) ;
00172 
00173         separator = gtk_hseparator_new () ; 
00174         gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (a_picker)->vbox),
00175                             separator, FALSE, TRUE, 0) ;
00176         gtk_widget_show (separator) ;
00177 
00178         label = gtk_label_new (_("attribute value :")) ;
00179         PRIVATE (a_picker)->value_edit_entry = GTK_ENTRY (gtk_entry_new ()) ;
00180         table = gtk_table_new (1,2, FALSE) ;    
00181         gtk_table_attach_defaults (GTK_TABLE (table), label,
00182                                    0,1,0,1) ;
00183         gtk_table_attach_defaults (GTK_TABLE (table), 
00184                                    GTK_WIDGET (PRIVATE (a_picker)->value_edit_entry),
00185                                    1,2,0,1) ;
00186         gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (a_picker)->vbox),
00187                             table, FALSE, TRUE, 0) ;
00188         gtk_widget_show_all (table) ;
00189 
00190 
00191         PRIVATE (a_picker)->values_list = GTK_LIST (gtk_list_new ()) ;
00192         gtk_signal_connect (GTK_OBJECT (PRIVATE (a_picker)->values_list),
00193                             "select-child",
00194                             GTK_SIGNAL_FUNC (attribute_value_selected_cb),
00195                             a_picker) ;
00196         PRIVATE (a_picker)->set_value_button = 
00197                 GTK_BUTTON (gtk_button_new_with_label (_("set value"))) ;       
00198         PRIVATE (a_picker)->add_to_value_button = 
00199                 GTK_BUTTON (gtk_button_new_with_label (_("add to value"))) ;
00200         gtk_signal_connect (GTK_OBJECT (PRIVATE (a_picker)->set_value_button),
00201                             "clicked",
00202                             GTK_SIGNAL_FUNC (set_value_button_cb),
00203                             a_picker) ;
00204         gtk_signal_connect (GTK_OBJECT (PRIVATE (a_picker)->add_to_value_button),
00205                             "clicked",
00206                             GTK_SIGNAL_FUNC (add_to_value_button_cb),
00207                             a_picker) ;
00208 
00209         vbox = gtk_vbox_new (FALSE, 0) ;
00210         gtk_box_pack_start (GTK_BOX (vbox),
00211                             GTK_WIDGET (PRIVATE (a_picker)->set_value_button),
00212                             FALSE,TRUE,0) ;
00213         gtk_box_pack_start (GTK_BOX (vbox),
00214                             GTK_WIDGET (PRIVATE (a_picker)->add_to_value_button),
00215                             FALSE,TRUE,0) ;
00216         PRIVATE (a_picker)->value_list_table = GTK_TABLE (gtk_table_new (1, 2, FALSE)) ;
00217 
00218         gtk_table_attach_defaults (PRIVATE (a_picker)->value_list_table, 
00219                                    GTK_WIDGET (PRIVATE (a_picker)->values_list),
00220                                    0,1,1,2) ;
00221         gtk_table_attach_defaults (PRIVATE (a_picker)->value_list_table, 
00222                                    vbox,
00223                                    1,2,1,2) ;
00224         gtk_widget_ref (GTK_WIDGET (PRIVATE (a_picker)->value_list_table)) ;
00225         
00226         gnome_dialog_close_hides (GNOME_DIALOG (a_picker), TRUE) ;
00227         gnome_dialog_set_default(GNOME_DIALOG (a_picker), 0) ;
00228 }
00229 
00230 
00236 static void
00237 mlview_attribute_picker_destroy (GtkObject * a_object)
00238 {
00239         MlViewAttributePicker * picker ;
00240 
00241         g_return_if_fail (a_object != NULL) ;
00242         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_object)) ;
00243 
00244         picker = MLVIEW_ATTRIBUTE_PICKER (a_object) ;
00245 
00246         if (PRIVATE (picker) == NULL)
00247                 return ;
00248 
00249         gtk_widget_unref (GTK_WIDGET (PRIVATE (picker)->value_list_table)) ;
00250 
00251         if (PRIVATE (picker)->names_completion_list) {
00252                 g_list_free (PRIVATE (picker)->names_completion_list) ;
00253                 PRIVATE (picker)->names_completion_list = NULL ;
00254         }
00255 
00256         if (PRIVATE (picker)->values_completion_list) {
00257                 g_list_free (PRIVATE (picker)->values_completion_list) ;
00258                 PRIVATE (picker)->values_completion_list = NULL ;
00259         }
00260 
00261         if (PRIVATE (picker)) {
00262                 g_free (PRIVATE (picker)) ;
00263                 PRIVATE (picker) = NULL ;
00264         }
00265 
00266         if ( GTK_OBJECT_CLASS (parent_class)->destroy  ) {
00267                 GTK_OBJECT_CLASS (parent_class)->destroy (a_object) ;
00268         }
00269 }
00270 
00271 
00278 static gchar *
00279 mlview_attribute_picker_attribute_type_to_string (xmlAttributeType a_attribute_type)
00280 {
00281         gchar * result=NULL ;
00282 
00283         switch (a_attribute_type) {
00284         case XML_ATTRIBUTE_CDATA:
00285                 result = g_strdup ("CDATA") ;
00286                 break;
00287         case XML_ATTRIBUTE_ID:
00288                 result = g_strdup ("ID") ;
00289                 break;
00290         case XML_ATTRIBUTE_IDREF:
00291                 result = g_strdup ("IDREF") ;
00292                 break ;
00293         case XML_ATTRIBUTE_IDREFS:
00294                 result = g_strdup ("IDREFS") ;
00295                 break ;
00296         case XML_ATTRIBUTE_ENTITY:
00297                 result = g_strdup ("ENTITY") ;
00298                 break ;
00299         case XML_ATTRIBUTE_ENTITIES:
00300                 result = g_strdup ("ENTITIES") ;
00301                 break ;
00302         case XML_ATTRIBUTE_NMTOKEN:
00303                 result = g_strdup ("NMTOKEN") ;
00304                 break ;
00305         case XML_ATTRIBUTE_NMTOKENS:
00306                 result = g_strdup ("NMTOKENS") ;
00307                 break ;
00308         case XML_ATTRIBUTE_ENUMERATION:
00309                 result = g_strdup ("ENUMERATION") ;
00310                 break ;
00311         case XML_ATTRIBUTE_NOTATION:
00312                 result = g_strdup ("NOTATION") ;
00313                 break ;
00314         default:
00315                 break ;
00316         }
00317         return result ;
00318 }
00319 
00327 static xmlAttributeType
00328 mlview_attribute_picker_parse_attribute_type (const gchar * a_string)
00329 {
00330         if (a_string == NULL || utils_is_white_string (a_string))
00331                 return XML_ATTRIBUTE_CDATA ;
00332 
00333         if (!strcmp (a_string, "CDATA"))
00334                 return XML_ATTRIBUTE_CDATA ;
00335         if (!strcmp (a_string, "ID"))
00336                 return XML_ATTRIBUTE_ID ;
00337         if (!strcmp (a_string, "IDREF"))
00338                 return XML_ATTRIBUTE_IDREF ;
00339         if (!strcmp (a_string, "IDREFS"))
00340                 return XML_ATTRIBUTE_IDREFS ;
00341         if (!strcmp (a_string, "ENTITY"))
00342                 return XML_ATTRIBUTE_ENTITY ;
00343         if (!strcmp (a_string, "ENTITIES"))
00344                 return XML_ATTRIBUTE_ENTITIES ;
00345         if (!strcmp (a_string, "NMTOKEN"))
00346                 return XML_ATTRIBUTE_NMTOKEN ;
00347         if (!strcmp (a_string, "NMTOKENS"))
00348                 return XML_ATTRIBUTE_NMTOKENS ;
00349         if (!strcmp (a_string, "ENUMERATION"))
00350                 return XML_ATTRIBUTE_ENUMERATION ;
00351         if (!strcmp (a_string, "NOTATION"))
00352                 return XML_ATTRIBUTE_NOTATION ;
00353 
00354         return XML_ATTRIBUTE_CDATA ;
00355 }
00356 
00357 
00363 static void 
00364 mlview_attribute_picker_show_attribute_values_list (MlViewAttributePicker *a_picker)
00365 {
00366         g_return_if_fail (a_picker != NULL) ;
00367         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00368         g_return_if_fail (PRIVATE (a_picker) != NULL) ;
00369 
00370         /*make sure the attribute list table is not there already...*/
00371         if (GTK_WIDGET (PRIVATE (a_picker)->value_list_table)->parent == GTK_WIDGET (GNOME_DIALOG (a_picker)->vbox))
00372                 gtk_container_remove (GTK_CONTAINER (GNOME_DIALOG (a_picker)->vbox),
00373                                       GTK_WIDGET (PRIVATE (a_picker)->value_list_table)) ;
00374         /*now, pack the attr list table*/
00375         gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (a_picker)->vbox),
00376                             GTK_WIDGET (PRIVATE (a_picker)->value_list_table),
00377                             FALSE, TRUE, 0) ;
00378         gtk_widget_show_all (GTK_WIDGET (PRIVATE (a_picker)->value_list_table)) ;
00379         gtk_widget_show_all (GTK_WIDGET (GNOME_DIALOG (a_picker)->vbox)) ;
00380 }
00381 
00382 
00387 static void 
00388 mlview_attribute_picker_hide_attribute_values_list (MlViewAttributePicker *a_picker)
00389 {
00390         g_return_if_fail (a_picker != NULL) ;
00391         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00392         g_return_if_fail (PRIVATE (a_picker) != NULL) ;
00393 
00394         /*Make sure the value_list_table is packed in the dialog vbox*/
00395         if ( GTK_WIDGET (PRIVATE (a_picker)->value_list_table)->parent 
00396              == GTK_WIDGET (GNOME_DIALOG (a_picker)->vbox)) {
00397                 gtk_container_remove (GTK_CONTAINER (GNOME_DIALOG (a_picker)->vbox),
00398                                       GTK_WIDGET (PRIVATE (a_picker)->value_list_table)) ;
00399                 gtk_widget_show_all (GTK_WIDGET (GNOME_DIALOG (a_picker)->vbox)) ;
00400         }
00401 }
00402 
00403 
00404 /*----------------------------------------------------
00405  *Private function callbacks.
00406  *----------------------------------------------------*/
00407 
00408 
00415 static void
00416 attribute_name_changed_cb (GtkEditable * a_text_entry,
00417                            gpointer a_picker)
00418 {
00419         gchar * content = NULL ;
00420         MlViewAttributePicker * picker= NULL ;
00421 
00422         g_return_if_fail (a_text_entry != NULL) ;
00423         g_return_if_fail (GTK_IS_EDITABLE (a_text_entry)) ;
00424         g_return_if_fail (a_picker != NULL) ;
00425         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00426 
00427         picker = MLVIEW_ATTRIBUTE_PICKER (a_picker) ;
00428 
00429         if (gv_attributes_completion == FALSE) {
00430                 return ;
00431         }
00432 
00433         gtk_entry_set_text (PRIVATE (picker)->value_edit_entry, "") ;
00434 
00435         content = gtk_editable_get_chars (a_text_entry, 0, -1) ;
00436 
00437         if ( !content ) {
00438                 mlview_attribute_picker_hide_attribute_values_list (picker) ;
00439                 return ;
00440         }
00441 
00442         if (PRIVATE (picker)->current_xml_node
00443             && PRIVATE (picker)->current_xml_node->name) {
00444                 xmlAttribute * attr_desc = NULL ;
00445 
00446                 /*test if the current attr is a defined attribute*/
00447                 if (PRIVATE (picker)->current_xml_node->doc->intSubset) {
00448                         attr_desc = 
00449                                 xmlGetDtdAttrDesc (PRIVATE (picker)->current_xml_node->doc->intSubset,
00450                                                    PRIVATE (picker)->current_xml_node->name,
00451                                                    content) ;                   
00452                 }
00453                 if (attr_desc == NULL
00454                     && PRIVATE (picker)->current_xml_node->doc->extSubset) {
00455                         attr_desc = 
00456                                 xmlGetDtdAttrDesc (PRIVATE (picker)->current_xml_node->doc->extSubset,
00457                                                    PRIVATE (picker)->current_xml_node->name,
00458                                                    content) ;
00459                 }
00460                 if (attr_desc == NULL) {/*attribute is unknown by the dtd*/
00461                         gchar * attr_type = NULL ;
00462 
00463                         mlview_attribute_picker_hide_attribute_values_list (picker) ;
00464                         attr_type = mlview_attribute_picker_attribute_type_to_string (XML_ATTRIBUTE_CDATA) ;
00465                         gtk_entry_set_text (GTK_ENTRY (PRIVATE (picker)->type_edit_entry->entry),
00466                                             attr_type) ;
00467                         if (attr_type) {
00468                                 g_free (attr_type) ;
00469                                 attr_type = NULL ;
00470                         }
00471                 }
00472                 else {/*set the the attribute type and the attribute list*/
00473                         GList * attr_vals = NULL ;
00474                         gchar * attr_type = NULL ;
00475                         gint * last_id_ptr = mlview_app_context_get_last_id_ptr (PRIVATE (picker)->app_context) ;
00476                         
00477                         g_return_if_fail (last_id_ptr != NULL) ;
00478                         attr_type = mlview_attribute_picker_attribute_type_to_string (attr_desc->atype) ;
00479                         gtk_entry_set_text (GTK_ENTRY (PRIVATE (picker)->type_edit_entry->entry),
00480                                             attr_type) ;
00481                         if (attr_type) {
00482                                 g_free (attr_type) ;
00483                                 attr_type = NULL ;
00484                         }
00485 
00486                         attr_vals = 
00487                                 mlview_parsing_utils_build_graphical_attribute_value_set (PRIVATE (picker)->app_context,
00488                                                                                           attr_desc, 
00489                                                                                           last_id_ptr) ;
00490 
00491                         if (attr_vals != NULL) {
00492 
00493                                 gtk_list_clear_items (PRIVATE (picker)->values_list, 0, -1) ;
00494                                 gtk_list_append_items (PRIVATE (picker)->values_list,
00495                                                       attr_vals) ;
00496                                 mlview_attribute_picker_show_attribute_values_list (picker) ;
00497 
00498                         } else {
00499 
00500                                 mlview_attribute_picker_hide_attribute_values_list (picker) ;
00501 
00502                         }
00503                         
00504                 }
00505         }
00506         g_free (content) ;
00507 }
00508 
00509 
00516 static void
00517 attribute_type_changed_cb (GtkEditable * a_text_entry,
00518                            gpointer a_picker)
00519 {
00520         gchar * content = NULL ;
00521         MlViewAttributePicker * picker= a_picker ;
00522 
00523         g_return_if_fail (a_text_entry != NULL) ;
00524         g_return_if_fail (GTK_IS_EDITABLE (a_text_entry)) ;
00525         g_return_if_fail (a_picker != NULL) ;
00526         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00527         
00528         content = gtk_editable_get_chars (GTK_EDITABLE (a_text_entry),
00529                                           0, -1) ;
00530         if (!strcmp (content, "IDRREFS")
00531             || !strcmp (content, "ENTITIES")) {
00532                 gtk_widget_set_sensitive (GTK_WIDGET (PRIVATE (picker)->add_to_value_button),
00533                                           TRUE) ;
00534         } else {
00535                 gtk_widget_set_sensitive (GTK_WIDGET (PRIVATE (picker)->add_to_value_button),
00536                                           FALSE) ;
00537         }
00538 }
00539 
00540 
00545 static void
00546 add_to_value_button_cb (GtkButton * a_button,
00547                         gpointer a_picker)
00548 {
00549         MlViewAttributePicker *picker= (MlViewAttributePicker *)a_picker ;
00550 
00551         g_return_if_fail (a_button != NULL) ;
00552         g_return_if_fail (GTK_IS_BUTTON (a_button)) ;
00553         g_return_if_fail (a_picker != NULL) ;
00554         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (picker)) ;
00555         g_return_if_fail (PRIVATE (picker) != NULL) ;
00556 
00557         if (PRIVATE (picker)->current_attribute_value) {
00558                 gchar * str=NULL ;
00559 
00560                 str = gtk_editable_get_chars (GTK_EDITABLE (PRIVATE (picker)->value_edit_entry),
00561                                              0, -1) ;
00562                 str = g_strconcat (str, " ", 
00563                                    PRIVATE (picker)->current_attribute_value,
00564                                    NULL) ;
00565                 gtk_entry_set_text (PRIVATE (picker)->value_edit_entry, 
00566                                     str) ;
00567 
00568                 if (str) {
00569                         g_free (str) ;
00570                         str = NULL ;
00571                 }
00572         }
00573 }
00574 
00580 static void
00581 set_value_button_cb (GtkButton *a_button,
00582                      gpointer a_picker)
00583 {
00584         MlViewAttributePicker *picker= (MlViewAttributePicker *)a_picker ;
00585 
00586         g_return_if_fail (a_button != NULL) ;
00587         g_return_if_fail (GTK_IS_BUTTON (a_button)) ;
00588         g_return_if_fail (picker != NULL) ;
00589         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (picker)) ;
00590         g_return_if_fail (PRIVATE (picker) != NULL) ;
00591 
00592         if (PRIVATE (picker)->current_attribute_value) {
00593                 gtk_entry_set_text (PRIVATE (picker)->value_edit_entry, 
00594                                     PRIVATE (picker)->current_attribute_value) ;
00595         }
00596 }
00597 
00598 
00602 static void
00603 attribute_value_selected_cb (GtkList * a_attribute_values_list,
00604                              GtkWidget *a_list_item,
00605                              gpointer * a_picker)
00606 {
00607         MlViewAttributePicker *picker= (MlViewAttributePicker *)a_picker ;
00608         GList * list = NULL ;
00609 
00610         g_return_if_fail (a_attribute_values_list != NULL) ;
00611         g_return_if_fail (a_list_item != NULL) ;
00612         g_return_if_fail (picker != NULL) ;
00613         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (picker)) ;
00614         g_return_if_fail (PRIVATE (picker) != NULL) ;
00615 
00616         /*get the label contained in the GtkItem*/
00617         list = gtk_container_children (GTK_CONTAINER (a_list_item)) ;
00618         if (list
00619             && list->data 
00620             && GTK_IS_LABEL (list->data)) {
00621                 GtkLabel * label = NULL ;
00622 
00623                 label = GTK_LABEL (list->data) ;
00624                 gtk_label_get (label, &PRIVATE (picker)->current_attribute_value) ;
00625 
00626         }else{
00627                 PRIVATE (picker)->current_attribute_value = NULL ;
00628         }
00629 }
00630 
00631 
00632 /*----------------------------------------------------
00633  *Public functions
00634  *----------------------------------------------------*/
00635 
00636 
00641 gint
00642 mlview_attribute_picker_get_type (void)
00643 {
00644         static gint type=0 ;
00645         
00646         if ( !type ) {
00647                 static const GtkTypeInfo type_info = {
00648                         "MlViewAttributePicker",
00649                         sizeof (MlViewAttributePicker) ,
00650                         sizeof (MlViewAttributePickerClass) ,
00651                         (GtkClassInitFunc) mlview_attribute_picker_init_class,
00652                         (GtkObjectInitFunc) mlview_attribute_picker_init,
00653                         NULL, NULL, NULL
00654                 } ;
00655                 type = gtk_type_unique (GNOME_TYPE_DIALOG, &type_info) ;
00656         }
00657         return type ;
00658 }
00659 
00666 GtkWidget *
00667 mlview_attribute_picker_new (gchar * a_title, MlViewAppContext * a_app_context)
00668 {
00669         MlViewAttributePicker * result = NULL  ;
00670 
00671         result = gtk_type_new (MLVIEW_TYPE_ATTRIBUTE_PICKER) ;
00672         mlview_attribute_picker_set_app_context (result, a_app_context) ;
00673         gtk_window_set_title (GTK_WINDOW (result), a_title) ;
00674         mlview_app_context_set_window_icon (a_app_context, GTK_WIDGET (result)) ;
00675         gtk_window_set_wmclass (GTK_WINDOW (result), "attribute-picker", "MlView") ;
00676 
00677         return GTK_WIDGET (result) ;
00678 }
00679 
00680 
00686 void
00687 mlview_attribute_picker_set_app_context (MlViewAttributePicker * a_picker, 
00688                                          MlViewAppContext * a_app_context)
00689 {
00690         g_return_if_fail (a_picker != NULL) ;
00691         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00692         g_return_if_fail (PRIVATE (a_picker)) ;
00693 
00694         PRIVATE (a_picker)->app_context = a_app_context ;
00695 
00696 }
00697 
00702 void
00703 mlview_attribute_picker_grab_focus_to_name_entry (MlViewAttributePicker * a_picker)
00704 {
00705         g_return_if_fail (a_picker != NULL) ;
00706         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00707         g_return_if_fail (PRIVATE (a_picker) != NULL) ;
00708 
00709         if ( PRIVATE (a_picker)->name_edit_entry  )
00710                 gtk_widget_grab_focus (PRIVATE (a_picker)->name_edit_entry->entry) ;
00711 }
00712 
00713 
00718 void
00719 mlview_attribute_picker_grab_focus_to_value_entry (MlViewAttributePicker * a_picker)
00720 {
00721         g_return_if_fail (a_picker != NULL) ;
00722         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00723         g_return_if_fail (PRIVATE (a_picker) != NULL) ;
00724 
00725         if ( PRIVATE (a_picker)->value_edit_entry  )
00726                 gtk_widget_grab_focus (GTK_WIDGET (PRIVATE (a_picker)->value_edit_entry)) ;
00727 }
00728 
00729 
00735 gchar *
00736 mlview_attribute_picker_get_attribute_name (MlViewAttributePicker * a_picker)
00737 {
00738         g_return_val_if_fail (a_picker != NULL, NULL) ;
00739         g_return_val_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker), NULL) ;
00740         g_return_val_if_fail (PRIVATE (a_picker) != NULL, NULL) ;
00741         
00742         if ( PRIVATE (a_picker)->name_edit_entry 
00743              && PRIVATE (a_picker)->name_edit_entry->entry)
00744                 return gtk_entry_get_text (GTK_ENTRY (PRIVATE (a_picker)->name_edit_entry->entry)) ;
00745         else
00746                 return NULL ;
00747 }
00748 
00754 gchar *
00755 mlview_attribute_picker_get_attribute_value (MlViewAttributePicker *a_picker)
00756 {
00757         g_return_val_if_fail (a_picker != NULL, NULL) ;
00758         g_return_val_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker), NULL) ;
00759         g_return_val_if_fail (PRIVATE (a_picker) != NULL, NULL) ;
00760 
00761         if ( PRIVATE (a_picker)->value_edit_entry )
00762                 return gtk_entry_get_text (PRIVATE (a_picker)->value_edit_entry) ;
00763         else
00764                 return NULL ;
00765 }
00766 
00772 xmlAttributeType 
00773 mlview_attribute_picker_get_attribute_type (MlViewAttributePicker *a_picker)
00774 {
00775         gchar *type_str = NULL ;
00776 
00777         g_return_val_if_fail (a_picker != NULL, XML_ATTRIBUTE_CDATA) ;
00778         g_return_val_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker), XML_ATTRIBUTE_CDATA) ;
00779         g_return_val_if_fail (PRIVATE (a_picker) != NULL, XML_ATTRIBUTE_CDATA) ;
00780 
00781         if (PRIVATE (a_picker)->type_edit_entry
00782             && PRIVATE (a_picker)->type_edit_entry->entry)
00783                 type_str =  gtk_entry_get_text (GTK_ENTRY (PRIVATE (a_picker)->type_edit_entry->entry)) ;
00784 
00785         if (type_str != NULL
00786             && utils_is_white_string (type_str) == FALSE) {
00787                 return mlview_attribute_picker_parse_attribute_type (type_str) ;
00788         } else {
00789                 return XML_ATTRIBUTE_CDATA ;
00790         }
00791 }
00792 
00797 void
00798 mlview_attribute_picker_select_attribute_name (MlViewAttributePicker *a_picker)
00799 {
00800         g_return_if_fail (a_picker != NULL) ;
00801         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00802         g_return_if_fail (PRIVATE (a_picker) != NULL) ;
00803 
00804         if ( PRIVATE (a_picker)->name_edit_entry
00805              && PRIVATE (a_picker)->name_edit_entry->entry )
00806                 gtk_entry_select_region (GTK_ENTRY (PRIVATE (a_picker)->name_edit_entry->entry),
00807                                          0, -1) ;
00808 }
00809 
00815 void
00816 mlview_attribute_picker_select_attribute_value (MlViewAttributePicker *a_picker)
00817 {
00818         g_return_if_fail (a_picker != NULL) ;
00819         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00820         g_return_if_fail (PRIVATE (a_picker) != NULL) ;
00821 
00822         if ( PRIVATE (a_picker)->value_edit_entry)
00823                 gtk_entry_select_region (PRIVATE (a_picker)->value_edit_entry,
00824                                          0, -1) ;
00825 }
00826 
00835 void
00836 mlview_attribute_picker_set_current_xml_node (MlViewAttributePicker * a_picker, 
00837                                               xmlNode * a_xml_node)
00838 {
00839         g_return_if_fail (a_picker != NULL) ;
00840         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00841         g_return_if_fail (PRIVATE (a_picker) != NULL) ;
00842         
00843         PRIVATE (a_picker)->current_xml_node = a_xml_node ;
00844 
00845 }
00846 
00854 void 
00855 mlview_attribute_picker_set_attribute_completion (gboolean a_completion_on)
00856 {
00857         gv_attributes_completion = a_completion_on ;
00858 }
00859 
00860 
00871 void 
00872 mlview_attribute_picker_build_attribute_name_choice_list (MlViewAttributePicker * a_picker, 
00873                                                           xmlNode * a_xml_node)
00874 {
00875         gint nb_of_attribute_names = 0 ;
00876 
00877         g_return_if_fail (a_picker != NULL) ;
00878         g_return_if_fail (MLVIEW_IS_ATTRIBUTE_PICKER (a_picker)) ;
00879         g_return_if_fail (PRIVATE (a_picker) != NULL) ;
00880 
00881         gtk_list_clear_items (GTK_LIST (PRIVATE (a_picker)->values_list),
00882                               0, -1) ;
00883         gtk_list_clear_items (GTK_LIST (PRIVATE (a_picker)->name_edit_entry->list),
00884                               0, -1) ;
00885         gtk_list_clear_items (GTK_LIST (PRIVATE (a_picker)->type_edit_entry->list),
00886                               0, -1) ;
00887         /*FIXME: clear the two GktEntry widgets too. This is a bug.*/
00888 
00889         if ( a_xml_node == NULL 
00890              || a_xml_node->doc == NULL 
00891              || gv_attributes_completion == FALSE)
00892                 return ;
00893 
00894         nb_of_attribute_names = 
00895                 mlview_parsing_utils_build_attribute_name_completion_list (PRIVATE (a_picker)->app_context, a_xml_node,
00896                                                                            &PRIVATE (a_picker)->names_completion_list,
00897                                                                            FALSE/*get all the attributes, even the optional*/) ;
00898         if (nb_of_attribute_names > 0) {
00899                 if ( PRIVATE (a_picker)->names_completion_list )
00900                         gtk_combo_set_popdown_strings (PRIVATE (a_picker)->name_edit_entry,
00901                                                        PRIVATE (a_picker)->names_completion_list) ;
00902         }
00903 }

Generated on Sat Jul 6 09:57:31 2002 for Gnome-MlView by doxygen1.2.16