PIPS
gtk_quit.c
Go to the documentation of this file.
1 /*
2 
3  $Id: gtk_quit.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 #include <stdio.h>
28 
29 #include <sys/time.h>
30 #include <sys/resource.h>
31 
32 #include "genC.h"
33 #include "database.h"
34 #include "misc.h"
35 #include "linear.h"
36 #include "ri.h"
37 
38 #include "ri-util.h"
39 #include "pipsdbm.h"
40 #include "top-level.h"
41 
42 #undef test_undefined // also defined in glib included from gtk
43 #include <gtk/gtk.h>
44 #include "gpips.h"
45 
46 #define QUICK_QUIT "Quit without saving"
47 #define CLOSE_QUIT "Close (save) the Workspace & Quit"
48 #define DELETE_QUIT "Delete the Workspace & Quit"
49 #define CD_HACK_QUIT "Change Directory (tcl/tk hack)"
50 
51 GtkWidget * quit_menu_item;
52 
53 void cd_notify(GtkWidget * widget, gpointer data) {
55 }
56 
57 void quit_notify(GtkWidget * widget, gpointer data) {
58  int result;
59  string pn;
60 
61  if ((pn = db_get_current_workspace_name())) {
62  string fmt = "Workspace %s not closed";
63  char str[SMALL_BUFFER_LENGTH];
64  string str1, str2;
65  const char *menu_string;
66 
67  str2 = "Do you really want to quit PIPS?";
68  menu_string = gpips_gtk_menu_item_get_label(widget);
69  if (strcmp(menu_string, CLOSE_QUIT) == 0)
70  str1 = " ";
71  else
72  str1 = "-=< Resources can get lost! >=-";
73 
74  sprintf(str, fmt, pn);
75 
76  GtkWidget * dialog = gtk_message_dialog_new(GTK_WINDOW(main_window),
77  GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO,
78  GTK_BUTTONS_YES_NO, "%s%s%s",str,str1,str2);
79  result = gtk_dialog_run(GTK_DIALOG(dialog));
80 
81  if (result == GTK_RESPONSE_NO)
82  return;
83  else if (strcmp(menu_string, CLOSE_QUIT) == 0)
84  close_workspace(TRUE);
85  else if (strcmp(menu_string, DELETE_QUIT) == 0) {
86  int win = 0;
87 
88  /* Destroy all the windows (close open files) */
89  for (win = 0; win < number_of_gpips_windows; win++)
90  gtk_widget_destroy(edit_window[win]);
91 
92  check_delete_workspace(pn, FALSE);
93  }
94 
95  }
96 
97  /* Clear the log window to avoid the message about the edited
98  state:
99  clear_log_subwindow(NULL, NULL);
100  Does not work...
101  Quit:
102  xv_destroy[_safe](main_frame);
103  */
104  /* Exit xv_main_loop() at top level: */
105  gtk_main_quit();
106 }
107 
109  GtkWidget * quit_menu;
110 
111  quit_menu = gtk_menu_new();
112  quit_menu_item = gtk_menu_item_new_with_label("Quit");
113  gtk_menu_item_set_submenu(GTK_MENU_ITEM(quit_menu_item), quit_menu);
114 
115  GtkWidget * menu_item;
116 
117  menu_item = gtk_menu_item_new_with_label(CLOSE_QUIT);
118  g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(quit_notify),
119  NULL);
120  gtk_menu_append(GTK_MENU(quit_menu), menu_item);
121 
122  menu_item = gtk_menu_item_new_with_label(QUICK_QUIT);
123  g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(quit_notify),
124  NULL);
125  gtk_menu_append(GTK_MENU(quit_menu), menu_item);
126 
127  menu_item = gtk_menu_item_new_with_label(DELETE_QUIT);
128  g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(quit_notify),
129  NULL);
130  gtk_menu_append(GTK_MENU(quit_menu), menu_item);
131 
132  menu_item = gtk_menu_item_new_with_label(CD_HACK_QUIT);
133  g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(cd_notify),
134  NULL);
135  gtk_menu_append(GTK_MENU(quit_menu), menu_item);
136 
137  gtk_widget_show(quit_menu_item);
138  gtk_widget_show_all(quit_menu);
139  gtk_menu_bar_append(GTK_MENU_BAR(main_window_menu_bar), quit_menu_item);
140 }
bool close_workspace(bool is_quit)
Definition: dbm.c:346
bool check_delete_workspace(const char *wname, bool check)
Definition: dbm.c:375
GtkWidget * edit_window[MAX_NUMBER_OF_GPIPS_WINDOWS]
Definition: gpips-local.h:37
GtkWidget * main_window
Definition: gpips.c:54
int number_of_gpips_windows
Definition: gtk_edit2.c:86
#define SMALL_BUFFER_LENGTH
Definition: gpips-local.h:24
GtkWidget * main_window_menu_bar
Definition: gpips.c:62
#define CD_HACK_QUIT
Definition: gtk_quit.c:49
#define DELETE_QUIT
Definition: gtk_quit.c:48
void quit_notify(GtkWidget *widget, gpointer data)
Definition: gtk_quit.c:57
void cd_notify(GtkWidget *widget, gpointer data)
Definition: gtk_quit.c:53
void create_quit_button()
Definition: gtk_quit.c:108
#define QUICK_QUIT
Definition: gtk_quit.c:46
GtkWidget * quit_menu_item
Definition: gtk_quit.c:51
#define CLOSE_QUIT
Definition: gtk_quit.c:47
void direct_change_directory()
FC: uses an external wish script I do not know how to activate this function safely....
Definition: gtk_select.c:126
const char * gpips_gtk_menu_item_get_label(GtkWidget *w)
Definition: gtk_utils.c:43
string db_get_current_workspace_name(void)
the function is used to check that there is some current workspace...
Definition: workspace.c:82