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"
27 #include "LyXAction.h"
29 extern bool keyseqUncomplete();
30 extern string keyseqOptions(int l= 190);
31 extern string keyseqStr(int l= 190);
32 extern LyXAction lyxaction;
34 void MiniBuffer::TimerCB(FL_OBJECT * ob, long)
36 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
40 extern "C" void C_MiniBuffer_TimerCB(FL_OBJECT * ob, long data)
42 MiniBuffer::TimerCB(ob, data);
45 void MiniBuffer::ExecutingCB(FL_OBJECT * ob, long)
47 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
48 lyxerr.debug() << "Getting ready to execute: " << obj->cur_cmd << endl;
50 obj->owner->view()->focus(true);
52 fl_set_focus_object(obj->owner->getForm(),
53 obj->owner->view()->getWorkArea());
55 if (obj->cur_cmd.empty()) {
59 obj->Set(_("Executing:"), obj->cur_cmd);
60 obj->addHistory(obj->cur_cmd);
62 // Dispatch only returns requested data for a few commands (ale)
63 string res = obj->owner->getLyXFunc()->Dispatch(obj->cur_cmd);
64 lyxerr.debug() << "Minibuffer Res: " << res << endl;
65 obj->shows_no_match = false;
70 extern "C" void C_MiniBuffer_ExecutingCB(FL_OBJECT * ob, long data)
72 MiniBuffer::TimerCB(ob, data);
75 // This is not as dirty as it seems, the hidden buttons removed by this
76 // function were just kludges for an uncomplete keyboard callback (ale)
77 int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord,
78 int key, void */*xev*/)
80 MiniBuffer * mini = static_cast<MiniBuffer*>(ob->u_vdata);
82 if (event == FL_KEYBOARD){
86 if (!mini->getHistory().empty()) {
87 fl_set_input(ob, mini->getHistory().c_str());
92 if (mini->history_idx > 0) mini->history_idx--;
93 fl_set_input(ob, mini->getHistory().c_str());
98 // complete or increment the command
99 string s = lyxaction.getApproxFuncName(fl_get_input(ob));
101 fl_set_input(ob, s.c_str());
108 mini->owner->view()->focus(true);
110 fl_set_focus_object(mini->owner->getForm(),
111 mini->owner->view()->getWorkArea());
117 // Execute a command.
118 mini->cur_cmd = string(fl_get_input(ob));
128 extern "C" int C_MiniBuffer_peek_event(FL_OBJECT * ob, int event,
132 return MiniBuffer::peek_event(ob, event, 0, 0, key, xev);
136 void MiniBuffer::ExecCommand()
139 fl_set_input(the_buffer, "");
140 fl_set_focus_object(owner->getForm(), the_buffer);
144 FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
145 FL_Coord w, FL_Coord h)
149 the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str());
150 fl_set_object_boxtype(obj, FL_DOWN_BOX);
151 fl_set_object_resize(obj, FL_RESIZE_ALL);
152 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
153 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
154 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
155 fl_set_object_callback(obj, C_MiniBuffer_ExecutingCB, 0);
157 // To intercept Up, Down, Table for history
158 fl_set_object_prehandler(obj, C_MiniBuffer_peek_event);
160 obj->wantkey = FL_KEY_TAB;
163 timer = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, "Timer");
164 fl_set_object_callback(timer, C_MiniBuffer_TimerCB, 0);
165 timer->u_vdata = this;
166 fl_set_input(the_buffer, text.c_str());
172 // Added optional arg `delay_secs', defaults to 4.
173 //When 0, no timeout is done. RVDK_PATCH_5
174 void MiniBuffer::Set(string const& s1, string const& s2,
175 string const& s3, int delay_secs)
177 setTimer(delay_secs);
179 string ntext = strip(s1 + ' ' + s2 + ' ' + s3);
181 if (!the_buffer->focus) {
182 fl_set_input(the_buffer, ntext.c_str());
189 void MiniBuffer::Init()
191 // If we have focus, we don't want to change anything.
192 if (the_buffer->focus)
195 // When meta-fake key is pressed, show the key sequence so far + "M-".
196 if (owner->getLyXFunc()->wasMetaKey()) {
197 text = owner->getLyXFunc()->keyseqStr();
201 // Else, when a non-complete key sequence is pressed,
202 // show the available options.
203 else if (owner->getLyXFunc()->keyseqUncomplete())
204 text = owner->getLyXFunc()->keyseqOptions();
206 // Else, show the buffer state.
207 else if (owner->view()->available()) {
209 MakeDisplayPath(owner->buffer()->
211 // Should we do this instead? (kindo like emacs)
212 // leaves more room for other information
215 if (owner->buffer()->lyxvc.inUse()) {
217 text += owner->buffer()->lyxvc.version();
219 text += owner->buffer()->lyxvc.locker();
220 if (owner->buffer()->isReadonly())
223 } else if (owner->buffer()->isReadonly())
225 if (!owner->buffer()->isLyxClean())
226 text += _(" (Changed)");
228 if (text != _("Welcome to LyX!")) // this is a hack
229 text = _("* No document open *");
233 fl_set_input(the_buffer, text.c_str());
239 // allows to store and reset the contents one time. Usefull for
240 // status messages like "load font" (Matthias)
241 void MiniBuffer::Store()
243 text_stored = fl_get_input(the_buffer);
247 void MiniBuffer::Reset()
249 if (!text_stored.empty()){
255 void MiniBuffer::Activate()
257 fl_activate_object(the_buffer);
258 fl_redraw_object(the_buffer);
261 void MiniBuffer::Deactivate()
263 fl_deactivate_object(the_buffer);