{
g_return_val_if_fail(glk || CHIMARA_IS_GLK(glk), FALSE);
g_return_val_if_fail(plugin, FALSE);
+ if(chimara_glk_get_running(glk)) {
+ g_set_error(error, CHIMARA_ERROR, CHIMARA_PLUGIN_ALREADY_RUNNING, _("There was already a plugin running."));
+ return FALSE;
+ }
ChimaraGlkPrivate *priv = CHIMARA_GLK_PRIVATE(glk);
struct StartupData *startup = g_slice_new0(struct StartupData);
* <listitem><para>An appropriate interpreter plugin for the autodetected
* game file type could not be found.</para></listitem>
* </varlistentry>
+ * <varlistentry>
+ * <term>CHIMARA_PLUGIN_ALREADY_RUNNING</term>
+ * <listitem><para>A plugin was opened while there was already another plugin
+ * running in the widget.</para></listitem>
* </variablelist>
*/
typedef enum _ChimaraError {
CHIMARA_LOAD_MODULE_ERROR,
CHIMARA_NO_GLK_MAIN,
- CHIMARA_PLUGIN_NOT_FOUND
+ CHIMARA_PLUGIN_NOT_FOUND,
+ CHIMARA_PLUGIN_ALREADY_RUNNING
} ChimaraError;
/**
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <gdk/gdkkeysyms.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
#include <libchimara/chimara-glk.h>
+#include <libchimara/chimara-if.h>
#include "error.h"
-void on_save(GtkAction *action, ChimaraGlk *glk) {
+void
+on_open_activate(GtkAction *action, ChimaraGlk *glk)
+{
+ GtkWindow *window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(glk)));
+
+ if(chimara_glk_get_running(glk)) {
+ GtkWidget *dialog = gtk_message_dialog_new(window,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_CANCEL,
+ _("Are you sure you want to open a new game?"));
+ gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
+ _("If you open a new game, you will quit the one you are currently playing."));
+ gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OPEN, GTK_RESPONSE_OK);
+ gint response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+
+ if(response != GTK_RESPONSE_OK)
+ return;
+
+ chimara_glk_stop(glk);
+ chimara_glk_wait(glk);
+ }
+
+ GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Open Game"),
+ window,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
+ GError *error = NULL;
+ gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ if(!chimara_if_run_game(CHIMARA_IF(glk), filename, &error))
+ error_dialog(window, error, _("Could not open game file."));
+ g_free(filename);
+ }
+ gtk_widget_destroy(dialog);
+}
+
+void
+on_recent_item_activated(GtkRecentChooser *chooser, ChimaraGlk *glk)
+{
+
+}
+
+void
+on_stop_activate(GtkAction *action, ChimaraGlk *glk)
+{
+ chimara_glk_stop(glk);
+}
+
+void
+on_quit_chimara_activate(GtkAction *action, ChimaraGlk *glk)
+{
+ gtk_main_quit();
+}
+
+void
+on_cut_activate(GtkAction *action, ChimaraGlk *glk)
+{
+
+}
+
+void
+on_copy_activate(GtkAction *action, ChimaraGlk *glk)
+{
+
+}
+
+void
+on_paste_activate(GtkAction *action, ChimaraGlk *glk)
+{
+
+}
+
+void
+on_preferences_activate(GtkAction *action, ChimaraGlk *glk)
+{
+
+}
+
+void
+on_undo_activate(GtkAction *action, ChimaraGlk *glk)
+{
+ chimara_glk_feed_line_input(glk, "undo");
+}
+
+void
+on_save_activate(GtkAction *action, ChimaraGlk *glk)
+{
chimara_glk_feed_line_input(glk, "save");
}
-void on_restore(GtkAction *action, ChimaraGlk *glk) {
+void
+on_restore_activate(GtkAction *action, ChimaraGlk *glk)
+{
chimara_glk_feed_line_input(glk, "restore");
}
-gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, ChimaraGlk *glk) {
- gtk_main_quit();
- return TRUE;
+void
+on_restart_activate(GtkAction *action, ChimaraGlk *glk)
+{
+ chimara_glk_feed_line_input(glk, "restart");
+}
+
+void
+on_quit_activate(GtkAction *action, ChimaraGlk *glk)
+{
+ chimara_glk_feed_line_input(glk, "quit");
}
-void on_quit(GtkAction *action, ChimaraGlk *glk) {
+void
+on_about_activate(GtkAction *action, ChimaraGlk *glk)
+{
+
+}
+
+gboolean
+on_window_delete_event(GtkWidget *widget, GdkEvent *event, ChimaraGlk *glk)
+{
gtk_main_quit();
+ return TRUE;
}
<menubar>
<menu action="game">
<menuitem action="open"/>
- <menuitem action="restore"/>
- <menuitem action="save"/>
+ <menuitem action="recent"/>
<separator/>
+ <menuitem action="stop"/>
+ <menuitem action="quit_chimara"/>
+ </menu>
+ <menu action="edit">
+ <menuitem action="cut"/>
+ <menuitem action="copy"/>
+ <menuitem action="paste"/>
+ <separator/>
+ <menuitem action="preferences"/>
+ </menu>
+ <menu action="command">
+ <menuitem action="undo"/>
+ <menuitem action="save"/>
+ <menuitem action="restore"/>
+ <menuitem action="restart"/>
<menuitem action="quit"/>
</menu>
+ <menu action="help">
+ <menuitem action="about"/>
+ </menu>
</menubar>
<toolbar>
<toolitem action="open"/>
+ <separator/>
<toolitem action="restore"/>
<toolitem action="save"/>
- <separator/>
- <toolitem action="quit"/>
</toolbar>
</ui>
<!-- interface-naming-policy toplevel-contextual -->
<object class="GtkWindow" id="chimara">
<property name="title" translatable="yes">Chimara</property>
- <property name="default_width">800</property>
+ <property name="default_width">600</property>
<property name="default_height">800</property>
<signal name="delete_event" handler="on_window_delete_event"/>
<child>
<property name="short_label">_Open</property>
<property name="tooltip">Quit the current game and load a new one</property>
<property name="stock_id">gtk-media-play</property>
+ <signal name="activate" handler="on_open_activate"/>
</object>
<object class="GtkAction" id="restore">
<property name="label">_Restore...</property>
<property name="short_label">_Restore</property>
<property name="tooltip">Restore a previously saved game</property>
<property name="stock_id">gtk-open</property>
- <signal name="activate" handler="on_restore"/>
+ <signal name="activate" handler="on_restore_activate"/>
</object>
<object class="GtkAction" id="save">
<property name="label">_Save</property>
<property name="tooltip">Save the game</property>
<property name="stock_id">gtk-save</property>
- <signal name="activate" handler="on_save"/>
+ <signal name="activate" handler="on_save_activate"/>
+ </object>
+ <object class="GtkAction" id="quit_chimara">
+ <property name="label">_Quit Chimara</property>
+ <property name="tooltip">Leave the program</property>
+ <property name="stock_id">gtk-quit</property>
+ <signal name="activate" handler="on_quit_chimara_activate"/>
+ </object>
+ <object class="GtkAction" id="command">
+ <property name="label">_Command</property>
+ </object>
+ <object class="GtkAction" id="edit">
+ <property name="label">_Edit</property>
+ </object>
+ <object class="GtkAction" id="stop">
+ <property name="label">_Stop Game</property>
+ <property name="short_label">_Stop</property>
+ <property name="tooltip">Immediately stop the running game</property>
+ <property name="stock_id">gtk-stop</property>
+ <signal name="activate" handler="on_stop_activate"/>
+ </object>
+ <object class="GtkRecentAction" id="recent">
+ <property name="label">Open _Recent</property>
+ <property name="limit">10</property>
+ <property name="sort_type">mru</property>
+ <signal name="item_activated" handler="on_recent_item_activated"/>
+ </object>
+ <object class="GtkAction" id="undo">
+ <property name="label">_Undo</property>
+ <property name="tooltip">Attempt to undo the last move (the game may not allow this)</property>
+ <property name="stock_id">gtk-undo</property>
+ <signal name="activate" handler="on_undo_activate"/>
+ </object>
+ <object class="GtkAction" id="restart">
+ <property name="label">Res_tart</property>
+ <property name="tooltip">Tell the game to restart</property>
+ <property name="stock_id">gtk-media-rewind</property>
+ <signal name="activate" handler="on_restart_activate"/>
</object>
<object class="GtkAction" id="quit">
<property name="label">_Quit</property>
- <property name="tooltip">Exit Chimara</property>
- <property name="stock_id">gtk-quit</property>
- <signal name="activate" handler="on_quit"/>
+ <property name="tooltip">Try to quit the game</property>
+ <property name="stock_id">gtk-media-stop</property>
+ <signal name="activate" handler="on_quit_activate"/>
+ </object>
+ <object class="GtkAction" id="cut">
+ <property name="label">Cu_t</property>
+ <property name="tooltip">Cut the selection</property>
+ <property name="stock_id">gtk-cut</property>
+ <signal name="activate" handler="on_cut_activate"/>
+ </object>
+ <object class="GtkAction" id="copy">
+ <property name="label">_Copy</property>
+ <property name="tooltip">Copy the selection</property>
+ <property name="stock_id">gtk-copy</property>
+ <signal name="activate" handler="on_copy_activate"/>
+ </object>
+ <object class="GtkAction" id="paste">
+ <property name="label">_Paste</property>
+ <property name="tooltip">Paste the clipboard</property>
+ <property name="stock_id">gtk-paste</property>
+ <signal name="activate" handler="on_paste_activate"/>
+ </object>
+ <object class="GtkAction" id="preferences">
+ <property name="label">P_references</property>
+ <property name="tooltip">Configure the application</property>
+ <property name="stock_id">gtk-preferences</property>
+ <signal name="activate" handler="on_preferences_activate"/>
+ </object>
+ <object class="GtkAction" id="help">
+ <property name="label">_Help</property>
+ </object>
+ <object class="GtkAction" id="about">
+ <property name="label">_About...</property>
+ <property name="short_label">_About</property>
+ <property name="tooltip">About this application</property>
+ <property name="stock_id">gtk-about</property>
+ <signal name="activate" handler="on_about_activate"/>
</object>
</interface>
action group. */
const gchar *actions[] = {
"game", "",
- "open", "<ctrl>F7",
- "restore", "<ctrl>O",
- "save", NULL, /* NULL means use stock accelerator */
- "quit", NULL,
+ "open", "<ctrl>O",
+ "recent", "",
+ "stop", "",
+ "quit_chimara", NULL, /* NULL means use stock accelerator */
+ "command", "",
+ "undo", "<ctrl>Z",
+ "save", NULL,
+ "restore", "<ctrl>R",
+ "restart", "",
+ "quit", "",
+ "edit", "",
+ "cut", NULL,
+ "copy", NULL,
+ "paste", NULL,
+ "preferences", "",
+ "help", "",
+ "about", "",
NULL
};
const gchar **ptr;
}
glk = chimara_if_new();
- //chimara_if_set_preferred_interpreter( CHIMARA_IF(glk), CHIMARA_IF_FORMAT_Z8, CHIMARA_IF_INTERPRETER_NITFOL);
-
- g_object_set(glk,
- "border-width", 6,
- "spacing", 6,
- "ignore-errors", TRUE,
- NULL);
- chimara_glk_set_default_font_string(CHIMARA_GLK(glk), "Serif 12");
- chimara_glk_set_monospace_font_string(CHIMARA_GLK(glk), "Monospace 12");
+ g_object_set(glk, "ignore-errors", TRUE, NULL);
GtkBox *vbox = GTK_BOX( gtk_builder_get_object(builder, "vbox") );
if(vbox == NULL)
g_object_unref( G_OBJECT(builder) );
g_object_unref( G_OBJECT(uimanager) );
- if(argc < 2) {
- error_dialog(GTK_WINDOW(window), NULL, "Must provide a game file");
- return 1;
- }
-
- if( !chimara_if_run_game(CHIMARA_IF(glk), argv[1], &error) ) {
- error_dialog(GTK_WINDOW(window), error, "Error starting Glk library: ");
- return 1;
+ if(argc >= 2) {
+ if( !chimara_if_run_game(CHIMARA_IF(glk), argv[1], &error) ) {
+ error_dialog(GTK_WINDOW(window), error, "Error starting Glk library: ");
+ return 1;
+ }
}
gdk_threads_enter();