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_);
56 connect(edit_, SIGNAL(escapePressed()), this, SLOT(cancel()));
57 connect(edit_, SIGNAL(returnPressed()), this, SLOT(dispatch()));
58 connect(edit_, SIGNAL(rightPressed()), this, SLOT(complete()));
59 connect(edit_, SIGNAL(upPressed()), this, SLOT(up()));
60 connect(edit_, SIGNAL(downPressed()), this, SLOT(down()));
65 void QCommandBuffer::focus_command()
71 void QCommandBuffer::cancel()
73 view_->centralWidget()->setFocus();
78 void QCommandBuffer::dispatch()
80 controller_.dispatch(edit_->text().latin1());
81 view_->centralWidget()->setFocus();
86 void QCommandBuffer::complete()
88 string const input = edit_->text().latin1();
90 vector<string> comp = controller_.completions(input, new_input);
92 if (comp.empty() && new_input == input) {
93 // show_info_suffix(_("[no match]"), input);
98 edit_->setText(new_input.c_str());
99 // show_info_suffix(("[only completion]"), new_input + " ");
103 edit_->setText(new_input.c_str());
105 QTempComboBox * combo = new QTempComboBox(view_);
106 combo->move(edit_->x() + x(), edit_->y() + y());
108 vector<string>::const_iterator cit = comp.begin();
109 vector<string>::const_iterator end = comp.end();
110 for (; cit != end; ++cit) {
111 combo->insertItem(cit->c_str());
114 combo->setMinimumWidth(combo->sizeHint().width());
115 combo->resize(combo->width(), edit_->height());
117 connect(combo, SIGNAL(activated(const QString &)),
118 this, SLOT(complete_selected(const QString &)));
126 void QCommandBuffer::complete_selected(const QString & str)
128 edit_->setText(str + " ");
130 QWidget const * widget = static_cast<QWidget const *>(sender());
132 const_cast<QWidget *>(widget)->hide();
136 void QCommandBuffer::up()
138 string const input = edit_->text().latin1();
139 string const h(controller_.historyUp());
142 // show_info_suffix(_("[Beginning of history]"), input);
144 edit_->setText(h.c_str());
149 void QCommandBuffer::down()
151 string const input = edit_->text().latin1();
152 string const h(controller_.historyDown());
155 // show_info_suffix(_("[End of history]"), input);
157 edit_->setText(h.c_str());
163 void XMiniBuffer::show_info_suffix(string const & suffix, string const & input)
165 stored_input_ = input;
166 info_suffix_shown_ = true;
167 set_input(input + " " + suffix);
168 suffix_timer_->start();
172 void XMiniBuffer::suffix_timeout()
174 info_suffix_shown_ = false;
175 set_input(stored_input_);