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,8 @@ 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+
200203 if (response_id == GTK_RESPONSE_YES )
201204 {
202205 _gui_styles_select_all_items (g , TRUE);
@@ -269,7 +272,6 @@ static void _gui_styles_new_style_response(GtkDialog *dialog,
269272
270273 // finalize the dialog
271274 g_free (g -> nameorig );
272- g_free (g );
273275
274276 gtk_widget_destroy (GTK_WIDGET (dialog ));
275277}
@@ -278,6 +280,8 @@ static void _gui_styles_edit_style_response(GtkDialog *dialog,
278280 const gint response_id ,
279281 dt_gui_styles_dialog_t * g )
280282{
283+ g -> cancelled = response_id == GTK_RESPONSE_DELETE_EVENT ;
284+
281285 if (response_id == GTK_RESPONSE_YES )
282286 {
283287 _gui_styles_select_all_items (g , TRUE);
@@ -288,14 +292,13 @@ static void _gui_styles_edit_style_response(GtkDialog *dialog,
288292 _gui_styles_select_all_items (g , FALSE);
289293 return ;
290294 }
295+ else if (response_id == GTK_RESPONSE_ACCEPT )
296+ {
297+ char * newname = g_strdup (gtk_entry_get_text (GTK_ENTRY (g -> name )));
291298
292- char * newname = g_strdup (gtk_entry_get_text (GTK_ENTRY (g -> name )));
293-
294- if (g -> newname )
295- * g -> newname = newname ;
299+ if (g -> newname )
300+ * g -> newname = newname ;
296301
297- if (response_id == GTK_RESPONSE_ACCEPT )
298- {
299302 /* get the filtered list from dialog */
300303 GList * result = NULL , * update = NULL ;
301304
@@ -349,7 +352,6 @@ static void _gui_styles_edit_style_response(GtkDialog *dialog,
349352
350353 // finalize the dialog
351354 g_free (g -> nameorig );
352- g_free (g );
353355
354356 gtk_widget_destroy (GTK_WIDGET (dialog ));
355357}
@@ -492,9 +494,9 @@ static void _gui_styles_update_toggled(GtkCellRendererToggle *cell,
492494 gtk_tree_path_free (path );
493495}
494496
495- void dt_gui_styles_dialog_new (const dt_imgid_t imgid )
497+ gboolean dt_gui_styles_dialog_new (const dt_imgid_t imgid )
496498{
497- _gui_styles_dialog_run (FALSE, NULL , imgid , NULL );
499+ return _gui_styles_dialog_run (FALSE, NULL , imgid , NULL );
498500}
499501
500502void dt_gui_styles_dialog_edit (const char * name , char * * new_name )
@@ -514,22 +516,23 @@ static void _name_changed(GtkEntry *entry,
514516 gtk_dialog_set_response_sensitive (dialog , GTK_RESPONSE_ACCEPT , name && * name );
515517}
516518
517- static void _gui_styles_dialog_run (gboolean edit ,
518- const char * name ,
519- const dt_imgid_t imgid ,
520- char * * new_name )
519+ static gboolean _gui_styles_dialog_run (const gboolean edit ,
520+ const char * name ,
521+ const dt_imgid_t imgid ,
522+ char * * new_name )
521523{
522524 char title [512 ];
523525
524526 /* check if style exists */
525- if (name && (dt_styles_exists (name )) == 0 ) return ;
527+ if (name && (dt_styles_exists (name )) == 0 ) return TRUE ;
526528
527529 /* initialize the dialog */
528530 dt_gui_styles_dialog_t * sd = g_malloc0 (sizeof (dt_gui_styles_dialog_t ));
529531
530532 sd -> nameorig = g_strdup (name );
531533 sd -> imgid = imgid ;
532534 sd -> newname = new_name ;
535+ sd -> cancelled = FALSE;
533536
534537 if (edit )
535538 {
@@ -835,7 +838,7 @@ static void _gui_styles_dialog_run(gboolean edit,
835838 else
836839 {
837840 dt_control_log (_ ("can't create style out of unaltered image" ));
838- return ;
841+ return TRUE ;
839842 }
840843 }
841844
@@ -860,8 +863,13 @@ static void _gui_styles_dialog_run(gboolean edit,
860863 gtk_widget_show_all (GTK_WIDGET (dialog ));
861864 gtk_dialog_run (GTK_DIALOG (dialog ));
862865
866+ const gboolean res = !sd -> cancelled ;
867+
863868 g_object_unref (is_active_pb );
864869 g_object_unref (is_inactive_pb );
870+ g_free (sd );
871+
872+ return res ;
865873}
866874
867875// style preview
0 commit comments