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"
31 extern bool keyseqUncomplete();
32 extern string keyseqOptions(int l= 190);
33 extern string keyseqStr(int l= 190);
34 extern LyXAction lyxaction;
36 void MiniBuffer::TimerCB(FL_OBJECT * ob, long)
38 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
42 extern "C" void C_MiniBuffer_TimerCB(FL_OBJECT * ob, long data)
44 MiniBuffer::TimerCB(ob, data);
47 void MiniBuffer::ExecutingCB(FL_OBJECT * ob, long)
49 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
50 lyxerr.debug() << "Getting ready to execute: " << obj->cur_cmd << endl;
51 obj->owner->view()->focus(true);
53 if (obj->cur_cmd.empty()) {
57 obj->Set(_("Executing:"), obj->cur_cmd);
58 obj->addHistory(obj->cur_cmd);
60 // Dispatch only returns requested data for a few commands (ale)
61 string res = obj->owner->getLyXFunc()->Dispatch(obj->cur_cmd);
62 lyxerr.debug() << "Minibuffer Res: " << res << endl;
63 obj->shows_no_match = false;
68 extern "C" void C_MiniBuffer_ExecutingCB(FL_OBJECT * ob, long data)
70 MiniBuffer::TimerCB(ob, data);
73 // This is not as dirty as it seems, the hidden buttons removed by this
74 // function were just kludges for an uncomplete keyboard callback (ale)
75 int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord,
76 int key, void */*xev*/)
78 MiniBuffer * mini = static_cast<MiniBuffer*>(ob->u_vdata);
80 if (event == FL_KEYBOARD){
84 if (!mini->getHistory().empty()) {
85 fl_set_input(ob, mini->getHistory().c_str());
90 if (mini->history_idx > 0) mini->history_idx--;
91 fl_set_input(ob, mini->getHistory().c_str());
96 // complete or increment the command
97 string s = lyxaction.getApproxFuncName(fl_get_input(ob));
99 fl_set_input(ob, s.c_str());
105 mini->owner->view()->focus(true);
110 // Execute a command.
111 mini->cur_cmd = string(fl_get_input(ob));
121 extern "C" int C_MiniBuffer_peek_event(FL_OBJECT * ob, int event,
125 return MiniBuffer::peek_event(ob, event, 0, 0, key, xev);
129 void MiniBuffer::ExecCommand()
132 fl_set_input(the_buffer, "");
133 fl_set_focus_object(owner->getForm(), the_buffer);
137 FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
138 FL_Coord w, FL_Coord h)
142 the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str());
143 fl_set_object_boxtype(obj, FL_DOWN_BOX);
144 fl_set_object_resize(obj, FL_RESIZE_ALL);
145 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
146 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
147 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
148 fl_set_object_callback(obj, C_MiniBuffer_ExecutingCB, 0);
150 // To intercept Up, Down, Table for history
151 fl_set_object_prehandler(obj, C_MiniBuffer_peek_event);
153 obj->wantkey = FL_KEY_TAB;
156 timer = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, "Timer");
157 fl_set_object_callback(timer, C_MiniBuffer_TimerCB, 0);
158 timer->u_vdata = this;
159 fl_set_input(the_buffer, text.c_str());
165 // Added optional arg `delay_secs', defaults to 4.
166 //When 0, no timeout is done. RVDK_PATCH_5
167 void MiniBuffer::Set(string const& s1, string const& s2,
168 string const& s3, int delay_secs)
170 setTimer(delay_secs);
172 string ntext = strip(s1 + ' ' + s2 + ' ' + s3);
174 if (!the_buffer->focus) {
175 fl_set_input(the_buffer, ntext.c_str());
182 void MiniBuffer::Init()
184 // If we have focus, we don't want to change anything.
185 if (the_buffer->focus)
188 // When meta-fake key is pressed, show the key sequence so far + "M-".
189 if (owner->getLyXFunc()->wasMetaKey()) {
190 text = owner->getLyXFunc()->keyseqStr();
194 // Else, when a non-complete key sequence is pressed,
195 // show the available options.
196 else if (owner->getLyXFunc()->keyseqUncomplete())
197 text = owner->getLyXFunc()->keyseqOptions();
199 // Else, show the buffer state.
200 else if (owner->view()->available()) {
202 MakeDisplayPath(owner->buffer()->
204 // Should we do this instead? (kindo like emacs)
205 // leaves more room for other information
208 if (owner->buffer()->lyxvc.inUse()) {
210 text += owner->buffer()->lyxvc.version();
212 text += owner->buffer()->lyxvc.locker();
213 if (owner->buffer()->isReadonly())
216 } else if (owner->buffer()->isReadonly())
218 if (!owner->buffer()->isLyxClean())
219 text += _(" (Changed)");
221 if (text != _("Welcome to LyX!")) // this is a hack
222 text = _("* No document open *");
226 fl_set_input(the_buffer, text.c_str());
232 // allows to store and reset the contents one time. Usefull for
233 // status messages like "load font" (Matthias)
234 void MiniBuffer::Store()
236 text_stored = fl_get_input(the_buffer);
240 void MiniBuffer::Reset()
242 if (!text_stored.empty()){
248 void MiniBuffer::Activate()
250 fl_activate_object(the_buffer);
251 fl_redraw_object(the_buffer);
254 void MiniBuffer::Deactivate()
256 fl_deactivate_object(the_buffer);