@@ -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 ,
@@ -378,6 +370,13 @@ xapp_icon_chooser_dialog_dispose (GObject *object)
378370 dialog = XAPP_ICON_CHOOSER_DIALOG (object );
379371 priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
380372
373+ if (priv -> cancellable != NULL )
374+ {
375+ g_cancellable_cancel (priv -> cancellable );
376+ g_object_unref (priv -> cancellable );
377+ priv -> cancellable = NULL ;
378+ }
379+
381380 if (priv -> categories != NULL )
382381 {
383382 g_hash_table_destroy (priv -> categories );
@@ -393,7 +392,6 @@ xapp_icon_chooser_dialog_dispose (GObject *object)
393392 g_clear_pointer (& priv -> icon_string , g_free );
394393 g_clear_pointer (& priv -> default_icon , g_free );
395394 g_clear_pointer (& priv -> current_text , g_free );
396- g_clear_object (& priv -> cancellable );
397395
398396 G_OBJECT_CLASS (xapp_icon_chooser_dialog_parent_class )-> dispose (object );
399397}
@@ -414,8 +412,6 @@ xapp_icon_chooser_dialog_init (XAppIconChooserDialog *dialog)
414412 GtkWidget * right_box ;
415413 GtkStyleContext * style ;
416414 GtkSizeGroup * button_size_group ;
417- GtkWidget * cancel_button ;
418- GtkWidget * button_area ;
419415 GtkWidget * scrolled_window ;
420416
421417 priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
@@ -450,11 +446,10 @@ xapp_icon_chooser_dialog_init (XAppIconChooserDialog *dialog)
450446
451447 gtk_window_set_default_size (GTK_WINDOW (dialog ), 600 , 450 );
452448 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog ), TRUE);
453- gtk_window_set_type_hint (GTK_WINDOW (dialog ), GDK_WINDOW_TYPE_HINT_DIALOG );
454449 gtk_window_set_title (GTK_WINDOW (dialog ), _ ("Choose an icon" ));
455450
456451 main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL , 0 );
457- gtk_container_add ( GTK_CONTAINER ( dialog ), main_box );
452+ gtk_box_pack_start ( GTK_BOX ( gtk_dialog_get_content_area ( GTK_DIALOG ( dialog ))) , main_box , TRUE, TRUE, 0 );
458453
459454 // toolbar
460455 toolbar = gtk_toolbar_new ();
@@ -576,40 +571,24 @@ xapp_icon_chooser_dialog_init (XAppIconChooserDialog *dialog)
576571 g_signal_connect (priv -> icon_view , "item-activated" ,
577572 G_CALLBACK (on_icon_view_item_activated ), dialog );
578573
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-
584574 button_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL );
585575
586576 priv -> default_button = gtk_button_new_with_label (_ ("Default" ));
587577 gtk_widget_set_no_show_all (priv -> default_button , TRUE);
588578 style = gtk_widget_get_style_context (GTK_WIDGET (priv -> default_button ));
589579 gtk_style_context_add_class (style , "text-button" );
590580 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-
581+ gtk_dialog_add_action_widget (GTK_DIALOG (dialog ), priv -> default_button , GTK_RESPONSE_NONE );
582+ gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog ))),
583+ priv -> default_button , TRUE);
593584 g_signal_connect (priv -> default_button , "clicked" ,
594585 G_CALLBACK (on_default_button_clicked ), dialog );
595586
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 );
587+ gtk_dialog_add_button (GTK_DIALOG (dialog ), _ ("Cancel" ), GTK_RESPONSE_CANCEL );
601588
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 );
610-
611- g_signal_connect (cancel_button , "clicked" ,
612- G_CALLBACK (on_cancel_button_clicked ), dialog );
589+ priv -> select_button = gtk_dialog_add_button (GTK_DIALOG (dialog ), _ ("Select" ), GTK_RESPONSE_OK );
590+ gtk_widget_set_can_default (priv -> select_button , TRUE);
591+ gtk_widget_grab_default (priv -> select_button );
613592
614593 load_categories (dialog );
615594}
@@ -669,14 +648,6 @@ xapp_icon_chooser_dialog_class_init (XAppIconChooserDialogClass *klass)
669648 g_object_class_install_properties (object_class , N_PROPERTIES , obj_properties );
670649
671650 // 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-
680651 signals [SELECT ] =
681652 g_signal_new ("select" ,
682653 G_TYPE_FROM_CLASS (klass ),
@@ -723,15 +694,16 @@ gint
723694xapp_icon_chooser_dialog_run (XAppIconChooserDialog * dialog )
724695{
725696 XAppIconChooserDialogPrivate * priv ;
697+ gint response ;
726698
727699 priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
728700
729701 gtk_widget_show_all (GTK_WIDGET (dialog ));
730702 gtk_widget_grab_focus (priv -> search_bar );
731703
732- gtk_main ( );
704+ response = gtk_dialog_run ( GTK_DIALOG ( dialog ) );
733705
734- return priv -> response ;
706+ return response ;
735707}
736708
737709/**
@@ -758,16 +730,17 @@ xapp_icon_chooser_dialog_run_with_icon (XAppIconChooserDialog *dialog,
758730 gchar * icon )
759731{
760732 XAppIconChooserDialogPrivate * priv ;
733+ gint response ;
761734
762735 priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
763736
764737 gtk_widget_show_all (GTK_WIDGET (dialog ));
765738 gtk_entry_set_text (GTK_ENTRY (priv -> search_bar ), icon );
766739 gtk_widget_grab_focus (priv -> search_bar );
767740
768- gtk_main ( );
741+ response = gtk_dialog_run ( GTK_DIALOG ( dialog ) );
769742
770- return priv -> response ;
743+ return response ;
771744}
772745
773746/**
@@ -792,6 +765,7 @@ xapp_icon_chooser_dialog_run_with_category (XAppIconChooserDialog *dialog,
792765{
793766 XAppIconChooserDialogPrivate * priv ;
794767 GList * children ;
768+ gint response ;
795769
796770 priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
797771
@@ -815,9 +789,9 @@ xapp_icon_chooser_dialog_run_with_category (XAppIconChooserDialog *dialog,
815789 }
816790 }
817791
818- gtk_main ( );
792+ response = gtk_dialog_run ( GTK_DIALOG ( dialog ) );
819793
820- return priv -> response ;
794+ return response ;
821795}
822796
823797/**
@@ -935,32 +909,19 @@ xapp_icon_chooser_dialog_close (XAppIconChooserDialog *dialog,
935909 priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
936910
937911 priv -> response = response ;
938- g_cancellable_cancel (priv -> cancellable );
939-
940- gtk_widget_hide (GTK_WIDGET (dialog ));
941-
942- gtk_main_quit ();
943- }
912+ gtk_dialog_response (GTK_DIALOG (dialog ), response );
944913
945- static void
946- on_custom_button_clicked (GtkButton * button ,
947- gpointer user_data )
948- {
949- GtkResponseType response_id ;
950-
951- response_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button ), "response-id" ));
952-
953- xapp_icon_chooser_dialog_close (XAPP_ICON_CHOOSER_DIALOG (user_data ), response_id );
914+ gtk_widget_hide (GTK_WIDGET (dialog ));
954915}
955916
956917/**
957918 * xapp_icon_chooser_dialog_add_button:
958919 * @dialog: an #XAppIconChooserDialog
959920 * @button: a #GtkButton to add
960- * @packing: the #GtkPackType to specify start or end packing to the action bar
921+ * @packing: the #GtkPackType to specify start or end packing to the action area
961922 * @response_id: the dialog response id to return when this button is clicked.
962923 *
963- * Allows a button to be added to the #GtkActionBar of the dialog with a custom
924+ * Allows a button to be added to the action area of the dialog with a custom
964925 * response id.
965926 */
966927void
@@ -969,26 +930,14 @@ xapp_icon_chooser_dialog_add_button (XAppIconChooserDialog *dialog,
969930 GtkPackType packing ,
970931 GtkResponseType response_id )
971932{
972- XAppIconChooserDialogPrivate * priv ;
973-
974- priv = xapp_icon_chooser_dialog_get_instance_private (dialog );
933+ GtkWidget * action_area ;
975934
976- g_signal_connect (button ,
977- "clicked" ,
978- G_CALLBACK (on_custom_button_clicked ),
979- dialog );
980-
981- /* This saves having to use a custom container for callback data. */
982- g_object_set_data (G_OBJECT (button ),
983- "response-id" , GINT_TO_POINTER (response_id ));
935+ gtk_dialog_add_action_widget (GTK_DIALOG (dialog ), button , response_id );
984936
985937 if (packing == GTK_PACK_START )
986938 {
987- gtk_action_bar_pack_start (GTK_ACTION_BAR (priv -> action_area ), button );
988- }
989- else
990- {
991- gtk_action_bar_pack_end (GTK_ACTION_BAR (priv -> action_area ), button );
939+ action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog ));
940+ gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area ), button , TRUE);
992941 }
993942}
994943
@@ -1974,20 +1923,6 @@ on_browse_button_clicked (GtkButton *button,
19741923 gtk_widget_destroy (file_dialog );
19751924}
19761925
1977- static void
1978- on_select_button_clicked (GtkButton * button ,
1979- gpointer user_data )
1980- {
1981- xapp_icon_chooser_dialog_close (XAPP_ICON_CHOOSER_DIALOG (user_data ), GTK_RESPONSE_OK );
1982- }
1983-
1984- static void
1985- on_cancel_button_clicked (GtkButton * button ,
1986- gpointer user_data )
1987- {
1988- xapp_icon_chooser_dialog_close (XAPP_ICON_CHOOSER_DIALOG (user_data ), GTK_RESPONSE_CANCEL );
1989- }
1990-
19911926static gboolean
19921927on_delete_event (GtkWidget * widget ,
19931928 GdkEventAny * event )
0 commit comments