/
Console.cpp
71 lines (57 loc) · 1.77 KB
/
Console.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
#include "Console.h"
#include "iradiant.h"
#include "wxutil/ConsoleView.h"
#include <wx/sizer.h>
#include "messages/ClearConsole.h"
namespace ui
{
Console::Console(wxWindow* parent) :
DockablePanel(parent),
_view(new wxutil::ConsoleView(this)),
_commandEntry(new CommandEntry(this))
{
SetSizer(new wxBoxSizer(wxVERTICAL));
GetSizer()->Add(_view, 1, wxEXPAND);
GetSizer()->Add(_commandEntry, 0, wxEXPAND);
// Get a lock on the logging system before doing these changes
std::lock_guard<std::mutex> lock(GlobalRadiantCore().getLogWriter().getStreamLock());
// We're ready to catch log output, register ourselves
GlobalRadiantCore().getLogWriter().attach(this);
_clearConsoleHandler = GlobalRadiantCore().getMessageBus().addListener(
radiant::IMessage::Type::ClearConsole,
radiant::TypeListener<radiant::ClearConsoleMessage>(
sigc::mem_fun(this, &Console::clear)));
}
Console::~Console()
{
GlobalRadiantCore().getMessageBus().removeListener(_clearConsoleHandler);
GlobalRadiantCore().getLogWriter().detach(this);
}
void Console::clear(radiant::ClearConsoleMessage& msg)
{
_view->Clear();
}
void Console::SetFocus()
{
// Propagate focus to command entry
_commandEntry->SetFocus();
}
void Console::writeLog(const std::string& outputStr, applog::LogLevel level)
{
switch (level)
{
case applog::LogLevel::Verbose:
case applog::LogLevel::Standard:
_view->appendText(outputStr, wxutil::ConsoleView::ModeStandard);
break;
case applog::LogLevel::Warning:
_view->appendText(outputStr, wxutil::ConsoleView::ModeWarning);
break;
case applog::LogLevel::Error:
_view->appendText(outputStr, wxutil::ConsoleView::ModeError);
break;
default:
_view->appendText(outputStr, wxutil::ConsoleView::ModeStandard);
};
}
} // namespace ui