aboutsummaryrefslogtreecommitdiff
path: root/src/CommandDialog.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/CommandDialog.cc')
-rw-r--r--src/CommandDialog.cc20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/CommandDialog.cc b/src/CommandDialog.cc
index 3fab06b..e502bc1 100644
--- a/src/CommandDialog.cc
+++ b/src/CommandDialog.cc
@@ -40,13 +40,17 @@
40#include <X11/keysym.h> 40#include <X11/keysym.h>
41#include <X11/Xutil.h> 41#include <X11/Xutil.h>
42 42
43#include <iostream>
44#include <memory> 43#include <memory>
45#include <stdexcept> 44#include <stdexcept>
46using namespace std; 45
46using std::string;
47using std::vector;
48using std::auto_ptr;
49using std::less;
50using std::out_of_range;
47 51
48CommandDialog::CommandDialog(BScreen &screen, 52CommandDialog::CommandDialog(BScreen &screen,
49 const std::string &title, const std::string precommand) : 53 const string &title, const string precommand) :
50 FbTk::FbWindow(screen.rootWindow().screenNumber(), 0, 0, 200, 1, ExposureMask), 54 FbTk::FbWindow(screen.rootWindow().screenNumber(), 0, 0, 200, 1, ExposureMask),
51 m_textbox(*this, screen.winFrameTheme().font(), ""), 55 m_textbox(*this, screen.winFrameTheme().font(), ""),
52 m_label(*this, screen.winFrameTheme().font(), title), 56 m_label(*this, screen.winFrameTheme().font(), title),
@@ -67,7 +71,7 @@ CommandDialog::~CommandDialog() {
67 m_screen.imageControl().removeImage(m_pixmap); 71 m_screen.imageControl().removeImage(m_pixmap);
68} 72}
69 73
70void CommandDialog::setText(const std::string &text) { 74void CommandDialog::setText(const string &text) {
71 m_textbox.setText(text); 75 m_textbox.setText(text);
72} 76}
73 77
@@ -135,7 +139,7 @@ void CommandDialog::keyPressEvent(XKeyEvent &event) {
135 if (ks == XK_Return) { 139 if (ks == XK_Return) {
136 hide(); // hide and return focus to a FluxboxWindow 140 hide(); // hide and return focus to a FluxboxWindow
137 // create command from line 141 // create command from line
138 std::auto_ptr<FbTk::Command> cmd(CommandParser::instance(). 142 auto_ptr<FbTk::Command> cmd(CommandParser::instance().
139 parseLine(m_precommand + m_textbox.text())); 143 parseLine(m_precommand + m_textbox.text()));
140 if (cmd.get()) 144 if (cmd.get())
141 cmd->execute(); 145 cmd->execute();
@@ -168,7 +172,7 @@ void CommandDialog::tabComplete() {
168 172
169 CommandParser::CommandFactoryMap::const_iterator it = CommandParser::instance().factorys().begin(); 173 CommandParser::CommandFactoryMap::const_iterator it = CommandParser::instance().factorys().begin();
170 const CommandParser::CommandFactoryMap::const_iterator it_end = CommandParser::instance().factorys().end(); 174 const CommandParser::CommandFactoryMap::const_iterator it_end = CommandParser::instance().factorys().end();
171 std::vector<std::string> matches; 175 vector<string> matches;
172 for (; it != it_end; ++it) { 176 for (; it != it_end; ++it) {
173 if ((*it).first.find(prefix) == 0) { 177 if ((*it).first.find(prefix) == 0) {
174 matches.push_back((*it).first); 178 matches.push_back((*it).first);
@@ -177,12 +181,12 @@ void CommandDialog::tabComplete() {
177 181
178 if (!matches.empty()) { 182 if (!matches.empty()) {
179 // sort and apply larges match 183 // sort and apply larges match
180 std::sort(matches.begin(), matches.end(), less<string>()); 184 sort(matches.begin(), matches.end(), less<string>());
181 m_textbox.setText(m_textbox.text() + matches[0].substr(prefix.size())); 185 m_textbox.setText(m_textbox.text() + matches[0].substr(prefix.size()));
182 } else 186 } else
183 XBell(FbTk::App::instance()->display(), 0); 187 XBell(FbTk::App::instance()->display(), 0);
184 188
185 } catch (std::out_of_range &oor) { 189 } catch (out_of_range &oor) {
186 XBell(FbTk::App::instance()->display(), 0); 190 XBell(FbTk::App::instance()->display(), 0);
187 } 191 }
188} 192}