/
DialogManager.cpp
92 lines (73 loc) · 2.05 KB
/
DialogManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "DialogManager.h"
#include "itextstream.h"
#include "imainframe.h"
#include "wxutil/dialog/MessageBox.h"
#include "wxutil/FileChooser.h"
#include "wxutil/DirChooser.h"
#include "SoundChooser.h"
#include "animationpreview/MD5AnimationChooser.h"
namespace ui
{
DialogManager::~DialogManager()
{
if (!_dialogs.empty())
{
rMessage() << "DialogManager: " << _dialogs.size()
<< " dialogs still in memory at shutdown." << std::endl;
_dialogs.clear();
}
}
IDialogPtr DialogManager::createDialog(const std::string& title, wxWindow* parent)
{
cleanupOldDialogs();
// Allocate a new dialog
wxutil::DialogPtr dialog(new wxutil::Dialog(title, parent));
_dialogs.push_back(dialog);
return dialog;
}
IDialogPtr DialogManager::createMessageBox(const std::string& title,
const std::string& text,
IDialog::MessageType type,
wxWindow* parent)
{
cleanupOldDialogs();
// Allocate a new dialog, use the main window if no parent specified
wxutil::MessageboxPtr box(new wxutil::Messagebox(title, text, type, parent));
// Store it in the local map so that references are held
_dialogs.push_back(box);
return box;
}
IFileChooserPtr DialogManager::createFileChooser(const std::string& title,
bool open, const std::string& pattern, const std::string& defaultExt)
{
return IFileChooserPtr(new wxutil::FileChooser(
GlobalMainFrame().getWxTopLevelWindow(),
title, open, pattern, defaultExt));
}
IDirChooserPtr DialogManager::createDirChooser(const std::string& title)
{
return IDirChooserPtr(new wxutil::DirChooser(GlobalMainFrame().getWxTopLevelWindow(), title));
}
void DialogManager::cleanupOldDialogs()
{
for (Dialogs::iterator i = _dialogs.begin(); i != _dialogs.end(); /* in-loop increment */)
{
if (i->unique())
{
_dialogs.erase(i++);
}
else
{
++i;
}
}
}
IResourceChooser* DialogManager::createSoundShaderChooser(wxWindow* parent)
{
return new SoundChooser(parent);
}
IAnimationChooser* DialogManager::createAnimationChooser(wxWindow* parent)
{
return new MD5AnimationChooser(parent);
}
} // namespace ui