+
+vector<string> const
+GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
+{
+ vector<string> comp;
+
+ copy_if(commands_.begin(), commands_.end(),
+ back_inserter(comp), prefix_p(prefix));
+
+ if (comp.empty()) {
+ new_prefix = prefix;
+ return comp;
+ }
+
+ if (comp.size() == 1) {
+ new_prefix = comp[0];
+ return vector<string>();
+ }
+
+ // find maximal available prefix
+ string const tmp = comp[0];
+ string test = prefix;
+ if (tmp.length() > test.length())
+ test += tmp[test.length()];
+ while (test.length() < tmp.length()) {
+ vector<string> vtmp;
+ copy_if(comp.begin(), comp.end(),
+ back_inserter(vtmp), prefix_p(test));
+ if (vtmp.size() != comp.size()) {
+ test.erase(test.length() - 1);
+ break;
+ }
+ test += tmp[test.length()];
+ }
+
+ new_prefix = test;
+ return comp;
+}
+
+
+void GuiCommandBuffer::dispatch(string const & str)
+{
+ if (str.empty())
+ return;
+
+ history_.push_back(trim(str));
+ history_pos_ = history_.end();
+ upPB->setEnabled(history_pos_ != history_.begin());
+ downPB->setEnabled(history_pos_ != history_.end());
+ FuncRequest func = lyxaction.lookupFunc(str);
+ func.origin = FuncRequest::COMMANDBUFFER;
+ lyx::dispatch(func);
+}