Skip to content

Commit 577cdb1

Browse files
committed
Stop creating styles with ESC key.
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 just ignore the current image but continue with the next one selected. Using the ESC key the whole process is stopped. Closes #18555.
1 parent 25921fc commit 577cdb1

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-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: 28 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,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

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

Comments
 (0)