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 if(!_active_dialogs[name])
83 _active_dialogs[name] = new FGDialog(_dialog_props[name]);
89 NewGUI::closeActiveDialog ()
91 if (_active_dialog == 0)
94 // Kill any entries in _active_dialogs... Is there an STL
95 // algorithm to do (delete map entries by value, not key)? I hate
97 map<string,FGDialog *>::iterator iter = _active_dialogs.begin();
98 for(/**/; iter != _active_dialogs.end(); iter++) {
99 if(iter->second == _active_dialog) {
100 _active_dialogs.erase(iter);
101 // iter is no longer valid
106 delete _active_dialog;
112 NewGUI::closeDialog (const string& name)
114 if(_active_dialogs.find(name) != _active_dialogs.end()) {
115 if(_active_dialog == _active_dialogs[name])
117 delete _active_dialogs[name];
118 _active_dialogs.erase(name);
121 return false; // dialog wasn't open...
125 NewGUI::setActiveDialog (FGDialog * dialog)
127 _active_dialog = dialog;
131 NewGUI::getActiveDialog ()
133 return _active_dialog;
137 NewGUI::getMenuBar ()
143 NewGUI::getMenuBarVisible () const
145 return _menubar->isVisible();
149 NewGUI::setMenuBarVisible (bool visible)
162 _dialog_props.clear();
166 test_extension (const char * path, const char * ext)
168 int pathlen = strlen(path);
169 int extlen = strlen(ext);
171 for (int i = 1; i <= pathlen && i <= extlen; i++) {
172 if (path[pathlen-i] != ext[extlen-i])
179 NewGUI::newDialog (SGPropertyNode* props)
181 const char* cname = props->getStringValue("name");
183 SG_LOG(SG_GENERAL, SG_ALERT, "New dialog has no <name> property");
186 string name = props->getStringValue("name");
187 _dialog_props[name] = props;
191 NewGUI::readDir (const char * path)
193 ulDir * dir = ulOpenDir(path);
196 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
201 for (ulDirEnt * dirEnt = ulReadDir(dir);
203 dirEnt = ulReadDir(dir)) {
207 ulMakePath(subpath, path, dirEnt->d_name);
209 if (!dirEnt->d_isdir && test_extension(subpath, ".xml")) {
210 SGPropertyNode * props = new SGPropertyNode;
212 readProperties(subpath, props);
213 } catch (const sg_exception &) {
214 SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
219 if (!props->hasValue("name")) {
220 SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath
221 << " has no name; skipping.");
231 // end of new_gui.cxx