- obj->Set(_("Executing:"), obj->cur_cmd);
- obj->addHistory(obj->cur_cmd);
-
- // Split command into function and argument
- // This is done wrong Asger. Instead of <function argument>
- // it ends up as <argument function> Queer solution:
- string arg = obj->cur_cmd;
- string function;
- if (contains(arg, " ")) {
- arg = split(arg, function, ' ');
- function = strip(function);
- } else {
- function = arg;
- arg.erase();
- }
- lyxerr.debug("Function: " + function);
- lyxerr.debug("Arg : " + arg);
- // Check if the name is valid (ale)
- // No, let the dispatch functions handle that.
- //int action = lyxaction.LookupFunc(function.c_str());
- //lyxerr.debug(string("minibuffer action: ") + action);
- //if (action>=0) {
- // Dispatch only returns requested data for a few commands (ale)
- string res=obj->owner->getLyXFunc()->Dispatch(function.c_str(),
- arg.c_str());
- lyxerr.debug(string("Minibuffer Res: ") + res);
-/* if (!res.empty())
- if(obj->owner->getLyXFunc()->errorStat())
- obj->Set(_("Error:"), _(res.c_str()), string(), 4);
- else
- obj->Set(_("Result:"), _(res.c_str()), string(), 4);
- else
- obj->Init();
-*/
- //} else {
-#ifdef WITH_WARNINGS
-#warning Look at this.
+}
+
+
+void MiniBuffer::stored_set(string const & str)
+{
+ stored_input = str;
+ stored_ = true;
+ stored_timer.start();
+}
+
+
+int MiniBuffer::peek_event(FL_OBJECT * ob, int event, int key)
+{
+ switch (event) {
+ case FL_KEYBOARD:
+ {
+ char const * tmp = fl_get_input(ob);
+ string input = tmp ? tmp : "";
+ if (stored_) {
+ stored_timer.stop();
+ input = stored_input;
+ fl_set_input(ob, input.c_str());
+ stored_ = false;
+ }
+
+ switch (key) {
+ case XK_Down:
+ if (hist_iter != history_->end()) {
+ ++hist_iter;
+ }
+ if (hist_iter == history_->end()) {
+ // no further history
+ stored_set(input);
+ fl_set_input(ob, _("[End of history]"));
+ } else {
+ fl_set_input(ob, (*hist_iter).c_str());
+ }
+ return 1;
+ case XK_Up:
+ if (hist_iter == history_->begin()) {
+ // no further history
+ stored_set(input);
+ fl_set_input(ob, _("[Beginning of history]"));
+ } else {
+ --hist_iter;
+ fl_set_input(ob, (*hist_iter).c_str());
+ }
+ return 1;
+ case 9:
+ case XK_Tab:
+ {
+ // Completion handling.
+
+ vector<string> comp;
+ lyx::copy_if(completion_.begin(),
+ completion_.end(),
+ std::back_inserter(comp), prefix(input));
+
+ if (comp.empty()) {
+ // No matches
+ string const tmp = input + _(" [no match]");
+ stored_set(input);
+ fl_set_input(ob, tmp.c_str());
+ } else if (comp.size() == 1) {
+ // Perfect match
+ string const tmp =
+ comp[0] + _(" [sole completion]");
+ stored_set(comp[0]);
+ fl_set_input(ob, tmp.c_str());
+ } else {
+ // More that one match
+ // Find maximal avaliable prefix
+ string const tmp = comp[0];
+ string test(input);
+ test += tmp[test.length()];
+ while (test.length() < tmp.length()) {
+ vector<string> vtmp;
+ lyx::copy_if(comp.begin(),
+ comp.end(),
+ std::back_inserter(vtmp),
+ prefix(test));
+ if (vtmp.size() != comp.size()) {
+ test.erase(test.length() - 1);
+ break;
+ }
+ test += tmp[test.length()];
+ }
+ fl_set_input(ob, test.c_str());
+
+ // How should the possible matches
+ // be visualized?
+ std::copy(comp.begin(), comp.end(),
+ std::ostream_iterator<string>(std::cerr, "\n"));
+ }
+ return 1;
+ }
+ case 27:
+ case XK_Escape:
+ // Abort
+ owner_->view()->focus(true);
+ init();
+ deactivate();
+ //escape.emit();
+ return 1;
+ case 13:
+ case XK_Return:
+ {
+#if 0
+ // This will go in again in a little while
+ // we need to be able to declare what types
+ // of argumetns LFUN's should have first. (Lgb)
+ // First check for match
+ vector<string>::const_iterator cit =
+ std::find(completion_.begin(),
+ completion_.end(),
+ input);
+ if (cit == completion_.end()) {
+ // no such func/item
+ stored_set(input);
+ string const tmp = input + _(" [no match]");
+ fl_set_input(ob, tmp.c_str());
+ } else {