summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-05-18 17:02:13 +0300
committerAndrei Karas <akaras@inbox.ru>2013-05-18 17:02:13 +0300
commitdd828df46a661fbd0a24fbe540a4a585360be005 (patch)
tree7963e4739a4f6ace5d5c847edd4e679cc6c9bf87
parentea28a76cfbace0ccc8d25e523b410f2dea339423 (diff)
downloadplus-dd828df46a661fbd0a24fbe540a4a585360be005.tar.gz
plus-dd828df46a661fbd0a24fbe540a4a585360be005.tar.bz2
plus-dd828df46a661fbd0a24fbe540a4a585360be005.tar.xz
plus-dd828df46a661fbd0a24fbe540a4a585360be005.zip
add named commands with enum.
use some named commands from popupmenu.
-rw-r--r--src/commandhandler.cpp42
-rw-r--r--src/commandhandler.h20
-rw-r--r--src/commands.h80
-rw-r--r--src/gui/popupmenu.cpp4
4 files changed, 141 insertions, 5 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index fc7d6dff8..a9b5672ee 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -34,7 +34,11 @@ CommandHandler::CommandHandler() :
{
const int sz = sizeof(commands) / sizeof(CommandInfo);
for (int f = 0; f < sz; f ++)
- mCommands[commands[f].name] = commands[f].func;
+ {
+ const std::string name = commands[f].name;
+ if (!name.empty())
+ mCommands[name] = commands[f].func;
+ }
}
void CommandHandler::handleCommands(const std::string &command,
@@ -75,3 +79,39 @@ void CommandHandler::invokeCommand(const std::string &type,
}
}
}
+
+void CommandHandler::invokeCommand(const int type,
+ const bool warn)
+{
+ if (type < 0 || type >= END_COMMANDS)
+ return;
+ (commands[type].func)("", nullptr);
+}
+
+void CommandHandler::invokeCommand(const int type,
+ ChatTab *const tab,
+ const bool warn)
+{
+ if (type < 0 || type >= END_COMMANDS)
+ return;
+ (commands[type].func)("", tab);
+}
+
+void CommandHandler::invokeCommand(const int type,
+ const std::string &args,
+ const bool warn)
+{
+ if (type < 0 || type >= END_COMMANDS)
+ return;
+ (commands[type].func)(args, nullptr);
+}
+
+void CommandHandler::invokeCommand(const int type,
+ const std::string &args,
+ ChatTab *const tab,
+ const bool warn)
+{
+ if (type < 0 || type >= END_COMMANDS)
+ return;
+ (commands[type].func)(args, tab);
+}
diff --git a/src/commandhandler.h b/src/commandhandler.h
index 58fe78bf5..2bcd9e596 100644
--- a/src/commandhandler.h
+++ b/src/commandhandler.h
@@ -61,13 +61,29 @@ class CommandHandler final
void handleCommand(const std::string &command,
ChatTab *const tab = localChatTab);
+ void handleCommands(const std::string &command,
+ ChatTab *const tab = localChatTab);
+
void invokeCommand(const std::string &type,
const std::string &args,
ChatTab *const tab,
const bool warn = false);
- void handleCommands(const std::string &command,
- ChatTab *const tab = localChatTab);
+ void invokeCommand(const int type,
+ const bool warn = false);
+
+ void invokeCommand(const int type,
+ const std::string &args,
+ ChatTab *const tab,
+ const bool warn = false);
+
+ void invokeCommand(const int type,
+ const std::string &args,
+ const bool warn = false);
+
+ void invokeCommand(const int type,
+ ChatTab *const tab,
+ const bool warn = false);
protected:
friend class ChatTab;
diff --git a/src/commands.h b/src/commands.h
index 96423d748..bd0b8107d 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -120,6 +120,86 @@ namespace Commands
void replaceVars(std::string &str);
} // namespace Commands
+enum
+{
+ COMMAND_CLOSEALL,
+ COMMAND_IGNOREALL,
+ COMMAND_HELP,
+ COMMAND_ANNOUNCE,
+ COMMAND_WHERE,
+ COMMAND_WHO,
+ COMMAND_MSG,
+ COMMAND_WHISPER,
+ COMMAND_W,
+ COMMAND_QUERY,
+ COMMAND_Q,
+ COMMAND_IGNORE,
+ COMMAND_UNIGNORE,
+ COMMAND_FRIEND,
+ COMMAND_BEFRIEND,
+ COMMAND_DISREGARD,
+ COMMAND_NEUTRAL,
+ COMMAND_BLACKLIST,
+ COMMAND_ENEMY,
+ COMMAND_ERASE,
+ COMMAND_CLEAR,
+ COMMAND_CLEANGRAPHICS,
+ COMMAND_CLEANFONTS,
+ COMMAND_CREATEPARTY,
+ COMMAND_CREATEGUILD,
+ COMMAND_PARTY,
+ COMMAND_ME,
+ COMMAND_TOGGLE,
+ COMMAND_PRESENT,
+ COMMAND_QUIT,
+ COMMAND_ALL,
+ COMMAND_MOVE,
+ COMMAND_TARGET,
+ COMMAND_ATKHUMAN,
+ COMMAND_OUTFIT,
+ COMMAND_EMOTE,
+ COMMAND_AWAY,
+ COMMAND_PSEUDOAWAY,
+ COMMAND_FOLLOW,
+ COMMAND_HEAL,
+ COMMAND_NAVIGATE,
+ COMMAND_IMITATION,
+ COMMAND_MAIL,
+ COMMAND_TRADE,
+ COMMAND_PRICELOAD,
+ COMMAND_PRICESAVE,
+ COMMAND_CACHEINFO,
+ COMMAND_DISCONNECT,
+ COMMAND_UNDRESS,
+ COMMAND_ATTACK,
+ COMMAND_DIRS,
+ COMMAND_INFO,
+ COMMAND_WAIT,
+ COMMAND_UPTIME,
+ COMMAND_ADDPRIORITYATTACK,
+ COMMAND_ADDATTACK,
+ COMMAND_REMOVEATTACK,
+ COMMAND_REMOVEIGNOREATTACK,
+ COMMAND_ADDIGNOREATTACK,
+ COMMAND_DUMP,
+ COMMAND_SERVERIGNOREALL,
+ COMMAND_SERVERUNIGNOREALL,
+ COMMAND_SETDROP,
+ COMMAND_ERROR,
+ COMMAND_DUMPG,
+ COMMAND_DUMPE,
+ COMMAND_DUMPT,
+ COMMAND_DUMPOGL,
+ COMMAND_URL,
+ COMMAND_OPEN,
+ COMMAND_EXECUTE,
+ COMMAND_TESTSDLFONT,
+ COMMAND_ENABLEHIGHLIGHT,
+ COMMAND_DISABLEHIGHLIGHT,
+ COMMAND_HACK,
+ END_COMMANDS,
+};
+
static const CommandInfo commands[] =
{
{"closeall", &Commands::closeAll},
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 53a8a11f7..f9e2d232d 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -1319,12 +1319,12 @@ void PopupMenu::handleLink(const std::string &link,
else if (link == "enable highlight" && mTab)
{
if (commandHandler)
- commandHandler->invokeCommand("enablehighlight", "", mTab);
+ commandHandler->invokeCommand(COMMAND_ENABLEHIGHLIGHT, mTab);
}
else if (link == "disable highlight" && mTab)
{
if (commandHandler)
- commandHandler->invokeCommand("disablehighlight", "", mTab);
+ commandHandler->invokeCommand(COMMAND_DISABLEHIGHLIGHT, mTab);
}
else if (link == "dont remove name" && mTab)
{