@@ -48,7 +48,6 @@ typedef struct
4848 GtkWidget * default_button ;
4949 GtkWidget * select_button ;
5050 GtkWidget * browse_button ;
51- GtkWidget * action_area ;
5251 GtkWidget * loading_bar ;
5352 GtkCellArea * ca_box ;
5453 gchar * icon_string ;
@@ -61,7 +60,7 @@ typedef struct
6160
6261struct _XAppIconChooserDialog
6362{
64- XAppGtkWindow parent_instance ;
63+ GtkDialog parent_instance ;
6564};
6665
6766typedef struct
@@ -128,7 +127,6 @@ static IconCategoryDefinition categories[] = {
128127
129128enum
130129{
131- CLOSE ,
132130 SELECT ,
133131 LAST_SIGNAL
134132};
@@ -153,7 +151,7 @@ static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
153151
154152static guint signals [LAST_SIGNAL ] = {0 , };
155153
156- G_DEFINE_TYPE_WITH_PRIVATE (XAppIconChooserDialog , xapp_icon_chooser_dialog , XAPP_TYPE_GTK_WINDOW )
154+ G_DEFINE_TYPE_WITH_PRIVATE (XAppIconChooserDialog , xapp_icon_chooser_dialog , GTK_TYPE_DIALOG )
157155
158156static void on_category_selected (GtkListBox * list_box ,
159157 XAppIconChooserDialog * dialog );
@@ -172,14 +170,8 @@ static void on_icon_store_icons_added (GtkTreeModel *tree_model,
172170static void on_browse_button_clicked (GtkButton * button ,
173171 gpointer user_data );
174172
175- static void on_select_button_clicked (GtkButton * button ,
176- gpointer user_data );
177-
178- static void on_cancel_button_clicked (GtkButton * button ,
179- gpointer user_data );
180-
181173static void on_default_button_clicked (GtkButton * button ,
182- gpointer user_data );
174+ gpointer user_data );
183175
184176static gboolean on_search_bar_key_pressed (GtkWidget * widget ,
185177 GdkEvent * event ,
@@ -414,8 +406,6 @@ xapp_icon_chooser_dialog_init (XAppIconChooserDialog *dialog)
414406 GtkWidget * right_box ;
415407 GtkStyleContext * style ;
416408 GtkSizeGroup * button_size_group ;
417- GtkWidget * cancel_button ;
418- GtkWidget * button_area ;
419409 GtkWidget * scrolled_window ;
420410
421411 priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
@@ -450,11 +440,10 @@ xapp_icon_chooser_dialog_init (XAppIconChooserDialog *dialog)
450440
451441 gtk_window_set_default_size (GTK_WINDOW (dialog ), 600 , 450 );
452442 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog ), TRUE);
453- gtk_window_set_type_hint (GTK_WINDOW (dialog ), GDK_WINDOW_TYPE_HINT_DIALOG );
454443 gtk_window_set_title (GTK_WINDOW (dialog ), _ ("Choose an icon" ));
455444
456445 main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL , 0 );
457- gtk_container_add ( GTK_CONTAINER ( dialog ), main_box );
446+ gtk_box_pack_start ( GTK_BOX ( gtk_dialog_get_content_area ( GTK_DIALOG ( dialog ))) , main_box , TRUE, TRUE, 0 );
458447
459448 // toolbar
460449 toolbar = gtk_toolbar_new ();
@@ -576,40 +565,24 @@ xapp_icon_chooser_dialog_init (XAppIconChooserDialog *dialog)
576565 g_signal_connect (priv -> icon_view , "item-activated" ,
577566 G_CALLBACK (on_icon_view_item_activated ), dialog );
578567
579- // buttons
580- button_area = gtk_action_bar_new ();
581- priv -> action_area = button_area ;
582- gtk_box_pack_start (GTK_BOX (main_box ), button_area , FALSE, FALSE, 0 );
583-
584568 button_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL );
585569
586570 priv -> default_button = gtk_button_new_with_label (_ ("Default" ));
587571 gtk_widget_set_no_show_all (priv -> default_button , TRUE);
588572 style = gtk_widget_get_style_context (GTK_WIDGET (priv -> default_button ));
589573 gtk_style_context_add_class (style , "text-button" );
590574 gtk_size_group_add_widget (button_size_group , priv -> default_button );
591- gtk_action_bar_pack_start (GTK_ACTION_BAR (button_area ), priv -> default_button );
592-
575+ gtk_dialog_add_action_widget (GTK_DIALOG (dialog ), priv -> default_button , GTK_RESPONSE_NONE );
576+ gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog ))),
577+ priv -> default_button , TRUE);
593578 g_signal_connect (priv -> default_button , "clicked" ,
594579 G_CALLBACK (on_default_button_clicked ), dialog );
595580
596- priv -> select_button = gtk_button_new_with_label (_ ("Select" ));
597- style = gtk_widget_get_style_context (GTK_WIDGET (priv -> select_button ));
598- gtk_style_context_add_class (style , "text-button" );
599- gtk_size_group_add_widget (button_size_group , priv -> select_button );
600- gtk_action_bar_pack_end (GTK_ACTION_BAR (button_area ), priv -> select_button );
601-
602- g_signal_connect (priv -> select_button , "clicked" ,
603- G_CALLBACK (on_select_button_clicked ), dialog );
604-
605- cancel_button = gtk_button_new_with_label (_ ("Cancel" ));
606- style = gtk_widget_get_style_context (GTK_WIDGET (cancel_button ));
607- gtk_style_context_add_class (style , "text-button" );
608- gtk_size_group_add_widget (button_size_group , cancel_button );
609- gtk_action_bar_pack_end (GTK_ACTION_BAR (button_area ), cancel_button );
581+ gtk_dialog_add_button (GTK_DIALOG (dialog ), _ ("Cancel" ), GTK_RESPONSE_CANCEL );
610582
611- g_signal_connect (cancel_button , "clicked" ,
612- G_CALLBACK (on_cancel_button_clicked ), dialog );
583+ priv -> select_button = gtk_dialog_add_button (GTK_DIALOG (dialog ), _ ("Select" ), GTK_RESPONSE_OK );
584+ gtk_widget_set_can_default (priv -> select_button , TRUE);
585+ gtk_widget_grab_default (priv -> select_button );
613586
614587 load_categories (dialog );
615588}
@@ -669,14 +642,6 @@ xapp_icon_chooser_dialog_class_init (XAppIconChooserDialogClass *klass)
669642 g_object_class_install_properties (object_class , N_PROPERTIES , obj_properties );
670643
671644 // keybinding signals
672- signals [CLOSE ] =
673- g_signal_new ("close" ,
674- G_TYPE_FROM_CLASS (klass ),
675- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION ,
676- G_STRUCT_OFFSET (GtkWidgetClass , delete_event ),
677- NULL , NULL , NULL ,
678- G_TYPE_NONE , 0 );
679-
680645 signals [SELECT ] =
681646 g_signal_new ("select" ,
682647 G_TYPE_FROM_CLASS (klass ),
@@ -723,15 +688,16 @@ gint
723688xapp_icon_chooser_dialog_run (XAppIconChooserDialog * dialog )
724689{
725690 XAppIconChooserDialogPrivate * priv ;
691+ gint response ;
726692
727693 priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
728694
729695 gtk_widget_show_all (GTK_WIDGET (dialog ));
730696 gtk_widget_grab_focus (priv -> search_bar );
731697
732- gtk_main ( );
698+ response = gtk_dialog_run ( GTK_DIALOG ( dialog ) );
733699
734- return priv -> response ;
700+ return response ;
735701}
736702
737703/**
@@ -758,16 +724,17 @@ xapp_icon_chooser_dialog_run_with_icon (XAppIconChooserDialog *dialog,
758724 gchar * icon )
759725{
760726 XAppIconChooserDialogPrivate * priv ;
727+ gint response ;
761728
762729 priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
763730
764731 gtk_widget_show_all (GTK_WIDGET (dialog ));
765732 gtk_entry_set_text (GTK_ENTRY (priv -> search_bar ), icon );
766733 gtk_widget_grab_focus (priv -> search_bar );
767734
768- gtk_main ( );
735+ response = gtk_dialog_run ( GTK_DIALOG ( dialog ) );
769736
770- return priv -> response ;
737+ return response ;
771738}
772739
773740/**
@@ -792,6 +759,7 @@ xapp_icon_chooser_dialog_run_with_category (XAppIconChooserDialog *dialog,
792759{
793760 XAppIconChooserDialogPrivate * priv ;
794761 GList * children ;
762+ gint response ;
795763
796764 priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
797765
@@ -815,9 +783,9 @@ xapp_icon_chooser_dialog_run_with_category (XAppIconChooserDialog *dialog,
815783 }
816784 }
817785
818- gtk_main ( );
786+ response = gtk_dialog_run ( GTK_DIALOG ( dialog ) );
819787
820- return priv -> response ;
788+ return response ;
821789}
822790
823791/**
@@ -935,30 +903,19 @@ xapp_icon_chooser_dialog_close (XAppIconChooserDialog *dialog,
935903 priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
936904
937905 priv -> response = response ;
938- gtk_widget_hide (GTK_WIDGET (dialog ));
939-
940- gtk_main_quit ();
941- }
942-
943- static void
944- on_custom_button_clicked (GtkButton * button ,
945- gpointer user_data )
946- {
947- GtkResponseType response_id ;
948-
949- response_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button ), "response-id" ));
906+ gtk_dialog_response (GTK_DIALOG (dialog ), response );
950907
951- xapp_icon_chooser_dialog_close ( XAPP_ICON_CHOOSER_DIALOG ( user_data ), response_id );
908+ gtk_widget_hide ( GTK_WIDGET ( dialog ) );
952909}
953910
954911/**
955912 * xapp_icon_chooser_dialog_add_button:
956913 * @dialog: an #XAppIconChooserDialog
957914 * @button: a #GtkButton to add
958- * @packing: the #GtkPackType to specify start or end packing to the action bar
915+ * @packing: the #GtkPackType to specify start or end packing to the action area
959916 * @response_id: the dialog response id to return when this button is clicked.
960917 *
961- * Allows a button to be added to the #GtkActionBar of the dialog with a custom
918+ * Allows a button to be added to the action area of the dialog with a custom
962919 * response id.
963920 */
964921void
@@ -967,26 +924,14 @@ xapp_icon_chooser_dialog_add_button (XAppIconChooserDialog *dialog,
967924 GtkPackType packing ,
968925 GtkResponseType response_id )
969926{
970- XAppIconChooserDialogPrivate * priv ;
927+ GtkWidget * action_area ;
971928
972- priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
973-
974- g_signal_connect (button ,
975- "clicked" ,
976- G_CALLBACK (on_custom_button_clicked ),
977- dialog );
978-
979- /* This saves having to use a custom container for callback data. */
980- g_object_set_data (G_OBJECT (button ),
981- "response-id" , GINT_TO_POINTER (response_id ));
929+ gtk_dialog_add_action_widget (GTK_DIALOG (dialog ), button , response_id );
982930
983931 if (packing == GTK_PACK_START )
984932 {
985- gtk_action_bar_pack_start (GTK_ACTION_BAR (priv -> action_area ), button );
986- }
987- else
988- {
989- gtk_action_bar_pack_end (GTK_ACTION_BAR (priv -> action_area ), button );
933+ action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog ));
934+ gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area ), button , TRUE);
990935 }
991936}
992937
@@ -1972,20 +1917,6 @@ on_browse_button_clicked (GtkButton *button,
19721917 gtk_widget_destroy (file_dialog );
19731918}
19741919
1975- static void
1976- on_select_button_clicked (GtkButton * button ,
1977- gpointer user_data )
1978- {
1979- xapp_icon_chooser_dialog_close (XAPP_ICON_CHOOSER_DIALOG (user_data ), GTK_RESPONSE_OK );
1980- }
1981-
1982- static void
1983- on_cancel_button_clicked (GtkButton * button ,
1984- gpointer user_data )
1985- {
1986- xapp_icon_chooser_dialog_close (XAPP_ICON_CHOOSER_DIALOG (user_data ), GTK_RESPONSE_CANCEL );
1987- }
1988-
19891920static gboolean
19901921on_delete_event (GtkWidget * widget ,
19911922 GdkEventAny * event )
0 commit comments