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
|
/* -*-c-*- -------------- mixgtk_gen_handlers.c :
* Implementation of the functions declared in mixgtk_gen_handlers.h
* ------------------------------------------------------------------
* $Id: mixgtk_gen_handlers.c,v 1.10 2005/09/20 19:43:14 jao Exp $
* ------------------------------------------------------------------
* Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
*
* 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.
*
*/
#include <mixlib/mix_vm_command.h>
#include "mixgtk_gen_handlers.h"
#include "mixgtk_cmd_dispatcher.h"
#include "mixgtk_config.h"
/* grab a file with an externally provided callback */
void
mixgtk_get_file (file_callback_t callback,
const gchar *title,
const gchar *pattern,
const gchar *def_file)
{
if (callback != NULL)
{
GtkWidget *dialog;
dialog =
gtk_file_chooser_dialog_new (title,
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
if (pattern != NULL)
{
GtkFileFilter *filter = gtk_file_filter_new ();
gtk_file_filter_add_pattern (filter, pattern);
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
}
if (def_file != NULL)
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), def_file);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
char *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
callback (filename);
g_free (filename);
}
gtk_widget_destroy (dialog);
}
}
/* exec prompt command */
static void
exec_cmd_ (mix_vm_command_t cmd, const gchar *arg)
{
gchar *command;
if (arg)
command = g_strdup_printf ("%s %s",
mix_vm_command_to_string (cmd),
arg);
else
command = g_strdup (mix_vm_command_to_string (cmd));
mixgtk_cmd_dispatcher_dispatch (command);
g_free (command);
}
/* load mix binary */
static void
open_cb_ (const gchar *file)
{
if (file)
exec_cmd_ (MIX_CMD_LOAD, file);
}
void
on_file_open_activate (GtkWidget *w, gpointer data)
{
mixgtk_get_file (open_cb_, _("Load MIX program..."), "*.mix", NULL);
}
/* edit mixal source */
static void
edit_cb_ (const gchar *file)
{
exec_cmd_ (MIX_CMD_EDIT, file);
}
void
on_file_edit_activate (GtkWidget *w, gpointer data)
{
mixgtk_get_file (edit_cb_, _("Edit MIXAL source file..."), "*.mixal",
mixgtk_cmd_dispatcher_get_src_path ());
}
/* compile mixal source */
static void
compile_cb_ (const gchar *file)
{
exec_cmd_ (MIX_CMD_COMPILE, file);
}
void
on_file_compile_activate (GtkWidget *w, gpointer data)
{
mixgtk_get_file (compile_cb_, _("Compile MIXAL source file..."), "*.mixal",
mixgtk_cmd_dispatcher_get_src_path ());
}
void
on_debug_run_activate (GtkWidget *w, gpointer p)
{
mixgtk_cmd_dispatcher_dispatch (mix_vm_command_to_string (MIX_CMD_RUN));
}
void
on_debug_next_activate (GtkWidget *w, gpointer p)
{
mixgtk_cmd_dispatcher_dispatch (mix_vm_command_to_string (MIX_CMD_NEXT));
}
void
on_file_exit_activate (GtkWidget *w, gpointer data)
{
gtk_main_quit ();
}
void
on_clear_breakpoints_activate (GtkWidget *w, gpointer data)
{
mixgtk_cmd_dispatcher_dispatch (mix_vm_command_to_string (MIX_CMD_CABP));
}
void
on_save_on_exit_toggle (GtkWidget *w, gpointer data)
{
mixgtk_config_set_autosave (GTK_CHECK_MENU_ITEM (w)->active);
}
void
on_save_activate (GtkWidget *w, gpointer data)
{
mixgtk_config_save ();
}
|