1 // new_gui.cxx: implementation of XML-configurable GUI support.
8 #include <simgear/compiler.h>
9 #include <simgear/misc/exception.hxx>
10 #include <Main/fg_props.hxx>
12 #include "menubar.hxx"
18 ////////////////////////////////////////////////////////////////////////
19 // Implementation of NewGUI.
20 ////////////////////////////////////////////////////////////////////////
24 : _menubar(new FGMenuBar),
39 ulMakePath(path1, globals->get_fg_root().c_str(), "gui");
40 ulMakePath(path2, path1, "dialogs");
50 _menubar = new FGMenuBar;
58 fgTie("/sim/menubar/visibility", this,
59 &NewGUI::getMenuBarVisible, &NewGUI::setMenuBarVisible);
65 fgUntie("/sim/menubar/visibility");
69 NewGUI::update (double delta_time_sec)
75 NewGUI::showDialog (const string &name)
77 if (_dialog_props.find(name) == _dialog_props.end()) {
78 SG_LOG(SG_GENERAL, SG_ALERT, "Dialog " << name << " not defined");
81 new FGDialog(_dialog_props[name]); // it will be deleted by a callback
87 NewGUI::closeActiveDialog ()
89 if (_active_dialog == 0) {
92 delete _active_dialog;
99 NewGUI::setActiveDialog (FGDialog * dialog)
101 _active_dialog = dialog;
105 NewGUI::getActiveDialog ()
107 return _active_dialog;
111 NewGUI::getMenuBar ()
117 NewGUI::getMenuBarVisible () const
119 return _menubar->isVisible();
123 NewGUI::setMenuBarVisible (bool visible)
137 map<string,SGPropertyNode *>::iterator it;
138 for (it = _dialog_props.begin(); it != _dialog_props.end(); it++)
140 _dialog_props.clear();
144 test_extension (const char * path, const char * ext)
146 int pathlen = strlen(path);
147 int extlen = strlen(ext);
149 for (int i = 1; i <= pathlen && i <= extlen; i++) {
150 if (path[pathlen-i] != ext[extlen-i])
157 NewGUI::readDir (const char * path)
159 ulDir * dir = ulOpenDir(path);
162 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
167 for (ulDirEnt * dirEnt = ulReadDir(dir);
169 dirEnt = ulReadDir(dir)) {
173 ulMakePath(subpath, path, dirEnt->d_name);
175 if (!dirEnt->d_isdir && test_extension(subpath, ".xml")) {
176 SGPropertyNode * props = new SGPropertyNode;
178 readProperties(subpath, props);
179 } catch (const sg_exception &ex) {
180 SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
185 if (!props->hasValue("name")) {
186 SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath
187 << " has no name; skipping.");
191 string name = props->getStringValue("name");
192 SG_LOG(SG_INPUT, SG_BULK, "Saving dialog " << name);
193 if (_dialog_props[name] != 0)
194 delete _dialog_props[name];
195 _dialog_props[name] = props;
201 // end of new_gui.cxx