Skip to content

Commit

Permalink
don't remove shortcut or crash when overwriting style/preset
Browse files Browse the repository at this point in the history
  • Loading branch information
dterrahe authored and TurboGit committed Jan 20, 2025
1 parent f114f6c commit e0408f0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
13 changes: 8 additions & 5 deletions src/common/styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ void dt_styles_apply_to_dev(const char *name, const dt_imgid_t imgid)
dt_control_log(_("applied style `%s' on current image"), name);
}

void dt_styles_delete_by_name_adv(const char *name, const gboolean raise)
void dt_styles_delete_by_name_adv(const char *name, const gboolean raise, const gboolean shortcut)
{
int id = 0;
if((id = dt_styles_get_id_by_name(name)) != 0)
Expand All @@ -1047,9 +1047,12 @@ void dt_styles_delete_by_name_adv(const char *name, const gboolean raise)
sqlite3_step(stmt);
sqlite3_finalize(stmt);

dt_action_t *old = dt_action_locate(&darktable.control->actions_global,
(gchar *[]){"styles", (gchar *)name, NULL}, FALSE);
dt_action_rename(old, NULL);
if(shortcut)
{
dt_action_t *old = dt_action_locate(&darktable.control->actions_global,
(gchar *[]){"styles", (gchar *)name, NULL}, FALSE);
dt_action_rename(old, NULL);
}

if(raise)
DT_CONTROL_SIGNAL_RAISE(DT_SIGNAL_STYLE_CHANGED);
Expand All @@ -1058,7 +1061,7 @@ void dt_styles_delete_by_name_adv(const char *name, const gboolean raise)

void dt_styles_delete_by_name(const char *name)
{
dt_styles_delete_by_name_adv(name, TRUE);
dt_styles_delete_by_name_adv(name, TRUE, FALSE);
}

GList *dt_styles_get_item_list(const char *name,
Expand Down
2 changes: 1 addition & 1 deletion src/common/styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void dt_styles_apply_to_image(const char *name,
void dt_styles_apply_to_dev(const char *name, const dt_imgid_t imgid);

/** delete a style by name */
void dt_styles_delete_by_name_adv(const char *name, const gboolean raise);
void dt_styles_delete_by_name_adv(const char *name, const gboolean raise, const gboolean shortcut);

/** delete a style by name, raise signal */
void dt_styles_delete_by_name(const char *name);
Expand Down
2 changes: 2 additions & 0 deletions src/gui/accelerators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,8 @@ static void _remove_shortcut(GSequenceIter *shortcut)
dt_shortcut_t *s = g_sequence_get(shortcut);
if(!s) return;

_selected_shortcut = NULL;

gboolean disabled = s->views == DT_VIEW_NONE;
if(s->is_default)
{
Expand Down
11 changes: 2 additions & 9 deletions src/libs/styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,6 @@ static void _delete_clicked(GtkWidget *w, dt_lib_styles_t *d)
if(style_names == NULL) return;

const gint select_cnt = g_list_length(style_names);
const gboolean single_raise = (select_cnt == 1);

const gboolean can_delete = _ask_before_delete_style(select_cnt);

if(can_delete)
Expand All @@ -421,14 +419,9 @@ static void _delete_clicked(GtkWidget *w, dt_lib_styles_t *d)

for(const GList *style = style_names; style; style = g_list_next(style))
{
dt_styles_delete_by_name_adv((char*)style->data, single_raise);
dt_styles_delete_by_name_adv((char*)style->data, !g_list_next(style), TRUE);
}

if(!single_raise) {
// raise signal at the end of processing all styles if we have more than 1 to delete
// this also calls _gui_styles_update_view
DT_CONTROL_SIGNAL_RAISE(DT_SIGNAL_STYLE_CHANGED);
}
dt_database_release_transaction(darktable.db);
}
g_list_free_full(style_names, g_free);
Expand Down Expand Up @@ -990,7 +983,7 @@ void gui_reset(dt_lib_module_t *self)
for(const GList *result = all_styles; result; result = g_list_next(result))
{
dt_style_t *style = result->data;
dt_styles_delete_by_name_adv((char*)style->name, FALSE);
dt_styles_delete_by_name_adv((char*)style->name, FALSE, TRUE);
}
DT_CONTROL_SIGNAL_RAISE(DT_SIGNAL_STYLE_CHANGED);
}
Expand Down

0 comments on commit e0408f0

Please sign in to comment.