/
CommandStatus.cpp
55 lines (42 loc) · 1.33 KB
/
CommandStatus.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
#include "CommandStatus.h"
#include "i18n.h"
#include "ui/istatusbarmanager.h"
#include "iradiant.h"
namespace ui
{
namespace statusbar
{
namespace
{
const char* const STATUS_BAR_ELEMENT = "Commands";
const int MESSAGE_LIFETIME_MSECS = 4000;
}
CommandStatus::CommandStatus() :
_timer(this)
{
_mapOperationListener = GlobalRadiantCore().getMessageBus().addListener(
radiant::IMessage::MapOperationFinished,
radiant::TypeListener<map::OperationMessage>(
sigc::mem_fun(this, &CommandStatus::onOperationFinished)));
// Add the status bar element
GlobalStatusBarManager().addTextElement(STATUS_BAR_ELEMENT, "", StandardPosition::Commands, "");
Bind(wxEVT_TIMER, &CommandStatus::onTimerIntervalReached, this);
}
CommandStatus::~CommandStatus()
{
_timer.Stop();
GlobalRadiantCore().getMessageBus().removeListener(_mapOperationListener);
}
void CommandStatus::onOperationFinished(map::OperationMessage& message)
{
GlobalStatusBarManager().setText(STATUS_BAR_ELEMENT, message.getMessage(), false);
// (re-)start the timer on every message
_timer.Start(MESSAGE_LIFETIME_MSECS, true);
}
void CommandStatus::onTimerIntervalReached(wxTimerEvent& ev)
{
// Clear the timer when the interval is reached
GlobalStatusBarManager().setText(STATUS_BAR_ELEMENT, _("Ready"), false);
}
}
}