~ubuntu-branches/debian/sid/geany-plugins/sid

« back to all changes in this revision

Viewing changes to geanygdb/src/gdb-ui-envir.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-07-10 22:56:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090710225641-xc1126t7pq0jmpos
Tags: upstream-0.17.1
ImportĀ upstreamĀ versionĀ 0.17.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * gdb-ui-envir.c - Environment and option settings for a GTK-based GDB user interface.
 
4
 *
 
5
 * See the file "gdb-ui.h" for license information.
 
6
 *
 
7
 */
 
8
 
 
9
 
 
10
#include <string.h>
 
11
#include <gtk/gtk.h>
 
12
#include "gdb-io.h"
 
13
#include "gdb-ui.h"
 
14
#include "support.h"
 
15
 
 
16
 
 
17
 
 
18
static GtkWidget *
 
19
newlabel(gchar * s)
 
20
{
 
21
        GtkWidget *w = gtk_label_new(s);
 
22
        gtk_misc_set_alignment(GTK_MISC(w), 0.0f, 0.0f);
 
23
        return w;
 
24
}
 
25
 
 
26
#define label(w,s) \
 
27
gtk_box_pack_start(vbox, newlabel(s), TRUE, TRUE, 0); \
 
28
gtk_box_pack_start(vbox, w, TRUE, TRUE, 0); \
 
29
gtk_entry_set_activates_default(GTK_ENTRY(w), TRUE);
 
30
 
 
31
static gboolean
 
32
same_str(const gchar * a, const gchar * b)
 
33
{
 
34
        if ((!a) && (!b))
 
35
        {
 
36
                return TRUE;
 
37
        }
 
38
        if (!a)
 
39
        {
 
40
                return (!b) || (!*b);
 
41
        }
 
42
        if (!b)
 
43
        {
 
44
                return (!a) || (!*a);
 
45
        }
 
46
        return g_str_equal(a, b);
 
47
}
 
48
 
 
49
 
 
50
 
 
51
static gchar *
 
52
fixup_path(const gchar * path)
 
53
{
 
54
        if (path && *path)
 
55
        {
 
56
                gchar **dirs = g_strsplit(path, ":", 0);
 
57
                if (dirs)
 
58
                {
 
59
                        gchar *rv = NULL;
 
60
                        gint i;
 
61
                        for (i = 0; dirs[i]; i++)
 
62
                        {
 
63
                                if (strchr(dirs[i], ' '))
 
64
                                {
 
65
                                        gchar *tmp = g_strconcat("\"", dirs[i], "\"", NULL);
 
66
                                        g_free(dirs[i]);
 
67
                                        dirs[i] = tmp;
 
68
                                }
 
69
                        }
 
70
                        rv = g_strjoinv(" ", dirs);
 
71
                        g_strfreev(dirs);
 
72
                        return rv;
 
73
                }
 
74
        }
 
75
        return g_strdup("");
 
76
}
 
77
 
 
78
 
 
79
 
 
80
void
 
81
gdbui_env_dlg(const GdbEnvironInfo * env)
 
82
{
 
83
        GtkWidget *dlg = gtk_dialog_new_with_buttons(_("Environment settings"),
 
84
                                                     GTK_WINDOW(gdbui_setup.main_window),
 
85
                                                     GTK_DIALOG_MODAL |
 
86
                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
 
87
                                                     GTK_STOCK_OK, GTK_RESPONSE_OK,
 
88
                                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
 
89
 
 
90
        GtkBox *vbox = GTK_BOX(GTK_DIALOG(dlg)->vbox);
 
91
        GtkWidget *cwd_box = gtk_entry_new();
 
92
        GtkWidget *path_box = gtk_entry_new();
 
93
        GtkWidget *args_box = gtk_entry_new();
 
94
        GtkWidget *dirs_box = gtk_entry_new();
 
95
 
 
96
        gtk_window_set_transient_for(GTK_WINDOW(dlg), GTK_WINDOW(gdbui_setup.main_window));
 
97
        gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
 
98
        gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK);
 
99
 
 
100
        gtk_entry_set_text(GTK_ENTRY(cwd_box), env->cwd ? env->cwd : "");
 
101
        gtk_entry_set_text(GTK_ENTRY(path_box), env->path ? env->path : "");
 
102
        gtk_entry_set_text(GTK_ENTRY(args_box), env->args ? env->args : "");
 
103
        gtk_entry_set_text(GTK_ENTRY(dirs_box), env->dirs ? env->dirs : "");
 
104
 
 
105
        label(args_box, _("\n Command-line arguments passed to target program:"));
 
106
        label(dirs_box, _("\n Search path for source files:"));
 
107
        label(cwd_box, _("\n Working directory for target program:"));
 
108
        label(path_box, _("\n Search path for executables:"));
 
109
 
 
110
        gtk_widget_show_all(dlg);
 
111
        gtk_widget_set_usize(dlg, (gdk_screen_get_width(gdk_screen_get_default()) / 2) * 1, 0);
 
112
        if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_OK)
 
