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