Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/common/styles.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2010-2024 darktable developers.
Copyright (C) 2010-2025 darktable developers.

darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -651,8 +651,9 @@ void dt_styles_create_from_list(const GList *list)
for(const GList *l = list; l; l = g_list_next(l))
{
const dt_imgid_t imgid = GPOINTER_TO_INT(l->data);
dt_gui_styles_dialog_new(imgid);
selected = TRUE;
if(!dt_gui_styles_dialog_new(imgid))
break;
}

if(!selected) dt_control_log(_("no image selected!"));
Expand Down
10 changes: 6 additions & 4 deletions src/gui/styles.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2010-2024 darktable developers.
Copyright (C) 2010-2025 darktable developers.

darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -24,11 +24,13 @@
/** returns NULL if the contents are not valid XML or do not name the style */
gchar *dt_get_style_name(const char *filename);

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

/** shows a dialog for creating a new style */
void dt_gui_styles_dialog_new(const dt_imgid_t imgid);
/** shows a dialog for creating a new style, return FALSE if cancel
* button clicked */
gboolean dt_gui_styles_dialog_new(const dt_imgid_t imgid);

/** shows a dialog for editing existing style */
void dt_gui_styles_dialog_edit(const char *name, char **new_name);
Expand Down
50 changes: 30 additions & 20 deletions src/gui/styles_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@
#endif

/* creates a styles dialog, if edit equals true id=styleid else id=imgid */
static void _gui_styles_dialog_run(gboolean edit,
const char *name,
const dt_imgid_t imgid,
char **new_name);
static gboolean _gui_styles_dialog_run(const gboolean edit,
const char *name,
const dt_imgid_t imgid,
char **new_name);

typedef struct dt_gui_styles_dialog_t
{
gboolean edit;
dt_imgid_t imgid;
gboolean cancelled;
gchar *nameorig;
gchar **newname;
GtkWidget *name, *description, *duplicate;
Expand Down Expand Up @@ -197,6 +198,9 @@ static void _gui_styles_new_style_response(GtkDialog *dialog,
const gint response_id,
dt_gui_styles_dialog_t *g)
{
g->cancelled = (response_id == GTK_RESPONSE_DELETE_EVENT)
|| (response_id == GTK_RESPONSE_REJECT);

if(response_id == GTK_RESPONSE_YES)
{
_gui_styles_select_all_items(g, TRUE);
Expand Down Expand Up @@ -269,7 +273,6 @@ static void _gui_styles_new_style_response(GtkDialog *dialog,

// finalize the dialog
g_free(g->nameorig);
g_free(g);

gtk_widget_destroy(GTK_WIDGET(dialog));
}
Expand All @@ -278,6 +281,9 @@ static void _gui_styles_edit_style_response(GtkDialog *dialog,
const gint response_id,
dt_gui_styles_dialog_t *g)
{
g->cancelled = (response_id == GTK_RESPONSE_DELETE_EVENT)
|| (response_id == GTK_RESPONSE_REJECT);

if(response_id == GTK_RESPONSE_YES)
{
_gui_styles_select_all_items(g, TRUE);
Expand All @@ -288,14 +294,13 @@ static void _gui_styles_edit_style_response(GtkDialog *dialog,
_gui_styles_select_all_items(g, FALSE);
return;
}
else if(response_id == GTK_RESPONSE_ACCEPT)
{
char *newname = g_strdup(gtk_entry_get_text(GTK_ENTRY(g->name)));

char *newname = g_strdup(gtk_entry_get_text(GTK_ENTRY(g->name)));

if(g->newname)
*g->newname = newname;
if(g->newname)
*g->newname = newname;

if(response_id == GTK_RESPONSE_ACCEPT)
{
/* get the filtered list from dialog */
GList *result = NULL, *update = NULL;

Expand Down Expand Up @@ -349,7 +354,6 @@ static void _gui_styles_edit_style_response(GtkDialog *dialog,

// finalize the dialog
g_free(g->nameorig);
g_free(g);

gtk_widget_destroy(GTK_WIDGET(dialog));
}
Expand Down Expand Up @@ -492,9 +496,9 @@ static void _gui_styles_update_toggled(GtkCellRendererToggle *cell,
gtk_tree_path_free(path);
}

void dt_gui_styles_dialog_new(const dt_imgid_t imgid)
gboolean dt_gui_styles_dialog_new(const dt_imgid_t imgid)
{
_gui_styles_dialog_run(FALSE, NULL, imgid, NULL);
return _gui_styles_dialog_run(FALSE, NULL, imgid, NULL);
}

void dt_gui_styles_dialog_edit(const char *name, char **new_name)
Expand All @@ -514,22 +518,23 @@ static void _name_changed(GtkEntry *entry,
gtk_dialog_set_response_sensitive(dialog, GTK_RESPONSE_ACCEPT, name && *name);
}

static void _gui_styles_dialog_run(gboolean edit,
const char *name,
const dt_imgid_t imgid,
char **new_name)
static gboolean _gui_styles_dialog_run(const gboolean edit,
const char *name,
const dt_imgid_t imgid,
char **new_name)
{
char title[512];

/* check if style exists */
if(name && (dt_styles_exists(name)) == 0) return;
if(name && (dt_styles_exists(name)) == 0) return TRUE;

/* initialize the dialog */
dt_gui_styles_dialog_t *sd = g_malloc0(sizeof(dt_gui_styles_dialog_t));

sd->nameorig = g_strdup(name);
sd->imgid = imgid;
sd->newname = new_name;
sd->cancelled = FALSE;

if(edit)
{
Expand Down Expand Up @@ -835,7 +840,7 @@ static void _gui_styles_dialog_run(gboolean edit,
else
{
dt_control_log(_("can't create style out of unaltered image"));
return;
return TRUE;
}
}

Expand All @@ -860,8 +865,13 @@ static void _gui_styles_dialog_run(gboolean edit,
gtk_widget_show_all(GTK_WIDGET(dialog));
gtk_dialog_run(GTK_DIALOG(dialog));

const gboolean res = !sd->cancelled;

g_object_unref(is_active_pb);
g_object_unref(is_inactive_pb);
g_free(sd);

return res;
}

// style preview
Expand Down
Loading