Skip to content

Commit 1cdb48b

Browse files
committed
update preset_label on param change
1 parent 05ff1b1 commit 1cdb48b

File tree

3 files changed

+70
-31
lines changed

3 files changed

+70
-31
lines changed

src/libs/filtering.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
#include "bauhaus/bauhaus.h"
2020
#include "common/collection.h"
2121
#include "common/darktable.h"
22-
#include "common/metadata.h"
2322
#include "control/conf.h"
2423
#include "control/control.h"
25-
#include "control/jobs.h"
2624
#include "dtgtk/button.h"
2725
#include "dtgtk/range.h"
2826
#include "gui/accelerators.h"
@@ -2252,6 +2250,12 @@ void gui_init(dt_lib_module_t *self)
22522250
DT_CONTROL_SIGNAL_HANDLE(DT_SIGNAL_IMAGES_ORDER_CHANGE, _dt_images_order_change);
22532251
}
22542252

2253+
void gui_update(dt_lib_module_t *self)
2254+
{
2255+
// Don't remove the empty function to not break the gui_update chain.
2256+
// It is needed to update the preset_label in the module header when params change.
2257+
}
2258+
22552259
void gui_cleanup(dt_lib_module_t *self)
22562260
{
22572261
dt_lib_filtering_t *d = self->data;

src/libs/import.c

Lines changed: 7 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) 2011-2024 darktable developers.
3+
Copyright (C) 2011-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
@@ -16,11 +16,9 @@
1616
along with darktable. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#include "bauhaus/bauhaus.h"
2019
#include "common/collection.h"
2120
#include "common/darktable.h"
2221
#include "common/file_location.h"
23-
#include "common/debug.h"
2422
#include "common/exif.h"
2523
#include "common/metadata.h"
2624
#include "common/datetime.h"
@@ -29,7 +27,6 @@
2927
#ifdef HAVE_GPHOTO2
3028
#include "control/jobs/camera_jobs.h"
3129
#endif
32-
#include "dtgtk/expander.h"
3330
#include "dtgtk/button.h"
3431
#include "gui/accelerators.h"
3532
#include "gui/gtk.h"
@@ -2505,6 +2502,12 @@ void gui_init(dt_lib_module_t *self)
25052502
dt_gui_update_collapsible_section(&d->cs);
25062503
}
25072504

2505+
void gui_update(dt_lib_module_t *self)
2506+
{
2507+
// Don't remove the empty function to not break the gui_update chain.
2508+
// It is needed to update the preset_label in the module header when params change.
2509+
}
2510+
25082511
void gui_cleanup(dt_lib_module_t *self)
25092512
{
25102513
dt_lib_import_t *d = self->data;

src/libs/lib.c

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of darktable,
3-
Copyright (C) 2009-2024 darktable developers.
3+
Copyright (C) 2009-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
@@ -23,13 +23,13 @@
2323
#include "control/control.h"
2424
#include "dtgtk/button.h"
2525
#include "dtgtk/expander.h"
26-
#include "dtgtk/icon.h"
2726
#include "gui/accelerators.h"
2827
#include "gui/drag_and_drop.h"
2928
#include "gui/gtk.h"
3029
#include "gui/presets.h"
30+
#include <glib-2.0/glib.h>
31+
#include <string.h>
3132
#ifdef GDK_WINDOWING_QUARTZ
32-
#include "osx/osx.h"
3333
#endif
3434
#include <stdbool.h>
3535
#include <stdlib.h>
@@ -103,6 +103,33 @@ gchar *dt_lib_get_active_preset_name(dt_lib_module_info_t *minfo)
103103
return name;
104104
}
105105

