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");
40 #if !defined(FG_OLD_MENUBAR)
48 fgTie("/sim/menubar/visibility", this,
49 &NewGUI::getMenuBarVisible, &NewGUI::setMenuBarVisible);
55 fgUntie("/sim/menubar/visibility");
59 NewGUI::update (double delta_time_sec)
65 NewGUI::showDialog (const string &name)
67 if (_dialog_props.find(name) == _dialog_props.end()) {
68 SG_LOG(SG_GENERAL, SG_ALERT, "Dialog " << name << " not defined");
71 new FGDialog(_dialog_props[name]); // it will be deleted by a callback
77 NewGUI::closeActiveDialog ()
79 if (_active_dialog == 0) {
82 delete _active_dialog;
89 NewGUI::setActiveDialog (FGDialog * dialog)
91 _active_dialog = dialog;
95 NewGUI::getActiveDialog ()
97 return _active_dialog;
101 NewGUI::getMenuBar ()
107 NewGUI::getMenuBarVisible () const
109 return _menubar->isVisible();
113 NewGUI::setMenuBarVisible (bool visible)
122 NewGUI::readDir (const char * path)
124 ulDir * dir = ulOpenDir(path);
127 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
132 ulDirEnt * dirEnt = ulReadDir(dir);
133 while (dirEnt != 0) {
136 ulMakePath(subpath, path, dirEnt->d_name);
138 if (dirEnt->d_isdir && dirEnt->d_name[0] != '.') {
141 SGPropertyNode_ptr props = new SGPropertyNode;
143 readProperties(subpath, props);
144 } catch (const sg_exception &ex) {
145 SG_LOG(SG_INPUT, SG_ALERT, "Error parsing GUI file "
148 if (!props->hasValue("name")) {
149 SG_LOG(SG_INPUT, SG_WARN, "GUI file " << subpath
150 << " has no name; skipping.");
152 string name = props->getStringValue("name");
153 SG_LOG(SG_INPUT, SG_BULK, "Saving GUI node " << name);
154 _dialog_props[name] = props;
157 dirEnt = ulReadDir(dir);
162 // end of new_gui.cxx