Skip to content

Commit af15505

Browse files
committed
Stop creating styles with ESC key or [Cancel] button.
When mutiple images are selected and the [Create] button of the styles modules is clicked one may want to stop the process. Using the button [Cancel] on the dialog or ESC key stop the process. Closes #18555.
1 parent 59d00e5 commit af15505

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

src/common/styles.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of darktable,
3-
Copyright (C) 2010-2024 darktable developers.
3+
Copyright (C) 2010-2025 darktable developers.
44
55
darktable is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -651,8 +651,9 @@ void dt_styles_create_from_list(const GList *list)
651651
for(const GList *l = list; l; l = g_list_next(l))
652652
{
653653
const dt_imgid_t imgid = GPOINTER_TO_INT(l->data);
654-
dt_gui_styles_dialog_new(imgid);
655654
selected = TRUE;
655+
if(!dt_gui_styles_dialog_new(imgid))
656+
break;
656657
}
657658

658659
if(!selected) dt_control_log(_("no image selected!"));

src/gui/styles.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of darktable,
3-
Copyright (C) 2010-2024 darktable developers.
3+
Copyright (C) 2010-2025 darktable developers.
44
55
darktable is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -24,11 +24,13 @@
2424
/** returns NULL if the contents are not valid XML or do not name the style */
2525
gchar *dt_get_style_name(const char *filename);
2626

27-
/** import styles stored in the shared directory if they are not already in our database */
27+
/** import styles stored in the shared directory if they are not
28+
* already in our database */
2829
void dt_import_default_styles(const char *sharedir);
2930

30-
/** shows a dialog for creating a new style */
31-
void dt_gui_styles_dialog_new(const dt_imgid_t imgid);
31+
/** shows a dialog for creating a new style, return FALSE if cancel
32+
* button clicked */
33+
gboolean dt_gui_styles_dialog_new(const dt_imgid_t imgid);
3234

3335
/** shows a dialog for editing existing style */
3436
void dt_gui_styles_dialog_edit(const char *name, char **new_name);

src/gui/styles_dialog.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@
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

3939
typedef 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

500504
void 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

Comments
 (0)