1 /*
2 Copyright (C) 1999/2002/2004 Kai Sterker <kai.sterker@gmail.com>
3 Part of the Adonthell Project <http://adonthell.nongnu.org>
4
5 Dlgedit is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 Dlgedit is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Dlgedit. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20 * @file gui_dlgedit_events.cc
21 *
22 * @author Kai Sterker
23 * @brief The Events triggered via the Dialogue Editor's main window
24 */
25
26 #include "cfg_data.h"
27 #include "gui_dlgedit.h"
28 #include "gui_file.h"
29
30 // Main Window: on_widget_destroy App
on_widget_destroy(GtkWidget * widget,gpointer data)31 void on_widget_destroy (GtkWidget * widget, gpointer data)
32 {
33 gtk_main_quit ();
34 gtk_widget_destroy (widget);
35 }
36
37 // File Menu: New
on_file_new_activate(GtkMenuItem * menuitem,gpointer user_data)38 void on_file_new_activate (GtkMenuItem * menuitem, gpointer user_data)
39 {
40 GuiDlgedit *dlgedit = (GuiDlgedit *) user_data;
41 dlgedit->newDialogue ();
42 }
43
44 // File Menu: Load
on_file_load_activate(GtkMenuItem * menuitem,gpointer user_data)45 void on_file_load_activate (GtkMenuItem * menuitem, gpointer user_data)
46 {
47 GuiDlgedit *dlgedit = (GuiDlgedit *) user_data;
48 GtkWindow *parent = (GtkWindow *) dlgedit->getWindow ();
49
50 GuiFile fs (parent, GTK_FILE_CHOOSER_ACTION_OPEN, "Load dialogue source", dlgedit->directory ());
51 fs.add_filter ("*" FILE_EXT, "Adonthell Dialogue Source");
52
53 // set shortcuts
54 const std::vector<std::string> & projects = CfgData::data->projectsFromDatadir ();
55 for (std::vector<std::string>::const_iterator i = projects.begin (); i != projects.end (); i++)
56 {
57 const std::string &dir = CfgData::data->getBasedir (*i);
58 fs.add_shortcut (dir);
59 }
60
61 // File selection closed with OK
62 if (fs.run ()) dlgedit->loadDialogue (fs.getSelection ());
63 }
64
65 // File Menu: Save As
on_file_save_as_activate(GtkMenuItem * menuitem,gpointer user_data)66 void on_file_save_as_activate (GtkMenuItem * menuitem, gpointer user_data)
67 {
68 GuiDlgedit *dlgedit = (GuiDlgedit *) user_data;
69 GtkWindow *parent = (GtkWindow *) dlgedit->getWindow ();
70
71 GuiFile fs (parent, GTK_FILE_CHOOSER_ACTION_SAVE, "Save dialogue source", dlgedit->filename ());
72 fs.add_filter ("*" FILE_EXT, "Adonthell Dialogue Source");
73
74 // set shortcuts
75 const std::vector<std::string> & projects = CfgData::data->projectsFromDatadir ();
76 for (std::vector<std::string>::const_iterator i = projects.begin (); i != projects.end (); i++)
77 {
78 const std::string &dir = CfgData::data->getBasedir (*i);
79 fs.add_shortcut (dir);
80 }
81
82 // File selection closed with OK
83 if (fs.run ()) dlgedit->saveDialogue (fs.getSelection ());
84 }
85
86 // File Menu: Save
on_file_save_activate(GtkMenuItem * menuitem,gpointer user_data)87 void on_file_save_activate (GtkMenuItem * menuitem, gpointer user_data)
88 {
89 GuiDlgedit *dlgedit = (GuiDlgedit *) user_data;
90 std::string filename = dlgedit->filename ();
91
92 // only save dialogues that aren't 'untitled'
93 if (filename.find ("untitled.adlg") == filename.npos)
94 dlgedit->saveDialogue (filename);
95 // otherwise open file selection
96 else
97 on_file_save_as_activate (menuitem, user_data);
98 }
99
100 // File Menu: Revert to Saved
on_file_revert_activate(GtkMenuItem * menuitem,gpointer user_data)101 void on_file_revert_activate (GtkMenuItem * menuitem, gpointer user_data)
102 {
103 GuiDlgedit::window->revertDialogue ();
104 }
105
106 // File Menu: Close
on_file_close_activate(GtkMenuItem * menuitem,gpointer user_data)107 void on_file_close_activate (GtkMenuItem * menuitem, gpointer user_data)
108 {
109 GuiDlgedit::window->closeDialogue ();
110 }
111
112 // Dialogue Menu: Compile
on_dialogue_compile_activate(GtkMenuItem * menuitem,gpointer user_data)113 void on_dialogue_compile_activate (GtkMenuItem * menuitem, gpointer user_data)
114 {
115 GuiDlgedit::window->compileDialogue ();
116 }
117
118 // Dialogue Menu: Settings
on_dialogue_player_activate(GtkMenuItem * menuitem,gpointer user_data)119 void on_dialogue_player_activate (GtkMenuItem * menuitem, gpointer user_data)
120 {
121 GuiDlgedit::window->settings ();
122 }
123
124 // Dialogue Menu: Functions
on_dialogue_functions_activate(GtkMenuItem * menuitem,gpointer user_data)125 void on_dialogue_functions_activate (GtkMenuItem * menuitem, gpointer user_data)
126 {
127 GuiDlgedit *dlgedit = (GuiDlgedit *) user_data;
128 dlgedit->customCode ();
129 }
130
131 // Dialogue Menu: Preview i18n
on_dialogue_preview_activate(GtkMenuItem * menuitem,gpointer user_data)132 void on_dialogue_preview_activate (GtkMenuItem * menuitem, gpointer user_data)
133 {
134 GuiDlgedit *dlgedit = (GuiDlgedit *) user_data;
135 GtkWindow *parent = (GtkWindow *) dlgedit->getWindow ();
136
137 GuiFile fs (parent, GTK_FILE_CHOOSER_ACTION_OPEN, "Select translation", dlgedit->directory ());
138 fs.add_filter ("*.mo", "Gettext Message Catalogue");
139
140 // start translation preview
141 if (dlgedit->mode () != L10N_PREVIEW)
142 {
143 // File selection closed with OK
144 if (fs.run ()) dlgedit->previewTranslation (fs.getSelection ());
145 }
146 // stop translation preview
147 else dlgedit->exitPreview ();
148 }
149
150 // Dialogue Menu: Run
on_dialogue_run_activate(GtkMenuItem * menuitem,gpointer user_data)151 void on_dialogue_run_activate (GtkMenuItem * menuitem, gpointer user_data)
152 {
153 /*
154 MainFrame *wnd = (MainFrame *) user_data;
155
156 if (wnd->test_dlg == NULL)
157 {
158 wnd->test_dlg = new run_dlg (wnd);
159 wnd->test_dlg->run ();
160 }
161 */
162 }
163
164 // Select an entry from the Window menu
on_window_activate(GtkMenuItem * menuitem,gpointer user_data)165 void on_window_activate (GtkMenuItem * menuitem, gpointer user_data)
166 {
167 DlgModule *module = (DlgModule*) user_data;
168 GuiDlgedit::window->showDialogue (module);
169 }
170
171 // Display help text associated with a menuitem to the statusbar
on_display_help(GtkWidget * widget,GdkEventCrossing * event,gpointer user_data)172 gboolean on_display_help (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
173 {
174 int id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "help-id"));
175 GuiMessages *message = (GuiMessages *) user_data;
176
177 message->display (id);
178 return FALSE;
179 }
180
181 // Clear text displayed by the statusbar
on_clear_help(GtkWidget * widget,GdkEventCrossing * event,gpointer user_data)182 gboolean on_clear_help (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
183 {
184 GuiMessages *message = (GuiMessages *) user_data;
185 message->clear ();
186 return FALSE;
187 }
188