Commit 4a8250dc43f17ec437e7c63f3be34792c1746b39
1 parent
e6cdf5f2
Exists in
master
and in
4 other branches
Only customized sessions can be renamed.
Showing
3 changed files
with
39 additions
and
5 deletions
Show diff stats
src/include/pw3270.h
| ... | ... | @@ -70,6 +70,9 @@ |
| 70 | 70 | const gchar * v3270_get_session_filename(GtkWidget *widget); |
| 71 | 71 | void v3270_set_session_filename(GtkWidget *widget, const gchar *filename); |
| 72 | 72 | |
| 73 | + /// @brief Check if the terminal has a customized session file. | |
| 74 | + gboolean v3270_allow_custom_settings(GtkWidget *widget); | |
| 75 | + | |
| 73 | 76 | GtkWidget * pw3270_settings_dialog_new(const gchar *title, GtkWindow *parent); |
| 74 | 77 | |
| 75 | 78 | G_END_DECLS | ... | ... |
src/objects/window/page.c
| ... | ... | @@ -312,11 +312,13 @@ |
| 312 | 312 | static const struct Item { |
| 313 | 313 | const gchar * label; |
| 314 | 314 | GCallback callback; |
| 315 | + gboolean (*check_permission)(GtkWidget *widget) | |
| 315 | 316 | } items[] = { |
| 316 | 317 | |
| 317 | 318 | { |
| 318 | 319 | .label = N_("_Rename session"), |
| 319 | - .callback = G_CALLBACK(rename_session) | |
| 320 | + .callback = G_CALLBACK(rename_session), | |
| 321 | + .check_permission = v3270_allow_custom_settings | |
| 320 | 322 | }, |
| 321 | 323 | |
| 322 | 324 | { |
| ... | ... | @@ -332,6 +334,10 @@ |
| 332 | 334 | |
| 333 | 335 | for(ix = 0; ix < G_N_ELEMENTS(items); ix++) { |
| 334 | 336 | GtkWidget *item = gtk_menu_item_new_with_mnemonic(gettext(items[ix].label)); |
| 337 | + | |
| 338 | + if(items[ix].check_permission) | |
| 339 | + gtk_widget_set_sensitive(item,items[ix].check_permission(terminal)); | |
| 340 | + | |
| 335 | 341 | g_signal_connect(G_OBJECT(item),"activate",items[ix].callback,terminal); |
| 336 | 342 | gtk_widget_show_all(item); |
| 337 | 343 | gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); | ... | ... |
src/objects/window/terminal.c
| ... | ... | @@ -28,6 +28,13 @@ |
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | 30 | #include "private.h" |
| 31 | + | |
| 32 | + #include <glib.h> | |
| 33 | + #include <glib/gstdio.h> | |
| 34 | + #include <fcntl.h> | |
| 35 | + #include <sys/types.h> | |
| 36 | + #include <sys/stat.h> | |
| 37 | + | |
| 31 | 38 | #include <pw3270/actions.h> |
| 32 | 39 | #include <lib3270/toggle.h> |
| 33 | 40 | #include <v3270/settings.h> |
| ... | ... | @@ -267,18 +274,36 @@ |
| 267 | 274 | |
| 268 | 275 | GtkWidget * pw3270_application_window_new_tab(GtkWidget *widget, const gchar *session_file) { |
| 269 | 276 | |
| 270 | - struct SessionDescriptor * descriptor; | |
| 271 | - | |
| 272 | 277 | g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(widget),NULL); |
| 273 | 278 | |
| 274 | - GtkWidget * window = PW3270_APPLICATION_WINDOW(widget); | |
| 275 | 279 | GtkWidget * terminal = pw3270_terminal_new(session_file); |
| 276 | 280 | |
| 277 | - pw3270_window_set_current_page(window,pw3270_application_window_append_page(window,terminal)); | |
| 281 | + pw3270_window_set_current_page(widget,pw3270_application_window_append_page(widget,terminal)); | |
| 278 | 282 | |
| 279 | 283 | return terminal; |
| 280 | 284 | |
| 281 | 285 | } |
| 282 | 286 | |
| 287 | + gboolean v3270_allow_custom_settings(GtkWidget *widget) { | |
| 288 | + | |
| 289 | + const struct SessionDescriptor * descriptor = (const struct SessionDescriptor *) g_object_get_data(G_OBJECT(widget),"session-descriptor"); | |
| 290 | + | |
| 291 | + if(!(descriptor && *descriptor->filename)) | |
| 292 | + return FALSE; | |
| 293 | + | |
| 294 | + if(g_access(descriptor->filename,W_OK)) | |
| 295 | + return FALSE; | |
| 296 | + | |
| 297 | +#ifdef _WIN32 | |
| 298 | + | |
| 299 | + return TRUE; | |
| 300 | + | |
| 301 | +#else | |
| 302 | + | |
| 303 | + return !g_str_has_prefix(descriptor->filename,g_get_user_config_dir()); | |
| 304 | + | |
| 305 | +#endif // _WIN32 | |
| 306 | + | |
| 307 | + } | |
| 283 | 308 | |
| 284 | 309 | ... | ... |