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);
46 QToolButton * downb = new QToolButton(qp, _("Down"), "", this, SLOT(down()), this);
49 edit_ = new QCommandEdit(this);
50 edit_->setMinimumSize(edit_->sizeHint());
52 setStretchableWidget(edit_);
54 setMinimumSize(sizeHint());
57 connect(edit_, SIGNAL(escapePressed()), this, SLOT(cancel()));
58 connect(edit_, SIGNAL(returnPressed()), this, SLOT(dispatch()));
59 connect(edit_, SIGNAL(rightPressed()), this, SLOT(complete()));
60 connect(edit_, SIGNAL(upPressed()), this, SLOT(up()));
61 connect(edit_, SIGNAL(downPressed()), this, SLOT(down()));
66 void QCommandBuffer::focus_command()
72 void QCommandBuffer::cancel()
74 view_->centralWidget()->setFocus();
79 void QCommandBuffer::dispatch()
81 controller_.dispatch(edit_->text().latin1());
82 view_->centralWidget()->setFocus();
87 void QCommandBuffer::complete()
89 string const input = edit_->text().latin1();
91 vector<string> comp = controller_.completions(input, new_input);
93 if (comp.empty() && new_input == input) {
94 // show_info_suffix(_("[no match]"), input);
99 edit_->setText(new_input.c_str());
100 // show_info_suffix(("[only completion]"), new_input + " ");
104 edit_->setText(new_input.c_str());
106 QTempComboBox * combo = new QTempComboBox(view_);
107 combo->move(edit_->x() + x(), edit_->y() + y());
109 vector<string>::const_iterator cit = comp.begin();
110 vector<string>::const_iterator end = comp.end();
111 for (; cit != end; ++cit) {
112 combo->insertItem(cit->c_str());
115 combo->setMinimumWidth(combo->sizeHint().width());
116 combo->resize(combo->width(), edit_->height());
118 connect(combo, SIGNAL(activated(const QString &)),
119 this, SLOT(complete_selected(const QString &)));
127 void QCommandBuffer::complete_selected(const QString & str)
129 edit_->setText(str + " ");
131 QWidget const * widget = static_cast<QWidget const *>(sender());
133 const_cast<QWidget *>(widget)->hide();
137 void QCommandBuffer::up()
139 string const input = edit_->text().latin1();
140 string const h(controller_.historyUp());
143 // show_info_suffix(_("[Beginning of history]"), input);
145 edit_->setText(h.c_str());
150 void QCommandBuffer::down()
152 string const input = edit_->text().latin1();
153 string const h(controller_.historyDown());
156 // show_info_suffix(_("[End of history]"), input);
158 edit_->setText(h.c_str());
164 void XMiniBuffer::show_info_suffix(string const & suffix, string const & input)
166 stored_input_ = input;
167 info_suffix_shown_ = true;
168 set_input(input + " " + suffix);
169 suffix_timer_->start();
173 void XMiniBuffer::suffix_timeout()
175 info_suffix_shown_ = false;
176 set_input(stored_input_);