PIPS
xv_quit.c
Go to the documentation of this file.
1 /*
2 
3  $Id: xv_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 #include <xview/xview.h>
32 #include <xview/panel.h>
33 #include <xview/notice.h>
34 
35 #include "genC.h"
36 #include "database.h"
37 #include "misc.h"
38 #include "linear.h"
39 #include "ri.h"
40 
41 #include "ri-util.h"
42 #include "pipsdbm.h"
43 #include "top-level.h"
44 
45 #include "wpips.h"
46 
47 #define QUICK_QUIT "Quit without saving"
48 #define CLOSE_QUIT "Close (save) the Workspace & Quit"
49 #define DELETE_QUIT "Delete the Workspace & Quit"
50 #define CD_HACK_QUIT "Change Directory (tcl/tk hack)"
51 
52 Panel_item quit_button;
53 
54 
55 void
56 cd_notify(Menu menu, Menu_item menu_item)
57 {
59 }
60 
61 void
62 quit_notify(Menu menu,
63  Menu_item menu_item)
64 {
65  Event e;
66  int result;
67  string pn;
68 
69  if ((pn = db_get_current_workspace_name())) {
70  string fmt="Workspace %s not closed";
71  char str[SMALL_BUFFER_LENGTH];
72  string str1, str2, menu_string;
73 
74  str2 = "Do you really want to quit PIPS?";
75  menu_string=(string) xv_get(menu_item, MENU_STRING);
76  if (strcmp(menu_string,CLOSE_QUIT)==0)
77  str1=" ";
78  else
79  str1="-=< Resources can get lost! >=-";
80 
81  sprintf(str, fmt , pn);
82 
83  /* Send to emacs if we are in the emacs mode: */
84  if (wpips_emacs_mode)
85  send_notice_prompt_to_emacs(str, str1, str2, NULL);
86  result = notice_prompt(xv_find(main_frame, WINDOW, 0),
87  &e,
88  NOTICE_MESSAGE_STRINGS,
89  str, str1, str2,
90  NULL,
91  NOTICE_BUTTON_YES, menu_string,
92  NOTICE_BUTTON_NO, "Cancel",
93  NULL);
94  if (result == NOTICE_NO)
95  return;
96  else if (strcmp(menu_string, CLOSE_QUIT) == 0)
97  close_workspace(TRUE);
98  else if (strcmp(menu_string, DELETE_QUIT) == 0)
99  {
100  int win = 0;
101 
102  /* Destroy all the windows (close open files) */
103  for (win = 0; win < number_of_wpips_windows ; win++)
104  xv_destroy(edit_frame[win]);
105 
106  check_delete_workspace(pn, FALSE);
107  }
108 
109  }
110 
111  /* Clear the log window to avoid the message about the edited
112  state:
113  clear_log_subwindow(NULL, NULL);
114  Does not work...
115  Quit:
116  xv_destroy[_safe](main_frame);
117  */
118  /* Exit xv_main_loop() at top level: */
119  notify_stop();
120 }
121 
122 
123 void
125 {
126  Menu menu;
127 
128  menu = xv_create(XV_NULL, MENU_COMMAND_MENU,
129  MENU_ACTION_ITEM, CLOSE_QUIT, quit_notify,
130  MENU_ACTION_ITEM, QUICK_QUIT, quit_notify,
131  MENU_ACTION_ITEM, DELETE_QUIT, quit_notify,
132  MENU_ACTION_ITEM, CD_HACK_QUIT, cd_notify,
133  NULL);
134 
135  quit_button = xv_create(main_panel, PANEL_BUTTON,
136  PANEL_LABEL_STRING, "Quit ",
137  PANEL_ITEM_MENU, menu,
138  NULL);
139 }
bool close_workspace(bool is_quit)
Definition: dbm.c:346
bool check_delete_workspace(const char *wname, bool check)
Definition: dbm.c:375
bool wpips_emacs_mode
Here are all the stuff to interface Pips with Emacs.
Definition: emacs.c:65
void send_notice_prompt_to_emacs(char *first_line,...)
Definition: emacs.c:220
#define SMALL_BUFFER_LENGTH
Definition: gpips-local.h:24
GtkWidget * main_frame
If we are in the Emacs mode, the log_frame is no longer really used:
Definition: gpips.c:60
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
char * string
STRING.
Definition: newgen_types.h:39
string db_get_current_workspace_name(void)
the function is used to check that there is some current workspace...
Definition: workspace.c:82
Frame edit_frame[MAX_NUMBER_OF_WPIPS_WINDOWS]
Definition: wpips-local.h:41
Panel main_panel
Definition: wpips.c:63
int number_of_wpips_windows
Definition: xv_edit2.c:77
Panel_item quit_button
Definition: xv_quit.c:52
#define CD_HACK_QUIT
Definition: xv_quit.c:50
#define DELETE_QUIT
Definition: xv_quit.c:49
void cd_notify(Menu menu, Menu_item menu_item)
Definition: xv_quit.c:56
void create_quit_button()
Definition: xv_quit.c:124
#define QUICK_QUIT
Definition: xv_quit.c:47
void quit_notify(Menu menu, Menu_item menu_item)
Definition: xv_quit.c:62
#define CLOSE_QUIT
Definition: xv_quit.c:48