-
Notifications
You must be signed in to change notification settings - Fork 263
/
tpage.c
421 lines (356 loc) · 10.6 KB
/
tpage.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/*
* tpage.c
*
* Copyright 2010 Alexander Petukhov <devel(at)apetukhov.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
/*
* Contains function to manipulate target page in debug notebook.
*/
#include <string.h>
#include <gtk/gtk.h>
#include <sys/stat.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "geanyplugin.h"
extern GeanyData *geany_data;
#include "breakpoints.h"
#include "utils.h"
#include "watch_model.h"
#include "wtree.h"
#include "debug.h"
#include "dconfig.h"
#include "tpage.h"
#include "tabs.h"
#include "envtree.h"
#include "gui.h"
/* boxes margins */
#define SPACING 7
/* root boxes border width */
#define ROOT_BORDER_WIDTH 10
/* root boxes border width */
#define BROWSE_BUTTON_WIDTH 65
/* widgets */
/* target */
static GtkWidget *target_label = NULL;
static GtkWidget *target_name = NULL;
static GtkWidget *target_button_browse = NULL;
/* debugger type */
static GtkWidget *debugger_label = NULL;
static GtkWidget *debugger_cmb = NULL;
/* argments */
static GtkWidget *args_frame = NULL;
static GtkWidget *args_textview = NULL;
/* environment variables */
static GtkWidget *env_frame = NULL;
/* widgets array for reference management when moving to another container */
static GtkWidget **widgets[] = {
&target_label, &target_name, &target_button_browse,
&debugger_label, &debugger_cmb,
&args_frame,
&env_frame,
NULL
};
/*
* tells config to update when target arguments change
*/
static void on_arguments_changed(GtkTextBuffer *textbuffer, gpointer user_data)
{
config_set_debug_changed();
}
/*
* target browse button clicked handler
*/
static void on_target_browse_clicked(GtkButton *button, gpointer user_data)
{
gchar *path;
const gchar *prevfile;
GtkWidget *dialog;
GeanyDocument *doc;
dialog = gtk_file_chooser_dialog_new (_("Choose target file"),
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
prevfile = gtk_entry_get_text(GTK_ENTRY(target_name));
path = g_path_get_dirname(prevfile);
if (strcmp(".", path) == 0 && (doc = document_get_current()) != NULL)
{
g_free(path);
path = g_path_get_dirname(DOC_FILENAME(doc));
}
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), path);
g_free(path);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
gchar *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
gtk_entry_set_text(GTK_ENTRY(target_name), filename);
g_free (filename);
config_set_debug_changed();
}
gtk_widget_destroy (dialog);
}
/*
* packs widgets into page depending one tabbed mode state
*/
void tpage_pack_widgets(gboolean tabbed)
{
/* root box */
GtkWidget *root = NULL, *oldroot = NULL;
GList *children = gtk_container_get_children(GTK_CONTAINER(tab_target));
if (children)
{
int i;
oldroot = (GtkWidget*)children->data;
/* unparent widgets */
i = 0;
while (widgets[i])
{
g_object_ref(*widgets[i]);
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(*widgets[i])), *widgets[i]);
i++;
}
g_list_free(children);
}
if (tabbed)
{
GtkWidget *hbox, *rbox, *lbox;
root = gtk_vbox_new(FALSE, SPACING);
gtk_container_set_border_width(GTK_CONTAINER(root), ROOT_BORDER_WIDTH);
/* filename */
hbox = gtk_hbox_new(FALSE, SPACING);
gtk_box_pack_start(GTK_BOX(root), hbox, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), target_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), target_name, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), target_button_browse, FALSE, FALSE, 0);
/* lower hbox */
hbox = gtk_hbox_new(TRUE, SPACING);
gtk_box_pack_start(GTK_BOX(root), hbox, TRUE, TRUE, 0);
/* lower left and right vboxes */
lbox = gtk_vbox_new(FALSE, SPACING);
rbox = gtk_vbox_new(FALSE, SPACING);
gtk_box_pack_start(GTK_BOX(hbox), lbox, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), rbox, TRUE, TRUE, 0);
/* environment */
gtk_box_pack_start(GTK_BOX(lbox), env_frame, TRUE, TRUE, 0);
/* arguments */
gtk_box_pack_start(GTK_BOX(rbox), args_frame, TRUE, TRUE, 0);
/* debugger type */
hbox = gtk_hbox_new(FALSE, SPACING);
gtk_box_pack_start(GTK_BOX(hbox), debugger_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), debugger_cmb, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(rbox), hbox, FALSE, FALSE, 0);
}
else
{
GtkWidget *lbox, *rbox, *hbox;
root = gtk_hbox_new(TRUE, SPACING);
gtk_container_set_border_width(GTK_CONTAINER(root), ROOT_BORDER_WIDTH);
lbox = gtk_vbox_new(FALSE, SPACING);
rbox = gtk_vbox_new(FALSE, SPACING);
gtk_box_pack_start(GTK_BOX(root), lbox, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(root), rbox, TRUE, TRUE, 0);
/* environment */
gtk_box_pack_start(GTK_BOX(lbox), env_frame, TRUE, TRUE, 0);
/* target */
hbox = gtk_hbox_new(FALSE, SPACING);
gtk_box_pack_start(GTK_BOX(hbox), target_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), target_name, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), target_button_browse, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(rbox), hbox, FALSE, FALSE, 0);
/* arguments */
gtk_box_pack_start(GTK_BOX(rbox), args_frame, TRUE, TRUE, 0);
/* debugger type */
hbox = gtk_hbox_new(FALSE, SPACING);
gtk_box_pack_start(GTK_BOX(hbox), debugger_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), debugger_cmb, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(rbox), hbox, FALSE, FALSE, 0);
}
if (oldroot)
{
int i = 0;
while (widgets[i])
{
g_object_unref(*widgets[i]);
i++;
}
gtk_container_remove(GTK_CONTAINER(tab_target), oldroot);
}
gtk_container_add(GTK_CONTAINER(tab_target), root);
gtk_widget_show_all(tab_target);
}
/*
* create widgets
*/
static void tpage_create_widgets(void)
{
GList *modules, *iter;
GtkWidget *hbox;
GtkTextBuffer *buffer;
GtkWidget *tree;
/* target */
target_label = gtk_label_new(_("Target:"));
target_name = gtk_entry_new ();
gtk_entry_set_editable(GTK_ENTRY(target_name), FALSE);
target_button_browse = create_stock_button(GTK_STOCK_OPEN, _("Browse"));
gtk_widget_set_size_request(target_button_browse, BROWSE_BUTTON_WIDTH, 0);
g_signal_connect(G_OBJECT(target_button_browse), "clicked", G_CALLBACK (on_target_browse_clicked), NULL);
/* debugger */
debugger_label = gtk_label_new(_("Debugger:"));
debugger_cmb = gtk_combo_box_new_text();
modules = debug_get_modules();
for (iter = modules; iter; iter = iter->next)
{
gtk_combo_box_append_text(GTK_COMBO_BOX(debugger_cmb), (gchar*)iter->data);
}
g_list_free(modules);
gtk_combo_box_set_active(GTK_COMBO_BOX(debugger_cmb), 0);
/* arguments */
args_frame = gtk_frame_new(_("Command Line Arguments"));
hbox = gtk_hbox_new(FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
args_textview = gtk_text_view_new ();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(args_textview), GTK_WRAP_CHAR);
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(args_textview));
g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK (on_arguments_changed), NULL);
gtk_container_add(GTK_CONTAINER(hbox), args_textview);
gtk_container_add(GTK_CONTAINER(args_frame), hbox);
/* environment */
env_frame = gtk_frame_new(_("Environment Variables"));
hbox = gtk_hbox_new(FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
tree = envtree_init();
gtk_container_add(GTK_CONTAINER(hbox), tree);
gtk_container_add(GTK_CONTAINER(env_frame), hbox);
}
/*
* set target
*/
void tpage_set_target(const gchar *newvalue)
{
gtk_entry_set_text(GTK_ENTRY(target_name), newvalue);
}
/*
* set debugger
*/
void tpage_set_debugger(const gchar *newvalue)
{
int module = debug_get_module_index(newvalue);
if (-1 == module)
{
module = 0;
}
gtk_combo_box_set_active(GTK_COMBO_BOX(debugger_cmb), module);
}
/*
* set command line
*/
void tpage_set_commandline(const gchar *newvalue)
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(args_textview));
gtk_text_buffer_set_text(buffer, newvalue, -1);
}
/*
* add environment variable
*/
void tpage_add_environment(const gchar *name, const gchar *value)
{
envtree_add_environment(name, value);
}
/*
* removes all data (clears widgets)
*/
void tpage_clear(void)
{
GtkTextBuffer *buffer;
/* target */
gtk_entry_set_text(GTK_ENTRY(target_name), "");
/* reset debugger type */
gtk_combo_box_set_active(GTK_COMBO_BOX(debugger_cmb), 0);
/* arguments */
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(args_textview));
gtk_text_buffer_set_text(buffer, "", -1);
/* environment variables */
envtree_clear();
}
/*
* get target file names
*/
gchar* tpage_get_target(void)
{
return g_strdup(gtk_entry_get_text(GTK_ENTRY(target_name)));
}
/*
* get selected debugger module index
*/
int tpage_get_debug_module_index(void)
{
return gtk_combo_box_get_active(GTK_COMBO_BOX(debugger_cmb));
}
/*
* get selected debugger name
*/
gchar* tpage_get_debugger(void)
{
return gtk_combo_box_get_active_text(GTK_COMBO_BOX(debugger_cmb));
}
/*
* get command line
*/
gchar* tpage_get_commandline(void)
{
gchar *args;
gchar **lines;
GtkTextIter start, end;
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(args_textview));
gtk_text_buffer_get_start_iter(buffer, &start);
gtk_text_buffer_get_end_iter(buffer, &end);
args = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
lines = g_strsplit(args, "\n", 0);
g_free(args);
args = g_strjoinv(" ", lines);
g_strfreev(lines);
return args;
}
/*
* get list of environment variables
*/
GList* tpage_get_environment(void)
{
return envpage_get_environment();
}
/*
* create target page
*/
void tpage_init(void)
{
tab_target = gtk_vbox_new(FALSE, 0);
tpage_create_widgets();
}
/*
* set the page readonly
*/
void tpage_set_readonly(gboolean readonly)
{
gtk_text_view_set_editable (GTK_TEXT_VIEW (args_textview), !readonly);
gtk_widget_set_sensitive (target_button_browse, !readonly);
gtk_widget_set_sensitive (debugger_cmb, !readonly);
envtree_set_readonly(readonly);
}