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);
102 delete _active_dialog;
108 NewGUI::closeDialog (const string& name)
110 if(_active_dialogs.find(name) != _active_dialogs.end()) {
111 if(_active_dialog == _active_dialogs[name])
113 delete _active_dialogs[name];
114 _active_dialogs.erase(name);
117 return false; // dialog wasn't open...
121 NewGUI::setActiveDialog (FGDialog * dialog)
123 _active_dialog = dialog;
127 NewGUI::getActiveDialog ()
129 return _active_dialog;
133 NewGUI::getMenuBar ()
139 NewGUI::getMenuBarVisible () const
141 return _menubar->isVisible();
145 NewGUI::setMenuBarVisible (bool visible)
158 _dialog_props.clear();
162 test_extension (const char * path, const char * ext)
164 int pathlen = strlen(path);
165 int extlen = strlen(ext);
167 for (int i = 1; i <= pathlen && i <= extlen; i++) {
168 if (path[pathlen-i] != ext[extlen-i])
175 NewGUI::newDialog (SGPropertyNode* props)
177 const char* cname = props->getStringValue("name");
179 SG_LOG(SG_GENERAL, SG_ALERT, "New dialog has no <name> property");
182 string name = props->getStringValue("name");
183 _dialog_props[name] = props;
187 NewGUI::readDir (const char * path)
189 ulDir * dir = ulOpenDir(path);
192 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
197 for (ulDirEnt * dirEnt = ulReadDir(dir);
199 dirEnt = ulReadDir(dir)) {
203 ulMakePath(subpath, path, dirEnt->d_name);
205 if (!dirEnt->d_isdir && test_extension(subpath, ".xml")) {
206 SGPropertyNode * props = new SGPropertyNode;
208 readProperties(subpath, props);
209 } catch (const sg_exception &ex) {
210 SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
215 if (!props->hasValue("name")) {
216 SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath
217 << " has no name; skipping.");
227 // end of new_gui.cxx