106+
// get dt_lib_module_info_t for a module. Must be freed by free_module_info()
107+
static dt_lib_module_info_t *_get_module_info_for_module(dt_lib_module_t *module)
108+
{
109+
dt_lib_module_info_t *mi = calloc(1, sizeof(dt_lib_module_info_t));
110+
111+
mi->plugin_name = g_strdup(module->plugin_name);
112+
mi->version = module->version();
113+
mi->module = module;
114+
mi->params = module->get_params ? module->get_params(module, &mi->params_size) : NULL;
115+
if(!mi->params)
116+
{
117+
// this is a valid case, for example in location.c when nothing got selected
118+
// fprintf(stderr, "something went wrong: &params=%p, size=%i\n",
119+
// mi->params, mi->params_size);
120+
mi->params_size = 0;
121+
}
122+
return mi;
123+
}
124+
125+
static void _set_module_preset_label(dt_lib_module_t *module, const gchar *preset_name)
126+
{
127+
gchar *preset_label_text = (*preset_name == '\0')? g_strdup("")
128+
: g_strdup_printf("• %s", preset_name);
129+
gtk_label_set_text(GTK_LABEL(module->preset_label), preset_label_text);
130+
g_free(preset_label_text);
131+
}
132+
106133
static void edit_preset(const char *name_in,
107134
dt_lib_module_info_t *minfo)
108135
{
@@ -237,6 +264,7 @@ static void menuitem_delete_preset(GtkMenuItem *menuitem,
237264
dt_action_rename_preset(&minfo->module->actions, name, NULL);
238265

239266
dt_lib_presets_remove(name, minfo->plugin_name, minfo->version);
267+
_set_module_preset_label(minfo->module, "");
240268

241269
DT_CONTROL_SIGNAL_RAISE(DT_SIGNAL_PRESETS_CHANGED,
242270
g_strdup(minfo->plugin_name));
@@ -356,6 +384,8 @@ gboolean dt_lib_presets_apply(const gchar *preset,
356384
dt_conf_set_string(tx, preset);
357385
g_free(tx);
358386
res = module->set_params(module, blob, length);
387+
if(!res)
388+
_set_module_preset_label(module, preset);
359389
break;
360390
}
361391
}
@@ -403,15 +433,8 @@ void dt_lib_presets_update(const gchar *preset,
403433
static void _menuitem_activate_preset(GtkMenuItem *menuitem,
404434
dt_lib_module_info_t *minfo)
405435
{
406-
gchar *preset_name = g_object_get_data(G_OBJECT(menuitem), "dt-preset-name");
407-
gboolean res = dt_lib_presets_apply(preset_name,
408-
minfo->plugin_name, minfo->version);
409-
410-
if(res){
411-
gchar *preset_label_text = g_strdup_printf("• %s", preset_name);
412-
gtk_label_set_text(GTK_LABEL(minfo->module->preset_label), preset_label_text);
413-
g_free(preset_label_text);
414-
}
436+
dt_lib_presets_apply(g_object_get_data(G_OBJECT(menuitem), "dt-preset-name"),
437+
minfo->plugin_name, minfo->version);
415438
}
416439

417440
static gboolean _menuitem_button_preset(GtkMenuItem *menuitem,
@@ -864,6 +887,12 @@ void dt_lib_gui_update(dt_lib_module_t *module)
864887
module->gui_update(module);
865888
module->gui_uptodate = TRUE;
866889
}
890+
891+
dt_lib_module_info_t *mi = _get_module_info_for_module(module);
892+
gchar *active_preset_name = dt_lib_get_active_preset_name(mi);
893+
free_module_info(NULL, mi);
894+
_set_module_preset_label(module, active_preset_name? active_preset_name : "");
895+
g_free(active_preset_name);
867896
}
868897

869898
static void dt_lib_init_module(void *m)
@@ -907,19 +936,7 @@ static gboolean _presets_popup_callback(GtkButton *button,
907936
GdkEventButton *e,
908937
dt_lib_module_t *module)
909938
{
910-
dt_lib_module_info_t *mi = calloc(1, sizeof(dt_lib_module_info_t));
911-
912-
mi->plugin_name = g_strdup(module->plugin_name);
913-
mi->version = module->version();
914-
mi->module = module;
915-
mi->params = module->get_params ? module->get_params(module, &mi->params_size) : NULL;
916-
if(!mi->params)
917-
{
918-
// this is a valid case, for example in location.c when nothing got selected
919-
// fprintf(stderr, "something went wrong: &params=%p, size=%i\n",
920-
// mi->params, mi->params_size);
921-
mi->params_size = 0;
922-
}
939+
dt_lib_module_info_t *mi = _get_module_info_for_module(module);
923940
dt_lib_presets_popup_menu_show(mi, GTK_WIDGET(button));
924941

925942
if(button)
@@ -1283,6 +1300,7 @@ GtkWidget *dt_lib_gui_get_expander(dt_lib_module_t *module)
12831300
dt_action_define(&module->actions, NULL, NULL, label_evb, NULL);
12841301
gtk_box_pack_start(GTK_BOX(header), label_evb, FALSE, FALSE, 0);
12851302

1303+
/* add preset label */
12861304
module->preset_label = gtk_label_new(NULL);
12871305
gtk_widget_set_name(module->preset_label, "lib-module-name");
12881306
gtk_label_set_ellipsize(GTK_LABEL(module->preset_label), PANGO_ELLIPSIZE_MIDDLE);
@@ -1331,6 +1349,15 @@ GtkWidget *dt_lib_gui_get_expander(dt_lib_module_t *module)
13311349
dt_gui_add_class(pluginui_frame, "dt_plugin_ui");
13321350
module->expander = expander;
13331351

1352+
// get active preset and set preset_label
1353+
dt_lib_module_info_t *mi = _get_module_info_for_module(module);
1354+
gchar *preset_name = dt_lib_get_active_preset_name(mi);
1355+
if(preset_name)
1356+
{
1357+
_set_module_preset_label(mi->module, preset_name);
1358+
g_free(preset_name);
1359+
}
1360+
free_module_info(NULL, mi);
13341361

13351362
return module->expander;
13361363
}
@@ -1553,6 +1580,11 @@ gboolean dt_lib_presets_can_autoapply(dt_lib_module_t *mod)
15531580
return mod->preset_autoapply(mod);
15541581
}
15551582

1583+
void dt_lib_reset_preset_label(dt_lib_module_t *mod)
1584+
{
1585+
gtk_label_set_text(GTK_LABEL(mod->preset_label), "");
1586+
}
1587+
15561588
static float _action_process(gpointer target,
15571589
const dt_action_element_t element,
15581590
const dt_action_effect_t effect,

0 commit comments

Comments
 (0)