1 // new_gui.cxx: implementation of XML-configurable GUI support.
8 #include <simgear/compiler.h>
9 #include <simgear/structure/exception.hxx>
11 #include <Main/fg_props.hxx>
13 #include "menubar.hxx"
19 ////////////////////////////////////////////////////////////////////////
20 // Implementation of NewGUI.
21 ////////////////////////////////////////////////////////////////////////
25 : _menubar(new FGMenuBar),
40 ulMakePath(path1, globals->get_fg_root().c_str(), "gui");
41 ulMakePath(path2, path1, "dialogs");
51 _menubar = new FGMenuBar;
59 fgTie("/sim/menubar/visibility", this,
60 &NewGUI::getMenuBarVisible, &NewGUI::setMenuBarVisible);
66 fgUntie("/sim/menubar/visibility");
70 NewGUI::update (double delta_time_sec)
76 NewGUI::showDialog (const string &name)
78 if (_dialog_props.find(name) == _dialog_props.end()) {
79 SG_LOG(SG_GENERAL, SG_ALERT, "Dialog " << name << " not defined");
82 new FGDialog(_dialog_props[name]); // it will be deleted by a callback
88 NewGUI::closeActiveDialog ()
90 if (_active_dialog == 0) {
93 delete _active_dialog;
100 NewGUI::setActiveDialog (FGDialog * dialog)
102 _active_dialog = dialog;
106 NewGUI::getActiveDialog ()
108 return _active_dialog;
112 NewGUI::getMenuBar ()
118 NewGUI::getMenuBarVisible () const
120 return _menubar->isVisible();
124 NewGUI::setMenuBarVisible (bool visible)
138 map<string,SGPropertyNode *>::iterator it;
139 for (it = _dialog_props.begin(); it != _dialog_props.end(); it++)
141 _dialog_props.clear();
145 test_extension (const char * path, const char * ext)
147 int pathlen = strlen(path);
148 int extlen = strlen(ext);
150 for (int i = 1; i <= pathlen && i <= extlen; i++) {
151 if (path[pathlen-i] != ext[extlen-i])
158 NewGUI::readDir (const char * path)
160 ulDir * dir = ulOpenDir(path);
163 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
168 for (ulDirEnt * dirEnt = ulReadDir(dir);
170 dirEnt = ulReadDir(dir)) {
174 ulMakePath(subpath, path, dirEnt->d_name);
176 if (!dirEnt->d_isdir && test_extension(subpath, ".xml")) {
177 SGPropertyNode * props = new SGPropertyNode;
179 readProperties(subpath, props);
180 } catch (const sg_exception &ex) {
181 SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
186 if (!props->hasValue("name")) {
187 SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath
188 << " has no name; skipping.");
192 string name = props->getStringValue("name");
193 SG_LOG(SG_INPUT, SG_BULK, "Saving dialog " << name);
194 if (_dialog_props[name] != 0)
195 delete _dialog_props[name];
196 _dialog_props[name] = props;
202 // end of new_gui.cxx