atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
work_menu.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
23/*
24* This file: 'work_menu.c'
25*
26* Contains:
27*
28
29 - The workspace menu GTK3 version
30 - Callbacks for the workspace menu
31
32*
33* List of functions:
34
35 G_MODULE_EXPORT void on_create_new_project (GtkWidget * widg, gpointer data);
36 G_MODULE_EXPORT void leaving_from_menu (GtkWidget * widg, gpointer data);
37 G_MODULE_EXPORT void compute_this_prop (GtkWidget * widg, gpointer data);
38
39 GtkWidget * this_work_menu (int p, int c);
40 GtkWidget * work_menu (int p, int c);
41
42*/
43
44#include "global.h"
45#include "callbacks.h"
46#include "interface.h"
47#include "project.h"
48#include "workspace.h"
49#include "glview.h"
50
51extern G_MODULE_EXPORT void on_calc_activate (GtkWidget * widg, gpointer data);
52extern G_MODULE_EXPORT void set_mode (GtkWidget * widg, gpointer data);
53
62G_MODULE_EXPORT void on_create_new_project (GtkWidget * widg, gpointer data)
63{
64 init_project (TRUE);
67 apply_project (FALSE);
68#ifdef GTK3
69 // GTK3 Menu Action To Check
70 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_project -> modelgl -> ogl_mode[1], TRUE);
71 set_mode (active_project -> modelgl -> ogl_mode[1], & active_project -> modelgl -> colorp[1][0]);
72#else
73 set_mode (NULL, & active_project -> modelgl -> colorp[1][0]);
74#endif
76}
77
86G_MODULE_EXPORT void leaving_from_menu (GtkWidget * widg, gpointer data)
87{
88#ifdef GTK4
89 leaving_question (NULL, NULL);
90#else
91 leaving_question (NULL, NULL, NULL);
92#endif
93}
94
96
105G_MODULE_EXPORT void compute_this_prop (GtkWidget * widg, gpointer data)
106{
107 activate_project (NULL, data);
108 on_calc_activate (NULL, GINT_TO_POINTER(calc_to_compute));
109}
110
111#ifdef GTK3
120GtkWidget * this_work_menu (int p, int c)
121{
122 GtkWidget * menu;
123 GtkWidget * port;
124 GtkWidget * dmenu;
125 gchar * imp_str[2] = {"Import", "Export"};
126 menu = gtk_menu_new ();
127 GtkAccelGroup * accel_group = gtk_accel_group_new ();
128 gtk_window_add_accel_group (GTK_WINDOW (MainWindow), accel_group);
129 widget_set_sensitive (gtk3_menu_item (menu, "Workspace", IMG_FILE, (gpointer)PACKAGE_TD, NULL, NULL, FALSE, 0, 0, FALSE, FALSE, FALSE), 0);
130 add_menu_separator (menu);
131 gtk3_menu_item (menu, "Open", IMG_STOCK, (gpointer)FOPEN, G_CALLBACK(on_open_save_activate), GINT_TO_POINTER(2), TRUE, GDK_KEY_w, GDK_CONTROL_MASK, FALSE, FALSE, FALSE);
132 gtk3_menu_item (menu, "Save", IMG_STOCK, (gpointer)FSAVE, G_CALLBACK(on_open_save_activate), GINT_TO_POINTER(3), FALSE, 0, 0, FALSE, FALSE, FALSE);
133 gtk3_menu_item (menu, "Save As", IMG_STOCK, (gpointer)FSAVEAS, G_CALLBACK(on_save_as_activate), GINT_TO_POINTER(3), TRUE, GDK_KEY_s, GDK_CONTROL_MASK, FALSE, FALSE, FALSE);
134 gtk3_menu_item (menu, "Close", IMG_STOCK, (gpointer)FCLOSE, G_CALLBACK(on_close_workspace), GINT_TO_POINTER(1), TRUE, GDK_KEY_c, GDK_CONTROL_MASK, FALSE, FALSE, FALSE);
135 add_menu_separator (menu);
136 if (p == -1)
137 {
138 widget_set_sensitive (gtk3_menu_item (menu, "Project(s)", IMG_FILE, (gpointer)PACKAGE_TD, NULL, NULL, FALSE, 0, 0, FALSE, FALSE, FALSE), FALSE);
139 add_menu_separator (menu);
140 gtk3_menu_item (menu, "New", IMG_STOCK, (gpointer)FNEW, G_CALLBACK(on_create_new_project), NULL, TRUE, GDK_KEY_n, GDK_CONTROL_MASK, FALSE, FALSE, FALSE);
141 gtk3_menu_item (menu, "Open", IMG_STOCK, (gpointer)FSAVE, G_CALLBACK(on_open_save_activate), GINT_TO_POINTER(0), TRUE, GDK_KEY_o, GDK_CONTROL_MASK, FALSE, FALSE, FALSE);
142 gtk3_menu_item (menu, "Save", IMG_STOCK, (gpointer)FSAVE, G_CALLBACK(on_open_save_activate), GINT_TO_POINTER(1), FALSE, 0, 0, FALSE, FALSE, FALSE);
143 gtk3_menu_item (menu, "Save As", IMG_STOCK, (gpointer)FSAVEAS, G_CALLBACK(on_save_as_activate), GINT_TO_POINTER(1), FALSE, 0, 0, FALSE, FALSE, FALSE);
144 gtk3_menu_item (menu, "Close", IMG_STOCK, (gpointer)FCLOSE, G_CALLBACK(on_close_activate), GINT_TO_POINTER(activep), FALSE, 0, 0, FALSE, FALSE, FALSE);
145 port = gtk3_menu_item (menu, imp_str[1], IMG_FILE, (gpointer)PACKAGE_CON, NULL, NULL, FALSE, 0, 0, FALSE, FALSE, FALSE);
146 dmenu = gtk_menu_new ();
147 gtk3_menu_item (dmenu, "ISAACS Project File '*.ipf'", IMG_FILE, (gpointer)PACKAGE_MOL, G_CALLBACK(on_isaacs_port), GINT_TO_POINTER(1), FALSE, 0, 0, FALSE, FALSE, FALSE);
148 gtk3_menu_item (dmenu, "Atomic Coordinates", IMG_FILE, (gpointer)PACKAGE_CON, G_CALLBACK(on_coord_port), GINT_TO_POINTER(1), FALSE, 0, 0, FALSE, FALSE, FALSE);
149 gtk_menu_item_set_submenu ((GtkMenuItem *)port, dmenu);
150 }
151 else
152 {
153 gchar * pname = g_strdup_printf ("<b>%s</b>", get_project_by_id(p) -> name);
154 widget_set_sensitive (gtk3_menu_item (menu, pname, IMG_FILE, (gpointer)PACKAGE_TD, NULL, NULL, FALSE, 0, 0, FALSE, FALSE, FALSE), 0);
155 g_free (pname);
156 add_menu_separator (menu);
157 if (p != activep)
158 {
159 gtk3_menu_item (menu, "Make Active", IMG_STOCK, (gpointer)YES, G_CALLBACK(activate_project), GINT_TO_POINTER(p), FALSE, 0, 0, FALSE, FALSE, FALSE);
160 }
161 if (c > -1)
162 {
163 gchar * str = g_strdup_printf ("Analyze: %s", work_menu_items[c+4]);
164 widget_set_sensitive (gtk3_menu_item (menu, str, IMG_FILE, (gpointer)graph_img[c], G_CALLBACK(compute_this_prop), GINT_TO_POINTER(p), FALSE, 0, 0, FALSE, FALSE, FALSE), get_project_by_id(p) -> runok[c]);
165 g_free (str);
166 }
167 gtk3_menu_item (menu, "Edit Name", IMG_STOCK, (gpointer)EDITA, G_CALLBACK(change_project_name), GINT_TO_POINTER(p), FALSE, 0, 0, FALSE, FALSE, FALSE);
168 gtk3_menu_item (menu, "Save", IMG_STOCK, (gpointer)FSAVE, G_CALLBACK(on_open_save_activate), GINT_TO_POINTER(1), FALSE, 0, 0, FALSE, FALSE, FALSE);
169 gtk3_menu_item (menu, "Save As", IMG_STOCK, (gpointer)FSAVEAS, G_CALLBACK(on_save_as_activate), GINT_TO_POINTER(1), FALSE, 0, 0, FALSE, FALSE, FALSE);
170 gtk3_menu_item (menu, "Close", IMG_STOCK, (gpointer)FCLOSE, G_CALLBACK(on_close_activate), GINT_TO_POINTER(p), FALSE, 0, 0, FALSE, FALSE, FALSE);
171 port = gtk3_menu_item (menu, imp_str[1], IMG_FILE, (gpointer)PACKAGE_CON, NULL, NULL, FALSE, 0, 0, FALSE, FALSE, FALSE);
172 dmenu = gtk_menu_new ();
173 gtk3_menu_item (dmenu, "ISAACS Project File '*.ipf'", IMG_FILE, (gpointer)PACKAGE_MOL, G_CALLBACK(on_isaacs_port), GINT_TO_POINTER(1), FALSE, 0, 0, FALSE, FALSE, FALSE);
174 gtk3_menu_item (dmenu, "Atomic Coordinates", IMG_FILE, (gpointer)PACKAGE_CON, G_CALLBACK(on_coord_port), GINT_TO_POINTER(1), FALSE, 0, 0, FALSE, FALSE, FALSE);
175 gtk_menu_item_set_submenu ((GtkMenuItem *)port, dmenu);
176 }
177 add_menu_separator (menu);
178 port = gtk3_menu_item (menu, imp_str[0], IMG_FILE, (gpointer)PACKAGE_IMP, NULL, NULL, FALSE, 0, 0, FALSE, FALSE, FALSE);
179 dmenu = gtk_menu_new ();
180 gtk_menu_item_set_submenu ((GtkMenuItem *)port, dmenu);
181 gtk3_menu_item (dmenu, "ISAACS Project File '*.ipf'", IMG_FILE, (gpointer)PACKAGE_MOL, G_CALLBACK(on_isaacs_port), GINT_TO_POINTER(0), FALSE, 0, 0, FALSE, FALSE, FALSE);
182 gtk3_menu_item (dmenu, "Atomic Coordinates", IMG_FILE, (gpointer)PACKAGE_IMP, G_CALLBACK(on_coord_port), GINT_TO_POINTER(0), FALSE, 0, 0, FALSE, FALSE, FALSE);
183 add_menu_separator (menu);
184 gtk3_menu_item (menu, "Quit", IMG_STOCK, (gpointer)FEXIT, G_CALLBACK(leaving_from_menu), NULL, TRUE, GDK_KEY_q, GDK_CONTROL_MASK, FALSE, FALSE, FALSE);
185 show_the_widgets (menu);
186 return menu;
187}
188#endif
189
190extern void atomes_menu_bar_action (GSimpleAction * action, GVariant * parameter, gpointer data);
191extern GMenu * create_workspace_menu (gchar * act, int pop_up, int proj, int calc);
192extern GSimpleAction * pop_act[7];
193
202GtkWidget * work_menu (int p, int c)
203{
204 GtkWidget * menu;
205
206 GSimpleActionGroup * action_popup = g_simple_action_group_new ();
207 GSimpleAction * pop_act[17];
208 pop_act[0] = g_simple_action_new ("workspace.open", NULL);
209 pop_act[1] = g_simple_action_new ("workspace.save", NULL);
210 pop_act[2] = g_simple_action_new ("workspace.save-as", NULL);
211 pop_act[3] = g_simple_action_new ("workspace.close", NULL);
212 pop_act[4] = g_simple_action_new ("project.active", NULL);
213 pop_act[5] = g_simple_action_new ("project.compute", NULL);
214 pop_act[6] = g_simple_action_new ("project.edit", NULL);
215 pop_act[7] = g_simple_action_new ("project.new", NULL);
216 pop_act[8] = g_simple_action_new ("project.open", NULL);
217 pop_act[9] = g_simple_action_new ("project.save", NULL);
218 pop_act[10] = g_simple_action_new ("project.save-as", NULL);
219 pop_act[11] = g_simple_action_new ("project.close", NULL);
220 pop_act[12] = g_simple_action_new ("export.isaacs", NULL);
221 pop_act[13] = g_simple_action_new ("export.coordinates", NULL);
222 pop_act[14] = g_simple_action_new ("import.isaacs", NULL);
223 pop_act[15] = g_simple_action_new ("import.coordinates", NULL);
224 pop_act[16] = g_simple_action_new ("program.quit", NULL);
225
226 int i;
227 for (i=0; i<17; i++) g_action_map_add_action (G_ACTION_MAP(action_popup), G_ACTION(pop_act[i]));
228 g_signal_connect (pop_act[0], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(2));
229 g_signal_connect (pop_act[1], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(3));
230 g_signal_connect (pop_act[2], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(3));
231 g_signal_connect (pop_act[3], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(1));
232 g_signal_connect (pop_act[4], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(p));
233 g_signal_connect (pop_act[5], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(p));
234 g_signal_connect (pop_act[6], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(p));
235 g_signal_connect (pop_act[7], "activate", G_CALLBACK(atomes_menu_bar_action), NULL);
236 g_signal_connect (pop_act[8], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(0));
237 g_signal_connect (pop_act[9], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(1));
238 g_signal_connect (pop_act[10], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(1));
239 g_signal_connect (pop_act[11], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(p));
240 g_signal_connect (pop_act[12], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(1));
241 g_signal_connect (pop_act[13], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(1));
242 g_signal_connect (pop_act[14], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(0));
243 g_signal_connect (pop_act[15], "activate", G_CALLBACK(atomes_menu_bar_action), GINT_TO_POINTER(0));
244 g_signal_connect (pop_act[16], "activate", G_CALLBACK(atomes_menu_bar_action), NULL);
245
246 calc_to_compute = (c < AN) ? c : c - 1;
247#ifdef GTK3
248 menu = this_work_menu (p, c);
249 // GMenu * popup = create_workspace_menu ("pop", 1, p, c);
250 // gtk_menu_new_from_model (G_MENU_MODEL(popup));
251#else
252 GMenu * popup = create_workspace_menu ("pop", 1, p, c);
253 menu = gtk_popover_menu_new_from_model_full (G_MENU_MODEL(popup), GTK_POPOVER_MENU_NESTED);
254 i = (nprojects) ? ((p > -1) ? 250 : 95) : 0;
255 gtk_widget_set_size_request (menu, -1, 310 + i);
256/* I need to use the ' gtk_popover_menu_new_from_model_full' command here,
257 the menu created using the 'gtk_popover_menu_new_from_model' does not behave properly,
258 that might be a bug, some items of the menu having the same name,
259 It is not possible to navigate the menu properly and some elements remains inaccessible,
260 this was solved with this '_full' command.
261 menu = gtk_popover_menu_new_from_model (G_MENU_MODEL(popup)); */
262#endif
263 gtk_widget_insert_action_group (menu, "pop", G_ACTION_GROUP(action_popup));
264 return menu;
265}
G_MODULE_EXPORT void on_close_workspace(GtkWidget *widg, gpointer data)
close the active workspace
Definition callbacks.c:133
G_MODULE_EXPORT void on_open_save_activate(GtkWidget *widg, gpointer data)
open or save an atomes file - prepare the dialog
Definition callbacks.c:423
void apply_project(gboolean showtools)
get project ready for calculation and initialize the OpenGL window
Definition callbacks.c:665
G_MODULE_EXPORT void on_isaacs_port(GtkWidget *widg, gpointer data)
open or write ISAACS XML file - prepare the dialog
Definition callbacks.c:775
G_MODULE_EXPORT void on_coord_port(GtkWidget *widg, gpointer data)
export or import atomic coordinates: prepare dialog
Definition callbacks.c:1604
G_MODULE_EXPORT void on_save_as_activate(GtkWidget *widg, gpointer data)
open or save, choosing a file name
Definition callbacks.c:621
Callback declarations for main window.
G_MODULE_EXPORT void on_close_activate(GtkWidget *widg, gpointer cdata)
signal to close a project
Definition close_p.c:332
color colorp[64]
int mol_update
Definition global.c:171
int activep
Definition global.c:159
gchar * PACKAGE_IMP
Definition global.c:79
gchar * PACKAGE_CON
Definition global.c:80
int nprojects
Definition global.c:158
int frag_update
Definition global.c:170
GtkWidget * MainWindow
Definition global.c:201
gchar * PACKAGE_TD
Definition global.c:98
gchar * PACKAGE_MOL
Definition global.c:99
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_STOCK
Definition global.h:264
@ IMG_FILE
Definition global.h:263
GtkWidget * gtk3_menu_item(GtkWidget *menu, gchar *name, int icon_format, gpointer item_icon, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod, gboolean check, gboolean radio, gboolean status)
project * proj
gchar * graph_img[NGRAPHS]
Definition gui.c:106
#define EDITA
Definition global.h:202
#define FEXIT
Definition global.h:212
#define FOPEN
Definition global.h:208
#define YES
Definition global.h:201
#define FNEW
Definition global.h:207
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
#define AN
Definition global.h:327
#define FSAVE
Definition global.h:209
void add_menu_separator(GtkWidget *menu)
#define FCLOSE
Definition global.h:211
project * active_project
Definition project.c:47
#define FSAVEAS
Definition global.h:210
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
action
Definition glview.h:189
void init_project(gboolean alloc_box)
initialize a new project
Definition init_p.c:72
G_MODULE_EXPORT gboolean leaving_question(GtkWidget *widget, GdkEvent *event, gpointer data)
Leaving atomes ?
Definition interface.c:418
Messaging function declarations.
void prep_calc_actions()
prepare analysis widgets
Definition update_p.c:58
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int c
Definition tab-1.c:95
G_MODULE_EXPORT void compute_this_prop(GtkWidget *widg, gpointer data)
to compute the 'calc_to_compute'
Definition work_menu.c:105
void atomes_menu_bar_action(GSimpleAction *action, GVariant *parameter, gpointer data)
atomes menu bar actions
Definition gui.c:462
GMenu * create_workspace_menu(gchar *act, int pop_up, int proj, int calc)
create atomes 'workspace' menu
Definition gui.c:952
GSimpleAction * pop_act[7]
G_MODULE_EXPORT void leaving_from_menu(GtkWidget *widg, gpointer data)
leaving atomes ?
Definition work_menu.c:86
G_MODULE_EXPORT void on_calc_activate(GtkWidget *widg, gpointer data)
create a calculation dialog - prepare the dialog
Definition calc_menu.c:1387
GtkWidget * work_menu(int p, int c)
create the workspace popup menu
Definition work_menu.c:202
G_MODULE_EXPORT void set_mode(GtkWidget *widg, gpointer data)
set mouse mode callback
Definition m_tools.c:172
int calc_to_compute
Definition work_menu.c:95
G_MODULE_EXPORT void on_create_new_project(GtkWidget *widg, gpointer data)
create a new project
Definition work_menu.c:62
void add_project_to_workspace()
add project(s) to the workspace tree
Definition workspace.c:594
G_MODULE_EXPORT void activate_project(GtkWidget *widg, gpointer data)
activate a project
Definition workspace.c:191
char * work_menu_items[NITEMS-2]
Definition workspace.c:89
G_MODULE_EXPORT void change_project_name(GtkWidget *wid, gpointer edata)
change project name
Definition workspace.c:357
Function declarations for workspace managment.