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 MiniBuffer::MiniBuffer(LyXView * o, FL_Coord x, FL_Coord y,
37 FL_Coord h, FL_Coord w)
40 text = _("Welcome to LyX!");
41 shows_no_match = true;
42 history_idx = history_cnt = 0;
43 add(FL_NORMAL_INPUT, x, y, h, w);
46 void MiniBuffer::TimerCB(FL_OBJECT * ob, long)
48 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
52 extern "C" void C_MiniBuffer_TimerCB(FL_OBJECT * ob, long data)
54 MiniBuffer::TimerCB(ob, data);
57 void MiniBuffer::ExecutingCB(FL_OBJECT * ob, long)
59 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
60 lyxerr.debug() << "Getting ready to execute: " << obj->cur_cmd << endl;
61 obj->owner->view()->focus(true);
63 if (obj->cur_cmd.empty()) {
67 obj->Set(_("Executing:"), obj->cur_cmd);
68 obj->addHistory(obj->cur_cmd);
70 // Dispatch only returns requested data for a few commands (ale)
71 string res = obj->owner->getLyXFunc()->Dispatch(obj->cur_cmd);
72 lyxerr.debug() << "Minibuffer Res: " << res << endl;
73 obj->shows_no_match = false;
78 extern "C" void C_MiniBuffer_ExecutingCB(FL_OBJECT * ob, long data)
80 MiniBuffer::TimerCB(ob, data);
83 // This is not as dirty as it seems, the hidden buttons removed by this
84 // function were just kludges for an uncomplete keyboard callback (ale)
85 int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord,
86 int key, void */*xev*/)
88 MiniBuffer * mini = static_cast<MiniBuffer*>(ob->u_vdata);
90 if (event == FL_KEYBOARD){
94 if (!mini->getHistory().empty()) {
95 fl_set_input(ob, mini->getHistory().c_str());
100 if (mini->history_idx > 0) mini->history_idx--;
101 fl_set_input(ob, mini->getHistory().c_str());
106 // complete or increment the command
107 string s = lyxaction.getApproxFuncName(fl_get_input(ob));
109 fl_set_input(ob, s.c_str());
115 mini->owner->view()->focus(true);
120 // Execute a command.
121 mini->cur_cmd = string(fl_get_input(ob));
131 extern "C" int C_MiniBuffer_peek_event(FL_OBJECT * ob, int event,
135 return MiniBuffer::peek_event(ob, event, 0, 0, key, xev);
139 void MiniBuffer::ExecCommand()
142 fl_set_input(the_buffer, "");
143 fl_set_focus_object(owner->getForm(), the_buffer);
147 FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
148 FL_Coord w, FL_Coord h)
152 the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str());
153 fl_set_object_boxtype(obj, FL_DOWN_BOX);
154 fl_set_object_resize(obj, FL_RESIZE_ALL);
155 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
156 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
157 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
158 fl_set_object_callback(obj, C_MiniBuffer_ExecutingCB, 0);
160 // To intercept Up, Down, Table for history
161 fl_set_object_prehandler(obj, C_MiniBuffer_peek_event);
163 obj->wantkey = FL_KEY_TAB;
166 timer = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, "Timer");
167 fl_set_object_callback(timer, C_MiniBuffer_TimerCB, 0);
168 timer->u_vdata = this;
169 fl_set_input(the_buffer, text.c_str());
175 // Added optional arg `delay_secs', defaults to 4.
176 //When 0, no timeout is done. RVDK_PATCH_5
177 void MiniBuffer::Set(string const& s1, string const& s2,
178 string const& s3, int delay_secs)
180 setTimer(delay_secs);
182 string ntext = strip(s1 + ' ' + s2 + ' ' + s3);
184 if (!the_buffer->focus) {
185 fl_set_input(the_buffer, ntext.c_str());
192 void MiniBuffer::Init()
194 // If we have focus, we don't want to change anything.
195 if (the_buffer->focus)
198 // When meta-fake key is pressed, show the key sequence so far + "M-".
199 if (owner->getLyXFunc()->wasMetaKey()) {
200 text = owner->getLyXFunc()->keyseqStr();
204 // Else, when a non-complete key sequence is pressed,
205 // show the available options.
206 else if (owner->getLyXFunc()->keyseqUncomplete())
207 text = owner->getLyXFunc()->keyseqOptions();
209 // Else, show the buffer state.
210 else if (owner->view()->available()) {
212 MakeDisplayPath(owner->buffer()->
214 // Should we do this instead? (kindo like emacs)
215 // leaves more room for other information
218 if (owner->buffer()->lyxvc.inUse()) {
220 text += owner->buffer()->lyxvc.version();
222 text += owner->buffer()->lyxvc.locker();
223 if (owner->buffer()->isReadonly())
226 } else if (owner->buffer()->isReadonly())
228 if (!owner->buffer()->isLyxClean())
229 text += _(" (Changed)");
231 if (text != _("Welcome to LyX!")) // this is a hack
232 text = _("* No document open *");
236 fl_set_input(the_buffer, text.c_str());
242 // allows to store and reset the contents one time. Usefull for
243 // status messages like "load font" (Matthias)
244 void MiniBuffer::Store()
246 text_stored = fl_get_input(the_buffer);
250 void MiniBuffer::Reset()
252 if (!text_stored.empty()){
258 void MiniBuffer::Activate()
260 fl_activate_object(the_buffer);
261 fl_redraw_object(the_buffer);
264 void MiniBuffer::Deactivate()
266 fl_deactivate_object(the_buffer);