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"
33 #ifdef SIGC_CXX_NAMESPACES
37 extern bool keyseqUncomplete();
38 extern string keyseqOptions(int l = 190);
39 extern string keyseqStr(int l = 190);
40 extern LyXAction lyxaction;
42 MiniBuffer::MiniBuffer(LyXView * o, FL_Coord x, FL_Coord y,
43 FL_Coord h, FL_Coord w)
46 text = _("Welcome to LyX!");
47 shows_no_match = true;
48 history_idx = history_cnt = 0;
49 add(FL_NORMAL_INPUT, x, y, h, w);
50 timer.timeout.connect(slot(this, &MiniBuffer::Init));
54 void MiniBuffer::ExecutingCB(FL_OBJECT * ob, long)
56 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
57 lyxerr.debug() << "Getting ready to execute: " << obj->cur_cmd << endl;
58 obj->owner->view()->focus(true);
60 if (obj->cur_cmd.empty()) {
64 obj->Set(_("Executing:"), obj->cur_cmd);
65 obj->addHistory(obj->cur_cmd);
67 // Dispatch only returns requested data for a few commands (ale)
68 string res = obj->owner->getLyXFunc()->Dispatch(obj->cur_cmd);
69 lyxerr.debug() << "Minibuffer Res: " << res << endl;
70 obj->shows_no_match = false;
76 extern "C" void C_MiniBuffer_ExecutingCB(FL_OBJECT * ob, long)
78 MiniBuffer * obj = static_cast<MiniBuffer*>(ob->u_vdata);
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);
95 if (!mini->getHistory().empty()) {
96 fl_set_input(ob, mini->getHistory().c_str());
101 if (mini->history_idx > 0) mini->history_idx--;
102 fl_set_input(ob, mini->getHistory().c_str());
107 // complete or increment the command
108 string s(lyxaction.getApproxFuncName(fl_get_input(ob)));
110 fl_set_input(ob, s.c_str());
116 mini->owner->view()->focus(true);
121 // Execute a command.
122 mini->cur_cmd = string(fl_get_input(ob));
129 // This actually clears the buffer.
130 mini->PrepareForCommand();
133 //lyxerr << "Minibuffer event: DRAW" << endl;
136 //lyxerr << "Unhandled minibuffer event!" << endl;
145 extern "C" int C_MiniBuffer_peek_event(FL_OBJECT * ob, int event,
149 return MiniBuffer::peek_event(ob, event, 0, 0, key, xev);
153 void MiniBuffer::PrepareForCommand()
156 fl_set_input(the_buffer, "");
157 fl_set_focus_object(owner->getForm(), the_buffer);
161 FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
162 FL_Coord w, FL_Coord h)
166 the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str());
167 fl_set_object_boxtype(obj, FL_DOWN_BOX);
168 fl_set_object_resize(obj, FL_RESIZE_ALL);
169 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
170 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
171 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
172 fl_set_object_callback(obj, C_MiniBuffer_ExecutingCB, 0);
174 // To intercept Up, Down, Table for history
175 fl_set_object_prehandler(obj, C_MiniBuffer_peek_event);
177 obj->wantkey = FL_KEY_TAB;
179 fl_set_input(the_buffer, text.c_str());
185 // Added optional arg `delay_secs', defaults to 4.
186 //When 0, no timeout is done. RVDK_PATCH_5
187 void MiniBuffer::Set(string const& s1, string const& s2,
188 string const& s3, unsigned int delay_secs)
191 timer.setTimeout(delay_secs * 1000).restart();
195 string ntext = strip(s1 + ' ' + s2 + ' ' + s3);
197 if (!the_buffer->focus) {
198 fl_set_input(the_buffer, ntext.c_str());
199 XFlush(fl_get_display());
205 void MiniBuffer::Init()
207 // If we have focus, we don't want to change anything.
208 if (the_buffer->focus)
211 // When meta-fake key is pressed, show the key sequence so far + "M-".
212 if (owner->getLyXFunc()->wasMetaKey()) {
213 text = owner->getLyXFunc()->keyseqStr();
217 // Else, when a non-complete key sequence is pressed,
218 // show the available options.
219 else if (owner->getLyXFunc()->keyseqUncomplete())
220 text = owner->getLyXFunc()->keyseqOptions();
222 // Else, show the buffer state.
223 else if (owner->view()->available()) {
225 MakeDisplayPath(owner->buffer()->
227 // Should we do this instead? (kindo like emacs)
228 // leaves more room for other information
231 if (owner->buffer()->lyxvc.inUse()) {
233 text += owner->buffer()->lyxvc.version();
235 text += owner->buffer()->lyxvc.locker();
236 if (owner->buffer()->isReadonly())
239 } else if (owner->buffer()->isReadonly())
241 if (!owner->buffer()->isLyxClean())
242 text += _(" (Changed)");
244 if (text != _("Welcome to LyX!")) // this is a hack
245 text = _("* No document open *");
249 fl_set_input(the_buffer, text.c_str());
253 XFlush(fl_get_display());
257 // allows to store and reset the contents one time. Usefull for
258 // status messages like "load font" (Matthias)
259 void MiniBuffer::Store()
261 text_stored = fl_get_input(the_buffer);
265 void MiniBuffer::Reset()
267 if (!text_stored.empty()){
274 void MiniBuffer::Activate()
276 fl_activate_object(the_buffer);
277 fl_redraw_object(the_buffer);
281 void MiniBuffer::Deactivate()
283 fl_deactivate_object(the_buffer);