aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FbCommandFactory.cc52
-rw-r--r--src/FbTk/MacroCommand.cc18
-rw-r--r--src/FbTk/MacroCommand.hh13
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() {
136 "taketoworkspace", 136 "taketoworkspace",
137 "taketonextworkspace", 137 "taketonextworkspace",
138 "taketoprevworkspace", 138 "taketoprevworkspace",
139 "togglecmd",
139 "toggledecor", 140 "toggledecor",
140 "windowmenu", 141 "windowmenu",
141 "workspace", 142 "workspace",
@@ -449,12 +450,15 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,
449 450
450 while (true) { 451 while (true) {
451 parse_pos+= err; 452 parse_pos+= err;
452 err= FbTk::StringUtil::getStringBetween(cmd, arguments.c_str() + parse_pos, 453 err= FbTk::StringUtil::getStringBetween(cmd, arguments.c_str() +
453 '{', '}', " \t\n", true); 454 parse_pos,
455 '{', '}', " \t\n", true);
454 if ( err > 0 ) { 456 if ( err > 0 ) {
455 std::string c, a; 457 std::string c, a;
456 std::string::size_type first_pos = FbTk::StringUtil::removeFirstWhitespace(cmd); 458 std::string::size_type first_pos =
457 std::string::size_type second_pos= cmd.find_first_of(" \t", first_pos); 459 FbTk::StringUtil::removeFirstWhitespace(cmd);
460 std::string::size_type second_pos =
461 cmd.find_first_of(" \t", first_pos);
458 if (second_pos != std::string::npos) { 462 if (second_pos != std::string::npos) {
459 a= cmd.substr(second_pos); 463 a= cmd.substr(second_pos);
460 FbTk::StringUtil::removeFirstWhitespace(a); 464 FbTk::StringUtil::removeFirstWhitespace(a);
@@ -467,8 +471,44 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command,
467 FbTk::RefCount<FbTk::Command> rfbcmd(fbcmd); 471 FbTk::RefCount<FbTk::Command> rfbcmd(fbcmd);
468 macro->add(rfbcmd); 472 macro->add(rfbcmd);
469 } 473 }
470 } 474 } else
471 else 475 break;
476 }
477
478 if ( macro->size() > 0 )
479 return macro;
480
481 delete macro;
482 } else if (command == "togglecmd") {
483 std::string cmd;
484 int err= 0;
485 int parse_pos= 0;
486 FbTk::ToggleCommand* macro= new FbTk::ToggleCommand();
487
488 while (true) {
489 parse_pos+= err;
490 err= FbTk::StringUtil::getStringBetween(cmd, arguments.c_str() +
491 parse_pos,
492 '{', '}', " \t\n", true);
493 if ( err > 0 ) {
494 std::string c, a;
495 std::string::size_type first_pos =
496 FbTk::StringUtil::removeFirstWhitespace(cmd);
497 std::string::size_type second_pos=
498 cmd.find_first_of(" \t", first_pos);
499 if (second_pos != std::string::npos) {
500 a= cmd.substr(second_pos);
501 FbTk::StringUtil::removeFirstWhitespace(a);
502 cmd.erase(second_pos);
503 }
504 c= FbTk::StringUtil::toLower(cmd);
505
506 FbTk::Command* fbcmd= stringToCommand(c,a);
507 if (fbcmd) {
508 FbTk::RefCount<FbTk::Command> rfbcmd(fbcmd);
509 macro->add(rfbcmd);
510 }
511 } else
472 break; 512 break;
473 } 513 }
474 514
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() {
38 m_commandlist[i]->execute(); 38 m_commandlist[i]->execute();
39} 39}
40 40
41ToggleCommand::ToggleCommand() {
42 m_state = 0;
43}
44
45void ToggleCommand::add(RefCount<Command> &com) {
46 m_commandlist.push_back(com);
47}
48
49size_t ToggleCommand::size() const {
50 return m_commandlist.size();
51}
52
53void ToggleCommand::execute() {
54 m_commandlist[m_state]->execute();
55 if (++m_state >= m_commandlist.size())
56 m_state = 0;
57}
58
41}; // end namespace FbTk 59}; // end namespace FbTk
42 60
43 61
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:
42 std::vector<RefCount<Command> > m_commandlist; 42 std::vector<RefCount<Command> > m_commandlist;
43}; 43};
44 44
45/// executes one command at a time
46class ToggleCommand:public Command {
47public:
48 ToggleCommand();
49 void add(RefCount<Command> &com);
50 size_t size() const;
51 virtual void execute();
52
53private:
54 std::vector<RefCount<Command> > m_commandlist;
55 size_t m_state;
56};
57
45} // end namespace FbTk 58} // end namespace FbTk
46 59
47#endif // FBTK_MACROCOMMAND_HH 60#endif // FBTK_MACROCOMMAND_HH