113
        {
 
114
                const gchar *cwd = gtk_entry_get_text(GTK_ENTRY(cwd_box));
 
115
                const gchar *path = gtk_entry_get_text(GTK_ENTRY(path_box));
 
116
                const gchar *args = gtk_entry_get_text(GTK_ENTRY(args_box));
 
117
                const gchar *dirs = gtk_entry_get_text(GTK_ENTRY(dirs_box));
 
118
                if (!same_str(cwd, env->cwd))
 
119
                {
 
120
                        gdbio_send_cmd("-environment-cd %s\n", cwd);
 
121
                }
 
122
                if (!same_str(path, env->path))
 
123
                {
 
124
                        gchar *fixed = fixup_path(path);
 
125
                        gdbio_send_cmd("-environment-path -r %s\n", fixed);
 
126
                        g_free(fixed);
 
127
                }
 
128
                if (!same_str(args, env->args))
 
129
                {
 
130
                        gdbio_send_cmd("-exec-arguments %s\n", args);
 
131
                }
 
132
                if (!same_str(dirs, env->dirs))
 
133
                {
 
134
                        gchar *fixed = fixup_path(dirs);
 
135
                        gdbio_send_cmd("-environment-directory -r %s\n", fixed);
 
136
                        g_free(fixed);
 
137
                }
 
138
        }
 
139
        gtk_widget_destroy(dlg);
 
140
}
 
141
 
 
142
#define MONO_FONT "monospace 12"
 
143
 
 
144
static void
 
145
font_click(GtkButton * button, gpointer user_data)
 
146
{
 
147
        GtkWidget *dlg;
 
148
        gchar *fn = NULL;
 
149
        gint resp;
 
150
        fn = (gchar *) gtk_entry_get_text(GTK_ENTRY(user_data));
 
151
        dlg = gtk_font_selection_dialog_new(_("Select Font"));
 
152
        if (fn && *fn)
 
153
        {
 
154
                gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dlg), fn);
 
155
        }
 
156
        resp = gtk_dialog_run(GTK_DIALOG(dlg));
 
157
        if (resp == GTK_RESPONSE_OK)
 
158
        {
 
159
                fn = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dlg));
 
160
                if (fn)
 
161
                {
 
162
                        gtk_entry_set_text(GTK_ENTRY(user_data), fn);
 
163
                        g_free(fn);
 
164
                }
 
165
        }
 
166
        gtk_widget_destroy(dlg);
 
167
}
 
168
 
 
169
 
 
170
void
 
171
gdbui_opts_dlg()
 
