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 string arg = obj->cur_cmd;
56 if (contains(arg, " ")) {
57 arg = split(arg, function, ' ');
58 function = strip(function);
63 lyxerr.debug() << "Function: " << function
64 << "\nArg : " << arg << endl;
66 // Dispatch only returns requested data for a few commands (ale)
67 string res=obj->owner->getLyXFunc()->Dispatch(function.c_str(),
69 lyxerr.debug() << "Minibuffer Res: " << res << endl;
70 obj->shows_no_match = false;
76 void MiniBuffer::ExecCommand()
79 fl_set_input(the_buffer, "");
80 fl_set_focus_object(owner->getForm(),the_buffer);
84 FL_OBJECT *MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
85 FL_Coord w, FL_Coord h)
89 the_buffer = obj = fl_add_input(type,x,y,w,h,text.c_str());
90 fl_set_object_boxtype(obj,FL_DOWN_BOX);
91 fl_set_object_resize(obj, FL_RESIZE_ALL);
92 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
93 fl_set_object_color(obj,FL_MCOL,FL_MCOL);
94 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
95 fl_set_object_callback(obj,ExecutingCB, 0);
97 // To intercept Up, Down, Table for history
98 fl_set_object_prehandler(obj, peek_event);
99 obj->u_vdata = (void*)this;
100 obj->wantkey = FL_KEY_TAB;
103 timer = fl_add_timer(FL_HIDDEN_TIMER, 0,0,0,0, "Timer");
104 fl_set_object_callback(timer, TimerCB, (long)this);
105 fl_set_input(the_buffer, text.c_str());
111 // Added optional arg `delay_secs', defaults to 4.
112 //When 0, no timeout is done. RVDK_PATCH_5
113 void MiniBuffer::Set(string const& s1, string const& s2,
114 string const& s3, int delay_secs)
116 setTimer(delay_secs);
118 string ntext = strip(s1 + ' ' + s2 + ' ' + s3);
120 if (!the_buffer->focus) {
121 fl_set_input(the_buffer, ntext.c_str());
128 void MiniBuffer::Init()
130 // If we have focus, we don't want to change anything.
131 if (the_buffer->focus)
134 // When meta-fake key is pressed, show the key sequence so far + "M-".
135 if (owner->getLyXFunc()->wasMetaKey()) {
136 text = owner->getLyXFunc()->keyseqStr();
140 // Else, when a non-complete key sequence is pressed,
141 // show the available options.
142 else if (owner->getLyXFunc()->keyseqUncomplete())
143 text = owner->getLyXFunc()->keyseqOptions();
145 // Else, show the buffer state.
146 else if (owner->currentView()->available()) {
148 MakeDisplayPath(owner->currentBuffer()->
150 // Should we do this instead? (kindo like emacs)
151 // leaves more room for other information
154 if (owner->currentBuffer()->lyxvc.inUse()) {
156 text += owner->currentBuffer()->lyxvc.getVersion();
158 text += owner->currentBuffer()->lyxvc.getLocker();
159 if (owner->currentBuffer()->isReadonly())
162 } else if (owner->currentBuffer()->isReadonly())
164 if (!owner->currentBuffer()->isLyxClean())
165 text += _(" (Changed)");
167 if (text != _("Welcome to LyX!")) // this is a hack
168 text = _("* No document open *");
172 fl_set_input(the_buffer, text.c_str());
178 // allows to store and reset the contents one time. Usefull for
179 // status messages like "load font" (Matthias)
180 void MiniBuffer::Store()
182 text_stored = fl_get_input(the_buffer);
186 void MiniBuffer::Reset()
188 if (!text_stored.empty()){
194 void MiniBuffer::Activate()
196 fl_activate_object(the_buffer);
197 fl_redraw_object(the_buffer);
200 void MiniBuffer::Deactivate()
202 fl_deactivate_object(the_buffer);
206 // This is not as dirty as it seems, the hidden buttons removed by this
207 // function were just kludges for an uncomplete keyboard callback (ale)
208 int MiniBuffer::peek_event(FL_OBJECT *ob, int event, FL_Coord, FL_Coord,
209 int key, void */*xev*/)
211 MiniBuffer *mini = (MiniBuffer*)ob->u_vdata;
213 if (event==FL_KEYBOARD){
217 if (!mini->getHistory().empty()) {
218 fl_set_input(ob, mini->getHistory().c_str());
223 if (mini->history_idx > 0) mini->history_idx--;
224 fl_set_input(ob, mini->getHistory().c_str());
229 // complete or increment the command
230 const char *s = lyxaction.getApproxFuncName(fl_get_input(ob));
238 fl_set_focus_object(mini->owner->getForm(),
239 mini->owner->currentView()->getWorkArea());
244 // Execute a command.
245 mini->cur_cmd = string(fl_get_input(ob));