2 * \file QCommandBuffer.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author John Levon <moz@compsoc.man.ac.uk>
11 #include "support/filetools.h"
12 #include "controllers/ControlCommandBuffer.h"
16 #include "QCommandBuffer.h"
17 #include "QCommandEdit.h"
19 #include <qcombobox.h>
20 #include <qtoolbutton.h>
25 class QTempComboBox : public QComboBox {
27 QTempComboBox(QWidget * parent) : QComboBox(parent) {
28 setWFlags(WDestructiveClose);
31 void popup() { QComboBox::popup(); }
36 QCommandBuffer::QCommandBuffer(QtView * view, ControlCommandBuffer & control)
37 : QToolBar(view), view_(view), controller_(control)
39 setHorizontalStretchable(true);
41 QPixmap qp(LibFileSearch("images", "unknown", "xpm").c_str());
43 QToolButton * upb = new QToolButton(qp, _("Up"), "", this, SLOT(up()), this);
44 upb->setMinimumSize(upb->sizeHint());
47 QToolButton * downb = new QToolButton(qp, _("Down"), "", this, SLOT(down()), this);
48 downb->setMinimumSize(downb->sizeHint());
51 edit_ = new QCommandEdit(this);
52 edit_->setMinimumSize(edit_->sizeHint());
54 setStretchableWidget(edit_);
56 setMinimumSize(sizeHint());
59 connect(edit_, SIGNAL(escapePressed()), this, SLOT(cancel()));
60 connect(edit_, SIGNAL(returnPressed()), this, SLOT(dispatch()));
61 connect(edit_, SIGNAL(rightPressed()), this, SLOT(complete()));
62 connect(edit_, SIGNAL(upPressed()), this, SLOT(up()));
63 connect(edit_, SIGNAL(downPressed()), this, SLOT(down()));
68 void QCommandBuffer::focus_command()
74 void QCommandBuffer::cancel()
76 view_->centralWidget()->setFocus();
81 void QCommandBuffer::dispatch()
83 controller_.dispatch(edit_->text().latin1());
84 view_->centralWidget()->setFocus();
89 void QCommandBuffer::complete()
91 string const input = edit_->text().latin1();
93 vector<string> comp = controller_.completions(input, new_input);
95 if (comp.empty() && new_input == input) {
96 // show_info_suffix(_("[no match]"), input);
101 edit_->setText(new_input.c_str());
102 // show_info_suffix(("[only completion]"), new_input + " ");
106 edit_->setText(new_input.c_str());
108 QTempComboBox * combo = new QTempComboBox(view_);
109 combo->move(edit_->x() + x(), edit_->y() + y());
111 vector<string>::const_iterator cit = comp.begin();
112 vector<string>::const_iterator end = comp.end();
113 for (; cit != end; ++cit) {
114 combo->insertItem(cit->c_str());
117 combo->setMinimumWidth(combo->sizeHint().width());
118 combo->resize(combo->width(), edit_->height());
120 connect(combo, SIGNAL(activated(const QString &)),
121 this, SLOT(complete_selected(const QString &)));
129 void QCommandBuffer::complete_selected(const QString & str)
131 edit_->setText(str + " ");
133 QWidget const * widget = static_cast<QWidget const *>(sender());
135 const_cast<QWidget *>(widget)->hide();
139 void QCommandBuffer::up()
141 string const input = edit_->text().latin1();
142 string const h(controller_.historyUp());
145 // show_info_suffix(_("[Beginning of history]"), input);
147 edit_->setText(h.c_str());
152 void QCommandBuffer::down()
154 string const input = edit_->text().latin1();
155 string const h(controller_.historyDown());
158 // show_info_suffix(_("[End of history]"), input);
160 edit_->setText(h.c_str());
166 void XMiniBuffer::show_info_suffix(string const & suffix, string const & input)
168 stored_input_ = input;
169 info_suffix_shown_ = true;
170 set_input(input + " " + suffix);
171 suffix_timer_->start();
175 void XMiniBuffer::suffix_timeout()
177 info_suffix_shown_ = false;
178 set_input(stored_input_);