1 /* ###########################################################################
4 * read minibuffer.h for more
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ###########################################################################
16 #pragma implementation "minibuffer.h"
19 #include "support/filetools.h"
22 #include FORMS_H_LOCATION
23 #include "minibuffer.h"
27 #include "LyXAction.h"
28 #include "BufferView.h"
33 extern bool keyseqUncomplete();
34 extern string keyseqOptions(int l = 190);
35 extern string keyseqStr(int l = 190);
36 extern LyXAction lyxaction;
38 MiniBuffer::MiniBuffer(LyXView * o, FL_Coord x, FL_Coord y,
39 FL_Coord h, FL_Coord w)
42 text = _("Welcome to LyX!");
43 shows_no_match = true;
44 history_idx = history_cnt = 0;
45 add(FL_NORMAL_INPUT, x, y, h, w);
46 timer.timeout.connect(slot(this, &MiniBuffer::Init));
50 void MiniBuffer::ExecutingCB(FL_OBJECT * ob, long)
52 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
53 lyxerr.debug() << "Getting ready to execute: " << obj->cur_cmd << endl;
54 obj->owner->view()->focus(true);
56 if (obj->cur_cmd.empty()) {
60 obj->Set(_("Executing:"), obj->cur_cmd);
61 obj->addHistory(obj->cur_cmd);
63 // Dispatch only returns requested data for a few commands (ale)
64 string res = obj->owner->getLyXFunc()->Dispatch(obj->cur_cmd);
65 lyxerr.debug() << "Minibuffer Res: " << res << endl;
66 obj->shows_no_match = false;
72 extern "C" void C_MiniBuffer_ExecutingCB(FL_OBJECT * ob, long)
74 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
79 // This is not as dirty as it seems, the hidden buttons removed by this
80 // function were just kludges for an uncomplete keyboard callback (ale)
81 int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord,
82 int key, void */*xev*/)
84 MiniBuffer * mini = static_cast<MiniBuffer*>(ob->u_vdata);
91 if (!mini->getHistory().empty()) {
92 fl_set_input(ob, mini->getHistory().c_str());
97 if (mini->history_idx > 0) mini->history_idx--;
98 fl_set_input(ob, mini->getHistory().c_str());
103 // complete or increment the command
104 string s(lyxaction.getApproxFuncName(fl_get_input(ob)));
106 fl_set_input(ob, s.c_str());
112 mini->owner->view()->focus(true);
117 // Execute a command.
118 mini->cur_cmd = string(fl_get_input(ob));
125 // This actually clears the buffer.
126 mini->PrepareForCommand();
129 //lyxerr << "Minibuffer event: DRAW" << endl;
132 //lyxerr << "Unhandled minibuffer event!" << endl;
141 extern "C" int C_MiniBuffer_peek_event(FL_OBJECT * ob, int event,
145 return MiniBuffer::peek_event(ob, event, 0, 0, key, xev);
149 void MiniBuffer::PrepareForCommand()
152 fl_set_input(the_buffer, "");
153 fl_set_focus_object(owner->getForm(), the_buffer);
157 FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
158 FL_Coord w, FL_Coord h)
162 the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str());
163 fl_set_object_boxtype(obj, FL_DOWN_BOX);
164 fl_set_object_resize(obj, FL_RESIZE_ALL);
165 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
166 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
167 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
168 fl_set_object_callback(obj, C_MiniBuffer_ExecutingCB, 0);
170 // To intercept Up, Down, Table for history
171 fl_set_object_prehandler(obj, C_MiniBuffer_peek_event);
173 obj->wantkey = FL_KEY_TAB;
175 fl_set_input(the_buffer, text.c_str());
181 // Added optional arg `delay_secs', defaults to 4.
182 //When 0, no timeout is done. RVDK_PATCH_5
183 void MiniBuffer::Set(string const& s1, string const& s2,
184 string const& s3, unsigned int delay_secs)
187 timer.setTimeout(delay_secs * 1000).restart();
191 string ntext = strip(s1 + ' ' + s2 + ' ' + s3);
193 if (!the_buffer->focus) {
194 fl_set_input(the_buffer, ntext.c_str());
195 XFlush(fl_get_display());
201 void MiniBuffer::Init()
203 // If we have focus, we don't want to change anything.
204 if (the_buffer->focus)
207 // When meta-fake key is pressed, show the key sequence so far + "M-".
208 if (owner->getLyXFunc()->wasMetaKey()) {
209 text = owner->getLyXFunc()->keyseqStr();
213 // Else, when a non-complete key sequence is pressed,
214 // show the available options.
215 else if (owner->getLyXFunc()->keyseqUncomplete())
216 text = owner->getLyXFunc()->keyseqOptions();
218 // Else, show the buffer state.
219 else if (owner->view()->available()) {
221 MakeDisplayPath(owner->buffer()->
223 // Should we do this instead? (kindo like emacs)
224 // leaves more room for other information
227 if (owner->buffer()->lyxvc.inUse()) {
229 text += owner->buffer()->lyxvc.version();
231 text += owner->buffer()->lyxvc.locker();
232 if (owner->buffer()->isReadonly())
235 } else if (owner->buffer()->isReadonly())
237 if (!owner->buffer()->isLyxClean())
238 text += _(" (Changed)");
240 if (text != _("Welcome to LyX!")) // this is a hack
241 text = _("* No document open *");
245 fl_set_input(the_buffer, text.c_str());
249 XFlush(fl_get_display());
253 // allows to store and reset the contents one time. Usefull for
254 // status messages like "load font" (Matthias)
255 void MiniBuffer::Store()
257 text_stored = fl_get_input(the_buffer);
261 void MiniBuffer::Reset()
263 if (!text_stored.empty()){
270 void MiniBuffer::Activate()
272 fl_activate_object(the_buffer);
273 fl_redraw_object(the_buffer);
277 void MiniBuffer::Deactivate()
279 fl_deactivate_object(the_buffer);