git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20823 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-07 18:58:47 +00:00
parent 6a2f951cf7
commit faafd03726
7 changed files with 30 additions and 342 deletions

View File

@ -1,55 +0,0 @@
/**
* \file ControlCommand.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "ControlCommand.h"
#include "FuncRequest.h"
#include "insets/InsetCommand.h"
using std::string;
namespace lyx {
namespace frontend {
ControlCommand::ControlCommand(Dialog & dialog, string const & insetType)
: Controller(dialog), params_(insetType), lfun_name_(insetType)
{}
bool ControlCommand::initialiseParams(string const & data)
{
// The name passed with LFUN_INSET_APPLY is also the name
// used to identify the mailer.
InsetCommandMailer::string2params(lfun_name_, data, params_);
return true;
}
void ControlCommand::clearParams()
{
params_.clear();
}
void ControlCommand::dispatchParams()
{
if (lfun_name_.empty())
return;
string const lfun =
InsetCommandMailer::params2string(lfun_name_, params_);
dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend
} // namespace lyx

View File

@ -1,56 +0,0 @@
// -*- C++ -*-
/**
* \file ControlCommand.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*
* ControlCommand is a controller class for dialogs that create or modify
* an inset derived from InsetCommand.
*/
#ifndef CONTROLCOMMAND_H
#define CONTROLCOMMAND_H
#include "Dialog.h"
#include "insets/InsetCommandParams.h"
namespace lyx {
namespace frontend {
class ControlCommand : public Controller {
public:
/// We need to know with what sort of inset we're associated.
ControlCommand(Dialog &, std::string const & insetType);
///
virtual ~ControlCommand() {}
///
InsetCommandParams & params() { return params_; }
///
InsetCommandParams const & params() const { return params_; }
///
virtual bool initialiseParams(std::string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
private:
///
InsetCommandParams params_;
//FIXME It should be possible to eliminate lfun_name_
//now and recover that information from params().insetType().
//But let's not do that quite yet.
/// Flags what action is taken by Kernel::dispatch()
std::string const lfun_name_;
};
} // namespace frontend
} // namespace lyx
#endif // CONTROLCOMMAND_H

View File

@ -1,146 +0,0 @@
/**
* \file ControlCommandBuffer.cpp
* 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_);
}
docstring const ControlCommandBuffer::getCurrentState() const
{
return lv_.view()->cursor().currentState();
}
void ControlCommandBuffer::hide() const
{
lv_.showMiniBuffer(false);
}
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

View File

@ -1,72 +0,0 @@
// -*- C++ -*-
/**
* \file ControlCommandBuffer.h
* 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.
*/
#ifndef CONTROLCOMMANDBUFFER_H
#define CONTROLCOMMANDBUFFER_H
#include "support/docstring.h"
#include <vector>
namespace lyx {
namespace frontend {
class LyXView;
/**
* ControlCommandBuffer
*
* This provides methods for the use of a toolkit's
* minibuffer/command buffer
*/
class ControlCommandBuffer {
public:
ControlCommandBuffer(LyXView & lv);
/// return the previous history entry if any
std::string const historyUp();
/// return the next history entry if any
std::string const historyDown();
/// return the font and depth in the active BufferView as a message.
docstring const getCurrentState() const;
/// hide the command buffer.
void hide() const;
/// return the possible completions
std::vector<std::string> const completions(std::string const & prefix,
std::string & new_prefix);
/// dispatch a command
void dispatch(std::string const & str);
private:
/// controlling LyXView
LyXView & lv_;
/// available command names
std::vector<std::string> commands_;
/// command history
std::vector<std::string> history_;
/// current position in command history
std::vector<std::string>::const_iterator history_pos_;
};
} // namespace frontend
} // namespace lyx
#endif // CONTROLCOMMANDBUFFER_H

View File

@ -9,7 +9,6 @@ noinst_LTLIBRARIES = liblyxcontrollers.la
SOURCEFILES = \ SOURCEFILES = \
Dialog.cpp \ Dialog.cpp \
ButtonPolicy.cpp \ ButtonPolicy.cpp \
ControlCommand.cpp \
ControlMath.cpp \ ControlMath.cpp \
ControlParagraph.cpp \ ControlParagraph.cpp \
frontend_helpers.cpp frontend_helpers.cpp
@ -17,7 +16,6 @@ SOURCEFILES = \
HEADERFILES = \ HEADERFILES = \
Dialog.h \ Dialog.h \
ButtonPolicy.h \ ButtonPolicy.h \
ControlCommand.h \
ControlMath.h \ ControlMath.h \
ControlParagraph.h \ ControlParagraph.h \
frontend_helpers.h frontend_helpers.h

View File

@ -16,6 +16,8 @@
#include "GuiView.h" #include "GuiView.h"
#include "DockView.h" #include "DockView.h"
#include "TocWidget.h" #include "TocWidget.h"
#include "FuncRequest.h"
#include "insets/InsetCommand.h"
#include "TocModel.h" #include "TocModel.h"
#include "qt_helpers.h" #include "qt_helpers.h"
@ -42,9 +44,8 @@ namespace lyx {
namespace frontend { namespace frontend {
GuiToc::GuiToc(Dialog & dialog) GuiToc::GuiToc(Dialog & dialog)
: ControlCommand(dialog, "toc") : Controller(dialog), params_("toc")
{ {}
}
int GuiToc::getTocDepth(int type) int GuiToc::getTocDepth(int type)
@ -129,8 +130,7 @@ TocList const & GuiToc::tocs() const
bool GuiToc::initialiseParams(string const & data) bool GuiToc::initialiseParams(string const & data)
{ {
if (!ControlCommand::initialiseParams(data)) InsetCommandMailer::string2params("toc", data, params_);
return false;
updateView(); updateView();
modelReset(); modelReset();
@ -147,10 +147,10 @@ bool GuiToc::initialiseParams(string const & data)
} }
string selected_type ; string selected_type ;
if(params()["type"].empty()) //Then plain toc... if (params_["type"].empty()) //Then plain toc...
selected_type = params().getCmdName(); selected_type = params_.getCmdName();
else else
selected_type = to_ascii(params()["type"]); selected_type = to_ascii(params_["type"]);
selected_type_ = -1; selected_type_ = -1;
for (size_t i = 0; i != types_.size(); ++i) { for (size_t i = 0; i != types_.size(); ++i) {
if (selected_type == types_[i]) { if (selected_type == types_[i]) {
@ -222,6 +222,14 @@ docstring GuiToc::guiName(string const & type) const
} }
void GuiToc::dispatchParams()
{
string const lfun =
InsetCommandMailer::params2string("toc", params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiToc(LyXView & lv) Dialog * createGuiToc(LyXView & lv)
{ {
GuiViewBase & guiview = static_cast<GuiViewBase &>(lv); GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);

View File

@ -15,8 +15,9 @@
#ifndef GUITOC_H #ifndef GUITOC_H
#define GUITOC_H #define GUITOC_H
#include "ControlCommand.h"
#include "TocBackend.h" #include "TocBackend.h"
#include "Dialog.h"
#include "insets/InsetCommandParams.h"
#include <QObject> #include <QObject>
#include <QStandardItemModel> #include <QStandardItemModel>
@ -29,7 +30,7 @@ namespace frontend {
class TocModel; class TocModel;
class GuiToc : public QObject, public ControlCommand class GuiToc : public QObject, public Controller
{ {
Q_OBJECT Q_OBJECT
@ -87,13 +88,23 @@ private:
/// ///
void updateBackend(); void updateBackend();
private:
std::vector<std::string> types_; std::vector<std::string> types_;
std::vector<docstring> type_names_; std::vector<docstring> type_names_;
int selected_type_; int selected_type_;
/// Return the guiname from a given cmdName of the TOC param /// Return the guiname from a given cmdName of the TOC param
docstring guiName(std::string const & type) const; docstring guiName(std::string const & type) const;
/// clean-up on hide.
void clearParams() { params_.clear(); }
///
void dispatchParams();
///
bool isBufferDependent() const { return true; }
private:
///
InsetCommandParams params_;
}; };
} // namespace frontend } // namespace frontend