diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index 3ad41ca97..de22f948f 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -115,7 +115,7 @@ GUIInfo::~GUIInfo () // Implementation of FGDialog. //////////////////////////////////////////////////////////////////////// -FGDialog::FGDialog (SGPropertyNode_ptr props) +FGDialog::FGDialog (SGPropertyNode * props) : _object(0) { display(props); @@ -189,7 +189,7 @@ FGDialog::applyValues () } void -FGDialog::display (SGPropertyNode_ptr props) +FGDialog::display (SGPropertyNode * props) { if (_object != 0) { SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active"); diff --git a/src/GUI/dialog.hxx b/src/GUI/dialog.hxx index 4b4752d16..cf0c199f8 100644 --- a/src/GUI/dialog.hxx +++ b/src/GUI/dialog.hxx @@ -40,7 +40,7 @@ public: * * @param props A property tree describing the dialog. */ - FGDialog (SGPropertyNode_ptr props); + FGDialog (SGPropertyNode * props); /** @@ -97,7 +97,7 @@ private: FGDialog (const FGDialog &); // Show the dialog. - void display (SGPropertyNode_ptr props); + void display (SGPropertyNode * props); // Build the dialog or a subobject of it. puObject * makeObject (SGPropertyNode * props, diff --git a/src/GUI/menubar.cxx b/src/GUI/menubar.cxx index 0fa6d496d..43e30fd81 100644 --- a/src/GUI/menubar.cxx +++ b/src/GUI/menubar.cxx @@ -58,15 +58,6 @@ do_hires_snapshot_dialog (const SGPropertyNode * arg) } #endif // TR_HIRES_SNAP -extern void dumpSnapShot (puObject *); -static bool -do_snapshot_dialog (const SGPropertyNode * arg) -{ - dumpSnapShot(0); - return true; -} - - #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__) extern void printScreen (puObject *); static bool @@ -215,7 +206,6 @@ static struct { #if defined(TR_HIRES_SNAP) { "old-hires-snapshot-dialog", do_hires_snapshot_dialog }, #endif - { "old-snapshot-dialog", do_snapshot_dialog }, #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__) { "old-print-dialog", do_print_dialog }, #endif @@ -359,7 +349,7 @@ FGMenuBar::fireItem (puObject * item) } void -FGMenuBar::make_menu (SGPropertyNode_ptr node) +FGMenuBar::make_menu (SGPropertyNode * node) { const char * name = strdup(node->getStringValue("label")); vector item_nodes = node->getChildren("item"); diff --git a/src/GUI/menubar.hxx b/src/GUI/menubar.hxx index 52e82ac04..10aeaf7a6 100644 --- a/src/GUI/menubar.hxx +++ b/src/GUI/menubar.hxx @@ -88,7 +88,7 @@ public: private: // Make a single menu. - void make_menu (SGPropertyNode_ptr node); + void make_menu (SGPropertyNode * node); // Make the top-level menubar. void make_menubar (); diff --git a/src/GUI/new_gui.cxx b/src/GUI/new_gui.cxx index a0e17a65e..4e06c320c 100644 --- a/src/GUI/new_gui.cxx +++ b/src/GUI/new_gui.cxx @@ -26,7 +26,7 @@ NewGUI::NewGUI () NewGUI::~NewGUI () { - delete _menubar; + clear(); } void @@ -46,13 +46,8 @@ void NewGUI::reinit () { unbind(); - -#if !defined(FG_OLD_MENUBAR) - delete _menubar; + clear(); _menubar = new FGMenuBar; -#endif - _dialog_props.clear(); - init(); bind(); } @@ -133,6 +128,18 @@ NewGUI::setMenuBarVisible (bool visible) _menubar->hide(); } +void +NewGUI::clear () +{ + delete _menubar; + _menubar = 0; + + map::iterator it; + for (it = _dialog_props.begin(); it != _dialog_props.end(); it++) + delete it->second; + _dialog_props.clear(); +} + void NewGUI::readDir (const char * path) { @@ -144,32 +151,39 @@ NewGUI::readDir (const char * path) return; } - ulDirEnt * dirEnt = ulReadDir(dir); - while (dirEnt != 0) { + for (ulDirEnt * dirEnt = ulReadDir(dir); + dirEnt != 0; + dirEnt = ulReadDir(dir)) { + char subpath[1024]; ulMakePath(subpath, path, dirEnt->d_name); - if (dirEnt->d_isdir && dirEnt->d_name[0] != '.') { - readDir(subpath); + if (dirEnt->d_isdir) { + if (dirEnt->d_name[0] != '.') + readDir(subpath); } else { - SGPropertyNode_ptr props = new SGPropertyNode; + SGPropertyNode * props = new SGPropertyNode; try { readProperties(subpath, props); } catch (const sg_exception &ex) { - SG_LOG(SG_INPUT, SG_ALERT, "Error parsing GUI file " + SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog " << subpath); + delete props; + continue; } if (!props->hasValue("name")) { - SG_LOG(SG_INPUT, SG_WARN, "GUI file " << subpath + SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath << " has no name; skipping."); - } else { - string name = props->getStringValue("name"); - SG_LOG(SG_INPUT, SG_BULK, "Saving GUI node " << name); - _dialog_props[name] = props; + delete props; + continue; } + string name = props->getStringValue("name"); + SG_LOG(SG_INPUT, SG_BULK, "Saving dialog " << name); + if (_dialog_props[name] != 0) + delete _dialog_props[name]; + _dialog_props[name] = props; } - dirEnt = ulReadDir(dir); } ulCloseDir(dir); } diff --git a/src/GUI/new_gui.hxx b/src/GUI/new_gui.hxx index 2fd8909f4..6d3c55369 100644 --- a/src/GUI/new_gui.hxx +++ b/src/GUI/new_gui.hxx @@ -142,12 +142,15 @@ protected: private: + // Free all allocated memory. + void clear (); + // Read all the configuration files in a directory. void readDir (const char * path); FGMenuBar * _menubar; FGDialog * _active_dialog; - map _dialog_props; + map _dialog_props; };