summaryrefslogtreecommitdiff
path: root/src/commandhandler.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-05-18 19:42:42 +0300
committerAndrei Karas <akaras@inbox.ru>2013-05-18 19:43:41 +0300
commit00c7073096a7bf40cee7595d0d419b9feff1c120 (patch)
tree307e3c76b2eb7b828478a8cd8f323158d26ca766 /src/commandhandler.cpp
parent25a143ac11baebc9ecaf5c2c05d4808f20d54e3c (diff)
downloadmv-00c7073096a7bf40cee7595d0d419b9feff1c120.tar.gz
mv-00c7073096a7bf40cee7595d0d419b9feff1c120.tar.bz2
mv-00c7073096a7bf40cee7595d0d419b9feff1c120.tar.xz
mv-00c7073096a7bf40cee7595d0d419b9feff1c120.zip
Add ability to call input action from commands.
add new commands: /drop - drop from first slot. /dropn - drop fro any slots. /movetotarget - move to target position. /movetohome - move to home position. /sethome - set home position.
Diffstat (limited to 'src/commandhandler.cpp')
-rw-r--r--src/commandhandler.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index a9b5672ee..d769f121f 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -22,6 +22,8 @@
#include "commandhandler.h"
+#include "inputmanager.h"
+
#include "gui/widgets/chattab.h"
#include "utils/gettext.h"
@@ -37,7 +39,7 @@ CommandHandler::CommandHandler() :
{
const std::string name = commands[f].name;
if (!name.empty())
- mCommands[name] = commands[f].func;
+ mCommands[name] = &commands[f];
}
}
@@ -68,7 +70,7 @@ void CommandHandler::invokeCommand(const std::string &type,
const CommandsMapIter it = mCommands.find(type);
if (it != mCommands.end())
{
- ((*it).second)(args, tab);
+ callFunc(*(*it).second, args, tab);
}
else if (!tab->handleCommand(type, args))
{
@@ -80,12 +82,23 @@ void CommandHandler::invokeCommand(const std::string &type,
}
}
+void CommandHandler::callFunc(const CommandInfo &info,
+ const std::string &args,
+ ChatTab *const tab)
+{
+ CommandFuncPtr func = info.func;
+ if (func)
+ func(args, tab);
+ else
+ inputManager.executeAction(info.actionId);
+}
+
void CommandHandler::invokeCommand(const int type,
const bool warn)
{
if (type < 0 || type >= END_COMMANDS)
return;
- (commands[type].func)("", nullptr);
+ callFunc(commands[type], "", nullptr);
}
void CommandHandler::invokeCommand(const int type,
@@ -94,7 +107,7 @@ void CommandHandler::invokeCommand(const int type,
{
if (type < 0 || type >= END_COMMANDS)
return;
- (commands[type].func)("", tab);
+ callFunc(commands[type], "", tab);
}
void CommandHandler::invokeCommand(const int type,
@@ -103,7 +116,7 @@ void CommandHandler::invokeCommand(const int type,
{
if (type < 0 || type >= END_COMMANDS)
return;
- (commands[type].func)(args, nullptr);
+ callFunc(commands[type], args, nullptr);
}
void CommandHandler::invokeCommand(const int type,
@@ -113,5 +126,5 @@ void CommandHandler::invokeCommand(const int type,
{
if (type < 0 || type >= END_COMMANDS)
return;
- (commands[type].func)(args, tab);
+ callFunc(commands[type], args, tab);
}