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>
26 class QTempComboBox : public QComboBox {
28 QTempComboBox(QWidget * parent) : QComboBox(parent) {
29 setWFlags(WDestructiveClose);
32 void popup() { QComboBox::popup(); }
37 QCommandBuffer::QCommandBuffer(QtView * view, ControlCommandBuffer & control)
38 : QToolBar(view), view_(view), controller_(control)
40 setHorizontalStretchable(true);
42 QPixmap qp(LibFileSearch("images", "unknown", "xpm").c_str());
44 QToolButton * upb = new QToolButton(qp, _("Up"), "", this, SLOT(up()), this);
45 upb->setMinimumSize(upb->sizeHint());
48 QToolButton * downb = new QToolButton(qp, _("Down"), "", this, SLOT(down()), this);
49 downb->setMinimumSize(downb->sizeHint());
52 edit_ = new QCommandEdit(this);
53 edit_->setMinimumSize(edit_->sizeHint());
55 setStretchableWidget(edit_);
57 setMinimumSize(sizeHint());
60 connect(edit_, SIGNAL(escapePressed()), this, SLOT(cancel()));
61 connect(edit_, SIGNAL(returnPressed()), this, SLOT(dispatch()));
62 connect(edit_, SIGNAL(rightPressed()), this, SLOT(complete()));
63 connect(edit_, SIGNAL(upPressed()), this, SLOT(up()));
64 connect(edit_, SIGNAL(downPressed()), this, SLOT(down()));
69 void QCommandBuffer::focus_command()
75 void QCommandBuffer::cancel()
77 view_->centralWidget()->setFocus();
82 void QCommandBuffer::dispatch()
84 controller_.dispatch(edit_->text().latin1());
85 view_->centralWidget()->setFocus();
90 void QCommandBuffer::complete()
92 string const input = edit_->text().latin1();
94 vector<string> comp = controller_.completions(input, new_input);
96 if (comp.empty() && new_input == input) {
97 // show_info_suffix(_("[no match]"), input);
102 edit_->setText(new_input.c_str());
103 // show_info_suffix(("[only completion]"), new_input + " ");
107 edit_->setText(new_input.c_str());
109 QTempComboBox * combo = new QTempComboBox(view_);
110 combo->move(edit_->x() + x(), edit_->y() + y());
112 vector<string>::const_iterator cit = comp.begin();
113 vector<string>::const_iterator end = comp.end();
114 for (; cit != end; ++cit) {
115 combo->insertItem(cit->c_str());
118 combo->setMinimumWidth(combo->sizeHint().width());
119 combo->resize(combo->width(), edit_->height());
121 connect(combo, SIGNAL(activated(const QString &)),
122 this, SLOT(complete_selected(const QString &)));
130 void QCommandBuffer::complete_selected(const QString & str)
132 edit_->setText(str + " ");
134 QWidget const * widget = static_cast<QWidget const *>(sender());
136 const_cast<QWidget *>(widget)->hide();
140 void QCommandBuffer::up()
142 string const input = edit_->text().latin1();
143 string const h(controller_.historyUp());
146 // show_info_suffix(_("[Beginning of history]"), input);
148 edit_->setText(h.c_str());
153 void QCommandBuffer::down()
155 string const input = edit_->text().latin1();
156 string const h(controller_.historyDown());
159 // show_info_suffix(_("[End of history]"), input);
161 edit_->setText(h.c_str());
167 void XMiniBuffer::show_info_suffix(string const & suffix, string const & input)
169 stored_input_ = input;
170 info_suffix_shown_ = true;
171 set_input(input + " " + suffix);
172 suffix_timer_->start();
176 void XMiniBuffer::suffix_timeout()
178 info_suffix_shown_ = false;
179 set_input(stored_input_);