mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-28 20:45:47 +00:00
28ad960255
* lyxfunc.h: - theLyXFunc(): new function in the global namespace. - lyx::dispatch(): new function in the lyx namespace. - lyx::getStatus(): new function in the lyx namespace. * bufferlist.h: - theBufferList(): new function in the global namespace. * Clipboard.h: - theClipboard(): new function in the global namespace. * Selection.h: - theSelection(): new function in the global namespace. * FontLoader.h: - theFontLoader(): new function in the global namespace. * FontMetrics.h: - theFontMetrics(LyXFont const &): new function in the global namespace. * Application.C: implements the functions defined above. * LyXView.h: - getLyXFunc(): deleted. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15298 a592a061-630c-0410-9148-cb99ea01b6c8
141 lines
2.6 KiB
C
141 lines
2.6 KiB
C
/**
|
|
* \file ControlCommandBuffer.C
|
|
* This file is part of LyX, the document processor.
|
|
* Licence details can be found in the file COPYING.
|
|
*
|
|
* \author Lars
|
|
* \author Asger and Jürgen
|
|
* \author John Levon
|
|
*
|
|
* Full author contact details are available in file CREDITS.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "ControlCommandBuffer.h"
|
|
|
|
#include "BufferView.h"
|
|
#include "cursor.h"
|
|
#include "lyxfunc.h"
|
|
#include "LyXAction.h"
|
|
#include "funcrequest.h"
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
#include "support/lyxalgo.h"
|
|
#include "support/lstrings.h"
|
|
|
|
using std::back_inserter;
|
|
using std::transform;
|
|
using std::string;
|
|
using std::vector;
|
|
|
|
namespace lyx {
|
|
|
|
using support::prefixIs;
|
|
|
|
namespace frontend {
|
|
|
|
namespace {
|
|
|
|
class prefix_p {
|
|
public:
|
|
string p;
|
|
prefix_p(string const & s)
|
|
: p(s) {}
|
|
bool operator()(string const & s) const {
|
|
return prefixIs(s, p);
|
|
}
|
|
};
|
|
|
|
} // end of anon namespace
|
|
|
|
|
|
ControlCommandBuffer::ControlCommandBuffer(LyXView & lv)
|
|
: lv_(lv), history_pos_(history_.end())
|
|
{
|
|
transform(lyxaction.func_begin(), lyxaction.func_end(),
|
|
back_inserter(commands_), firster());
|
|
}
|
|
|
|
|
|
string const ControlCommandBuffer::historyUp()
|
|
{
|
|
if (history_pos_ == history_.begin())
|
|
return string();
|
|
|
|
return *(--history_pos_);
|
|
}
|
|
|
|
|
|
string const ControlCommandBuffer::historyDown()
|
|
{
|
|
if (history_pos_ == history_.end())
|
|
return string();
|
|
if (history_pos_ + 1 == history_.end())
|
|
return string();
|
|
|
|
return *(++history_pos_);
|
|
}
|
|
|
|
|
|
string const ControlCommandBuffer::getCurrentState() const
|
|
{
|
|
return lv_.view()->cursor().currentState();
|
|
}
|
|
|
|
|
|
vector<string> const
|
|
ControlCommandBuffer::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 ControlCommandBuffer::dispatch(string const & str)
|
|
{
|
|
if (str.empty())
|
|
return;
|
|
|
|
history_.push_back(str);
|
|
history_pos_ = history_.end();
|
|
FuncRequest func = lyxaction.lookupFunc(str);
|
|
func.origin = FuncRequest::COMMANDBUFFER;
|
|
lv_.dispatch(func);
|
|
}
|
|
|
|
} // namespace frontend
|
|
} // namespace lyx
|