1 // new_gui.cxx: implementation of XML-configurable GUI support.
8 #include <simgear/misc/exception.hxx>
9 #include <Main/fg_props.hxx>
11 #include "menubar.hxx"
16 ////////////////////////////////////////////////////////////////////////
17 // Implementation of NewGUI.
18 ////////////////////////////////////////////////////////////////////////
22 : _menubar(new FGMenuBar),
37 ulMakePath(path1, globals->get_fg_root().c_str(), "gui");
38 ulMakePath(path2, path1, "dialogs");
48 _menubar = new FGMenuBar;
56 fgTie("/sim/menubar/visibility", this,
57 &NewGUI::getMenuBarVisible, &NewGUI::setMenuBarVisible);
63 fgUntie("/sim/menubar/visibility");
67 NewGUI::update (double delta_time_sec)
73 NewGUI::showDialog (const string &name)
75 if (_dialog_props.find(name) == _dialog_props.end()) {
76 SG_LOG(SG_GENERAL, SG_ALERT, "Dialog " << name << " not defined");
79 new FGDialog(_dialog_props[name]); // it will be deleted by a callback
85 NewGUI::closeActiveDialog ()
87 if (_active_dialog == 0) {
90 delete _active_dialog;
97 NewGUI::setActiveDialog (FGDialog * dialog)
99 _active_dialog = dialog;
103 NewGUI::getActiveDialog ()
105 return _active_dialog;
109 NewGUI::getMenuBar ()
115 NewGUI::getMenuBarVisible () const
117 return _menubar->isVisible();
121 NewGUI::setMenuBarVisible (bool visible)
135 map<string,SGPropertyNode *>::iterator it;
136 for (it = _dialog_props.begin(); it != _dialog_props.end(); it++)
138 _dialog_props.clear();
142 test_extension (const char * path, const char * ext)
144 int pathlen = strlen(path);
145 int extlen = strlen(ext);
147 for (int i = 1; i <= pathlen && i <= extlen; i++) {
148 if (path[pathlen-i] != ext[extlen-i])
155 NewGUI::readDir (const char * path)
157 ulDir * dir = ulOpenDir(path);
160 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
165 for (ulDirEnt * dirEnt = ulReadDir(dir);
167 dirEnt = ulReadDir(dir)) {
171 ulMakePath(subpath, path, dirEnt->d_name);
173 if (!dirEnt->d_isdir && test_extension(subpath, ".xml")) {
174 SGPropertyNode * props = new SGPropertyNode;
176 readProperties(subpath, props);
177 } catch (const sg_exception &ex) {
178 SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
183 if (!props->hasValue("name")) {
184 SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath
185 << " has no name; skipping.");
189 string name = props->getStringValue("name");
190 SG_LOG(SG_INPUT, SG_BULK, "Saving dialog " << name);
191 if (_dialog_props[name] != 0)
192 delete _dialog_props[name];
193 _dialog_props[name] = props;
199 // end of new_gui.cxx