aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/MacroCommand.cc
diff options
context:
space:
mode:
authormarkt <markt>2007-12-13 05:48:00 (GMT)
committermarkt <markt>2007-12-13 05:48:00 (GMT)
commit8b7464046cea5e521ac46811591b0fce0c45aca1 (patch)
tree09df752f426a249ae15375a626a98436c8727593 /src/FbTk/MacroCommand.cc
parentdaca07edafc2e75eb9ee04d35fe80759308a8583 (diff)
downloadfluxbox-8b7464046cea5e521ac46811591b0fce0c45aca1.zip
fluxbox-8b7464046cea5e521ac46811591b0fce0c45aca1.tar.bz2
added FbTk::CommandRegistry, decentralized command parsing, and made them auto-register
Diffstat (limited to 'src/FbTk/MacroCommand.cc')
-rw-r--r--src/FbTk/MacroCommand.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/FbTk/MacroCommand.cc b/src/FbTk/MacroCommand.cc
index 491b01e..20e91e4 100644
--- a/src/FbTk/MacroCommand.cc
+++ b/src/FbTk/MacroCommand.cc
@@ -23,8 +23,56 @@
23 23
24#include "MacroCommand.hh" 24#include "MacroCommand.hh"
25 25
26#include "CommandRegistry.hh"
27#include "StringUtil.hh"
28
29#include <string>
30
26namespace FbTk { 31namespace FbTk {
27 32
33namespace {
34
35template <typename M>
36M *addCommands(M *macro, const std::string &args, bool trusted) {
37
38 std::string cmd;
39 int err = 0;
40 int pos = 0;
41
42 while (true) {
43 RefCount<Command> next(0);
44 pos += err;
45 err = StringUtil::getStringBetween(cmd, args.c_str() + pos,
46 '{', '}', " \t\n", true);
47 if (err == 0)
48 break;
49 if (err > 0)
50 next = CommandRegistry::instance().parseLine(cmd, trusted);
51 if (*next != 0)
52 macro->add(next);
53 }
54
55 if (macro->size() > 0)
56 return macro;
57
58 delete macro;
59 return 0;
60}
61
62Command *parseMacroCmd(const std::string &command, const std::string &args,
63 bool trusted) {
64 if (command == "macrocmd")
65 return addCommands<MacroCommand>(new MacroCommand, args, trusted);
66 else if (command == "togglecmd")
67 return addCommands<ToggleCommand>(new ToggleCommand, args, trusted);
68 return 0;
69}
70
71REGISTER_COMMAND_PARSER(macrocmd, parseMacroCmd);
72REGISTER_COMMAND_PARSER(togglecmd, parseMacroCmd);
73
74}; // end anonymous namespace
75
28void MacroCommand::add(RefCount<Command> &com) { 76void MacroCommand::add(RefCount<Command> &com) {
29 m_commandlist.push_back(com); 77 m_commandlist.push_back(com);
30} 78}