2 * \file ControlCommandBuffer.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Asger and Jürgen
10 * Full author contact details are available in file CREDITS.
15 #include "ControlCommandBuffer.h"
17 #include "BufferView.h"
20 #include "LyXAction.h"
21 #include "FuncRequest.h"
23 #include "frontends/LyXView.h"
25 #include "support/lyxalgo.h"
26 #include "support/lstrings.h"
28 using std::back_inserter;
35 using support::prefixIs;
44 prefix_p(string const & s)
46 bool operator()(string const & s) const {
47 return prefixIs(s, p);
51 } // end of anon namespace
54 ControlCommandBuffer::ControlCommandBuffer(LyXView & lv)
55 : lv_(lv), history_pos_(history_.end())
57 transform(lyxaction.func_begin(), lyxaction.func_end(),
58 back_inserter(commands_), firster());
62 string const ControlCommandBuffer::historyUp()
64 if (history_pos_ == history_.begin())
67 return *(--history_pos_);
71 string const ControlCommandBuffer::historyDown()
73 if (history_pos_ == history_.end())
75 if (history_pos_ + 1 == history_.end())
78 return *(++history_pos_);
82 docstring const ControlCommandBuffer::getCurrentState() const
84 return lv_.view()->cursor().currentState();
88 void ControlCommandBuffer::hide() const
90 lv_.showMiniBuffer(false);
95 ControlCommandBuffer::completions(string const & prefix, string & new_prefix)
99 copy_if(commands_.begin(), commands_.end(),
100 back_inserter(comp), prefix_p(prefix));
107 if (comp.size() == 1) {
108 new_prefix = comp[0];
109 return vector<string>();
112 // find maximal available prefix
113 string const tmp = comp[0];
114 string test = prefix;
115 if (tmp.length() > test.length())
116 test += tmp[test.length()];
117 while (test.length() < tmp.length()) {
119 copy_if(comp.begin(), comp.end(),
120 back_inserter(vtmp), prefix_p(test));
121 if (vtmp.size() != comp.size()) {
122 test.erase(test.length() - 1);
125 test += tmp[test.length()];
133 void ControlCommandBuffer::dispatch(string const & str)
138 history_.push_back(str);
139 history_pos_ = history_.end();
140 FuncRequest func = lyxaction.lookupFunc(str);
141 func.origin = FuncRequest::COMMANDBUFFER;
145 } // namespace frontend