| 1 |
/* |
| 2 |
Copyright (C) 2002/2003 Kai Sterker <[email protected]> |
| 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.h |
| 21 |
* |
| 22 |
* @author Kai Sterker |
| 23 |
* @brief The Dialogue Editor's main window |
| 24 |
*/ |
| 25 |
|
| 26 |
#ifndef GUI_DLGEDIT_H |
| 27 |
#define GUI_DLGEDIT_H |
| 28 |
|
| 29 |
#include "gui_recent_files.h" |
| 30 |
|
| 31 |
#include "gui_messages.h" |
| 32 |
#include "gui_graph.h" |
| 33 |
#include "gui_list.h" |
| 34 |
#include "gui_tree.h" |
| 35 |
|
| 36 |
/** |
| 37 |
* The application's main window. Contains the menu- and statusbar, as |
| 38 |
* well as pointers to the other widgets. The main window is created at |
| 39 |
* program startup, and closed on termination of the program. There can |
| 40 |
* be only one main window at a time, but several dialogues may be open |
| 41 |
* simultanously. |
| 42 |
*/ |
| 43 |
class GuiDlgedit : public GuiRecentFileListener |
| 44 |
{ |
| 45 |
public: |
| 46 |
/** |
| 47 |
* Constructor. Creates the main window with all the sub-widgets, |
| 48 |
* such as the dialogue view or the instant preview. |
| 49 |
*/ |
| 50 |
GuiDlgedit (); |
| 51 |
/** |
| 52 |
* Destructor. |
| 53 |
*/ |
| 54 |
virtual ~GuiDlgedit (); |
| 55 |
|
| 56 |
/** |
| 57 |
* Global pointer to the main window, to allow easy access from anywhere. |
| 58 |
*/ |
| 59 |
static GuiDlgedit *window; |
| 60 |
|
| 61 |
/** |
| 62 |
* Widget access methods |
| 63 |
*/ |
| 64 |
//@{ |
| 65 |
/** |
| 66 |
* Retrieve the dialogue view. |
| 67 |
* @return the widget containing the graphical representation of the |
| 68 |
* dialogue graph. |
| 69 |
*/ |
| 70 |
GuiGraph *graph () { return graph_; } |
| 71 |
/** |
| 72 |
* Retrieve the instant preview widget. |
| 73 |
* @return the widget containing the text of the selected DlgNode and |
| 74 |
* that of it's parents and children. |
| 75 |
*/ |
| 76 |
GuiList *list () { return list_; } |
| 77 |
/** |
| 78 |
* Retrieve the module structure view. |
| 79 |
* @return the widget displaying the dialogue and its sub-modules. |
| 80 |
*/ |
| 81 |
GuiTree *tree () { return tree_; } |
| 82 |
|
| 83 |
/** |
| 84 |
* Retrieve the main window of the applictaion. |
| 85 |
* @return a GtkWidget. |
| 86 |
*/ |
| 87 |
GtkWidget *getWindow () { return wnd; } |
| 88 |
//@} |
| 89 |
|
| 90 |
/** |
| 91 |
* Set the program state and display it in the status bar |
| 92 |
* @param mode The new program state. |
| 93 |
*/ |
| 94 |
void setMode (mode_type mode); |
| 95 |
/** |
| 96 |
* Get the current program state |
| 97 |
* @return The program state. |
| 98 |
*/ |
| 99 |
mode_type mode () { return mode_; } |
| 100 |
|
| 101 |
/** |
| 102 |
* Create a new dialogue. |
| 103 |
*/ |
| 104 |
void newDialogue (); |
| 105 |
/** |
| 106 |
* Load a (top level) dialogue from a file |
| 107 |
* @param file Filename (and path) of the dialogue to load. |
| 108 |
*/ |
| 109 |
void loadDialogue (const std::string &file); |
| 110 |
/** |
| 111 |
* Load a sub-dialogue from a file. Sub-dialogues are not |
| 112 |
* directly available for editing; instead they become part |
| 113 |
* of a (top level) dialogue. |
| 114 |
* @param file Filename (and path) of the dialogue to load. |
| 115 |
* @return the sub-dialogue, or \b NULL if loading failed. |
| 116 |
*/ |
| 117 |
DlgModule* loadSubdialogue (const std::string &file); |
| 118 |
/** |
| 119 |
* Save a dialogue to file |
| 120 |
* @param file Filename (and path) of the dialogue to load. |
| 121 |
*/ |
| 122 |
void saveDialogue (const std::string &file); |
| 123 |
/** |
| 124 |
* Reload dialogue from disk if possible. This discards all |
| 125 |
* changes since the last save. |
| 126 |
*/ |
| 127 |
void revertDialogue (); |
| 128 |
/** |
| 129 |
* Close a dialogue |
| 130 |
*/ |
| 131 |
void closeDialogue (); |
| 132 |
/** |
| 133 |
* Display a dialogue |
| 134 |
* @param module The dialogue to display. |
| 135 |
* @param center whether to center the dialgue in view or not |
| 136 |
*/ |
| 137 |
void showDialogue (DlgModule *module, bool center = false); |
| 138 |
/** |
| 139 |
* Compile a dialogue |
| 140 |
*/ |
| 141 |
void compileDialogue (); |
| 142 |
/** |
| 143 |
* Test whether the given filename points to a valid dialogue |
| 144 |
* @param file path of the dialogue |
| 145 |
* @return <b>true</b> if the dialogue is valid, <b>false</b> otherwise. |
| 146 |
*/ |
| 147 |
static bool checkDialogue (const std::string &file); |
| 148 |
/** |
| 149 |
* Edit the custom code of the current module. |
| 150 |
*/ |
| 151 |
void customCode (); |
| 152 |
/** |
| 153 |
* Edit the settings of the current module. |
| 154 |
*/ |
| 155 |
void settings (); |
| 156 |
/** |
| 157 |
* preview translation for a dialogue |
| 158 |
* @param catalogue full path to a gnu gettext compliant binary catalogue |
| 159 |
* (.mo) file |
| 160 |
*/ |
| 161 |
void previewTranslation (const std::string &catalogue); |
| 162 |
/** |
| 163 |
* stop translation preview |
| 164 |
*/ |
| 165 |
void exitPreview (); |
| 166 |
/** |
| 167 |
* Indicate that the active dialogue has been changed by the user |
| 168 |
*/ |
| 169 |
void setChanged (); |
| 170 |
/** |
| 171 |
* Indicate that the acive dialogue has been assigned to a new project. |
| 172 |
*/ |
| 173 |
void updateProject (); |
| 174 |
/** |
| 175 |
* Get the directory where the last fileselection took place. |
| 176 |
* @return Path to the directory last opened. |
| 177 |
*/ |
| 178 |
std::string directory () { return directory_+"/"; } |
| 179 |
/** |
| 180 |
* Get the full path and name of the dialogue currently in the view. |
| 181 |
* @return Filename of the current dialogue. |
| 182 |
*/ |
| 183 |
std::string filename (); |
| 184 |
/** |
| 185 |
* Callback when user chooses to load a previously opened file. |
| 186 |
* @param full path to the filename. |
| 187 |
*/ |
| 188 |
virtual void OnRecentFileActivated (const std::string & file); |
| 189 |
|
| 190 |
private: |
| 191 |
/** |
| 192 |
* (Re)build the 'windows' menu |
| 193 |
*/ |
| 194 |
void initMenu (); |
| 195 |
/** |
| 196 |
* (Re)build the 'open recent' sub-menu. |
| 197 |
*/ |
| 198 |
void initRecentFiles (); |
| 199 |
/** |
| 200 |
* Display the correct window title |
| 201 |
*/ |
| 202 |
void initTitle (); |
| 203 |
/** |
| 204 |
* Add a dialogue to the GUI |
| 205 |
*/ |
| 206 |
DlgModule *initDialogue (std::string); |
| 207 |
/** |
| 208 |
* Set the GUI back to it's initial state. |
| 209 |
*/ |
| 210 |
void clear (); |
| 211 |
|
| 212 |
/// serial number of open dialogues |
| 213 |
int number; |
| 214 |
/// the program mode |
| 215 |
mode_type mode_; |
| 216 |
/// instant preview widget |
| 217 |
GuiList *list_; |
| 218 |
/// dialogue structure view |
| 219 |
GuiTree *tree_; |
| 220 |
/// dialogue view |
| 221 |
GuiGraph *graph_; |
| 222 |
/// statusbar for displaying help/error texts |
| 223 |
GuiMessages *message; |
| 224 |
/// actual main window |
| 225 |
GtkWidget *wnd; |
| 226 |
/// pointers to a few menu-items |
| 227 |
GtkWidget *menuItem[MAX_ITEM]; |
| 228 |
/// the 'Windows' dropdown menu |
| 229 |
GtkWidget *windowMenu; |
| 230 |
/// the menu bar |
| 231 |
GtkWidget *mainMenu; |
| 232 |
/// statusbar displaying the program state |
| 233 |
GtkWidget *status_mode; |
| 234 |
/// dialogues currently loaded |
| 235 |
std::vector<DlgModule*> dialogues_; |
| 236 |
/// directory used in last file-selection |
| 237 |
std::string directory_; |
| 238 |
/// Textual program states |
| 239 |
static const char *progState[NUM_MODES]; |
| 240 |
/// recent files |
| 241 |
GuiRecentFiles *RecentFiles; |
| 242 |
}; |
| 243 |
|
| 244 |
#endif // GUI_DLGEDIT_H |