3434#include "nip4.h"
3535
3636struct _SaveOptions {
37- GtkDialog parent_instance ;
37+ GtkApplicationWindow parent_instance ;
3838
3939 VipsImage * image ;
4040 VipsOperation * save_operation ;
@@ -47,7 +47,7 @@ struct _SaveOptions {
4747 GtkWidget * progress ;
4848 GtkWidget * error_bar ;
4949 GtkWidget * error_label ;
50- GtkWidget * ok_button ;
50+ GtkWidget * title ;
5151
5252 // hash property names to the widget for that property ... we fetch
5353 // values from here when we make the saver
@@ -60,10 +60,10 @@ struct _SaveOptions {
6060};
6161
6262struct _SaveOptionsClass {
63- GtkDialogClass parent_class ;
63+ GtkApplicationWindowClass parent_class ;
6464};
6565
66- G_DEFINE_TYPE (SaveOptions , save_options , GTK_TYPE_DIALOG );
66+ G_DEFINE_TYPE (SaveOptions , save_options , GTK_TYPE_APPLICATION_WINDOW );
6767
6868static void
6969save_options_dispose (GObject * object )
@@ -81,32 +81,17 @@ save_options_dispose(GObject *object)
8181static void
8282save_options_error (SaveOptions * options )
8383{
84- int i ;
85-
8684 /* Remove any trailing \n.
8785 */
8886 g_autofree char * err = vips_error_buffer_copy ();
8987 vips_error_clear ();
90- for (i = strlen (err ); i > 0 && err [i - 1 ] == '\n' ; i -- )
88+ for (int i = strlen (err ); i > 0 && err [i - 1 ] == '\n' ; i -- )
9189 err [i - 1 ] = '\0' ;
9290 gtk_label_set_text (GTK_LABEL (options -> error_label ), err );
9391
9492 gtk_info_bar_set_revealed (GTK_INFO_BAR (options -> error_bar ), TRUE);
9593}
9694
97- static void
98- save_options_error_hide (SaveOptions * options )
99- {
100- gtk_info_bar_set_revealed (GTK_INFO_BAR (options -> error_bar ), FALSE);
101- }
102-
103- static void
104- save_options_error_response (GtkWidget * button , int response ,
105- SaveOptions * options )
106- {
107- save_options_error_hide (options );
108- }
109-
11095static void
11196save_options_preeval (VipsImage * image ,
11297 VipsProgress * progress , SaveOptions * options )
@@ -287,7 +272,7 @@ save_options_fetch_option(SaveOptions *options, GParamSpec *pspec)
287272}
288273
289274static void *
290- save_options_response_map_fn (VipsObject * operation ,
275+ save_options_set_argument (VipsObject * operation ,
291276 GParamSpec * pspec , VipsArgumentClass * argument_class ,
292277 VipsArgumentInstance * argument_instance , void * a , void * b )
293278{
@@ -307,42 +292,61 @@ save_options_response_map_fn(VipsObject *operation,
307292}
308293
309294static void
310- save_options_response (GtkWidget * dialog , int response , void * user_data )
295+ save_options_ok_action (GSimpleAction * action ,
296+ GVariant * parameter , gpointer user_data )
311297{
312- SaveOptions * options = SAVE_OPTIONS (dialog );
298+ SaveOptions * options = SAVE_OPTIONS (user_data );
313299
314- if (response == GTK_RESPONSE_OK ) {
315- vips_argument_map (VIPS_OBJECT (options -> save_operation ),
316- save_options_response_map_fn , options , NULL );
317-
318- // this will trigger the save and loop while we write ... the
319- // UI will stay live thanks to event processing in the eval
320- // handler
321- if (vips_cache_operation_buildp (& options -> save_operation ))
322- save_options_error (options );
323- else
324- // everything worked, we can post success back to
325- // our caller
326- gtk_dialog_response (GTK_DIALOG (dialog ), GTK_RESPONSE_ACCEPT );
327- }
300+ vips_argument_map (VIPS_OBJECT (options -> save_operation ),
301+ save_options_set_argument , options , NULL );
302+
303+ // this will trigger the save and loop while we write ... the
304+ // UI will stay live thanks to event processing in the eval
305+ // handler
306+ if (vips_cache_operation_buildp (& options -> save_operation ))
307+ save_options_error (options );
308+ else
309+ // everything worked, we can post success back to
310+ // our caller
311+ gtk_window_destroy (GTK_WINDOW (options ));
328312}
329313
330314static void
331- save_options_cancel_clicked (GtkWidget * button , SaveOptions * options )
315+ save_options_cancel_action (GSimpleAction * action ,
316+ GVariant * parameter , gpointer user_data )
332317{
333- vips_image_set_kill (options -> image , TRUE);
318+ SaveOptions * options = SAVE_OPTIONS (user_data );
319+
320+ gtk_window_destroy (GTK_WINDOW (options ));
334321}
335322
323+ static GActionEntry save_options_entries [] = {
324+ { "ok" , save_options_ok_action },
325+ { "cancel" , save_options_cancel_action },
326+ };
327+
336328static void
337329save_options_init (SaveOptions * options )
338330{
339331 gtk_widget_init_template (GTK_WIDGET (options ));
340332
333+ g_action_map_add_action_entries (G_ACTION_MAP (options ),
334+ save_options_entries , G_N_ELEMENTS (save_options_entries ),
335+ options );
336+
341337 options -> value_widgets = g_hash_table_new (g_str_hash , g_str_equal );
342338
343339 options -> progress_timer = g_timer_new ();
344340}
345341
342+ static void
343+ save_options_cancel_clicked (GtkWidget * button , gpointer user_data )
344+ {
345+ SaveOptions * options = SAVE_OPTIONS (user_data );
346+
347+ vips_image_set_kill (options -> image , TRUE);
348+ }
349+
346350static void
347351save_options_class_init (SaveOptionsClass * class )
348352{
@@ -357,11 +361,9 @@ save_options_class_init(SaveOptionsClass *class)
357361 BIND_VARIABLE (SaveOptions , error_bar );
358362 BIND_VARIABLE (SaveOptions , error_label );
359363 BIND_VARIABLE (SaveOptions , options_grid );
360- BIND_VARIABLE (SaveOptions , ok_button );
364+ BIND_VARIABLE (SaveOptions , title );
361365
362- BIND_CALLBACK (save_options_response );
363366 BIND_CALLBACK (save_options_cancel_clicked );
364- BIND_CALLBACK (save_options_error_response );
365367}
366368
367369/* This function is used by:
@@ -569,15 +571,14 @@ save_options_new(GtkWindow *parent_window,
569571 const char * saver ;
570572 SaveOptions * options ;
571573
572- g_autofree char * base = g_path_get_basename (filename );
573- g_autofree char * title = g_strdup_printf ("Save image to \"%s\"" , base );
574574 options = g_object_new (SAVE_OPTIONS_TYPE ,
575- // we have to set this here, not in the ui file, for some reason
576- "use-header-bar" , true,
577575 "transient-for" , parent_window ,
578- "title " , title ,
576+ "application " , gtk_window_get_application ( parent_window ) ,
579577 NULL );
580578
579+ g_autofree char * base = g_path_get_basename (filename );
580+ set_glabel (options -> title , "Save image to \"%s\"" , base );
581+
581582 options -> image = image ;
582583 g_object_ref (image );
583584
@@ -608,7 +609,5 @@ save_options_new(GtkWindow *parent_window,
608609 save_options_add_options_fn , options , & row );
609610 }
610611
611- gtk_widget_grab_focus (options -> ok_button );
612-
613612 return options ;
614613}
0 commit comments