From dd34eba30cd90659975dc8b56d00dfe36f243854 Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Mon, 26 Nov 2007 21:40:20 +0000 Subject: ** Fixes bug #495951 Use GtkTreeView in place of ETable 2007-11-26 Gilles Dartiguelongue ** Fixes bug #495951 Use GtkTreeView in place of ETable svn path=/trunk/; revision=34590 --- widgets/ChangeLog | 17 ++ widgets/menus/gal-view-instance-save-as-dialog.c | 223 +++++++++------- .../menus/gal-view-instance-save-as-dialog.glade | 286 +++++++-------------- widgets/menus/gal-view-instance-save-as-dialog.h | 9 +- 4 files changed, 259 insertions(+), 276 deletions(-) (limited to 'widgets') diff --git a/widgets/ChangeLog b/widgets/ChangeLog index 19c993c5c4..ea71714eac 100644 --- a/widgets/ChangeLog +++ b/widgets/ChangeLog @@ -1,3 +1,20 @@ +2007-11-26 Gilles Dartiguelongue + + ** Fixes bug #495951 + + * menus/gal-view-instance-save-as-dialog.c: + (gal_view_instance_save_as_dialog_set_instance), + (gvisad_setup_validate_button), (gvisad_setup_radio_buttons), + (gvisad_entry_changed), + (gal_view_instance_save_as_dialog_set_property), + (gal_view_instance_save_as_dialog_dispose), + (gal_view_instance_save_as_dialog_init), + (gal_view_instance_save_as_dialog_new), + (gal_view_instance_save_as_dialog_save): + * menus/gal-view-instance-save-as-dialog.glade: + * menus/gal-view-instance-save-as-dialog.h: + Use GtkTreeView in place of ETable + 2007-11-05 Milan Crha ** Fix for bug #341085 diff --git a/widgets/menus/gal-view-instance-save-as-dialog.c b/widgets/menus/gal-view-instance-save-as-dialog.c index 1a3b917c28..7fcaf6699d 100644 --- a/widgets/menus/gal-view-instance-save-as-dialog.c +++ b/widgets/menus/gal-view-instance-save-as-dialog.c @@ -25,8 +25,8 @@ #include -#include "table/e-table-scrolled.h" #include +#include "e-util/e-util.h" #include "e-util/e-util-private.h" #include "gal-define-views-model.h" @@ -41,56 +41,109 @@ enum { PROP_INSTANCE, }; -typedef struct { - char *title; - ETableModel *model; - GalViewInstanceSaveAsDialog *names; -} GalViewInstanceSaveAsDialogChild; - +enum { + COL_GALVIEW_NAME, + COL_GALVIEW_DATA +}; /* Static functions */ static void -gal_view_instance_save_as_dialog_set_instance(GalViewInstanceSaveAsDialog *dialog, - GalViewInstance *instance) +gal_view_instance_save_as_dialog_set_instance (GalViewInstanceSaveAsDialog *dialog, + GalViewInstance *instance) { + int i; + GtkListStore *store; + GtkCellRenderer *renderer; dialog->instance = instance; - if (dialog->model) { - GtkWidget *table; - g_object_set(dialog->model, - "collection", instance ? instance->collection : NULL, - NULL); - table = glade_xml_get_widget(dialog->gui, "custom-replace"); - if (table) { - ETable *etable; - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (table)); - e_selection_model_select_single_row (e_table_get_selection_model (etable), 0); - e_selection_model_change_cursor (e_table_get_selection_model (etable), 0, 0); - } + + store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); + + for (i=0; icollection->view_count; i++) { + GalViewCollectionItem *item = instance->collection->view_data[i]; + GtkTreeIter iter; + char *title = NULL; + + /* hide built in views */ + /*if (item->built_in == 1) + continue;*/ + + title = e_str_without_underscores (item->title); + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + COL_GALVIEW_NAME, title, + COL_GALVIEW_DATA, item, + -1); + + g_free (title); + } + + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), + COL_GALVIEW_NAME, GTK_SORT_ASCENDING); + + /* attaching treeview to model */ + gtk_tree_view_set_model (dialog->treeview, GTK_TREE_MODEL (store)); + gtk_tree_view_set_search_column (dialog->treeview, COL_GALVIEW_NAME); + + dialog->model = GTK_TREE_MODEL (store); + + renderer = gtk_cell_renderer_text_new (); + + gtk_tree_view_insert_column_with_attributes (dialog->treeview, + COL_GALVIEW_NAME, _("Name"), + renderer, "text", COL_GALVIEW_NAME, + NULL); + + /* set sort column */ + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dialog->model), + COL_GALVIEW_NAME, GTK_SORT_ASCENDING); +} + +static void +gvisad_setup_validate_button (GalViewInstanceSaveAsDialog *dialog) +{ + if ((dialog->toggle == GAL_VIEW_INSTANCE_SAVE_AS_DIALOG_TOGGLE_CREATE + && g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (dialog->entry_create)), -1) > 0) + || dialog->toggle == GAL_VIEW_INSTANCE_SAVE_AS_DIALOG_TOGGLE_REPLACE) { + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE); + } else { + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE); } } + static void gvisad_setup_radio_buttons (GalViewInstanceSaveAsDialog *dialog) { - GtkWidget *radio_replace = glade_xml_get_widget (dialog->gui, "radiobutton-replace"); - GtkWidget *radio_create = glade_xml_get_widget (dialog->gui, "radiobutton-create" ); - GtkWidget *widget; + GtkWidget *widget; + + widget = dialog->scrolledwindow; + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_replace))) { + GtkTreeIter iter; + GtkTreeSelection *selection; + + selection = gtk_tree_view_get_selection (dialog->treeview); + if (!gtk_tree_selection_get_selected (selection, &dialog->model, &iter)) { + if (gtk_tree_model_get_iter_first (dialog->model, &iter)) { + gtk_tree_selection_select_iter (selection, &iter); + } + } - widget = glade_xml_get_widget (dialog->gui, "custom-replace"); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_replace))) { gtk_widget_set_sensitive (widget, TRUE); dialog->toggle = GAL_VIEW_INSTANCE_SAVE_AS_DIALOG_TOGGLE_REPLACE; } else { gtk_widget_set_sensitive (widget, FALSE); } - widget = glade_xml_get_widget (dialog->gui, "entry-create"); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_create))) { + widget = dialog->entry_create; + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_create))) { gtk_widget_set_sensitive (widget, TRUE); dialog->toggle = GAL_VIEW_INSTANCE_SAVE_AS_DIALOG_TOGGLE_CREATE; } else { gtk_widget_set_sensitive (widget, FALSE); } + + gvisad_setup_validate_button (dialog); } static void @@ -100,16 +153,12 @@ gvisad_radio_toggled (GtkWidget *widget, GalViewInstanceSaveAsDialog *dialog) } static void -gvisad_connect_signal(GalViewInstanceSaveAsDialog *dialog, char *widget_name, char *signal, GCallback handler) +gvisad_entry_changed (GtkWidget *widget, GalViewInstanceSaveAsDialog *dialog) { - GtkWidget *widget; - - widget = glade_xml_get_widget(dialog->gui, widget_name); - - if (widget) - g_signal_connect (G_OBJECT (widget), signal, handler, dialog); + gvisad_setup_validate_button (dialog); } + /* Method override implementations */ static void gal_view_instance_save_as_dialog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) @@ -118,12 +167,12 @@ gal_view_instance_save_as_dialog_set_property (GObject *object, guint prop_id, c dialog = GAL_VIEW_INSTANCE_SAVE_AS_DIALOG (object); - switch (prop_id){ + switch (prop_id) { case PROP_INSTANCE: if (g_value_get_object (value)) - gal_view_instance_save_as_dialog_set_instance(dialog, GAL_VIEW_INSTANCE(g_value_get_object (value))); + gal_view_instance_save_as_dialog_set_instance (dialog, GAL_VIEW_INSTANCE (g_value_get_object (value))); else - gal_view_instance_save_as_dialog_set_instance(dialog, NULL); + gal_view_instance_save_as_dialog_set_instance (dialog, NULL); break; default: @@ -152,10 +201,10 @@ gal_view_instance_save_as_dialog_get_property (GObject *object, guint prop_id, G static void gal_view_instance_save_as_dialog_dispose (GObject *object) { - GalViewInstanceSaveAsDialog *gal_view_instance_save_as_dialog = GAL_VIEW_INSTANCE_SAVE_AS_DIALOG(object); + GalViewInstanceSaveAsDialog *gal_view_instance_save_as_dialog = GAL_VIEW_INSTANCE_SAVE_AS_DIALOG (object); if (gal_view_instance_save_as_dialog->gui) - g_object_unref(gal_view_instance_save_as_dialog->gui); + g_object_unref (gal_view_instance_save_as_dialog->gui); gal_view_instance_save_as_dialog->gui = NULL; if (G_OBJECT_CLASS (gal_view_instance_save_as_dialog_parent_class)->dispose) @@ -187,68 +236,55 @@ gal_view_instance_save_as_dialog_init (GalViewInstanceSaveAsDialog *dialog) { GladeXML *gui; GtkWidget *widget; - GtkWidget *table; + gchar *filename = g_build_filename (EVOLUTION_GLADEDIR, "gal-view-instance-save-as-dialog.glade", NULL); dialog->instance = NULL; + dialog->model = NULL; + dialog->collection = NULL; gui = glade_xml_new_with_domain (filename , NULL, GETTEXT_PACKAGE); g_free (filename); dialog->gui = gui; - widget = glade_xml_get_widget(gui, "vbox-top"); + widget = glade_xml_get_widget (gui, "vbox-top"); if (!widget) { return; } - g_object_ref(widget); + + g_object_ref (widget); gtk_container_remove (GTK_CONTAINER (widget->parent), widget); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), widget, TRUE, TRUE, 0); - g_object_unref(widget); + + /* TODO: add position/size saving/restoring */ + gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 360); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), widget, TRUE, TRUE, 0); + g_object_unref (widget); gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - gvisad_connect_signal(dialog, "radiobutton-replace", "toggled", G_CALLBACK(gvisad_radio_toggled)); - gvisad_connect_signal(dialog, "radiobutton-create", "toggled", G_CALLBACK(gvisad_radio_toggled)); + dialog->scrolledwindow = glade_xml_get_widget (dialog->gui, "scrolledwindow2"); + dialog->treeview = GTK_TREE_VIEW (glade_xml_get_widget (dialog->gui, "custom-replace")); + dialog->entry_create = glade_xml_get_widget (dialog->gui, "entry-create"); + dialog->radiobutton_replace = glade_xml_get_widget (dialog->gui, "radiobutton-replace"); + dialog->radiobutton_create = glade_xml_get_widget (dialog->gui, "radiobutton-create"); - dialog->model = NULL; - table = glade_xml_get_widget(dialog->gui, "custom-replace"); - if (table) { - dialog->model = g_object_get_data(G_OBJECT (table), "GalViewInstanceSaveAsDialog::model"); + gtk_tree_view_set_reorderable (GTK_TREE_VIEW (dialog->treeview), FALSE); + gtk_tree_view_set_headers_visible (dialog->treeview, FALSE); - gal_view_instance_save_as_dialog_set_instance (dialog, dialog->instance); - gtk_widget_show_all (table); - } + g_signal_connect (dialog->radiobutton_replace, "toggled", G_CALLBACK (gvisad_radio_toggled), dialog); + g_signal_connect (dialog->radiobutton_create, "toggled", G_CALLBACK (gvisad_radio_toggled), dialog); + g_signal_connect (dialog->entry_create, "changed", G_CALLBACK (gvisad_entry_changed), dialog); gvisad_setup_radio_buttons (dialog); - gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, TRUE, FALSE); - gtk_window_set_title (GTK_WINDOW (dialog), _("Save Current View")); -} + gvisad_setup_validate_button (dialog); - -/* For use from libglade. */ -/* ETable creation */ -#define SPEC "" \ - "" \ - " " \ - "" - -GtkWidget *gal_view_instance_save_as_dialog_create_etable(char *name, char *string1, char *string2, int int1, int int2); - -GtkWidget * -gal_view_instance_save_as_dialog_create_etable(char *name, char *string1, char *string2, int int1, int int2) -{ - GtkWidget *table; - ETableModel *model; - model = gal_define_views_model_new (); - table = e_table_scrolled_new(model, NULL, SPEC, NULL); - g_object_set_data(G_OBJECT (table), "GalViewInstanceSaveAsDialog::model", model); - - return table; + gtk_window_set_title (GTK_WINDOW (dialog), _("Save Current View")); + gtk_widget_show (GTK_WIDGET (dialog)); } /* External methods */ @@ -259,11 +295,11 @@ gal_view_instance_save_as_dialog_create_etable(char *name, char *string1, char * * * Returns: The GalViewInstanceSaveAsDialog. */ -GtkWidget* +GtkWidget * gal_view_instance_save_as_dialog_new (GalViewInstance *instance) { GtkWidget *widget = g_object_new (GAL_VIEW_INSTANCE_SAVE_AS_DIALOG_TYPE, NULL); - gal_view_instance_save_as_dialog_set_instance(GAL_VIEW_INSTANCE_SAVE_AS_DIALOG (widget), instance); + gal_view_instance_save_as_dialog_set_instance (GAL_VIEW_INSTANCE_SAVE_AS_DIALOG (widget), instance); return widget; } @@ -271,25 +307,36 @@ void gal_view_instance_save_as_dialog_save (GalViewInstanceSaveAsDialog *dialog) { GalView *view = gal_view_instance_get_current_view (dialog->instance); - GtkWidget *widget; const char *title; int n; const char *id = NULL; + GalViewCollectionItem *item; view = gal_view_clone (view); switch (dialog->toggle) { case GAL_VIEW_INSTANCE_SAVE_AS_DIALOG_TOGGLE_REPLACE: - widget = glade_xml_get_widget(dialog->gui, "custom-replace"); - if (widget && E_IS_TABLE_SCROLLED (widget)) { - n = e_table_get_cursor_row (e_table_scrolled_get_table (E_TABLE_SCROLLED (widget))); - id = gal_view_collection_set_nth_view (dialog->instance->collection, n, view); - gal_view_collection_save (dialog->instance->collection); + if (dialog->treeview) { + GtkTreeIter iter; + GtkTreeSelection *selection; + + selection = gtk_tree_view_get_selection (dialog->treeview); + if (gtk_tree_selection_get_selected (selection, &dialog->model, &iter)) { + gtk_tree_model_get (dialog->model, &iter, COL_GALVIEW_DATA, &item, -1); + + for (n=0; ninstance->collection->view_count; n++) { + if (item == dialog->instance->collection->view_data[n]) { + id = gal_view_collection_set_nth_view (dialog->instance->collection, n, view); + gal_view_collection_save (dialog->instance->collection); + } + } + } + } break; + case GAL_VIEW_INSTANCE_SAVE_AS_DIALOG_TOGGLE_CREATE: - widget = glade_xml_get_widget(dialog->gui, "entry-create"); - if (widget && GTK_IS_ENTRY (widget)) { - title = gtk_entry_get_text (GTK_ENTRY (widget)); + if (dialog->entry_create && GTK_IS_ENTRY (dialog->entry_create)) { + title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_create)); id = gal_view_collection_append_with_title (dialog->instance->collection, title, view); gal_view_collection_save (dialog->instance->collection); } diff --git a/widgets/menus/gal-view-instance-save-as-dialog.glade b/widgets/menus/gal-view-instance-save-as-dialog.glade index d7e3d8c948..aa40910113 100644 --- a/widgets/menus/gal-view-instance-save-as-dialog.glade +++ b/widgets/menus/gal-view-instance-save-as-dialog.glade @@ -1,256 +1,170 @@ - - - + + + - - - - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - True - False - True - False - False GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - True - True - False 8 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-ok - True - GTK_RELIEF_NORMAL - True - 0 - - - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - 0 - - - - - 0 - False - True - GTK_PACK_END - - - - 18 True - False + 18 12 - - + True - False 6 - True True _Create new view True - GTK_RELIEF_NORMAL - True + 0 True - False True - 0 False False - - + True - False - 6 - - - - True - - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 24 - + True - _Name: - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - entry-create - - - 0 - False - False - - - - - - True - False - True - True - True - 0 - - True - * - False + 6 + + + True + _Name: + True + entry-create + + + False + False + + + + + True + False + True + + + 1 + + - - 0 - True - True - - 0 - True - True + 1 - 0 False False - - - - True - True - _Replace existing view - True - GTK_RELIEF_NORMAL - True - False - False - True - radiobutton-create - - - 0 - False - False - - - - + True - False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 6 - - + True - - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 + True + _Replace existing view + True + 0 + True + radiobutton-create - 0 False False - - + True - gal_view_instance_save_as_dialog_create_etable - 0 - 0 - Fri, 01 Feb 2002 20:18:32 GMT + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 24 + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + + + + - 0 - True - True + 1 - 0 - True - True + 1 + + + + + 2 + + + + + True + GTK_BUTTONBOX_END + + + True + True + True + gtk-cancel + True + 0 + + + + + True + True + True + gtk-ok + True + 0 + + + 1 - 0 - True - True + False + GTK_PACK_END diff --git a/widgets/menus/gal-view-instance-save-as-dialog.h b/widgets/menus/gal-view-instance-save-as-dialog.h index 5808d9840c..f3d30ad7d0 100644 --- a/widgets/menus/gal-view-instance-save-as-dialog.h +++ b/widgets/menus/gal-view-instance-save-as-dialog.h @@ -26,7 +26,8 @@ #include #include -#include +#include +#include #include #include @@ -63,7 +64,11 @@ struct _GalViewInstanceSaveAsDialog /* item specific fields */ GladeXML *gui; - ETableModel *model; + GtkTreeView *treeview; + GtkTreeModel *model; + + GtkWidget *scrolledwindow, *radiobutton_replace; + GtkWidget *entry_create, *radiobutton_create; GalViewInstance *instance; GalViewCollection *collection; -- cgit v1.2.3