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"
34 extern bool keyseqUncomplete();
35 extern string keyseqOptions(int l = 190);
36 extern string keyseqStr(int l = 190);
37 extern LyXAction lyxaction;
39 MiniBuffer::MiniBuffer(LyXView * o, FL_Coord x, FL_Coord y,
40 FL_Coord h, FL_Coord w)
43 text = _("Welcome to LyX!");
44 shows_no_match = true;
45 history_idx = history_cnt = 0;
46 add(FL_NORMAL_INPUT, x, y, h, w);
47 timer.timeout.connect(slot(this, &MiniBuffer::Init));
51 void MiniBuffer::ExecutingCB(FL_OBJECT * ob, long)
53 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
54 lyxerr.debug() << "Getting ready to execute: " << obj->cur_cmd << endl;
55 obj->owner->view()->focus(true);
57 if (obj->cur_cmd.empty()) {
61 obj->Set(_("Executing:"), obj->cur_cmd);
62 obj->addHistory(obj->cur_cmd);
64 // Dispatch only returns requested data for a few commands (ale)
65 string res = obj->owner->getLyXFunc()->Dispatch(obj->cur_cmd);
66 lyxerr.debug() << "Minibuffer Res: " << res << endl;
67 obj->shows_no_match = false;
73 extern "C" void C_MiniBuffer_ExecutingCB(FL_OBJECT * ob, long)
75 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
80 // This is not as dirty as it seems, the hidden buttons removed by this
81 // function were just kludges for an uncomplete keyboard callback (ale)
82 int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord,
83 int key, void */*xev*/)
85 MiniBuffer * mini = static_cast<MiniBuffer*>(ob->u_vdata);
92 if (!mini->getHistory().empty()) {
93 fl_set_input(ob, mini->getHistory().c_str());
98 if (mini->history_idx > 0) mini->history_idx--;
99 fl_set_input(ob, mini->getHistory().c_str());
104 // complete or increment the command
105 string s(lyxaction.getApproxFuncName(fl_get_input(ob)));
107 fl_set_input(ob, s.c_str());
113 mini->owner->view()->focus(true);
118 // Execute a command.
119 mini->cur_cmd = string(fl_get_input(ob));
126 // This actually clears the buffer.
127 mini->PrepareForCommand();
130 //lyxerr << "Minibuffer event: DRAW" << endl;
133 //lyxerr << "Unhandled minibuffer event!" << endl;
142 extern "C" int C_MiniBuffer_peek_event(FL_OBJECT * ob, int event,
146 return MiniBuffer::peek_event(ob, event, 0, 0, key, xev);
150 void MiniBuffer::PrepareForCommand()
153 fl_set_input(the_buffer, "");
154 fl_set_focus_object(owner->getForm(), the_buffer);
158 FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
159 FL_Coord w, FL_Coord h)
163 the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str());
164 fl_set_object_boxtype(obj, FL_DOWN_BOX);
165 fl_set_object_resize(obj, FL_RESIZE_ALL);
166 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
167 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
168 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
169 fl_set_object_callback(obj, C_MiniBuffer_ExecutingCB, 0);
171 // To intercept Up, Down, Table for history
172 fl_set_object_prehandler(obj, C_MiniBuffer_peek_event);
174 obj->wantkey = FL_KEY_TAB;
176 fl_set_input(the_buffer, text.c_str());
182 // Added optional arg `delay_secs', defaults to 4.
183 //When 0, no timeout is done. RVDK_PATCH_5
184 void MiniBuffer::Set(string const& s1, string const& s2,
185 string const& s3, unsigned int delay_secs)
188 timer.setTimeout(delay_secs * 1000).restart();
192 string ntext = strip(s1 + ' ' + s2 + ' ' + s3);
194 if (!the_buffer->focus) {
195 fl_set_input(the_buffer, ntext.c_str());
196 XFlush(fl_get_display());
202 void MiniBuffer::Init()
204 // If we have focus, we don't want to change anything.
205 if (the_buffer->focus)
208 // When meta-fake key is pressed, show the key sequence so far + "M-".
209 if (owner->getLyXFunc()->wasMetaKey()) {
210 text = owner->getLyXFunc()->keyseqStr();
214 // Else, when a non-complete key sequence is pressed,
215 // show the available options.
216 else if (owner->getLyXFunc()->keyseqUncomplete())
217 text = owner->getLyXFunc()->keyseqOptions();
219 // Else, show the buffer state.
220 else if (owner->view()->available()) {
222 MakeDisplayPath(owner->buffer()->
224 // Should we do this instead? (kindo like emacs)
225 // leaves more room for other information
228 if (owner->buffer()->lyxvc.inUse()) {
230 text += owner->buffer()->lyxvc.version();
232 text += owner->buffer()->lyxvc.locker();
233 if (owner->buffer()->isReadonly())
236 } else if (owner->buffer()->isReadonly())
238 if (!owner->buffer()->isLyxClean())
239 text += _(" (Changed)");
241 if (text != _("Welcome to LyX!")) // this is a hack
242 text = _("* No document open *");
246 fl_set_input(the_buffer, text.c_str());
250 XFlush(fl_get_display());
254 // allows to store and reset the contents one time. Usefull for
255 // status messages like "load font" (Matthias)
256 void MiniBuffer::Store()
258 text_stored = fl_get_input(the_buffer);
262 void MiniBuffer::Reset()
264 if (!text_stored.empty()){
271 void MiniBuffer::Activate()
273 fl_activate_object(the_buffer);
274 fl_redraw_object(the_buffer);
278 void MiniBuffer::Deactivate()
280 fl_deactivate_object(the_buffer);