From d218f02f80395bdfa34fcac3b8147d0be5e6b420 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sat, 10 Jun 2006 20:04:34 +0000 Subject: added new command: ToggleCmd, works like a macro but executes the commands one at the time. Thanks Mark Tiefenbruck --- src/FbCommandFactory.cc | 52 ++++++++++++++++++++++++++++++++++++++++++------ src/FbTk/MacroCommand.cc | 18 +++++++++++++++++ src/FbTk/MacroCommand.hh | 13 ++++++++++++ 3 files changed, 77 insertions(+), 6 deletions(-) diff --git a/src/FbCommandFactory.cc b/src/FbCommandFactory.cc index 50f0fef..4e129af 100644 --- a/src/FbCommandFactory.cc +++ b/src/FbCommandFactory.cc @@ -136,6 +136,7 @@ FbCommandFactory::FbCommandFactory() { "taketoworkspace", "taketonextworkspace", "taketoprevworkspace", + "togglecmd", "toggledecor", "windowmenu", "workspace", @@ -449,12 +450,15 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, while (true) { parse_pos+= err; - err= FbTk::StringUtil::getStringBetween(cmd, arguments.c_str() + parse_pos, - '{', '}', " \t\n", true); + err= FbTk::StringUtil::getStringBetween(cmd, arguments.c_str() + + parse_pos, + '{', '}', " \t\n", true); if ( err > 0 ) { std::string c, a; - std::string::size_type first_pos = FbTk::StringUtil::removeFirstWhitespace(cmd); - std::string::size_type second_pos= cmd.find_first_of(" \t", first_pos); + std::string::size_type first_pos = + FbTk::StringUtil::removeFirstWhitespace(cmd); + std::string::size_type second_pos = + cmd.find_first_of(" \t", first_pos); if (second_pos != std::string::npos) { a= cmd.substr(second_pos); FbTk::StringUtil::removeFirstWhitespace(a); @@ -467,8 +471,44 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, FbTk::RefCount rfbcmd(fbcmd); macro->add(rfbcmd); } - } - else + } else + break; + } + + if ( macro->size() > 0 ) + return macro; + + delete macro; + } else if (command == "togglecmd") { + std::string cmd; + int err= 0; + int parse_pos= 0; + FbTk::ToggleCommand* macro= new FbTk::ToggleCommand(); + + while (true) { + parse_pos+= err; + err= FbTk::StringUtil::getStringBetween(cmd, arguments.c_str() + + parse_pos, + '{', '}', " \t\n", true); + if ( err > 0 ) { + std::string c, a; + std::string::size_type first_pos = + FbTk::StringUtil::removeFirstWhitespace(cmd); + std::string::size_type second_pos= + cmd.find_first_of(" \t", first_pos); + if (second_pos != std::string::npos) { + a= cmd.substr(second_pos); + FbTk::StringUtil::removeFirstWhitespace(a); + cmd.erase(second_pos); + } + c= FbTk::StringUtil::toLower(cmd); + + FbTk::Command* fbcmd= stringToCommand(c,a); + if (fbcmd) { + FbTk::RefCount rfbcmd(fbcmd); + macro->add(rfbcmd); + } + } else break; } diff --git a/src/FbTk/MacroCommand.cc b/src/FbTk/MacroCommand.cc index adee9cb..491b01e 100644 --- a/src/FbTk/MacroCommand.cc +++ b/src/FbTk/MacroCommand.cc @@ -38,6 +38,24 @@ void MacroCommand::execute() { m_commandlist[i]->execute(); } +ToggleCommand::ToggleCommand() { + m_state = 0; +} + +void ToggleCommand::add(RefCount &com) { + m_commandlist.push_back(com); +} + +size_t ToggleCommand::size() const { + return m_commandlist.size(); +} + +void ToggleCommand::execute() { + m_commandlist[m_state]->execute(); + if (++m_state >= m_commandlist.size()) + m_state = 0; +} + }; // end namespace FbTk diff --git a/src/FbTk/MacroCommand.hh b/src/FbTk/MacroCommand.hh index f29e05c..7aa9d66 100644 --- a/src/FbTk/MacroCommand.hh +++ b/src/FbTk/MacroCommand.hh @@ -42,6 +42,19 @@ private: std::vector > m_commandlist; }; +/// executes one command at a time +class ToggleCommand:public Command { +public: + ToggleCommand(); + void add(RefCount &com); + size_t size() const; + virtual void execute(); + +private: + std::vector > m_commandlist; + size_t m_state; +}; + } // end namespace FbTk #endif // FBTK_MACROCOMMAND_HH -- cgit v0.11.2