]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QCommandBuffer.C
toolbar - remove dead code
[lyx.git] / src / frontends / qt2 / QCommandBuffer.C
1 /**
2  * \file QCommandBuffer.C
3  * Copyright 2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon <moz@compsoc.man.ac.uk>
7  */
8
9 #include <config.h>
10  
11 #include "support/filetools.h"
12 #include "controllers/ControlCommandBuffer.h"
13 #include "gettext.h"
14  
15 #include "QtView.h"
16 #include "QCommandBuffer.h"
17 #include "QCommandEdit.h"
18  
19 #include <qcombobox.h>
20 #include <qtoolbutton.h>
21 #include <qsize.h>
22 #include <qpixmap.h>
23  
24 namespace {
25  
26 class QTempComboBox : public QComboBox {
27 public:
28         QTempComboBox(QWidget * parent) : QComboBox(parent) {
29                 setWFlags(WDestructiveClose);
30         }
31
32         void popup() { QComboBox::popup(); }
33 };
34
35 };
36  
37 QCommandBuffer::QCommandBuffer(QtView * view, ControlCommandBuffer & control)
38         : QToolBar(view), view_(view), controller_(control)
39 {
40         setHorizontalStretchable(true);
41  
42         QPixmap qp(LibFileSearch("images", "unknown", "xpm").c_str());
43
44         QToolButton * upb = new QToolButton(qp, _("Up"), "", this, SLOT(up()), this);
45         upb->setMinimumSize(upb->sizeHint());
46         upb->show();
47  
48         QToolButton * downb = new QToolButton(qp, _("Down"), "", this, SLOT(down()), this);
49         downb->setMinimumSize(downb->sizeHint());
50         downb->show();
51  
52         edit_ = new QCommandEdit(this);
53         edit_->setMinimumSize(edit_->sizeHint());
54         edit_->show();
55         setStretchableWidget(edit_);
56  
57         setMinimumSize(sizeHint()); 
58         show();
59  
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()));
65 }
66
67
68
69 void QCommandBuffer::focus_command()
70 {
71         edit_->setFocus();
72 }
73
74  
75 void QCommandBuffer::cancel()
76 {
77         view_->centralWidget()->setFocus();
78         edit_->setText("");
79 }
80
81  
82 void QCommandBuffer::dispatch()
83 {
84         controller_.dispatch(edit_->text().latin1());
85         view_->centralWidget()->setFocus();
86         edit_->setText("");
87 }
88
89
90 void QCommandBuffer::complete()
91 {
92         string const input = edit_->text().latin1();
93         string new_input;
94         vector<string> comp = controller_.completions(input, new_input);
95                          
96         if (comp.empty() && new_input == input) {
97         //      show_info_suffix(_("[no match]"), input);
98                 return;
99         }
100
101         if (comp.empty()) {
102                 edit_->setText(new_input.c_str());
103         //      show_info_suffix(("[only completion]"), new_input + " ");
104                 return;
105         }
106                                  
107         edit_->setText(new_input.c_str());
108
109         QTempComboBox * combo = new QTempComboBox(view_);
110         combo->move(edit_->x() + x(), edit_->y() + y());
111
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());
116         }
117
118         combo->setMinimumWidth(combo->sizeHint().width());
119         combo->resize(combo->width(), edit_->height());
120  
121         connect(combo, SIGNAL(activated(const QString &)),
122                 this, SLOT(complete_selected(const QString &))); 
123  
124         combo->show();
125         combo->setFocus();
126         combo->popup();
127 }
128
129
130 void QCommandBuffer::complete_selected(const QString & str)
131 {
132         edit_->setText(str + " ");
133         // FIXME
134         QWidget const * widget = static_cast<QWidget const *>(sender());
135         edit_->setFocus();
136         const_cast<QWidget *>(widget)->hide();
137 }
138
139  
140 void QCommandBuffer::up()
141 {
142         string const input = edit_->text().latin1();
143         string const h(controller_.historyUp());
144  
145         if (h.empty()) {
146         //      show_info_suffix(_("[Beginning of history]"), input);
147         } else {
148                 edit_->setText(h.c_str());
149         }
150 }
151
152
153 void QCommandBuffer::down()
154 {
155         string const input = edit_->text().latin1();
156         string const h(controller_.historyDown());
157  
158         if (h.empty()) {
159         //      show_info_suffix(_("[End of history]"), input);
160         } else {
161                 edit_->setText(h.c_str());
162         }
163 }
164
165
166 #if 0 
167 void XMiniBuffer::show_info_suffix(string const & suffix, string const & input)
168 {
169         stored_input_ = input;
170         info_suffix_shown_ = true;
171         set_input(input + " " + suffix); 
172         suffix_timer_->start();
173 }
174  
175
176 void XMiniBuffer::suffix_timeout()
177 {
178         info_suffix_shown_ = false;
179         set_input(stored_input_);
180 }
181
182 #endif