1 /* ###########################################################################
4 * read minibuffer.h for more
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-1999 The LyX Team.
10 * ###########################################################################
16 #pragma implementation "minibuffer.h"
19 #include "support/filetools.h"
22 #include FORMS_H_LOCATION
23 #include "minibuffer.h"
28 extern bool keyseqUncomplete();
29 extern string keyseqOptions(int l= 190);
30 extern string keyseqStr(int l= 190);
31 extern LyXAction lyxaction;
33 void MiniBuffer::TimerCB(FL_OBJECT * ob, long)
35 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
39 extern "C" void C_MiniBuffer_TimerCB(FL_OBJECT * ob, long data)
41 MiniBuffer::TimerCB(ob, data);
44 void MiniBuffer::ExecutingCB(FL_OBJECT * ob, long)
46 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
47 lyxerr.debug() << "Getting ready to execute: " << obj->cur_cmd << endl;
48 fl_set_focus_object(obj->owner->getForm(),
49 obj->owner->currentView()->getWorkArea());
50 if (obj->cur_cmd.empty()) {
54 obj->Set(_("Executing:"), obj->cur_cmd);
55 obj->addHistory(obj->cur_cmd);
57 // Dispatch only returns requested data for a few commands (ale)
58 string res = obj->owner->getLyXFunc()->Dispatch(obj->cur_cmd);
59 lyxerr.debug() << "Minibuffer Res: " << res << endl;
60 obj->shows_no_match = false;
65 extern "C" void C_MiniBuffer_ExecutingCB(FL_OBJECT * ob, long data)
67 MiniBuffer::TimerCB(ob, data);
70 // This is not as dirty as it seems, the hidden buttons removed by this
71 // function were just kludges for an uncomplete keyboard callback (ale)
72 int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord,
73 int key, void */*xev*/)
75 MiniBuffer * mini = static_cast<MiniBuffer*>(ob->u_vdata);
77 if (event == FL_KEYBOARD){
81 if (!mini->getHistory().empty()) {
82 fl_set_input(ob, mini->getHistory().c_str());
87 if (mini->history_idx > 0) mini->history_idx--;
88 fl_set_input(ob, mini->getHistory().c_str());
93 // complete or increment the command
94 char const * s = lyxaction.getApproxFuncName(fl_get_input(ob));
102 fl_set_focus_object(mini->owner->getForm(),
103 mini->owner->currentView()->getWorkArea());
108 // Execute a command.
109 mini->cur_cmd = string(fl_get_input(ob));
119 extern "C" int C_MiniBuffer_peek_event(FL_OBJECT * ob, int event,
123 return MiniBuffer::peek_event(ob, event, 0, 0, key, xev);
127 void MiniBuffer::ExecCommand()
130 fl_set_input(the_buffer, "");
131 fl_set_focus_object(owner->getForm(), the_buffer);
135 FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
136 FL_Coord w, FL_Coord h)
140 the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str());
141 fl_set_object_boxtype(obj, FL_DOWN_BOX);
142 fl_set_object_resize(obj, FL_RESIZE_ALL);
143 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
144 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
145 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
146 fl_set_object_callback(obj, C_MiniBuffer_ExecutingCB, 0);
148 // To intercept Up, Down, Table for history
149 fl_set_object_prehandler(obj, C_MiniBuffer_peek_event);
151 obj->wantkey = FL_KEY_TAB;
154 timer = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, "Timer");
155 fl_set_object_callback(timer, C_MiniBuffer_TimerCB, 0);
156 timer->u_vdata = this;
157 fl_set_input(the_buffer, text.c_str());
163 // Added optional arg `delay_secs', defaults to 4.
164 //When 0, no timeout is done. RVDK_PATCH_5
165 void MiniBuffer::Set(string const& s1, string const& s2,
166 string const& s3, int delay_secs)
168 setTimer(delay_secs);
170 string ntext = strip(s1 + ' ' + s2 + ' ' + s3);
172 if (!the_buffer->focus) {
173 fl_set_input(the_buffer, ntext.c_str());
180 void MiniBuffer::Init()
182 // If we have focus, we don't want to change anything.
183 if (the_buffer->focus)
186 // When meta-fake key is pressed, show the key sequence so far + "M-".
187 if (owner->getLyXFunc()->wasMetaKey()) {
188 text = owner->getLyXFunc()->keyseqStr();
192 // Else, when a non-complete key sequence is pressed,
193 // show the available options.
194 else if (owner->getLyXFunc()->keyseqUncomplete())
195 text = owner->getLyXFunc()->keyseqOptions();
197 // Else, show the buffer state.
198 else if (owner->currentView()->available()) {
200 MakeDisplayPath(owner->buffer()->
202 // Should we do this instead? (kindo like emacs)
203 // leaves more room for other information
206 if (owner->buffer()->lyxvc.inUse()) {
208 text += owner->buffer()->lyxvc.version();
210 text += owner->buffer()->lyxvc.locker();
211 if (owner->buffer()->isReadonly())
214 } else if (owner->buffer()->isReadonly())
216 if (!owner->buffer()->isLyxClean())
217 text += _(" (Changed)");
219 if (text != _("Welcome to LyX!")) // this is a hack
220 text = _("* No document open *");
224 fl_set_input(the_buffer, text.c_str());
230 // allows to store and reset the contents one time. Usefull for
231 // status messages like "load font" (Matthias)
232 void MiniBuffer::Store()
234 text_stored = fl_get_input(the_buffer);
238 void MiniBuffer::Reset()
240 if (!text_stored.empty()){
246 void MiniBuffer::Activate()
248 fl_activate_object(the_buffer);
249 fl_redraw_object(the_buffer);
252 void MiniBuffer::Deactivate()
254 fl_deactivate_object(the_buffer);