172
{
 
173
        GtkWidget *dlg = gtk_dialog_new_with_buttons(_("Preferences"),
 
174
                                                     GTK_WINDOW(gdbui_setup.main_window),
 
175
                                                     GTK_DIALOG_MODAL |
 
176
                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
 
177
                                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
178
                                                     GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
 
179
 
 
180
        GtkBox *vbox = GTK_BOX(GTK_DIALOG(dlg)->vbox);
 
181
        GtkWidget *hbox;
 
182
        GtkWidget *font_btn = gtk_button_new();
 
183
//  GtkWidget*font_btn=gtk_button_new_with_label("Choose...");
 
184
// GtkWidget*font_btn=gtk_button_new_from_stock(GTK_STOCK_SELECT_FONT);
 
185
 
 
186
        GtkWidget *font_box = gtk_entry_new();
 
187
        GtkWidget *term_box = gtk_entry_new();
 
188
#ifdef STANDALONE
 
189
        GtkWidget *top_chk = gtk_check_button_new_with_label(_("Keep debug window on top."));
 
190
#endif
 
191
        GtkWidget *tip_chk = gtk_check_button_new_with_label(_("Show tooltips."));
 
192
        GtkWidget *ico_chk = gtk_check_button_new_with_label(_("Show icons."));
 
193
 
 
194
        gtk_button_set_image(GTK_BUTTON(font_btn),
 
195
                             gtk_image_new_from_stock(GTK_STOCK_SELECT_FONT, GTK_ICON_SIZE_BUTTON));
 
196
 
 
197
        gtk_box_pack_start(vbox, newlabel(_("Font for source code listings:")), FALSE, FALSE, 2);
 
198
        if (gdbui_setup.options.mono_font)
 
199
        {
 
200
                gtk_entry_set_text(GTK_ENTRY(font_box), gdbui_setup.options.mono_font);
 
201
        }
 
202
        g_signal_connect(G_OBJECT(font_btn), "clicked", G_CALLBACK(font_click), font_box);
 
203
        hbox = gtk_hbox_new(FALSE, 0);
 
204
        gtk_box_pack_start(vbox, hbox, FALSE, FALSE, 0);
 
205
        gtk_box_pack_start(GTK_BOX(hbox), font_box, TRUE, TRUE, 0);
 
206
        gtk_box_pack_start(GTK_BOX(hbox), font_btn, FALSE, FALSE, 0);
 
207
 
 
208
        gtk_box_pack_start(vbox, gtk_hseparator_new(), FALSE, FALSE, 8);
 
209
        gtk_box_pack_start(vbox, newlabel(_("Terminal program:")), FALSE, FALSE, 2);
 
210
        gtk_box_pack_start(vbox, term_box, FALSE, FALSE, 0);
 
211
        if (gdbui_setup.options.term_cmd)
 
212
        {
 
213
                gtk_entry_set_text(GTK_ENTRY(term_box), gdbui_setup.options.term_cmd);
 
214
        }
 
215
 
 
216
        gtk_box_pack_start(vbox, gtk_hseparator_new(), FALSE, FALSE, 8);
 
217
#ifdef STANDALONE
 
218
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(top_chk), gdbui_setup.options.stay_on_top);
 
219
        gtk_box_pack_start(vbox, top_chk, FALSE, FALSE, 0);
 
220
#endif
 
221
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tip_chk), gdbui_setup.options.show_tooltips);
 
222
        gtk_box_pack_start(vbox, tip_chk, FALSE, FALSE, 0);
 
223
 
 
224
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ico_chk), gdbui_setup.options.show_icons);
 
225
        gtk_box_pack_start(vbox, ico_chk, FALSE, FALSE, 0);
 
226
 
 
227
 
 
228
        gtk_widget_show_all(dlg);
 
229
        if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_OK)
 
230
        {
 
231
                gchar *font = (gchar *) gtk_entry_get_text(GTK_ENTRY(font_box));
 
232
                gchar *term = (gchar *) gtk_entry_get_text(GTK_ENTRY(term_box));
 
233
                if ((font && *font)
 
234
                    && !(gdbui_setup.options.mono_font
 
235
                         && g_str_equal(gdbui_setup.options.mono_font, font)))
 
236
                {
 
237
                        g_free(gdbui_setup.options.mono_font);
 
238
                        gdbui_setup.options.mono_font = g_strdup(font);
 
239
                }
 
240
 
 
241
                if ((term && *term)
 
242
                    && !(gdbui_setup.options.term_cmd
 
243
                         && g_str_equal(gdbui_setup.options.term_cmd, term)))
 
244
                {
 
245
                        g_free(gdbui_setup.options.term_cmd);
 
246
                        gdbui_setup.options.term_cmd = g_strdup(term);
 
247
                }
 
248
        }
 
249
#ifdef STANDALONE
 
250
        gdbui_opts.stay_on_top = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(top_chk));
 
251
#endif
 
252
        gdbui_setup.options.show_tooltips =
 
253
                gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tip_chk));
 
254
        gdbui_setup.options.show_icons = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ico_chk));
 
255
        gtk_widget_destroy(dlg);
 
256
        if (gdbui_setup.opts_func)
 
257
        {
 
258
                gdbui_setup.opts_func();
 
259
        }
 
260
}
 
261
 
 
262
 
 
263
void
 
264
gdbui_opts_init()
 
265
{
 
266
        gdbui_setup.options.term_cmd = g_strdup("xterm");
 
267
        gdbui_setup.options.mono_font = g_strdup(MONO_FONT);
 
268
        gdbui_setup.options.show_tooltips = TRUE;
 
269
        gdbui_setup.options.show_icons = TRUE;
 
270
#ifdef STANDALONE
 
271
        gdbui_setup.options.stay_on_top = FALSE;
 
272
#endif
 
273
}
 
274
 
 
275
 
 
276
void
 
277
gdbui_opts_done()
 
278
{
 
279
        g_free(gdbui_setup.options.mono_font);
 
280
        gdbui_setup.options.mono_font = NULL;
 
281
}