summaryrefslogtreecommitdiffhomepage
path: root/mixgtk/mixgtk_gen_handlers.c
diff options
context:
space:
mode:
Diffstat (limited to 'mixgtk/mixgtk_gen_handlers.c')
-rw-r--r--mixgtk/mixgtk_gen_handlers.c112
1 files changed, 54 insertions, 58 deletions
diff --git a/mixgtk/mixgtk_gen_handlers.c b/mixgtk/mixgtk_gen_handlers.c
index 656286b..d33fbac 100644
--- a/mixgtk/mixgtk_gen_handlers.c
+++ b/mixgtk/mixgtk_gen_handlers.c
@@ -1,24 +1,24 @@
/* -*-c-*- -------------- mixgtk_gen_handlers.c :
* Implementation of the functions declared in mixgtk_gen_handlers.h
* ------------------------------------------------------------------
- * $Id: mixgtk_gen_handlers.c,v 1.8 2002/04/10 23:39:40 jao Exp $
+ * $Id: mixgtk_gen_handlers.c,v 1.9 2004/06/23 10:50:10 jao Exp $
* ------------------------------------------------------------------
- * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
- *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
+ *
*/
#include <mixlib/mix_vm_command.h>
@@ -26,58 +26,51 @@
#include "mixgtk_cmd_dispatcher.h"
#include "mixgtk_config.h"
-static file_callback_t callback_ = NULL;
-
-
-static void
-on_file_ok_ (GtkWidget *w, gpointer fs)
-{
- gchar *file = g_strdup
- (gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
- gtk_widget_destroy (GTK_WIDGET (fs));
- if (callback_) callback_ (file);
- g_free (file);
-}
-
-static void
-on_file_destroy_ (GtkWidget *w, gpointer data)
-{
- gtk_grab_remove (GTK_WIDGET (w));
-}
-
-static void show_dlg_ (const gchar *title, const gchar *pattern)
-{
- GtkWidget *file = gtk_file_selection_new (title);
- if (pattern)
- gtk_file_selection_complete (GTK_FILE_SELECTION (file), pattern);
-
- gtk_signal_connect (GTK_OBJECT (file), "destroy",
- (GtkSignalFunc) on_file_destroy_,
- GTK_OBJECT (file));
- gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file)->ok_button),
- "clicked", (GtkSignalFunc) on_file_ok_,
- GTK_OBJECT (file));
- gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION
- (file)->cancel_button),
- "clicked", (GtkSignalFunc) gtk_widget_destroy,
- GTK_OBJECT (file));
- gtk_widget_show (file);
- gtk_grab_add (file);
-}
-
/* grab a file with an externally provided callback */
void
mixgtk_get_file (file_callback_t callback,
- const gchar *title, const gchar *pattern)
+ const gchar *title,
+ const gchar *pattern,
+ const gchar *def_file)
{
- g_return_if_fail (callback != NULL);
- callback_ = callback;
- show_dlg_ (title, pattern);
-}
+ 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)
+static void
+exec_cmd_ (mix_vm_command_t cmd, const gchar *arg)
{
gchar *command;
if (arg)
@@ -89,9 +82,10 @@ static void exec_cmd_ (mix_vm_command_t cmd, const gchar *arg)
mixgtk_cmd_dispatcher_dispatch (command);
g_free (command);
}
-
+
/* load mix binary */
-static void open_cb_ (const gchar *file)
+static void
+open_cb_ (const gchar *file)
{
if (file)
exec_cmd_ (MIX_CMD_LOAD, file);
@@ -100,11 +94,12 @@ static void open_cb_ (const gchar *file)
void
on_file_open_activate (GtkWidget *w, gpointer data)
{
- mixgtk_get_file (open_cb_, _("Load MIX program..."), "*.mix");
+ mixgtk_get_file (open_cb_, _("Load MIX program..."), "*.mix", NULL);
}
/* edit mixal source */
-static void edit_cb_ (const gchar *file)
+static void
+edit_cb_ (const gchar *file)
{
exec_cmd_ (MIX_CMD_EDIT, file);
}
@@ -112,12 +107,13 @@ static void edit_cb_ (const gchar *file)
void
on_file_edit_activate (GtkWidget *w, gpointer data)
{
- mixgtk_get_file (edit_cb_, _("Edit MIXAL source file..."),
+ 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)
+static void
+compile_cb_ (const gchar *file)
{
exec_cmd_ (MIX_CMD_COMPILE, file);
}
@@ -125,7 +121,7 @@ static void compile_cb_ (const gchar *file)
void
on_file_compile_activate (GtkWidget *w, gpointer data)
{
- mixgtk_get_file (compile_cb_, _("Compile MIXAL source file..."),
+ mixgtk_get_file (compile_cb_, _("Compile MIXAL source file..."), "*.mixal",
mixgtk_cmd_dispatcher_get_src_path ());
}