Skip to content

Commit

Permalink
#5408: Messages have a time to live before they disappear
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 27, 2021
1 parent 2263151 commit f18aa2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
16 changes: 15 additions & 1 deletion radiant/ui/statusbar/CommandStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ namespace statusbar
namespace
{
const char* const STATUS_BAR_ELEMENT = "Commands";
const int MESSAGE_LIFETIME_MSECS = 4000;
}

CommandStatus::CommandStatus()
CommandStatus::CommandStatus() :
_timer(this)
{
_mapOperationListener = GlobalRadiantCore().getMessageBus().addListener(
radiant::IMessage::MapOperationFinished,
Expand All @@ -23,16 +25,28 @@ CommandStatus::CommandStatus()

// 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);
}

}
Expand Down
8 changes: 7 additions & 1 deletion radiant/ui/statusbar/CommandStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "iundo.h"
#include "imap.h"
#include <wx/timer.h>

#include "messages/MapOperationMessage.h"

Expand All @@ -15,16 +16,21 @@ namespace statusbar
* Status bar widget displaying the most recently completed
* operation or any undo / redo activitiy.
*/
class CommandStatus final
class CommandStatus final :
public wxEvtHandler
{
private:
std::size_t _mapOperationListener;

wxTimer _timer;

public:
CommandStatus();
~CommandStatus();

private:
void onOperationFinished(map::OperationMessage& message);
void onTimerIntervalReached(wxTimerEvent& ev);
};

}
Expand Down
5 changes: 5 additions & 0 deletions radiant/ui/statusbar/StatusBarManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ void StatusBarManager::addTextElement(const std::string& name, const std::string
textPanel->SetSizer(new wxBoxSizer(wxHORIZONTAL));
textPanel->SetName("Statusbarconainer " + name);

if (pos == StandardPosition::Commands)
{
textPanel->SetMinSize(wxSize(150, -1));
}

if (!description.empty())
{
textPanel->SetToolTip(description);
Expand Down

0 comments on commit f18aa2d

Please sign in to comment.