diff options
author | fluxgen <fluxgen> | 2004-01-02 13:53:21 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2004-01-02 13:53:21 (GMT) |
commit | 1feb5a66234cf9fc9c81dbc659d316d7d31bec50 (patch) | |
tree | a7e6076a2c3310b5637bafd0dcab12df35abb4ea /src/CommandDialog.cc | |
parent | 5103e80e9adaeac1cfc5dc21cc28de993dc9d710 (diff) | |
download | fluxbox_pavel-1feb5a66234cf9fc9c81dbc659d316d7d31bec50.zip fluxbox_pavel-1feb5a66234cf9fc9c81dbc659d316d7d31bec50.tar.bz2 |
tab complete commands
Diffstat (limited to 'src/CommandDialog.cc')
-rw-r--r-- | src/CommandDialog.cc | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/CommandDialog.cc b/src/CommandDialog.cc index 47aeddd..813fbd0 100644 --- a/src/CommandDialog.cc +++ b/src/CommandDialog.cc | |||
@@ -20,7 +20,7 @@ | |||
20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
21 | // DEALINGS IN THE SOFTWARE. | 21 | // DEALINGS IN THE SOFTWARE. |
22 | 22 | ||
23 | // $Id: CommandDialog.cc,v 1.2 2003/12/19 18:16:01 fluxgen Exp $ | 23 | // $Id: CommandDialog.cc,v 1.3 2004/01/02 13:53:21 fluxgen Exp $ |
24 | 24 | ||
25 | #include "CommandDialog.hh" | 25 | #include "CommandDialog.hh" |
26 | 26 | ||
@@ -32,6 +32,7 @@ | |||
32 | 32 | ||
33 | #include "FbTk/ImageControl.hh" | 33 | #include "FbTk/ImageControl.hh" |
34 | #include "FbTk/EventManager.hh" | 34 | #include "FbTk/EventManager.hh" |
35 | #include "FbTk/StringUtil.hh" | ||
35 | #include "FbTk/App.hh" | 36 | #include "FbTk/App.hh" |
36 | 37 | ||
37 | #include <X11/keysym.h> | 38 | #include <X11/keysym.h> |
@@ -39,6 +40,7 @@ | |||
39 | 40 | ||
40 | #include <iostream> | 41 | #include <iostream> |
41 | #include <memory> | 42 | #include <memory> |
43 | #include <stdexcept> | ||
42 | using namespace std; | 44 | using namespace std; |
43 | 45 | ||
44 | CommandDialog::CommandDialog(BScreen &screen, const std::string &title): | 46 | CommandDialog::CommandDialog(BScreen &screen, const std::string &title): |
@@ -156,6 +158,45 @@ void CommandDialog::keyPressEvent(XKeyEvent &event) { | |||
156 | delete this; // end this | 158 | delete this; // end this |
157 | } else if (ks == XK_Escape) | 159 | } else if (ks == XK_Escape) |
158 | delete this; // end this | 160 | delete this; // end this |
161 | else if (ks == XK_Tab) { | ||
162 | // try to expand a command | ||
163 | tabComplete(); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | void CommandDialog::tabComplete() { | ||
168 | try { | ||
169 | string::size_type first = m_textbox.text().find_last_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
170 | "abcdefghijklmnopqrstuvwxyz" | ||
171 | "0123456789", | ||
172 | m_textbox.cursorPosition()); | ||
173 | if (first == string::npos) | ||
174 | first = 0; | ||
175 | string prefix = FbTk::StringUtil::toLower(m_textbox.text().substr(first, m_textbox.cursorPosition())); | ||
176 | if (prefix.size() == 0) { | ||
177 | XBell(FbTk::App::instance()->display(), 0); | ||
178 | return; | ||
179 | } | ||
180 | |||
181 | CommandParser::CommandFactoryMap::const_iterator it = CommandParser::instance().factorys().begin(); | ||
182 | const CommandParser::CommandFactoryMap::const_iterator it_end = CommandParser::instance().factorys().end(); | ||
183 | std::vector<std::string> matches; | ||
184 | for (; it != it_end; ++it) { | ||
185 | if ((*it).first.find(prefix) == 0) { | ||
186 | matches.push_back((*it).first); | ||
187 | } | ||
188 | } | ||
189 | |||
190 | if (!matches.empty()) { | ||
191 | // sort and apply larges match | ||
192 | std::sort(matches.begin(), matches.end(), less<string>()); | ||
193 | m_textbox.setText(m_textbox.text() + matches[0].substr(prefix.size())); | ||
194 | } else | ||
195 | XBell(FbTk::App::instance()->display(), 0); | ||
196 | |||
197 | } catch (std::out_of_range &oor) { | ||
198 | XBell(FbTk::App::instance()->display(), 0); | ||
199 | } | ||
159 | } | 200 | } |
160 | 201 | ||
161 | void CommandDialog::render() { | 202 | void CommandDialog::render() { |