3131#endif
3232
3333/* creates a styles dialog, if edit equals true id=styleid else id=imgid */
34- static void _gui_styles_dialog_run (gboolean edit ,
35- const char * name ,
36- const dt_imgid_t imgid ,
37- char * * new_name );
34+ static gboolean _gui_styles_dialog_run (const gboolean edit ,
35+ const char * name ,
36+ const dt_imgid_t imgid ,
37+ char * * new_name );
3838
3939typedef struct dt_gui_styles_dialog_t
4040{
4141 gboolean edit ;
4242 dt_imgid_t imgid ;
43+ gboolean cancelled ;
4344 gchar * nameorig ;
4445 gchar * * newname ;
4546 GtkWidget * name , * description , * duplicate ;
@@ -197,6 +198,9 @@ static void _gui_styles_new_style_response(GtkDialog *dialog,
197198 const gint response_id ,
198199 dt_gui_styles_dialog_t * g )
199200{
201+ g -> cancelled = (response_id == GTK_RESPONSE_DELETE_EVENT )
202+ || (response_id == GTK_RESPONSE_REJECT );
203+
200204 if (response_id == GTK_RESPONSE_YES )
201205 {
202206 _gui_styles_select_all_items (g , TRUE);
@@ -269,7 +273,6 @@ static void _gui_styles_new_style_response(GtkDialog *dialog,
269273
270274 // finalize the dialog
271275 g_free (g -> nameorig );
272- g_free (g );
273276
274277 gtk_widget_destroy (GTK_WIDGET (dialog ));
275278}
@@ -278,6 +281,9 @@ static void _gui_styles_edit_style_response(GtkDialog *dialog,
278281 const gint response_id ,
279282 dt_gui_styles_dialog_t * g )
280283{
284+ g -> cancelled = (response_id == GTK_RESPONSE_DELETE_EVENT )
285+ || (response_id == GTK_RESPONSE_REJECT );
286+
281287 if (response_id == GTK_RESPONSE_YES )
282288 {
283289 _gui_styles_select_all_items (g , TRUE);
@@ -288,14 +294,13 @@ static void _gui_styles_edit_style_response(GtkDialog *dialog,
288294 _gui_styles_select_all_items (g , FALSE);
289295 return ;
290296 }
297+ else if (response_id == GTK_RESPONSE_ACCEPT )
298+ {
299+ char * newname = g_strdup (gtk_entry_get_text (GTK_ENTRY (g -> name )));
291300
292- char * newname = g_strdup (gtk_entry_get_text (GTK_ENTRY (g -> name )));
293-
294- if (g -> newname )
295- * g -> newname = newname ;
301+ if (g -> newname )
302+ * g -> newname = newname ;
296303
297- if (response_id == GTK_RESPONSE_ACCEPT )
298- {
299304 /* get the filtered list from dialog */
300305 GList * result = NULL , * update = NULL ;
301306
@@ -349,7 +354,6 @@ static void _gui_styles_edit_style_response(GtkDialog *dialog,
349354
350355 // finalize the dialog
351356 g_free (g -> nameorig );
352- g_free (g );
353357
354358 gtk_widget_destroy (GTK_WIDGET (dialog ));
355359}
@@ -492,9 +496,9 @@ static void _gui_styles_update_toggled(GtkCellRendererToggle *cell,
492496 gtk_tree_path_free (path );
493497}
494498
495- void dt_gui_styles_dialog_new (const dt_imgid_t imgid )
499+ gboolean dt_gui_styles_dialog_new (const dt_imgid_t imgid )
496500{
497- _gui_styles_dialog_run (FALSE, NULL , imgid , NULL );
501+ return _gui_styles_dialog_run (FALSE, NULL , imgid , NULL );
498502}
499503
500504void dt_gui_styles_dialog_edit (const char * name , char * * new_name )
@@ -514,22 +518,23 @@ static void _name_changed(GtkEntry *entry,
514518 gtk_dialog_set_response_sensitive (dialog , GTK_RESPONSE_ACCEPT , name && * name );
515519}
516520
517- static void _gui_styles_dialog_run (gboolean edit ,
518- const char * name ,
519- const dt_imgid_t imgid ,
520- char * * new_name )
521+ static gboolean _gui_styles_dialog_run (const gboolean edit ,
522+ const char * name ,
523+ const dt_imgid_t imgid ,
524+ char * * new_name )
521525{
522526 char title [512 ];
523527
524528 /* check if style exists */
525- if (name && (dt_styles_exists (name )) == 0 ) return ;
529+ if (name && (dt_styles_exists (name )) == 0 ) return TRUE ;
526530
527531 /* initialize the dialog */
528532 dt_gui_styles_dialog_t * sd = g_malloc0 (sizeof (dt_gui_styles_dialog_t ));
529533
530534 sd -> nameorig = g_strdup (name );
531535 sd -> imgid = imgid ;
532536 sd -> newname = new_name ;
537+ sd -> cancelled = FALSE;
533538
534539 if (edit )
535540 {
@@ -835,7 +840,7 @@ static void _gui_styles_dialog_run(gboolean edit,
835840 else
836841 {
837842 dt_control_log (_ ("can't create style out of unaltered image" ));
838- return ;
843+ return TRUE ;
839844 }
840845 }
841846
@@ -860,8 +865,13 @@ static void _gui_styles_dialog_run(gboolean edit,
860865 gtk_widget_show_all (GTK_WIDGET (dialog ));
861866 gtk_dialog_run (GTK_DIALOG (dialog ));
862867
868+ const gboolean res = !sd -> cancelled ;
869+
863870 g_object_unref (is_active_pb );
864871 g_object_unref (is_inactive_pb );
872+ g_free (sd );
873+
874+ return res ;
865875}
866876
867877// style preview
0 commit comments