Skip to content

Commit

Permalink
Some house keeping in EventManager class
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 7, 2017
1 parent 5a778e8 commit 74e810a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 52 deletions.
3 changes: 0 additions & 3 deletions install/debug.xml
Expand Up @@ -3,9 +3,6 @@
<!-- <discardEntityClass value="func_static" /> -->
<!-- <entityRange start="0" end="100" /> -->
</mapdoom3>
<ui>
<debugEventManager value="0" />
</ui>
<automatedTest>
<runTest value="0" />
<testMap value="/home/greebo/.doom3/darkmod/maps/brush_test.map" />
Expand Down
61 changes: 16 additions & 45 deletions plugins/eventmanager/EventManager.cpp
Expand Up @@ -34,18 +34,15 @@
namespace ui
{

namespace
{
const std::string RKEY_DEBUG = "debug/ui/debugEventManager";
}

// RegisterableModule implementation
const std::string& EventManager::getName() const {
const std::string& EventManager::getName() const
{
static std::string _name(MODULE_EVENTMANAGER);
return _name;
}

const StringSet& EventManager::getDependencies() const {
const StringSet& EventManager::getDependencies() const
{
static StringSet _dependencies;

if (_dependencies.empty())
Expand All @@ -58,28 +55,19 @@ const StringSet& EventManager::getDependencies() const {

void EventManager::initialiseModule(const ApplicationContext& ctx)
{
rMessage() << "EventManager::initialiseModule called." << std::endl;

_debugMode = registry::getValue<bool>(RKEY_DEBUG);
rMessage() << getName() << "::initialiseModule called." << std::endl;

// Deactivate the empty event, so it's safe to return it as NullEvent
_emptyEvent->setEnabled(false);

_shortcutFilter.reset(new ui::GlobalKeyEventFilter(*this));
_shortcutFilter.reset(new GlobalKeyEventFilter(*this));

if (_debugMode)
{
rMessage() << "EventManager intitialised in debug mode." << std::endl;
}
else
{
rMessage() << "EventManager successfully initialised." << std::endl;
}
rMessage() << getName() << " successfully initialised." << std::endl;
}

void EventManager::shutdownModule()
{
rMessage() << "EventManager: shutting down." << std::endl;
rMessage() << getName() << "::shutdownModule called" << std::endl;
_shortcutFilter.reset();

saveEventListToRegistry();
Expand All @@ -91,8 +79,7 @@ void EventManager::shutdownModule()
// Constructor
EventManager::EventManager() :
_emptyEvent(new Event()),
_emptyAccelerator(0, 0, _emptyEvent),
_debugMode(false)
_emptyAccelerator(0, 0, _emptyEvent)
{}

IAccelerator& EventManager::addAccelerator(const std::string& key, const std::string& modifierStr)
Expand Down Expand Up @@ -199,7 +186,7 @@ IEventPtr EventManager::addCommand(const std::string& name, const std::string& s
return _emptyEvent;
}

IEventPtr EventManager::addKeyEvent(const std::string& name, const ui::KeyStateChangeCallback& keyStateChangeCallback)
IEventPtr EventManager::addKeyEvent(const std::string& name, const KeyStateChangeCallback& keyStateChangeCallback)
{
if (!alreadyRegistered(name))
{
Expand Down Expand Up @@ -341,10 +328,6 @@ void EventManager::disconnectToolbar(wxToolBar* toolbar)
// Loads the default shortcuts from the registry
void EventManager::loadAccelerators()
{
if (_debugMode) {
rConsole() << "EventManager: Loading accelerators..." << std::endl;
}

// Register all custom statements as events too to make them shortcut-bindable
// before going ahead
GlobalCommandSystem().foreachStatement([&] (const std::string& statementName)
Expand All @@ -354,10 +337,6 @@ void EventManager::loadAccelerators()

xml::NodeList shortcutSets = GlobalRegistry().findXPath("user/ui/input//shortcuts");

if (_debugMode) {
rConsole() << "Found " << shortcutSets.size() << " sets." << std::endl;
}

// If we have two sets of shortcuts, delete the default ones
if (shortcutSets.size() > 1) {
GlobalRegistry().deleteXPath("user/ui/input//shortcuts[@name='default']");
Expand All @@ -375,12 +354,6 @@ void EventManager::loadAccelerators()
const std::string key = shortcutList[i].getAttributeValue("key");
const std::string cmd = shortcutList[i].getAttributeValue("command");

if (_debugMode)
{
rConsole() << "Looking up command: " << cmd << std::endl;
rConsole() << "Key is: >> " << key << " << " << std::endl;
}

// Try to lookup the command
IEventPtr event = findEvent(cmd);

Expand Down Expand Up @@ -418,22 +391,20 @@ void EventManager::loadAccelerators()
}
}

void EventManager::foreachEvent(IEventVisitor& eventVisitor) {
void EventManager::foreachEvent(IEventVisitor& eventVisitor)
{
// Cycle through the event and pass them to the visitor class
for (EventMap::iterator i = _events.begin(); i != _events.end(); i++) {
const std::string eventName = i->first;
IEventPtr event = i->second;

eventVisitor.visit(eventName, event);
for (const EventMap::value_type& pair : _events)
{
eventVisitor.visit(pair.first, pair.second);
}
}

// Tries to locate an accelerator, that is connected to the given command
IAccelerator& EventManager::findAccelerator(const IEventPtr& event)
{
// Cycle through the accelerators and check for matches
AcceleratorList::iterator end = _accelerators.end();
for (AcceleratorList::iterator i = _accelerators.begin(); i != end; ++i)
for (AcceleratorList::iterator i = _accelerators.begin(); i != _accelerators.end(); ++i)
{
if (i->match(event))
{
Expand Down
6 changes: 2 additions & 4 deletions plugins/eventmanager/EventManager.h
Expand Up @@ -36,9 +36,7 @@ class EventManager :
IEventPtr _emptyEvent;
Accelerator _emptyAccelerator;

bool _debugMode;

ui::GlobalKeyEventFilterPtr _shortcutFilter;
GlobalKeyEventFilterPtr _shortcutFilter;

public:
// RegisterableModule implementation
Expand Down Expand Up @@ -66,7 +64,7 @@ class EventManager :
// Add a command and specify the statement to execute when triggered
IEventPtr addCommand(const std::string& name, const std::string& statement, bool reactOnKeyUp);

IEventPtr addKeyEvent(const std::string& name, const ui::KeyStateChangeCallback& keyStateChangeCallback);
IEventPtr addKeyEvent(const std::string& name, const KeyStateChangeCallback& keyStateChangeCallback);
IEventPtr addWidgetToggle(const std::string& name);
IEventPtr addRegistryToggle(const std::string& name, const std::string& registryKey);
IEventPtr addToggle(const std::string& name, const ToggleCallback& onToggled);
Expand Down

0 comments on commit 74e810a

Please sign in to comment.