Close dialogs on GUI shutdown
- avoids orphaned dialogs on reset - requires some guards in NasalSys since Nasal is shutdown first, but dialogs can have Nasal modules.
This commit is contained in:
parent
2d5d43a57d
commit
070dba29f9
4 changed files with 31 additions and 4 deletions
src
|
@ -88,6 +88,12 @@ NewGUI::init ()
|
||||||
void
|
void
|
||||||
NewGUI::shutdown()
|
NewGUI::shutdown()
|
||||||
{
|
{
|
||||||
|
DialogDict::iterator it = _active_dialogs.begin();
|
||||||
|
for (; it != _active_dialogs.end(); ++it) {
|
||||||
|
delete it->second;
|
||||||
|
}
|
||||||
|
_active_dialogs.clear();
|
||||||
|
|
||||||
fgUntie("/sim/menubar/visibility");
|
fgUntie("/sim/menubar/visibility");
|
||||||
_menubar.reset();
|
_menubar.reset();
|
||||||
_dialog_props.clear();
|
_dialog_props.clear();
|
||||||
|
@ -129,7 +135,7 @@ NewGUI::createMenuBarImplementation()
|
||||||
void
|
void
|
||||||
NewGUI::reset (bool reload)
|
NewGUI::reset (bool reload)
|
||||||
{
|
{
|
||||||
map<string,FGDialog *>::iterator iter;
|
DialogDict::iterator iter;
|
||||||
string_list openDialogs;
|
string_list openDialogs;
|
||||||
// close all open dialogs and remember them ...
|
// close all open dialogs and remember them ...
|
||||||
for (iter = _active_dialogs.begin(); iter != _active_dialogs.end(); ++iter)
|
for (iter = _active_dialogs.begin(); iter != _active_dialogs.end(); ++iter)
|
||||||
|
|
|
@ -223,7 +223,8 @@ private:
|
||||||
|
|
||||||
std::auto_ptr<FGMenuBar> _menubar;
|
std::auto_ptr<FGMenuBar> _menubar;
|
||||||
FGDialog * _active_dialog;
|
FGDialog * _active_dialog;
|
||||||
std::map<std::string,FGDialog *> _active_dialogs;
|
typedef std::map<std::string,FGDialog *> DialogDict;
|
||||||
|
DialogDict _active_dialogs;
|
||||||
|
|
||||||
typedef std::map<std::string, SGPath> NamePathDict;
|
typedef std::map<std::string, SGPath> NamePathDict;
|
||||||
// mapping from dialog names to the corresponding XML property list
|
// mapping from dialog names to the corresponding XML property list
|
||||||
|
|
|
@ -201,7 +201,8 @@ static char* readfile(const char* file, int* lenOut)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
FGNasalSys::FGNasalSys()
|
FGNasalSys::FGNasalSys() :
|
||||||
|
_inited(false)
|
||||||
{
|
{
|
||||||
nasalSys = this;
|
nasalSys = this;
|
||||||
_context = 0;
|
_context = 0;
|
||||||
|
@ -249,6 +250,9 @@ naRef FGNasalSys::callMethod(naRef code, naRef self, int argc, naRef* args, naRe
|
||||||
|
|
||||||
FGNasalSys::~FGNasalSys()
|
FGNasalSys::~FGNasalSys()
|
||||||
{
|
{
|
||||||
|
if (_inited) {
|
||||||
|
SG_LOG(SG_GENERAL, SG_ALERT, "Nasal was not shutdown");
|
||||||
|
}
|
||||||
nasalSys = 0;
|
nasalSys = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,6 +736,9 @@ void FGNasalSys::setCmdArg(SGPropertyNode* aNode)
|
||||||
|
|
||||||
void FGNasalSys::init()
|
void FGNasalSys::init()
|
||||||
{
|
{
|
||||||
|
if (_inited) {
|
||||||
|
SG_LOG(SG_GENERAL, SG_ALERT, "duplicate init of Nasal");
|
||||||
|
}
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
_context = naNewContext();
|
_context = naNewContext();
|
||||||
|
@ -803,10 +810,16 @@ void FGNasalSys::init()
|
||||||
// now Nasal modules are loaded, we can do some delayed work
|
// now Nasal modules are loaded, we can do some delayed work
|
||||||
postinitNasalPositioned(_globals, _context);
|
postinitNasalPositioned(_globals, _context);
|
||||||
postinitNasalGUI(_globals, _context);
|
postinitNasalGUI(_globals, _context);
|
||||||
|
|
||||||
|
_inited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGNasalSys::shutdown()
|
void FGNasalSys::shutdown()
|
||||||
{
|
{
|
||||||
|
if (!_inited) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
shutdownNasalPositioned();
|
shutdownNasalPositioned();
|
||||||
|
|
||||||
map<int, FGNasalListener *>::iterator it, end = _listener.end();
|
map<int, FGNasalListener *>::iterator it, end = _listener.end();
|
||||||
|
@ -837,7 +850,7 @@ void FGNasalSys::shutdown()
|
||||||
_globals = naNil();
|
_globals = naNil();
|
||||||
|
|
||||||
naGC();
|
naGC();
|
||||||
|
_inited = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
naRef FGNasalSys::wrappedPropsNode(SGPropertyNode* aProps)
|
naRef FGNasalSys::wrappedPropsNode(SGPropertyNode* aProps)
|
||||||
|
@ -1085,6 +1098,12 @@ bool FGNasalSys::createModule(const char* moduleName, const char* fileName,
|
||||||
|
|
||||||
void FGNasalSys::deleteModule(const char* moduleName)
|
void FGNasalSys::deleteModule(const char* moduleName)
|
||||||
{
|
{
|
||||||
|
if (!_inited) {
|
||||||
|
// can occur on shutdown due to us being shutdown first, but other
|
||||||
|
// subsystems having Nasal objects.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
naContext ctx = naNewContext();
|
naContext ctx = naNewContext();
|
||||||
naRef modname = naNewString(ctx);
|
naRef modname = naNewString(ctx);
|
||||||
naStr_fromdata(modname, (char*)moduleName, strlen(moduleName));
|
naStr_fromdata(modname, (char*)moduleName, strlen(moduleName));
|
||||||
|
|
|
@ -172,6 +172,7 @@ private:
|
||||||
naRef parse(const char* filename, const char* buf, int len);
|
naRef parse(const char* filename, const char* buf, int len);
|
||||||
naRef genPropsModule();
|
naRef genPropsModule();
|
||||||
|
|
||||||
|
bool _inited;
|
||||||
naContext _context;
|
naContext _context;
|
||||||
naRef _globals,
|
naRef _globals,
|
||||||
_string;
|
_string;
|
||||||
|
|
Loading…
Add table
Reference in a new issue