Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
views.c
Go to the documentation of this file.
1/*
2 This file is part of the Ansel project.
3 Copyright (C) 2023 Alynx Zhou.
4 Copyright (C) 2023, 2025 Aurélien PIERRE.
5 Copyright (C) 2023 Luca Zulberti.
6 Copyright (C) 2026 Guillaume Stutin.
7
8 Ansel is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 Ansel is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Ansel. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "common/darktable.h"
23#include "common/debug.h"
24#include "control/conf.h"
25#include "control/control.h"
26#include "develop/develop.h"
27#include "gui/gtk.h"
28
29#include "gui/actions/menu.h"
30
31
32gboolean views_active_callback(GtkWidget *menu_item)
33{
34 // The insensitive view is the one whose name matches the menu item label
36 const char *current_label = get_custom_data(menu_item);
37 return !g_strcmp0(current_label, current_view->module_name);
38}
39
41{
42 // The insensitive view is the one whose name matches the menu item label
44 const char *current_label = get_custom_data(menu_item);
45 return g_strcmp0(current_label, current_view->module_name);
46}
47
48#define MACRO_VIEW(view) \
49 static gboolean view_switch_to_##view(GtkAccelGroup *group, GObject *acceleratable, guint keyval, \
50 GdkModifierType mods, GtkWidget *widget) \
51 { \
52 if(views_sensitive_callback(widget)) \
53 dt_ctl_switch_mode_to(#view); \
54 return TRUE; \
55}
56
57MACRO_VIEW(lighttable);
58MACRO_VIEW(darkroom);
60MACRO_VIEW(slideshow);
62
63void append_views(GtkWidget **menus, GList **lists, const dt_menus_t index)
64{
65 for(GList *view_iter = darktable.view_manager->views; view_iter; view_iter = g_list_next(view_iter))
66 {
67 dt_view_t *view = (dt_view_t *)view_iter->data;
68 if(view->flags() & VIEW_FLAGS_HIDDEN) continue;
69
70 void *callback = NULL;
71 if(!g_strcmp0(view->module_name, "lighttable"))
73 else if(!g_strcmp0(view->module_name, "darkroom"))
74 callback = view_switch_to_darkroom;
75 else if(!g_strcmp0(view->module_name, "print"))
76 callback = view_switch_to_print;
77 else if(!g_strcmp0(view->module_name, "slideshow"))
78 callback = view_switch_to_slideshow;
79 else if(!g_strcmp0(view->module_name, "map"))
80 callback = view_switch_to_map;
81
82 guint key = 0;
83 if(!g_strcmp0(view->module_name, "lighttable"))
84 key = GDK_KEY_Escape;
85 else if(!g_strcmp0(view->module_name, "darkroom"))
86 key = GDK_KEY_Return;
87 else if(!g_strcmp0(view->module_name, "print"))
88 key = 0;
89 else if(!g_strcmp0(view->module_name, "slideshow"))
90 key = 0;
91 else if(!g_strcmp0(view->module_name, "map"))
92 key = 0;
93
94
95 add_no_accel_sub_menu_entry(menus, lists, view->name(view), index, view->module_name, callback,
97
98 // Darkroom is not handled in global menu since it needs to be opened with an image ID,
99 // so we only handle it from filmstrip and lighttable thumbnails.
100 // Map and Print are too niche to bother.
101 }
102}
103
104/* TODO ?
105* The current logic is to execute state callbacks (active, sensisitive, check) on each menu activation,
106* in the menu.h:update_menu_entries() function.
107* This is inexpensive as long as there are not too many items.
108* The other approach is to connect menu.h:update_entry() to signals, e.g.
109
110 DT_DEBUG_CONTROL_SIGNAL_CONNECT(darktable.signals, DT_SIGNAL_VIEWMANAGER_VIEW_CHANGED,
111 G_CALLBACK(update_entry), self);
112 DT_DEBUG_CONTROL_SIGNAL_CONNECT(darktable.signals, DT_SIGNAL_VIEWMANAGER_VIEW_CANNOT_CHANGE,
113 G_CALLBACK(_lib_viewswitcher_view_cannot_change_callback), self);
114
115 DT_DEBUG_CONTROL_SIGNAL_DISCONNECT(darktable.signals, G_CALLBACK(update_entry), self);
116 DT_DEBUG_CONTROL_SIGNAL_DISCONNECT(darktable.signals, G_CALLBACK(_lib_viewswitcher_view_cannot_change_callback), self);
117*
118* So the update happens as soon as the signal is emited, only for the relevant menuitems.
119*
120* To re-evaluate in the future...
121*/
char * key
uint32_t view(const dt_view_t *self)
Definition darkroom.c:227
darktable_t darktable
Definition darktable.c:181
void add_no_accel_sub_menu_entry(GtkWidget **menus, GList **lists, const gchar *label, const dt_menus_t index, void *data, gboolean(*action_callback)(GtkAccelGroup *group, GObject *acceleratable, guint keyval, GdkModifierType mods, gpointer user_data), gboolean(*checked_callback)(GtkWidget *widget), gboolean(*active_callback)(GtkWidget *widget), gboolean(*sensitive_callback)(GtkWidget *widget), guint key_val, GdkModifierType mods)
Definition menu.c:553
void * get_custom_data(GtkWidget *widget)
Definition menu.c:612
dt_menus_t
Definition menu.h:42
struct _GtkWidget GtkWidget
Definition splash.h:29
struct dt_view_manager_t * view_manager
Definition darktable.h:772
GList * views
Definition view.h:200
GModule *void * data
Definition view.h:157
char module_name[64]
Definition view.h:153
const dt_view_t * dt_view_manager_get_current_view(dt_view_manager_t *vm)
Definition view.c:140
@ VIEW_FLAGS_HIDDEN
Definition view.h:88
void append_views(GtkWidget **menus, GList **lists, const dt_menus_t index)
Definition views.c:63
#define MACRO_VIEW(view)
Definition views.c:48
gboolean views_sensitive_callback(GtkWidget *menu_item)
Definition views.c:40
static gboolean view_switch_to_map(GtkAccelGroup *group, GObject *acceleratable, guint keyval, GdkModifierType mods, GtkWidget *widget)
Definition views.c:61
gboolean views_active_callback(GtkWidget *menu_item)
Definition views.c:32
static gboolean view_switch_to_darkroom(GtkAccelGroup *group, GObject *acceleratable, guint keyval, GdkModifierType mods, GtkWidget *widget)
Definition views.c:58
static gboolean view_switch_to_print(GtkAccelGroup *group, GObject *acceleratable, guint keyval, GdkModifierType mods, GtkWidget *widget)
Definition views.c:59
static gboolean view_switch_to_slideshow(GtkAccelGroup *group, GObject *acceleratable, guint keyval, GdkModifierType mods, GtkWidget *widget)
Definition views.c:60
static gboolean view_switch_to_lighttable(GtkAccelGroup *group, GObject *acceleratable, guint keyval, GdkModifierType mods, GtkWidget *widget)
Definition views.c:57