From: Jim Evins Date: Sat, 16 Apr 2005 18:05:01 +0000 (+0000) Subject: 2005-04-16 Jim Evins X-Git-Tag: glabels-2_3_0~428 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8b5703b7bbbbb9c7bd88090bc6d3b58aee4e99f8;p=glabels 2005-04-16 Jim Evins * data/glade/Makefile.am: * data/glade/merge-properties-dialog.glade: Added merge properties dialog glade description file. * src/merge-properties-dialog.h: * src/merge-properties-dialog.c: (gl_merge_properties_dialog_get_type), (gl_merge_properties_dialog_init), (gl_merge_properties_dialog_finalize), (gl_merge_properties_dialog_new), (gl_merge_properties_dialog_construct), (type_changed_cb), (src_changed_cb), (response_cb), (load_tree), (record_select_toggled_cb), (select_all_button_clicked_cb), (unselect_all_button_clicked_cb): Modified merge properties dialog to use libglade. Added "select all" and "unselect all" buttons. * src/merge-text.c: (parse_line): Handle empty lines better. * src/merge.c: (gl_merge_eval_key): Evaluate the key whether the record is selected or not. * src/util.h: * src/util.c: (gl_util_combo_box_add_text_model): Since libglade does not use the gtk_combo_box_new_text() constructor for GtkComboBoxes, a utility function was created to add an appropriate text model to a GtkComboBox. * src/view.c: (gl_view_edit_merge_props): Removed unnecessary "show all's". git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@521 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 70e15df1..2406a2a0 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,32 @@ +2005-04-16 Jim Evins + + * data/glade/Makefile.am: + * data/glade/merge-properties-dialog.glade: + Added merge properties dialog glade description file. + * src/merge-properties-dialog.h: + * src/merge-properties-dialog.c: + (gl_merge_properties_dialog_get_type), + (gl_merge_properties_dialog_init), + (gl_merge_properties_dialog_finalize), + (gl_merge_properties_dialog_new), + (gl_merge_properties_dialog_construct), (type_changed_cb), + (src_changed_cb), (response_cb), (load_tree), + (record_select_toggled_cb), (select_all_button_clicked_cb), + (unselect_all_button_clicked_cb): + Modified merge properties dialog to use libglade. Added + "select all" and "unselect all" buttons. + * src/merge-text.c: (parse_line): + Handle empty lines better. + * src/merge.c: (gl_merge_eval_key): + Evaluate the key whether the record is selected or not. + * src/util.h: + * src/util.c: (gl_util_combo_box_add_text_model): + Since libglade does not use the gtk_combo_box_new_text() + constructor for GtkComboBoxes, a utility function was created + to add an appropriate text model to a GtkComboBox. + * src/view.c: (gl_view_edit_merge_props): + Removed unnecessary "show all's". + 2005-04-15 Jim Evins * po/ru.po: diff --git a/glabels2/data/glade/Makefile.am b/glabels2/data/glade/Makefile.am index 373e2cc1..5572e385 100644 --- a/glabels2/data/glade/Makefile.am +++ b/glabels2/data/glade/Makefile.am @@ -5,7 +5,8 @@ gladedir = $(datadir)/glabels/glade/ glade_DATA = \ object-editor.glade \ prefs-dialog.glade \ - template-designer.glade + template-designer.glade \ + merge-properties-dialog.glade EXTRA_DIST = $(glade_DATA) diff --git a/glabels2/data/glade/merge-properties-dialog.glade b/glabels2/data/glade/merge-properties-dialog.glade new file mode 100644 index 00000000..0571d9f3 --- /dev/null +++ b/glabels2/data/glade/merge-properties-dialog.glade @@ -0,0 +1,376 @@ + + + + + + + True + dialog1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + False + 0 + + + + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + 12 + True + 2 + 2 + False + 6 + 6 + + + + True + Format: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + False + True + + + 1 + 2 + 0 + 1 + fill + + + + + + True + False + 0 + + + + + + + 1 + 2 + 1 + 2 + fill + fill + + + + + + True + Location: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + + + + + True + <b>Source</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 0 + False + True + + + + + + 6 + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + False + 6 + + + + 6 + 500 + 350 + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + False + False + False + + + + + 0 + True + True + + + + + + 6 + True + False + 12 + + + + True + True + Select all + True + GTK_RELIEF_NORMAL + True + + + 0 + False + False + + + + + + True + True + Unselect all + True + GTK_RELIEF_NORMAL + True + + + 0 + False + False + + + + + 0 + False + True + + + + + + + + + + True + <b>Record selection/preview</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + + diff --git a/glabels2/src/merge-properties-dialog.c b/glabels2/src/merge-properties-dialog.c index e76bdfaa..120a1329 100644 --- a/glabels2/src/merge-properties-dialog.c +++ b/glabels2/src/merge-properties-dialog.c @@ -21,12 +21,16 @@ */ #include +#include "merge-properties-dialog.h" + #include +#include +#include +#include #include "view.h" #include "merge.h" -#include "merge-properties-dialog.h" -#include "hig.h" +#include "util.h" #include "debug.h" @@ -36,16 +40,21 @@ struct _glMergePropertiesDialogPrivate { + GladeXML *gui; + glView *view; glLabel *label; glMerge *merge; - GtkWidget *type_entry; - GtkWidget *src_entry_holder; + GtkWidget *type_combo; + GtkWidget *location_vbox; GtkWidget *src_entry; GtkTreeStore *store; - GtkWidget *tree; + GtkWidget *treeview; + + GtkWidget *select_all_button; + GtkWidget *unselect_all_button; gchar *saved_src; @@ -68,7 +77,7 @@ enum { /* Private globals */ /*===========================================*/ -static glHigDialogClass* parent_class = NULL; +static GtkDialogClass* parent_class = NULL; /*===========================================*/ /* Local function prototypes */ @@ -97,6 +106,11 @@ static void record_select_toggled_cb (GtkCellRendererToggle gchar *path_str, GtkTreeStore *store); +static void select_all_button_clicked_cb (GtkWidget *widget, + glMergePropertiesDialog *dialog); + +static void unselect_all_button_clicked_cb (GtkWidget *widget, + glMergePropertiesDialog *dialog); /*****************************************************************************/ @@ -123,7 +137,7 @@ gl_merge_properties_dialog_get_type (void) NULL }; - type = g_type_register_static (GL_TYPE_HIG_DIALOG, + type = g_type_register_static (GTK_TYPE_DIALOG, "glMergePropertiesDialog", &info, 0); } @@ -145,18 +159,20 @@ gl_merge_properties_dialog_class_init (glMergePropertiesDialogClass *klass) static void gl_merge_properties_dialog_init (glMergePropertiesDialog *dialog) { - gl_debug (DEBUG_MERGE, ""); + gl_debug (DEBUG_MERGE, "START"); - dialog->private = g_new0 (glMergePropertiesDialogPrivate, 1); + dialog->priv = g_new0 (glMergePropertiesDialogPrivate, 1); - gtk_dialog_add_buttons (GTK_DIALOG(dialog), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); + dialog->priv->gui = glade_xml_new (GLABELS_GLADE_DIR "merge-properties-dialog.glade", + "merge_properties_vbox", + NULL); - g_signal_connect (G_OBJECT(dialog), "response", - G_CALLBACK(response_cb), NULL); + if (!dialog->priv->gui) { + g_warning ("Could not open merge-properties-dialog.glade, reinstall glabels!"); + return; + } + gl_debug (DEBUG_MERGE, "END"); } static void @@ -164,22 +180,24 @@ gl_merge_properties_dialog_finalize (GObject *object) { glMergePropertiesDialog* dialog; - gl_debug (DEBUG_MERGE, ""); + gl_debug (DEBUG_MERGE, "START"); g_return_if_fail (object != NULL); dialog = GL_MERGE_PROPERTIES_DIALOG (object); g_return_if_fail (GL_IS_MERGE_PROPERTIES_DIALOG (dialog)); - g_return_if_fail (dialog->private != NULL); + g_return_if_fail (dialog->priv != NULL); G_OBJECT_CLASS (parent_class)->finalize (object); - if (dialog->private->merge != NULL) { - g_object_unref (G_OBJECT(dialog->private->merge)); + if (dialog->priv->merge != NULL) { + g_object_unref (G_OBJECT (dialog->priv->merge)); } - g_free (dialog->private); + g_free (dialog->priv); + + gl_debug (DEBUG_MERGE, "END"); } /*****************************************************************************/ @@ -190,13 +208,15 @@ gl_merge_properties_dialog_new (glView *view) { GtkWidget *dialog; - gl_debug (DEBUG_MERGE, ""); + gl_debug (DEBUG_MERGE, "START"); dialog = GTK_WIDGET (g_object_new (GL_TYPE_MERGE_PROPERTIES_DIALOG, NULL)); - gl_merge_properties_dialog_construct (GL_MERGE_PROPERTIES_DIALOG(dialog), + gl_merge_properties_dialog_construct (GL_MERGE_PROPERTIES_DIALOG (dialog), view); + gl_debug (DEBUG_MERGE, "END"); + return dialog; } @@ -207,26 +227,56 @@ static void gl_merge_properties_dialog_construct (glMergePropertiesDialog *dialog, glView *view) { - GtkWidget *wframe, *whbox, *wtable, *wlabel, *wcombo, *wscroll, *wentry; - GList *texts; gchar *description; glMergeSrcType src_type; gchar *src; - GtkSizeGroup *label_size_group; + gchar *name, *title; + GList *texts; + GtkWidget *vbox; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkTreeSelection *selection; - gchar *name, *title; gl_debug (DEBUG_MERGE, "START"); - dialog->private->view = view; - dialog->private->label = view->label; + g_return_if_fail (GL_IS_MERGE_PROPERTIES_DIALOG (dialog)); + g_return_if_fail (dialog->priv != NULL); + + gtk_dialog_add_buttons (GTK_DIALOG (dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); + + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); + + g_signal_connect(G_OBJECT (dialog), "response", + G_CALLBACK (response_cb), NULL); + + vbox = glade_xml_get_widget (dialog->priv->gui, + "merge_properties_vbox"); + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox); - dialog->private->merge = gl_label_get_merge (dialog->private->label); - description = gl_merge_get_description (dialog->private->merge); - src_type = gl_merge_get_src_type (dialog->private->merge); - src = gl_merge_get_src (dialog->private->merge); + dialog->priv->type_combo = glade_xml_get_widget (dialog->priv->gui, + "type_combo"); + dialog->priv->location_vbox = glade_xml_get_widget (dialog->priv->gui, + "location_vbox"); + dialog->priv->treeview = glade_xml_get_widget (dialog->priv->gui, + "treeview"); + + dialog->priv->select_all_button = glade_xml_get_widget (dialog->priv->gui, + "select_all_button"); + dialog->priv->unselect_all_button = glade_xml_get_widget (dialog->priv->gui, + "unselect_all_button"); + + gl_util_combo_box_add_text_model (GTK_COMBO_BOX (dialog->priv->type_combo)); + + dialog->priv->view = view; + dialog->priv->label = view->label; + + dialog->priv->merge = gl_label_get_merge (dialog->priv->label); + description = gl_merge_get_description (dialog->priv->merge); + src_type = gl_merge_get_src_type (dialog->priv->merge); + src = gl_merge_get_src (dialog->priv->merge); /* --- Window title --- */ name = gl_label_get_short_name (view->label); @@ -235,21 +285,6 @@ gl_merge_properties_dialog_construct (glMergePropertiesDialog *dialog, g_free (name); g_free (title); - /* ---- Source section ---- */ - wframe = gl_hig_category_new (_("Source")); - gl_hig_dialog_add_widget (GL_HIG_DIALOG(dialog), wframe); - label_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - - /* Format line */ - whbox = gl_hig_hbox_new(); - gl_hig_category_add_widget (GL_HIG_CATEGORY (wframe), whbox); - - wlabel = gtk_label_new (_("Format:")); - gtk_size_group_add_widget (label_size_group, wlabel); - gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5); - gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), wlabel); - - wcombo = gtk_combo_new (); texts = gl_merge_get_descriptions (); gl_debug (DEBUG_MERGE, "DESCRIPTIONS:"); { @@ -259,95 +294,84 @@ gl_merge_properties_dialog_construct (glMergePropertiesDialog *dialog, gl_debug (DEBUG_MERGE, " \"%s\"", p->data); } } - gtk_combo_set_popdown_strings (GTK_COMBO (wcombo), texts); + gl_util_combo_box_set_strings (GTK_COMBO_BOX (dialog->priv->type_combo), + texts); gl_merge_free_descriptions (&texts); - dialog->private->type_entry = GTK_COMBO (wcombo)->entry; - gtk_entry_set_editable (GTK_ENTRY (dialog->private->type_entry), FALSE); - gtk_entry_set_text (GTK_ENTRY (dialog->private->type_entry), description); - gl_hig_hbox_add_widget_justify (GL_HIG_HBOX(whbox), wcombo); - g_signal_connect (G_OBJECT (dialog->private->type_entry), "changed", + gl_util_combo_box_set_active_text (GTK_COMBO_BOX (dialog->priv->type_combo), + description); + g_signal_connect (G_OBJECT (dialog->priv->type_combo), "changed", G_CALLBACK (type_changed_cb), dialog); - whbox = gl_hig_hbox_new(); - gl_hig_category_add_widget (GL_HIG_CATEGORY (wframe), whbox); - - /* Location line */ - wlabel = gtk_label_new (_("Location:")); - gtk_size_group_add_widget (label_size_group, wlabel); - gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5); - gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), wlabel); - gl_debug (DEBUG_MERGE, "Src_type = %d", src_type); switch (src_type) { case GL_MERGE_SRC_IS_FILE: - dialog->private->src_entry = - gnome_file_entry_new (NULL, _("Select merge-database source")); - wentry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY(dialog->private->src_entry)); - gtk_entry_set_text (GTK_ENTRY(wentry), src); - g_signal_connect (G_OBJECT (wentry), "changed", + dialog->priv->src_entry = + gtk_file_chooser_button_new (_("Select merge-database source"), + GTK_FILE_CHOOSER_ACTION_OPEN); + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog->priv->src_entry), + src); + g_signal_connect (G_OBJECT (dialog->priv->src_entry), + "selection-changed", G_CALLBACK (src_changed_cb), dialog); break; default: - dialog->private->src_entry = gtk_label_new (_("N/A")); - gtk_misc_set_alignment (GTK_MISC (dialog->private->src_entry), 0.0, 0.5); + dialog->priv->src_entry = gtk_label_new (_("N/A")); + gtk_misc_set_alignment (GTK_MISC (dialog->priv->src_entry), 0.0, 0.5); break; } - dialog->private->src_entry_holder = gtk_hbox_new (FALSE, 0); - gtk_container_add( GTK_CONTAINER(dialog->private->src_entry_holder), - dialog->private->src_entry); - gl_hig_hbox_add_widget_justify (GL_HIG_HBOX(whbox), - dialog->private->src_entry_holder); - - /* ---- Sample Fields section ---- */ - wframe = gl_hig_category_new (_("Record selection/preview:")); - gl_hig_dialog_add_widget (GL_HIG_DIALOG(dialog), wframe); - - wscroll = gtk_scrolled_window_new (NULL, NULL); - gtk_container_set_border_width (GTK_CONTAINER (wscroll), 5); - gtk_widget_set_usize (wscroll, 500, 350); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (wscroll), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gl_hig_category_add_widget (GL_HIG_CATEGORY (wframe), wscroll); - - dialog->private->store = gtk_tree_store_new (N_COLUMNS, + gtk_box_pack_start (GTK_BOX (dialog->priv->location_vbox), + dialog->priv->src_entry, FALSE, FALSE, 0); + gtk_widget_show_all (GTK_WIDGET (dialog->priv->location_vbox)); + + dialog->priv->store = gtk_tree_store_new (N_COLUMNS, G_TYPE_BOOLEAN, /* Record selector */ G_TYPE_STRING, /* Record/Field name */ G_TYPE_STRING, /* Field value */ G_TYPE_BOOLEAN, /* Is Record? */ G_TYPE_POINTER /* Pointer to record */); - load_tree (dialog->private->store, dialog->private->merge); - dialog->private->tree = - gtk_tree_view_new_with_model (GTK_TREE_MODEL(dialog->private->store)); - gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(dialog->private->tree), TRUE); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dialog->private->tree)); + load_tree (dialog->priv->store, dialog->priv->merge); + + gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->priv->treeview), + GTK_TREE_MODEL (dialog->priv->store)); + + gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (dialog->priv->treeview), + TRUE); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->treeview)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE); renderer = gtk_cell_renderer_toggle_new (); g_signal_connect (G_OBJECT (renderer), "toggled", - G_CALLBACK (record_select_toggled_cb), dialog->private->store); + G_CALLBACK (record_select_toggled_cb), dialog->priv->store); column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer, "active", SELECT_COLUMN, "visible", IS_RECORD_COLUMN, NULL); gtk_tree_view_column_set_clickable (column, TRUE); - gtk_tree_view_append_column (GTK_TREE_VIEW(dialog->private->tree), column); + gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->priv->treeview), column); renderer = gtk_cell_renderer_text_new (); - gtk_object_set (GTK_OBJECT(renderer), "yalign", 0.0, NULL); + gtk_object_set (GTK_OBJECT (renderer), "yalign", 0.0, NULL); column = gtk_tree_view_column_new_with_attributes (_("Record/Field"), renderer, "text", RECORD_FIELD_COLUMN, NULL); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); - gtk_tree_view_append_column (GTK_TREE_VIEW(dialog->private->tree), column); - gtk_tree_view_set_expander_column (GTK_TREE_VIEW(dialog->private->tree), column); + gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->priv->treeview), column); + gtk_tree_view_set_expander_column (GTK_TREE_VIEW (dialog->priv->treeview), column); renderer = gtk_cell_renderer_text_new (); - gtk_object_set (GTK_OBJECT(renderer), "yalign", 0.0, NULL); + gtk_object_set (GTK_OBJECT (renderer), "yalign", 0.0, NULL); column = gtk_tree_view_column_new_with_attributes (_("Data"), renderer, "text", VALUE_COLUMN, NULL); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); - gtk_tree_view_append_column (GTK_TREE_VIEW(dialog->private->tree), column); - gtk_container_add (GTK_CONTAINER (wscroll), dialog->private->tree); - + gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->priv->treeview), column); + + g_signal_connect (G_OBJECT (dialog->priv->select_all_button), + "clicked", + G_CALLBACK (select_all_button_clicked_cb), dialog); + + g_signal_connect (G_OBJECT (dialog->priv->unselect_all_button), + "clicked", + G_CALLBACK (unselect_all_button_clicked_cb), dialog); + + g_free (src); g_free (description); @@ -371,46 +395,48 @@ type_changed_cb (GtkWidget *widget, gl_debug (DEBUG_MERGE, "START"); - description = gtk_editable_get_chars (GTK_EDITABLE (dialog->private->type_entry), - 0, -1); + description = gtk_combo_box_get_active_text (GTK_COMBO_BOX (dialog->priv->type_combo)); name = gl_merge_description_to_name (description); - src = gl_merge_get_src (dialog->private->merge); /* keep current src if possible */ + src = gl_merge_get_src (dialog->priv->merge); /* keep current src if possible */ if ( src != NULL ) { gl_debug (DEBUG_MERGE, "Saving src = \"%s\"", src); - g_free (dialog->private->saved_src); - dialog->private->saved_src = src; + g_free (dialog->priv->saved_src); + dialog->priv->saved_src = src; } - if (dialog->private->merge != NULL) { - g_object_unref (G_OBJECT(dialog->private->merge)); + if (dialog->priv->merge != NULL) { + g_object_unref (G_OBJECT(dialog->priv->merge)); } - dialog->private->merge = gl_merge_new (name); + dialog->priv->merge = gl_merge_new (name); - gtk_widget_destroy (dialog->private->src_entry); - src_type = gl_merge_get_src_type (dialog->private->merge); + gtk_widget_destroy (dialog->priv->src_entry); + src_type = gl_merge_get_src_type (dialog->priv->merge); switch (src_type) { case GL_MERGE_SRC_IS_FILE: - dialog->private->src_entry = - gnome_file_entry_new (NULL, _("Select merge-database source")); - wentry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY(dialog->private->src_entry)); - if (dialog->private->saved_src != NULL) { - gl_debug (DEBUG_MERGE, "Setting src = \"%s\"", dialog->private->saved_src); - gtk_entry_set_text (GTK_ENTRY(wentry), dialog->private->saved_src); - gl_merge_set_src (dialog->private->merge, dialog->private->saved_src); + dialog->priv->src_entry = + gtk_file_chooser_button_new (_("Select merge-database source"), + GTK_FILE_CHOOSER_ACTION_OPEN); + if (dialog->priv->saved_src != NULL) { + gl_debug (DEBUG_MERGE, "Setting src = \"%s\"", dialog->priv->saved_src); + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog->priv->src_entry), + dialog->priv->saved_src); + gl_merge_set_src (dialog->priv->merge, dialog->priv->saved_src); } - g_signal_connect (G_OBJECT (wentry), "changed", + g_signal_connect (G_OBJECT (dialog->priv->src_entry), + "selection-changed", G_CALLBACK (src_changed_cb), dialog); break; default: - dialog->private->src_entry = gtk_label_new (_("N/A")); - gtk_misc_set_alignment (GTK_MISC (dialog->private->src_entry), 0.0, 0.5); + dialog->priv->src_entry = gtk_label_new (_("N/A")); + gtk_misc_set_alignment (GTK_MISC (dialog->priv->src_entry), 0.0, 0.5); break; } - gtk_container_add( GTK_CONTAINER(dialog->private->src_entry_holder), dialog->private->src_entry); - gtk_widget_show (dialog->private->src_entry); + gtk_box_pack_start( GTK_BOX (dialog->priv->location_vbox), + dialog->priv->src_entry, FALSE, FALSE, 0); + gtk_widget_show_all (dialog->priv->location_vbox); - load_tree (dialog->private->store, dialog->private->merge); + load_tree (dialog->priv->store, dialog->priv->merge); g_free (description); g_free (name); @@ -425,17 +451,24 @@ static void src_changed_cb (GtkWidget *widget, glMergePropertiesDialog *dialog) { - gchar *src; + gchar *src, *orig_src; GtkWidget *wentry; gl_debug (DEBUG_MERGE, "START"); - wentry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY(dialog->private->src_entry)); - src = gtk_editable_get_chars (GTK_EDITABLE (wentry), 0, -1); - gl_merge_set_src (dialog->private->merge, src); + orig_src = gl_merge_get_src (dialog->priv->merge); + src = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog->priv->src_entry)); + + gl_debug (DEBUG_MERGE, "orig=\"%s\", new=\"%s\"\n", orig_src, src); + + if (!orig_src || strcmp (src, orig_src)) { + gl_merge_set_src (dialog->priv->merge, src); + load_tree (dialog->priv->store, dialog->priv->merge); + } + + g_free (orig_src); g_free (src); - load_tree (dialog->private->store, dialog->private->merge); gl_debug (DEBUG_MERGE, "END"); } @@ -453,13 +486,20 @@ response_cb (glMergePropertiesDialog *dialog, switch (response) { case GTK_RESPONSE_OK: - - gl_label_set_merge (dialog->private->label, dialog->private->merge); + gl_label_set_merge (dialog->priv->label, dialog->priv->merge); + gtk_widget_hide (GTK_WIDGET (dialog)); + break; + case GTK_RESPONSE_CANCEL: + /* Let the dialog get rebuilt next time to recover state. */ + gtk_widget_destroy (GTK_WIDGET (dialog)); break; + case GTK_RESPONSE_DELETE_EVENT: + break; + default: + g_print ("response = %d", response); + g_assert_not_reached (); } - gtk_widget_destroy (GTK_WIDGET(dialog)); - gl_debug (DEBUG_MERGE, "END"); } @@ -478,6 +518,8 @@ load_tree (GtkTreeStore *store, gchar *primary_key; gchar *primary_value; + gl_debug (DEBUG_MERGE, "START"); + gtk_tree_store_clear (store); primary_key = gl_merge_get_primary_key (merge); @@ -511,7 +553,8 @@ load_tree (GtkTreeStore *store, } g_free (primary_key); - + + gl_debug (DEBUG_MERGE, "END"); } /*--------------------------------------------------------------------------*/ @@ -522,28 +565,107 @@ record_select_toggled_cb (GtkCellRendererToggle *cell, gchar *path_str, GtkTreeStore *store) { - GtkTreePath *path; - GtkTreeIter iter; - glMergeRecord *record; + GtkTreePath *path; + GtkTreeIter iter; + glMergeRecord *record; + + gl_debug (DEBUG_MERGE, "START"); + + /* get toggled iter */ + path = gtk_tree_path_new_from_string (path_str); + gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path); + + /* get current data */ + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, + DATA_COLUMN, &record, + -1); + + /* toggle the select flag within the record */ + record->select_flag ^= 1; + + /* set new value in store */ + gtk_tree_store_set (store, &iter, + SELECT_COLUMN, record->select_flag, + -1); + + /* clean up */ + gtk_tree_path_free (path); + + gl_debug (DEBUG_MERGE, "END"); +} + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. "Select All" button callback. */ +/*--------------------------------------------------------------------------*/ +static void +select_all_button_clicked_cb (GtkWidget *widget, + glMergePropertiesDialog *dialog) +{ + GtkTreeModel *store = GTK_TREE_MODEL (dialog->priv->store); + GtkTreeIter iter; + glMergeRecord *record; + gboolean good; + + gl_debug (DEBUG_MERGE, "START"); - /* get toggled iter */ - path = gtk_tree_path_new_from_string (path_str); - gtk_tree_model_get_iter (GTK_TREE_MODEL(store), &iter, path); + for ( good = gtk_tree_model_get_iter_first (store, &iter); + good; + good = gtk_tree_model_iter_next (store, &iter) ) + { + + /* get current data */ + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, + DATA_COLUMN, &record, + -1); - /* get current data */ - gtk_tree_model_get (GTK_TREE_MODEL(store), &iter, - DATA_COLUMN, &record, - -1); + + /* Set select flag within the record */ + record->select_flag = TRUE; - /* toggle the select flag within the record */ - record->select_flag ^= 1; + /* set new value in store */ + gtk_tree_store_set (GTK_TREE_STORE (store), &iter, + SELECT_COLUMN, record->select_flag, + -1); - /* set new value in store */ - gtk_tree_store_set (store, &iter, - SELECT_COLUMN, record->select_flag, - -1); + } - /* clean up */ - gtk_tree_path_free (path); + gl_debug (DEBUG_MERGE, "END"); } +/*--------------------------------------------------------------------------*/ +/* PRIVATE. "Unselect All" button callback. */ +/*--------------------------------------------------------------------------*/ +static void +unselect_all_button_clicked_cb (GtkWidget *widget, + glMergePropertiesDialog *dialog) +{ + GtkTreeModel *store = GTK_TREE_MODEL (dialog->priv->store); + GtkTreeIter iter; + glMergeRecord *record; + gboolean good; + + gl_debug (DEBUG_MERGE, "START"); + + for ( good = gtk_tree_model_get_iter_first (store, &iter); + good; + good = gtk_tree_model_iter_next (store, &iter) ) + { + + /* get current data */ + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, + DATA_COLUMN, &record, + -1); + + + /* Set select flag within the record */ + record->select_flag = FALSE; + + /* set new value in store */ + gtk_tree_store_set (GTK_TREE_STORE (store), &iter, + SELECT_COLUMN, record->select_flag, + -1); + + } + + gl_debug (DEBUG_MERGE, "END"); +} diff --git a/glabels2/src/merge-properties-dialog.h b/glabels2/src/merge-properties-dialog.h index c7e71f71..eb5a7a9b 100644 --- a/glabels2/src/merge-properties-dialog.h +++ b/glabels2/src/merge-properties-dialog.h @@ -22,8 +22,7 @@ #ifndef __MERGE_PROPERTIES_DIALOG_H__ #define __MERGE_PROPERTIES_DIALOG_H__ -#include -#include "hig.h" +#include #include "view.h" G_BEGIN_DECLS @@ -43,15 +42,15 @@ typedef struct _glMergePropertiesDialogPrivate glMergePropertiesDialogPrivate; struct _glMergePropertiesDialog { - glHigDialog parent_instance; + GtkDialog parent_instance; - glMergePropertiesDialogPrivate *private; + glMergePropertiesDialogPrivate *priv; }; struct _glMergePropertiesDialogClass { - glHigDialogClass parent_class; + GtkDialogClass parent_class; }; GType gl_merge_properties_dialog_get_type (void) G_GNUC_CONST; diff --git a/glabels2/src/merge-text.c b/glabels2/src/merge-text.c index 637badbe..8802235a 100644 --- a/glabels2/src/merge-text.c +++ b/glabels2/src/merge-text.c @@ -22,10 +22,10 @@ #include -#include - #include "merge-text.h" +#include + #include "debug.h" #define LINE_BUF_LEN 1024 @@ -413,6 +413,11 @@ parse_line (FILE *fp, state = NORMAL; break; case '\n': + /* treat as one empty field. */ + list = g_list_append (list, + g_strdup ("")); + state = DONE; + break; case EOF: state = DONE; break; diff --git a/glabels2/src/merge.c b/glabels2/src/merge.c index 2edebc10..744ca257 100644 --- a/glabels2/src/merge.c +++ b/glabels2/src/merge.c @@ -21,12 +21,12 @@ */ #include +#include "merge.h" + #include #include #include -#include "merge.h" - #include "debug.h" /*========================================================*/ @@ -697,7 +697,7 @@ gl_merge_eval_key (glMergeRecord *record, gl_debug (DEBUG_MERGE, "START"); - if ( (record != NULL) && record->select_flag ) { + if ( (record != NULL) ) { for (p = record->field_list; p != NULL; p = p->next) { field = (glMergeField *) p->data; diff --git a/glabels2/src/util.c b/glabels2/src/util.c index 53f3deee..7678233c 100644 --- a/glabels2/src/util.c +++ b/glabels2/src/util.c @@ -22,14 +22,13 @@ #include +#include "util.h" + #include #include -#include #include #include -#include "util.h" - #define FRAC_EPSILON 0.00005 @@ -193,6 +192,9 @@ gl_util_string_to_weight (const gchar *string) } +/****************************************************************************/ +/* Convienience function to set strings in a text combo_box from a GList */ +/****************************************************************************/ void gl_util_combo_box_set_strings (GtkComboBox *combo, GList *list) @@ -208,6 +210,10 @@ gl_util_combo_box_set_strings (GtkComboBox *combo, } } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. gl_util_combo_box_set_active_text support. */ +/*---------------------------------------------------------------------------*/ + typedef struct { const gchar *text; GtkTreeIter iter; @@ -235,6 +241,9 @@ search_text_func (GtkTreeModel *model, return FALSE; } +/****************************************************************************/ +/* Convienience function to set active text in a text combo_box from text */ +/****************************************************************************/ void gl_util_combo_box_set_active_text (GtkComboBox *combo, const gchar *text) @@ -265,3 +274,25 @@ gl_util_combo_box_set_active_text (GtkComboBox *combo, } +/****************************************************************************/ +/* Convienience function to add a simple text model to an existing */ +/* combo_box. This is needed since combo_boxes created with glade do not */ +/* use the gtk_combo_box_new_text() constructor. */ +/****************************************************************************/ +void +gl_util_combo_box_add_text_model (GtkComboBox *combo) +{ + GtkCellRenderer *cell; + GtkListStore *store; + + store = gtk_list_store_new (1, G_TYPE_STRING); + gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store)); + g_object_unref (store); + + cell = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell, + "text", 0, + NULL); +} + diff --git a/glabels2/src/util.h b/glabels2/src/util.h index 89af5b03..cef32b6d 100644 --- a/glabels2/src/util.h +++ b/glabels2/src/util.h @@ -45,6 +45,7 @@ void gl_util_combo_box_set_strings (GtkComboBox *combo, GList *list); void gl_util_combo_box_set_active_text (GtkComboBox *combo, const gchar *text); +void gl_util_combo_box_add_text_model (GtkComboBox *combo); G_END_DECLS diff --git a/glabels2/src/view.c b/glabels2/src/view.c index c302dcca..1b962015 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -3291,13 +3291,12 @@ gl_view_edit_merge_props (glView *view) g_return_if_fail (view && GL_IS_VIEW (view)); if (view->merge_props_dialog != NULL) { - gtk_widget_show_all (view->merge_props_dialog); gtk_window_present (GTK_WINDOW(view->merge_props_dialog)); return; } view->merge_props_dialog = gl_merge_properties_dialog_new (view); - gtk_widget_show_all (view->merge_props_dialog); + gtk_window_present (GTK_WINDOW (view->merge_props_dialog)); g_signal_connect (G_OBJECT(view->merge_props_dialog), "destroy", G_CALLBACK (gtk_widget_destroyed),