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>
27 class QTempComboBox : public QComboBox {
29 QTempComboBox(QWidget * parent) : QComboBox(parent) {
30 setWFlags(WDestructiveClose);
33 void popup() { QComboBox::popup(); }
38 QCommandBuffer::QCommandBuffer(QtView * view, ControlCommandBuffer & control)
39 : QToolBar(view), view_(view), controller_(control)
41 setHorizontalStretchable(true);
43 QPixmap qp(LibFileSearch("images", "unknown", "xpm").c_str());
45 QToolButton * upb = new QToolButton(qp, _("Up"), "", this, SLOT(up()), this);
48 QToolButton * downb = new QToolButton(qp, _("Down"), "", this, SLOT(down()), this);
51 edit_ = new QCommandEdit(this);
52 edit_->setMinimumSize(edit_->sizeHint());
54 setStretchableWidget(edit_);
58 connect(edit_, SIGNAL(escapePressed()), this, SLOT(cancel()));
59 connect(edit_, SIGNAL(returnPressed()), this, SLOT(dispatch()));
60 connect(edit_, SIGNAL(rightPressed()), this, SLOT(complete()));
61 connect(edit_, SIGNAL(upPressed()), this, SLOT(up()));
62 connect(edit_, SIGNAL(downPressed()), this, SLOT(down()));
67 void QCommandBuffer::focus_command()
73 void QCommandBuffer::cancel()
75 view_->centralWidget()->setFocus();
80 void QCommandBuffer::dispatch()
82 controller_.dispatch(edit_->text().latin1());
83 view_->centralWidget()->setFocus();
88 void QCommandBuffer::complete()
90 string const input = edit_->text().latin1();
92 vector<string> comp = controller_.completions(input, new_input);
94 if (comp.empty() && new_input == input) {
95 // show_info_suffix(_("[no match]"), input);
100 edit_->setText(new_input.c_str());
101 // show_info_suffix(("[only completion]"), new_input + " ");
105 edit_->setText(new_input.c_str());
107 QTempComboBox * combo = new QTempComboBox(view_);
108 combo->move(edit_->x() + x(), edit_->y() + y());
110 vector<string>::const_iterator cit = comp.begin();
111 vector<string>::const_iterator end = comp.end();
112 for (; cit != end; ++cit) {
113 combo->insertItem(cit->c_str());
116 combo->setMinimumWidth(combo->sizeHint().width());
117 combo->resize(combo->width(), edit_->height());
119 connect(combo, SIGNAL(activated(const QString &)),
120 this, SLOT(complete_selected(const QString &)));
128 void QCommandBuffer::complete_selected(const QString & str)
130 edit_->setText(str + " ");
132 QWidget const * widget = static_cast<QWidget const *>(sender());
134 const_cast<QWidget *>(widget)->hide();
138 void QCommandBuffer::up()
140 string const input = edit_->text().latin1();
141 string const h(controller_.historyUp());
144 // show_info_suffix(_("[Beginning of history]"), input);
146 edit_->setText(h.c_str());
151 void QCommandBuffer::down()
153 string const input = edit_->text().latin1();
154 string const h(controller_.historyDown());
157 // show_info_suffix(_("[End of history]"), input);
159 edit_->setText(h.c_str());
165 void XMiniBuffer::show_info_suffix(string const & suffix, string const & input)
167 stored_input_ = input;
168 info_suffix_shown_ = true;
169 set_input(input + " " + suffix);
170 suffix_timer_->start();
174 void XMiniBuffer::suffix_timeout()
176 info_suffix_shown_ = false;
177 set_input(stored_input_);