summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CommandDialog.cc43
-rw-r--r--src/CommandDialog.hh5
2 files changed, 46 insertions, 2 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>
42using namespace std; 44using namespace std;
43 45
44CommandDialog::CommandDialog(BScreen &screen, const std::string &title): 46CommandDialog::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
167void 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
161void CommandDialog::render() { 202void CommandDialog::render() {
diff --git a/src/CommandDialog.hh b/src/CommandDialog.hh
index 84ed01c..bc9d3a6 100644
--- a/src/CommandDialog.hh
+++ b/src/CommandDialog.hh
@@ -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.hh,v 1.2 2003/12/19 18:15:19 fluxgen Exp $ 23// $Id: CommandDialog.hh,v 1.3 2004/01/02 13:48:28 fluxgen Exp $
24 24
25#ifndef RUNCOMMANDDIALOG_HH 25#ifndef RUNCOMMANDDIALOG_HH
26#define RUNCOMMANDDIALOG_HH 26#define RUNCOMMANDDIALOG_HH
@@ -52,6 +52,9 @@ public:
52 void handleEvent(XEvent &event); 52 void handleEvent(XEvent &event);
53 void keyPressEvent(XKeyEvent &event); 53 void keyPressEvent(XKeyEvent &event);
54 54
55protected:
56 virtual void tabComplete();
57
55private: 58private:
56 void init(); 59 void init();
57 void render(); 60 void render();