diff options
author | Mark Tiefenbruck <mark@fluxbox.org> | 2007-12-20 20:23:56 (GMT) |
---|---|---|
committer | Mark Tiefenbruck <mark@fluxbox.org> | 2007-12-20 20:23:56 (GMT) |
commit | 03dce043b78103a977bd6c48b81bb1b462aaac5f (patch) | |
tree | 6cc49956acf8c4049f7d6702058534d29c1c15c2 /src | |
parent | b90a7e21a9f56f8e9f92c7ec357cbf683e6fd712 (diff) | |
download | fluxbox-03dce043b78103a977bd6c48b81bb1b462aaac5f.zip fluxbox-03dce043b78103a977bd6c48b81bb1b462aaac5f.tar.bz2 |
added ForEach key command
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/StringUtil.hh | 21 | ||||
-rw-r--r-- | src/FocusableList.cc | 5 | ||||
-rw-r--r-- | src/WorkspaceCmd.cc | 47 | ||||
-rw-r--r-- | src/WorkspaceCmd.hh | 10 |
4 files changed, 69 insertions, 14 deletions
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh index d3c131e..bca48bc 100644 --- a/src/FbTk/StringUtil.hh +++ b/src/FbTk/StringUtil.hh | |||
@@ -67,6 +67,27 @@ std::string::size_type removeTrailingWhitespace(std::string &str); | |||
67 | /// splits input at first non-leading whitespace and returns both parts | 67 | /// splits input at first non-leading whitespace and returns both parts |
68 | void getFirstWord(const std::string &in, std::string &first, std::string &rest); | 68 | void getFirstWord(const std::string &in, std::string &first, std::string &rest); |
69 | 69 | ||
70 | template <typename Container> | ||
71 | static void stringTokensBetween(Container &container, const std::string &in, | ||
72 | std::string &rest, char first, char last, | ||
73 | const char *ok_chars = " \t\n", bool allow_nesting = true) { | ||
74 | |||
75 | std::string token; | ||
76 | int err = 0, pos = 0; | ||
77 | |||
78 | while (true) { | ||
79 | err = getStringBetween(token, in.c_str() + pos, first, last, ok_chars, | ||
80 | allow_nesting); | ||
81 | if (err == 0) | ||
82 | break; | ||
83 | container.push_back(token); | ||
84 | pos += err; | ||
85 | } | ||
86 | |||
87 | rest = in.c_str() + pos; | ||
88 | |||
89 | } | ||
90 | |||
70 | /// Breaks a string into tokens | 91 | /// Breaks a string into tokens |
71 | template <typename Container> | 92 | template <typename Container> |
72 | static void | 93 | static void |
diff --git a/src/FocusableList.cc b/src/FocusableList.cc index 8c43181..366ef8a 100644 --- a/src/FocusableList.cc +++ b/src/FocusableList.cc | |||
@@ -38,10 +38,11 @@ using std::vector; | |||
38 | 38 | ||
39 | void FocusableList::parseArgs(const string &in, int &opts, string &pat) { | 39 | void FocusableList::parseArgs(const string &in, int &opts, string &pat) { |
40 | string options; | 40 | string options; |
41 | int err = FbTk::StringUtil::getStringBetween(options, in.c_str(), '{', '}'); | 41 | int err = FbTk::StringUtil::getStringBetween(options, in.c_str(), '{', '}', |
42 | " \t\n"); | ||
42 | 43 | ||
43 | // the rest of the string is a ClientPattern | 44 | // the rest of the string is a ClientPattern |
44 | pat = in.c_str() + err; | 45 | pat = in.c_str() + (err > 0 ? err : 0); |
45 | 46 | ||
46 | // now parse the options | 47 | // now parse the options |
47 | vector<string> args; | 48 | vector<string> args; |
diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc index 2d2964e..bb1537e 100644 --- a/src/WorkspaceCmd.cc +++ b/src/WorkspaceCmd.cc | |||
@@ -35,6 +35,7 @@ | |||
35 | #include "FbTk/KeyUtil.hh" | 35 | #include "FbTk/KeyUtil.hh" |
36 | #include "FbTk/ObjectRegistry.hh" | 36 | #include "FbTk/ObjectRegistry.hh" |
37 | #include "FbTk/stringstream.hh" | 37 | #include "FbTk/stringstream.hh" |
38 | #include "FbTk/StringUtil.hh" | ||
38 | 39 | ||
39 | #ifdef HAVE_CMATH | 40 | #ifdef HAVE_CMATH |
40 | #include <cmath> | 41 | #include <cmath> |
@@ -43,30 +44,58 @@ | |||
43 | #endif | 44 | #endif |
44 | #include <algorithm> | 45 | #include <algorithm> |
45 | #include <functional> | 46 | #include <functional> |
47 | #include <vector> | ||
46 | 48 | ||
47 | using std::string; | 49 | using std::string; |
48 | using FbTk::Command; | 50 | using FbTk::Command; |
49 | using FbTk::BoolCommand; | 51 | using FbTk::BoolCommand; |
50 | 52 | ||
51 | void WindowListCmd::execute() { | 53 | REGISTER_OBJECT_PARSER(map, WindowListCmd::parse, Command); |
52 | if (m_pat.error()) { | 54 | REGISTER_OBJECT_PARSER(foreach, WindowListCmd::parse, Command); |
53 | m_cmd->execute(); | 55 | |
54 | return; | 56 | FbTk::Command *WindowListCmd::parse(const string &command, const string &args, |
57 | bool trusted) { | ||
58 | FbTk::Command *cmd = 0; | ||
59 | FbTk::BoolCommand *filter = 0; | ||
60 | std::vector<string> tokens; | ||
61 | int opts; | ||
62 | string pat; | ||
63 | |||
64 | FbTk::StringUtil::stringTokensBetween(tokens, args, pat, '{', '}'); | ||
65 | if (tokens.empty()) | ||
66 | return 0; | ||
67 | |||
68 | cmd = FbTk::ObjectRegistry<Command>::instance().parse(tokens[0], trusted); | ||
69 | if (!cmd) | ||
70 | return 0; | ||
71 | |||
72 | if (tokens.size() > 1) { | ||
73 | FocusableList::parseArgs(tokens[1], opts, pat); | ||
74 | |||
75 | filter = FbTk::ObjectRegistry<BoolCommand>::instance().parse(pat, | ||
76 | trusted); | ||
55 | } | 77 | } |
56 | 78 | ||
79 | return new WindowListCmd(FbTk::RefCount<Command>(cmd), opts, | ||
80 | FbTk::RefCount<BoolCommand>(filter)); | ||
81 | } | ||
82 | |||
83 | void WindowListCmd::execute() { | ||
57 | BScreen *screen = Fluxbox::instance()->keyScreen(); | 84 | BScreen *screen = Fluxbox::instance()->keyScreen(); |
58 | if (screen != 0) { | 85 | if (screen != 0) { |
59 | FocusControl::Focusables win_list(screen->focusControl().creationOrderWinList().clientList()); | 86 | FocusableList::Focusables win_list(FocusableList::getListFromOptions(*screen, m_opts)->clientList()); |
60 | 87 | ||
61 | FocusControl::Focusables::iterator it = win_list.begin(), | 88 | FocusableList::Focusables::iterator it = win_list.begin(), |
62 | it_end = win_list.end(); | 89 | it_end = win_list.end(); |
63 | // save old value, so we can restore it later | 90 | // save old value, so we can restore it later |
64 | WinClient *old = WindowCmd<void>::client(); | 91 | WinClient *old = WindowCmd<void>::client(); |
65 | for (; it != it_end; ++it) { | 92 | for (; it != it_end; ++it) { |
66 | if (m_pat.match(**it) && (*it)->fbwindow()) { | 93 | if (typeid(**it) == typeid(FluxboxWindow)) |
67 | WindowCmd<void>::setWindow((*it)->fbwindow()); | 94 | WindowCmd<void>::setWindow((*it)->fbwindow()); |
95 | else if (typeid(**it) == typeid(WinClient)) | ||
96 | WindowCmd<void>::setClient(dynamic_cast<WinClient *>(*it)); | ||
97 | if (!*m_filter || m_filter->bool_execute()) | ||
68 | m_cmd->execute(); | 98 | m_cmd->execute(); |
69 | } | ||
70 | } | 99 | } |
71 | WindowCmd<void>::setClient(old); | 100 | WindowCmd<void>::setClient(old); |
72 | } | 101 | } |
diff --git a/src/WorkspaceCmd.hh b/src/WorkspaceCmd.hh index fa8cb58..13adec3 100644 --- a/src/WorkspaceCmd.hh +++ b/src/WorkspaceCmd.hh | |||
@@ -36,14 +36,18 @@ | |||
36 | 36 | ||
37 | class WindowListCmd: public FbTk::Command { | 37 | class WindowListCmd: public FbTk::Command { |
38 | public: | 38 | public: |
39 | WindowListCmd(FbTk::RefCount<FbTk::Command> cmd, const std::string &pat): | 39 | WindowListCmd(FbTk::RefCount<FbTk::Command> cmd, int opts, |
40 | m_cmd(cmd), m_pat(pat.c_str()) { } | 40 | FbTk::RefCount<FbTk::BoolCommand> filter): |
41 | m_cmd(cmd), m_opts(opts), m_filter(filter) { } | ||
41 | 42 | ||
42 | void execute(); | 43 | void execute(); |
44 | static FbTk::Command *parse(const std::string &command, | ||
45 | const std::string &args, bool trusted); | ||
43 | 46 | ||
44 | private: | 47 | private: |
45 | FbTk::RefCount<FbTk::Command> m_cmd; | 48 | FbTk::RefCount<FbTk::Command> m_cmd; |
46 | ClientPattern m_pat; | 49 | int m_opts; |
50 | FbTk::RefCount<FbTk::BoolCommand> m_filter; | ||
47 | }; | 51 | }; |
48 | 52 | ||
49 | class SomeCmd: public FbTk::BoolCommand { | 53 | class SomeCmd: public FbTk::BoolCommand { |