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 *, long tmp)
35 MiniBuffer *obj= (MiniBuffer*)tmp;
40 void MiniBuffer::ExecutingCB(FL_OBJECT *ob, long)
42 MiniBuffer *obj = (MiniBuffer*)ob->u_vdata;
43 lyxerr.debug() << "Getting ready to execute: " << obj->cur_cmd << endl;
44 fl_set_focus_object(obj->owner->getForm(),
45 obj->owner->currentView()->getWorkArea());
46 if (obj->cur_cmd.empty()) {
50 obj->Set(_("Executing:"), obj->cur_cmd);
51 obj->addHistory(obj->cur_cmd);
53 // Split command into function and argument
54 // This is done wrong Asger. Instead of <function argument>
55 // it ends up as <argument function> Queer solution:
56 string arg = obj->cur_cmd;
58 if (contains(arg, " ")) {
59 arg = split(arg, function, ' ');
60 function = strip(function);
65 lyxerr.debug() << "Function: " << function
66 << "\nArg : " << arg << endl;
67 // Check if the name is valid (ale)
68 // No, let the dispatch functions handle that.
69 //int action = lyxaction.LookupFunc(function.c_str());
70 //lyxerr.debug(string("minibuffer action: ") + action);
72 // Dispatch only returns requested data for a few commands (ale)
73 string res=obj->owner->getLyXFunc()->Dispatch(function.c_str(),
75 lyxerr.debug() << "Minibuffer Res: " << res << endl;
77 if(obj->owner->getLyXFunc()->errorStat())
78 obj->Set(_("Error:"), _(res.c_str()), string(), 4);
80 obj->Set(_("Result:"), _(res.c_str()), string(), 4);
86 #warning Look at this.
88 //obj->Set(_("Cannot find function"), function, "!");
89 obj->shows_no_match = false;
96 void MiniBuffer::ExecCommand()
99 fl_set_input(the_buffer, "");
100 fl_set_focus_object(owner->getForm(),the_buffer);
104 FL_OBJECT *MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
105 FL_Coord w, FL_Coord h)
109 the_buffer = obj = fl_add_input(type,x,y,w,h,text.c_str());
110 fl_set_object_boxtype(obj,FL_DOWN_BOX);
111 fl_set_object_resize(obj, FL_RESIZE_ALL);
112 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
113 fl_set_object_color(obj,FL_MCOL,FL_MCOL);
114 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
115 fl_set_object_callback(obj,ExecutingCB, 0);
117 // To intercept Up, Down, Table for history
118 fl_set_object_prehandler(obj, peek_event);
119 obj->u_vdata = (void*)this;
120 obj->wantkey = FL_KEY_TAB;
123 timer = fl_add_timer(FL_HIDDEN_TIMER, 0,0,0,0, "Timer");
124 fl_set_object_callback(timer, TimerCB, (long)this);
125 fl_set_input(the_buffer, text.c_str());
131 // Added optional arg `delay_secs', defaults to 4.
132 //When 0, no timeout is done. RVDK_PATCH_5
133 void MiniBuffer::Set(string const& s1, string const& s2,
134 string const& s3, int delay_secs)
136 setTimer(delay_secs);
138 string ntext = strip(s1 + ' ' + s2 + ' ' + s3);
140 if (!the_buffer->focus) {
141 fl_set_input(the_buffer, ntext.c_str());
148 void MiniBuffer::Init()
150 // If we have focus, we don't want to change anything.
151 if (the_buffer->focus)
154 // When meta-fake key is pressed, show the key sequence so far + "M-".
155 if (owner->getLyXFunc()->wasMetaKey()) {
156 text = owner->getLyXFunc()->keyseqStr();
160 // Else, when a non-complete key sequence is pressed,
161 // show the available options.
162 else if (owner->getLyXFunc()->keyseqUncomplete())
163 text = owner->getLyXFunc()->keyseqOptions();
165 // Else, show the buffer state.
166 else if (owner->currentView()->available()) {
168 MakeDisplayPath(owner->currentBuffer()->
170 // Should we do this instead? (kindo like emacs)
171 // leaves more room for other information
174 if (owner->currentBuffer()->lyxvc.inUse()) {
176 text += owner->currentBuffer()->lyxvc.getVersion();
178 text += owner->currentBuffer()->lyxvc.getLocker();
179 if (owner->currentBuffer()->isReadonly())
182 } else if (owner->currentBuffer()->isReadonly())
184 if (!owner->currentBuffer()->isLyxClean())
185 text += _(" (Changed)");
187 if (text != _("Welcome to LyX!")) // this is a hack
188 text = _("* No document open *");
192 fl_set_input(the_buffer, text.c_str());
198 // allows to store and reset the contents one time. Usefull for
199 // status messages like "load font" (Matthias)
200 void MiniBuffer::Store()
202 text_stored = fl_get_input(the_buffer);
206 void MiniBuffer::Reset()
208 if (!text_stored.empty()){
214 void MiniBuffer::Activate()
216 fl_activate_object(the_buffer);
217 fl_redraw_object(the_buffer);
220 void MiniBuffer::Deactivate()
222 fl_deactivate_object(the_buffer);
226 // This is not as dirty as it seems, the hidden buttons removed by this
227 // function were just kludges for an uncomplete keyboard callback (ale)
228 int MiniBuffer::peek_event(FL_OBJECT *ob, int event, FL_Coord, FL_Coord,
229 int key, void */*xev*/)
231 MiniBuffer *mini = (MiniBuffer*)ob->u_vdata;
233 if (event==FL_KEYBOARD){
237 if (!mini->getHistory().empty()) {
238 fl_set_input(ob, mini->getHistory().c_str());
243 if (mini->history_idx > 0) mini->history_idx--;
244 fl_set_input(ob, mini->getHistory().c_str());
249 // complete or increment the command
250 const char *s = lyxaction.getApproxFuncName(fl_get_input(ob));
258 fl_set_focus_object(mini->owner->getForm(),
259 mini->owner->currentView()->getWorkArea());
264 // Execute a command.
265 mini->cur_cmd = string(fl_get_input(ob));