- lyxerr.debug() << "Function: " << function
- << "\nArg : " << arg << endl;
- // 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() << "Minibuffer Res: " << res << endl;
-/* 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_UNFOCUS:
+ deactivate();
+ break;
+ case FL_KEYBOARD:
+ {
+ char const * tmp = fl_get_input(ob);
+ string input = tmp ? tmp : "";
+ if (stored_) {
+ stored_timer->stop();
+ input = stored_input;
+ set_input(input);
+ 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);
+ set_input(_("[End of history]"));
+ } else {
+ set_input((*hist_iter));
+ }
+ return 1;
+ case XK_Up:
+ if (hist_iter == history_->begin()) {
+ // no further history
+ stored_set(input);
+ set_input(_("[Beginning of history]"));
+ } else {
+ --hist_iter;
+ set_input((*hist_iter));
+ }
+ return 1;
+ case 9:
+ case XK_Tab:
+ {
+ // Completion handling.
+
+ vector<string> comp;
+ lyx::copy_if(completion_.begin(),
+ completion_.end(),
+ back_inserter(comp), prefix(input));
+
+ if (comp.empty()) {
+ // No matches
+ string const tmp = input + _(" [no match]");
+ stored_set(input);
+ set_input(tmp);
+ } else if (comp.size() == 1) {
+ // Perfect match
+ string const tmp =
+ comp[0] + _(" [sole completion]");
+ stored_set(comp[0] + " ");
+ set_input(tmp);
+ } else {
+ // More that one match
+ // Find maximal avaliable prefix
+ string const tmp = comp[0];
+ string test(input);
+ if (tmp.length() > test.length())
+ test += tmp[test.length()];
+ while (test.length() < tmp.length()) {
+ vector<string> vtmp;
+ lyx::copy_if(comp.begin(),
+ comp.end(),
+ back_inserter(vtmp),
+ prefix(test));
+ if (vtmp.size() != comp.size()) {
+ test.erase(test.length() - 1);
+ break;
+ }
+ test += tmp[test.length()];
+ }
+ set_input(test);
+
+ int x,y,w,h;
+ fl_get_wingeometry(fl_get_real_object_window(the_buffer),
+ &x, &y, &w, &h);
+
+ // asynchronous completion
+ int const air = the_buffer->x;
+ x += air;
+ y += h - (the_buffer->h + air);
+ w = the_buffer->w;
+ dropdown_->select(comp, x, y, w);
+ }
+ 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 =
+ find(completion_.begin(),
+ completion_.end(),
+ input);
+ if (cit == completion_.end()) {
+ // no such func/item
+ stored_set(input);
+ string const tmp = input + _(" [no match]");
+ set_input(tmp);
+ } else {
+#endif
+ // Return the inputted string
+ deactivate();
+ owner_->view()->focus(true);
+ if (!input.empty()) {
+ history_->push_back(input);
+ }
+ stringReady.emit(input);
+# if 0
+ }