3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
22 #include "GMiniBuffer.h"
24 #include "bufferview_funcs.h"
26 #include "frontends/controllers/ControlCommandBuffer.h"
28 #include <boost/bind.hpp>
36 GMiniBuffer::GMiniBuffer(GView * view, ControlCommandBuffer & control) :
37 controller_(control), view_(view)
39 listCols_.add(listCol_);
40 listStore_ = Gtk::ListStore::create(listCols_);
41 listView_.set_model(listStore_);
42 listView_.append_column("Completions", listCol_);
43 listView_.signal_key_press_event().connect(
44 sigc::mem_fun(*this, &GMiniBuffer::onListKeyPress));
45 listView_.signal_focus_in_event().connect(
46 sigc::mem_fun(*this, &GMiniBuffer::onListFocusIn));
47 listView_.signal_focus_out_event().connect(
48 sigc::mem_fun(*this, &GMiniBuffer::onFocusOut));
49 listSel_ = listView_.get_selection();
50 listSel_->signal_changed().connect(
51 sigc::mem_fun(*this, &GMiniBuffer::onSelected));
54 scrolledWindow_.set_policy(Gtk::POLICY_AUTOMATIC,
55 Gtk::POLICY_AUTOMATIC);
56 scrolledWindow_.set_size_request(300, 150);
57 scrolledWindow_.add(listView_);
59 view_->getBox(GView::Bottom).children().push_back(
60 Gtk::Box_Helpers::Element(scrolledWindow_,Gtk::PACK_SHRINK));
62 entry_.signal_key_press_event().connect(
63 sigc::mem_fun(*this, &GMiniBuffer::onKeyPress));
64 entry_.signal_focus_in_event().connect(
65 sigc::mem_fun(*this, &GMiniBuffer::onFocusIn));
66 entry_.signal_focus_out_event().connect(
67 sigc::mem_fun(*this, &GMiniBuffer::onFocusOut));
68 entry_.signal_activate().connect(
69 sigc::mem_fun(*this, &GMiniBuffer::onCommit));
72 view_->getBox(GView::Bottom).children().push_back(
73 Gtk::Box_Helpers::Element(entry_, Gtk::PACK_SHRINK));
75 infoTimer_.reset(new Timeout(1500));
76 idleTimer_.reset(new Timeout(6000));
77 focusTimer_.reset(new Timeout(50));
78 infoCon_ = infoTimer_->timeout.connect(
79 boost::bind(&GMiniBuffer::infoTimeout, this));
80 idleCon_ = idleTimer_->timeout.connect(
81 boost::bind(&GMiniBuffer::idleTimeout, this));
82 focusTimer_->timeout.connect(
83 boost::bind(&GMiniBuffer::focusTimeout, this));
89 GMiniBuffer::~GMiniBuffer()
94 void GMiniBuffer::message(string const & str)
97 setInput(Glib::locale_to_utf8(str));
101 void GMiniBuffer::showInfo(Glib::ustring const & info, bool append)
103 storedInput_ = entry_.get_text();
104 entry_.set_editable(false);
107 setInput(storedInput_ + ' ' + info);
114 void GMiniBuffer::onSelected()
116 if (!listSel_->count_selected_rows())
118 Gtk::TreeModel::iterator it = listSel_->get_selected();
119 Glib::ustring sel = (*it)[listCol_];
124 void GMiniBuffer::onCommit()
126 controller_.dispatch(Glib::locale_from_utf8(entry_.get_text()));
131 bool GMiniBuffer::onListFocusIn(GdkEventFocus * /*event*/)
133 if (focusTimer_->running())
143 bool GMiniBuffer::onFocusIn(GdkEventFocus * /*event*/)
149 if (focusTimer_->running()) {
159 bool GMiniBuffer::onFocusOut(GdkEventFocus * /*event*/)
161 focusTimer_->start();
166 void GMiniBuffer::focusTimeout()
175 scrolledWindow_.hide();
179 bool GMiniBuffer::onListKeyPress(GdkEventKey * event)
185 switch (event->keyval) {
191 setInput(entry_.get_text() + ' ');
198 bool GMiniBuffer::onKeyPress(GdkEventKey * event)
204 switch (event->keyval) {
207 Glib::ustring const h =
208 Glib::locale_to_utf8(controller_.historyDown());
210 showInfo("[End of history]", false);
217 Glib::ustring const h =
218 Glib::locale_to_utf8(controller_.historyUp());
220 showInfo("[Beginning of history]", false);
230 string new_input_locale;
231 Glib::ustring input = entry_.get_text();
232 std::vector<string> comp =
233 controller_.completions(Glib::locale_from_utf8(input),
235 Glib::ustring new_input =
236 Glib::locale_to_utf8(new_input_locale);
238 if (comp.empty() && new_input == input) {
239 showInfo("[no match]");
244 setInput(new_input + ' ');
245 showInfo("[only completion]");
250 std::vector<string>::iterator it;
251 for (it = comp.begin(); it != comp.end(); ++it)
252 (*listStore_->append())[listCol_] =
253 Glib::locale_to_utf8(*it);
254 scrolledWindow_.show();
262 bool GMiniBuffer::isEditMode() const
264 return entry_.has_focus() || listView_.has_focus();
268 void GMiniBuffer::infoTimeout()
271 setInput(storedInput_);
272 entry_.set_editable(true);
276 void GMiniBuffer::idleTimeout()
278 setInput(Glib::locale_to_utf8(controller_.getCurrentState()));
282 void GMiniBuffer::editMode()
288 void GMiniBuffer::messageMode()
290 view_->focusWorkArea();
294 void GMiniBuffer::setInput(Glib::ustring const & input)
296 entry_.set_text(input);
297 entry_.set_position(-1);
300 } // namespace frontend