From faafd03726ed9d6e435bd1bc94c0a9de3b37416b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sun, 7 Oct 2007 18:58:47 +0000 Subject: [PATCH] more git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20823 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ControlCommand.cpp | 55 ------- src/frontends/controllers/ControlCommand.h | 56 ------- .../controllers/ControlCommandBuffer.cpp | 146 ------------------ .../controllers/ControlCommandBuffer.h | 72 --------- src/frontends/controllers/Makefile.am | 2 - src/frontends/qt4/GuiToc.cpp | 24 ++- src/frontends/qt4/GuiToc.h | 17 +- 7 files changed, 30 insertions(+), 342 deletions(-) delete mode 100644 src/frontends/controllers/ControlCommand.cpp delete mode 100644 src/frontends/controllers/ControlCommand.h delete mode 100644 src/frontends/controllers/ControlCommandBuffer.cpp delete mode 100644 src/frontends/controllers/ControlCommandBuffer.h diff --git a/src/frontends/controllers/ControlCommand.cpp b/src/frontends/controllers/ControlCommand.cpp deleted file mode 100644 index 8bf8cc0aab..0000000000 --- a/src/frontends/controllers/ControlCommand.cpp +++ /dev/null @@ -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 - -#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 diff --git a/src/frontends/controllers/ControlCommand.h b/src/frontends/controllers/ControlCommand.h deleted file mode 100644 index 3680fea14f..0000000000 --- a/src/frontends/controllers/ControlCommand.h +++ /dev/null @@ -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 diff --git a/src/frontends/controllers/ControlCommandBuffer.cpp b/src/frontends/controllers/ControlCommandBuffer.cpp deleted file mode 100644 index 6ed5a51a78..0000000000 --- a/src/frontends/controllers/ControlCommandBuffer.cpp +++ /dev/null @@ -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 - -#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 const -ControlCommandBuffer::completions(string const & prefix, string & new_prefix) -{ - vector 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(); - } - - // 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 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 diff --git a/src/frontends/controllers/ControlCommandBuffer.h b/src/frontends/controllers/ControlCommandBuffer.h deleted file mode 100644 index c337726ff0..0000000000 --- a/src/frontends/controllers/ControlCommandBuffer.h +++ /dev/null @@ -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 - - -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 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 commands_; - - /// command history - std::vector history_; - - /// current position in command history - std::vector::const_iterator history_pos_; -}; - -} // namespace frontend -} // namespace lyx - -#endif // CONTROLCOMMANDBUFFER_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index ff6f51d348..dc0861d898 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -9,7 +9,6 @@ noinst_LTLIBRARIES = liblyxcontrollers.la SOURCEFILES = \ Dialog.cpp \ ButtonPolicy.cpp \ - ControlCommand.cpp \ ControlMath.cpp \ ControlParagraph.cpp \ frontend_helpers.cpp @@ -17,7 +16,6 @@ SOURCEFILES = \ HEADERFILES = \ Dialog.h \ ButtonPolicy.h \ - ControlCommand.h \ ControlMath.h \ ControlParagraph.h \ frontend_helpers.h diff --git a/src/frontends/qt4/GuiToc.cpp b/src/frontends/qt4/GuiToc.cpp index cf1d54362a..3f3e07ef15 100644 --- a/src/frontends/qt4/GuiToc.cpp +++ b/src/frontends/qt4/GuiToc.cpp @@ -16,6 +16,8 @@ #include "GuiView.h" #include "DockView.h" #include "TocWidget.h" +#include "FuncRequest.h" +#include "insets/InsetCommand.h" #include "TocModel.h" #include "qt_helpers.h" @@ -42,9 +44,8 @@ namespace lyx { namespace frontend { GuiToc::GuiToc(Dialog & dialog) - : ControlCommand(dialog, "toc") -{ -} + : Controller(dialog), params_("toc") +{} int GuiToc::getTocDepth(int type) @@ -129,8 +130,7 @@ TocList const & GuiToc::tocs() const bool GuiToc::initialiseParams(string const & data) { - if (!ControlCommand::initialiseParams(data)) - return false; + InsetCommandMailer::string2params("toc", data, params_); updateView(); modelReset(); @@ -147,10 +147,10 @@ bool GuiToc::initialiseParams(string const & data) } string selected_type ; - if(params()["type"].empty()) //Then plain toc... - selected_type = params().getCmdName(); + if (params_["type"].empty()) //Then plain toc... + selected_type = params_.getCmdName(); else - selected_type = to_ascii(params()["type"]); + selected_type = to_ascii(params_["type"]); selected_type_ = -1; for (size_t i = 0; i != types_.size(); ++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) { GuiViewBase & guiview = static_cast(lv); diff --git a/src/frontends/qt4/GuiToc.h b/src/frontends/qt4/GuiToc.h index 81a9a65b53..95beb91b43 100644 --- a/src/frontends/qt4/GuiToc.h +++ b/src/frontends/qt4/GuiToc.h @@ -15,8 +15,9 @@ #ifndef GUITOC_H #define GUITOC_H -#include "ControlCommand.h" #include "TocBackend.h" +#include "Dialog.h" +#include "insets/InsetCommandParams.h" #include #include @@ -29,7 +30,7 @@ namespace frontend { class TocModel; -class GuiToc : public QObject, public ControlCommand +class GuiToc : public QObject, public Controller { Q_OBJECT @@ -87,13 +88,23 @@ private: /// void updateBackend(); -private: std::vector types_; std::vector type_names_; int selected_type_; /// Return the guiname from a given cmdName of the TOC param 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 -- 2.39.2