-
Notifications
You must be signed in to change notification settings - Fork 47
/
Console.cpp
71 lines (56 loc) · 1.7 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 "iuimanager.h"
#include "igroupdialog.h"
#include "wxutil/ConsoleView.h"
#include <wx/sizer.h>
#include <functional>
namespace ui
{
Console::Console(wxWindow* parent) :
wxPanel(parent, wxID_ANY),
_view(new wxutil::ConsoleView(this)),
_commandEntry(new CommandEntry(this))
{
SetSizer(new wxBoxSizer(wxVERTICAL));
GetSizer()->Add(_view, 1, wxEXPAND);
GetSizer()->Add(_commandEntry, 0, wxEXPAND);
GlobalCommandSystem().addCommand("clear",
std::bind(&Console::clearCmd, this, std::placeholders::_1));
// 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);
}
Console::~Console()
{
// TODO - there might be more than one console instance handle this
GlobalCommandSystem().removeCommand("clear");
GlobalRadiantCore().getLogWriter().detach(this);
}
void Console::clearCmd(const cmd::ArgumentList& args)
{
_view->Clear();
}
void Console::toggle(const cmd::ArgumentList& args)
{
GlobalGroupDialog().togglePage("console");
}
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