summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2006-08-06 02:29:13 +0000
committerJose Antonio Ortega Ruiz <jao@gnu.org>2006-08-06 02:29:13 +0000
commit55f2e4fdb81f450849246cfe6d670a5667e49bf4 (patch)
tree9a4f7827146662492dbf4f139a6ece2237e694b6
parent38572a19e884716f6f8e15c7c523ab98270356a5 (diff)
downloadmdk-55f2e4fdb81f450849246cfe6d670a5667e49bf4.tar.gz
mdk-55f2e4fdb81f450849246cfe6d670a5667e49bf4.tar.bz2
Refactoring of the previous patch
git-archimport-id: mdk@sv.gnu.org/mdk--devel--1--patch-19
-rw-r--r--NEWS4
-rw-r--r--mixgtk/mixgtk_gen_handlers.c77
2 files changed, 49 insertions, 32 deletions
diff --git a/NEWS b/NEWS
index 3adb557..c42e5c4 100644
--- a/NEWS
+++ b/NEWS
@@ -11,9 +11,11 @@ Please send mdk bug reports to bug-mdk@gnu.org.
** MIXAL compliance fixes (thanks to Xiaofeng Zhao):
- NOP accepts an F-spec.
- - Invalid F-spec values are reported as warning instead of errors,
+ - Invalid F-spec values are reported as warnings instead of errors,
since they can be legitimately (if hackishly) used.
+** gmixvm: the load file dialog now remembers last directory.
+
** Bug fixes:
- smem in mixvm correctly handles negative zero (thanks to Michael
diff --git a/mixgtk/mixgtk_gen_handlers.c b/mixgtk/mixgtk_gen_handlers.c
index 7ebadfb..73978cb 100644
--- a/mixgtk/mixgtk_gen_handlers.c
+++ b/mixgtk/mixgtk_gen_handlers.c
@@ -27,56 +27,71 @@
/* grab a file with an externally provided callback */
typedef void (*file_callback_t)(const gchar *file);
+static GtkFileChooser *
+get_chooser_ (const gchar *title, gboolean src)
+{
+ static GtkFileChooser *dialog = NULL;
+ static GtkFileFilter *src_filter = NULL;
+ static GtkFileFilter *code_filter = NULL;
+
+ if (dialog == NULL)
+ {
+ dialog = GTK_FILE_CHOOSER
+ (gtk_file_chooser_dialog_new ("gmixvm",
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL));
+ src_filter = gtk_file_filter_new ();
+ gtk_file_filter_add_pattern (src_filter, "*.mixal");
+ code_filter = gtk_file_filter_new ();
+ gtk_file_filter_add_pattern (code_filter, "*.mix");
+ gtk_file_chooser_add_filter (dialog, src_filter);
+ gtk_file_chooser_add_filter (dialog, code_filter);
+ }
+
+ gtk_file_chooser_set_filter (dialog, src? src_filter : code_filter);
+ gtk_window_set_title (GTK_WINDOW (dialog), title);
+
+ return dialog;
+}
+
static void
get_file_ (file_callback_t callback,
const gchar *title,
- const gchar *pattern,
+ gboolean is_src,
const gchar *def_file)
{
static gchar *last_folder = NULL;
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);
- }
+ GtkFileChooser *dialog = get_chooser_ (title, is_src);
if (def_file != NULL)
{
- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), def_file);
+ gtk_file_chooser_set_filename (dialog, def_file);
}
else if (last_folder != NULL)
{
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
- last_folder);
+ gtk_file_chooser_set_current_folder (dialog, last_folder);
}
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ gint result = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_hide (GTK_WIDGET (dialog));
+
+ if (result == GTK_RESPONSE_ACCEPT)
{
- gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- callback (filename);
+ gchar *filename = gtk_file_chooser_get_filename (dialog);
if (filename)
{
+ callback (filename);
if (last_folder) g_free (last_folder);
last_folder = g_path_get_dirname (filename);
g_free (filename);
}
}
-
- gtk_widget_destroy (dialog);
}
}
@@ -99,20 +114,20 @@ exec_cmd_ (mix_vm_command_t cmd, const gchar *arg)
static void
open_cb_ (const gchar *file)
{
- if (file) exec_cmd_ (MIX_CMD_LOAD, file);
+ exec_cmd_ (MIX_CMD_LOAD, file);
}
void
on_file_open_activate (GtkWidget *w, gpointer data)
{
- get_file_ (open_cb_, _("Load MIX program..."), "*.mix", NULL);
+ get_file_ (open_cb_, _("Load MIX program..."), FALSE, NULL);
}
/* edit mixal source */
static void
edit_cb_ (const gchar *file)
{
- if (file) exec_cmd_ (MIX_CMD_EDIT, file);
+ exec_cmd_ (MIX_CMD_EDIT, file);
}
void
@@ -120,7 +135,7 @@ on_file_edit_activate (GtkWidget *w, gpointer data)
{
get_file_ (edit_cb_,
_("Edit MIXAL source file..."),
- "*.mixal",
+ TRUE,
mixgtk_cmd_dispatcher_get_src_path ());
}
@@ -128,7 +143,7 @@ on_file_edit_activate (GtkWidget *w, gpointer data)
static void
compile_cb_ (const gchar *file)
{
- if (file) exec_cmd_ (MIX_CMD_COMPILE, file);
+ exec_cmd_ (MIX_CMD_COMPILE, file);
}
void
@@ -136,7 +151,7 @@ on_file_compile_activate (GtkWidget *w, gpointer data)
{
get_file_ (compile_cb_,
_("Compile MIXAL source file..."),
- "*.mixal",
+ TRUE,
mixgtk_cmd_dispatcher_get_src_path ());
}