From 64e0e5663b792585d7ae448fef3a89b209331c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 6 Oct 2007 20:09:40 +0000 Subject: [PATCH] one more git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20799 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ControlSendto.cpp | 115 ------------------ src/frontends/controllers/ControlSendto.h | 62 ---------- .../controllers/ControlThesaurus.cpp | 65 ---------- src/frontends/controllers/ControlThesaurus.h | 63 ---------- src/frontends/controllers/Makefile.am | 4 - src/frontends/qt4/Dialogs.cpp | 5 +- src/frontends/qt4/GuiSendto.cpp | 112 +++++++++++++---- src/frontends/qt4/GuiSendto.h | 27 +++- 8 files changed, 116 insertions(+), 337 deletions(-) delete mode 100644 src/frontends/controllers/ControlSendto.cpp delete mode 100644 src/frontends/controllers/ControlSendto.h delete mode 100644 src/frontends/controllers/ControlThesaurus.cpp delete mode 100644 src/frontends/controllers/ControlThesaurus.h diff --git a/src/frontends/controllers/ControlSendto.cpp b/src/frontends/controllers/ControlSendto.cpp deleted file mode 100644 index 95b42ec639..0000000000 --- a/src/frontends/controllers/ControlSendto.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/** - * \file ControlSendto.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 "ControlSendto.h" - -#include "Buffer.h" -#include "Converter.h" -#include "Format.h" -#include "FuncRequest.h" -#include "LyXRC.h" - -#include "support/filetools.h" -#include "support/lstrings.h" - -using std::vector; -using std::string; - -namespace lyx { - -using support::trim; - -namespace frontend { - - -ControlSendto::ControlSendto(Dialog & parent) - : Controller(parent) -{} - - -bool ControlSendto::initialiseParams(std::string const &) -{ - format_ = 0; - command_ = lyxrc.custom_export_command; - return true; -} - - -void ControlSendto::dispatchParams() -{ - if (command_.empty() || !format_ || format_->name().empty()) - return; - - string const data = format_->name() + " " + command_; - dispatch(FuncRequest(getLfun(), data)); -} - - -vector const ControlSendto::allFormats() const -{ - // What formats can we output natively? - vector exports; - exports.push_back("lyx"); - exports.push_back("text"); - - if (buffer().isLatex()) - exports.push_back("latex"); - else if (buffer().isDocBook()) - exports.push_back("docbook"); - else if (buffer().isLiterate()) - exports.push_back("literate"); - - // Loop over these native formats and ascertain what formats we - // can convert to - vector to; - - vector::const_iterator ex_it = exports.begin(); - vector::const_iterator ex_end = exports.end(); - for (; ex_it != ex_end; ++ex_it) { - // Start off with the native export format. - // "formats" is LyX's list of recognised formats - to.push_back(formats.getFormat(*ex_it)); - - Formats::const_iterator fo_it = formats.begin(); - Formats::const_iterator fo_end = formats.end(); - for (; fo_it != fo_end; ++fo_it) { - // we need to hide the default graphic export formats - // from the external menu, because we need them only - // for the internal lyx-view and external latex run - string const name = fo_it->name(); - if (name != "eps" && name != "xpm" && name != "png" && - theConverters().isReachable(*ex_it, name)) - to.push_back(&(*fo_it)); - } - } - - // Remove repeated formats. - std::sort(to.begin(), to.end()); - to.erase(std::unique(to.begin(), to.end()), to.end()); - - return to; -} - - -void ControlSendto::setFormat(Format const * fmt) -{ - format_ = fmt; -} - - -void ControlSendto::setCommand(string const & cmd) -{ - command_ = trim(cmd); -} - -} // namespace frontend -} // namespace lyx diff --git a/src/frontends/controllers/ControlSendto.h b/src/frontends/controllers/ControlSendto.h deleted file mode 100644 index 870034933f..0000000000 --- a/src/frontends/controllers/ControlSendto.h +++ /dev/null @@ -1,62 +0,0 @@ -// -*- C++ -*- -/** - * \file ControlSendto.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. - */ - -#ifndef CONTROLSENDTO_H -#define CONTROLSENDTO_H - -#include "Dialog.h" -#include - - -namespace lyx { - -class Format; - -namespace frontend { - -/** A controller for the Custom Export dialogs. - */ -class ControlSendto : public Controller { -public: - /// - ControlSendto(Dialog &); - /// - virtual bool initialiseParams(std::string const & data); - /// - virtual void clearParams() {} - /// - virtual void dispatchParams(); - /// - virtual bool isBufferDependent() const { return true; } - /// - virtual kb_action getLfun() const { return LFUN_BUFFER_EXPORT_CUSTOM; } - - /// Return a vector of those formats that can be exported from "lyx". - std::vector const allFormats() const; - - /// The format to export to - Format const * getFormat() { return format_; } - void setFormat(Format const *); - - /// The command to be executed - std::string const getCommand() const { return command_; }; - void setCommand(std::string const &); -private: - /// - Format const * format_; - /// - std::string command_; -}; - -} // namespace frontend -} // namespace lyx - -#endif // CONTROLSENDTO_H diff --git a/src/frontends/controllers/ControlThesaurus.cpp b/src/frontends/controllers/ControlThesaurus.cpp deleted file mode 100644 index b9832253a0..0000000000 --- a/src/frontends/controllers/ControlThesaurus.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/** - * \file ControlThesaurus.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author John Levon - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "ControlThesaurus.h" - -#include "lyxfind.h" -#include "FuncRequest.h" - -using std::string; - -namespace lyx { -namespace frontend { - -ControlThesaurus::ControlThesaurus(Dialog & parent) - : Controller(parent) -{} - - -bool ControlThesaurus::initialiseParams(string const & data) -{ - oldstr_ = from_utf8(data); - return true; -} - - -void ControlThesaurus::clearParams() -{ - oldstr_.erase(); -} - - -void ControlThesaurus::replace(docstring const & newstr) -{ - /* FIXME: this is not suitable ! We need to have a "lock" - * on a particular charpos in a paragraph that is broken on - * deletion/change ! - */ - docstring const data = - replace2string(oldstr_, newstr, - true, // case sensitive - true, // match word - false, // all words - true); // forward - dispatch(FuncRequest(LFUN_WORD_REPLACE, data)); -} - - -Thesaurus::Meanings const & ControlThesaurus::getMeanings(docstring const & str) -{ - if (str != laststr_) - meanings_ = thesaurus.lookup(str); - return meanings_; -} - -} // namespace frontend -} // namespace lyx diff --git a/src/frontends/controllers/ControlThesaurus.h b/src/frontends/controllers/ControlThesaurus.h deleted file mode 100644 index 9bbd936446..0000000000 --- a/src/frontends/controllers/ControlThesaurus.h +++ /dev/null @@ -1,63 +0,0 @@ -// -*- C++ -*- -/** - * \file ControlThesaurus.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author John Levon - * - * Full author contact details are available in file CREDITS. - */ - - -#ifndef CONTROLTHESAURUS_H -#define CONTROLTHESAURUS_H - -#include "Dialog.h" -#include "Thesaurus.h" - -namespace lyx { -namespace frontend { - -/** A controller for Thesaurus dialogs. - */ -class ControlThesaurus : public Controller { -public: - /// - ControlThesaurus(Dialog &); - /// - virtual bool initialiseParams(std::string const & data); - /// - virtual void clearParams(); - /// - virtual void dispatchParams() {} - /// - virtual bool isBufferDependent() const { return true; } - - /// replace the particular string - void replace(docstring const & newstr); - - /// get meanings - Thesaurus::Meanings const & getMeanings(docstring const & str); - - /// the text - docstring const & text() const { return oldstr_; } - -private: - /// last string looked up - docstring laststr_; - - /// entries for last string - Thesaurus::Meanings meanings_; - - /// original string - docstring oldstr_; - - /// not needed. - virtual void apply() {} -}; - -} // namespace frontend -} // namespace lyx - -#endif // CONTROLTHESAURUS_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index ffb999b38e..4772778136 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -19,8 +19,6 @@ SOURCEFILES = \ ControlPrefs.cpp \ ControlPrint.cpp \ ControlSearch.cpp \ - ControlSendto.cpp \ - ControlThesaurus.cpp \ ControlToc.cpp \ frontend_helpers.cpp @@ -36,8 +34,6 @@ HEADERFILES = \ ControlPrefs.h \ ControlPrint.h \ ControlSearch.h \ - ControlSendto.h \ - ControlThesaurus.h \ ControlToc.h \ frontend_helpers.h diff --git a/src/frontends/qt4/Dialogs.cpp b/src/frontends/qt4/Dialogs.cpp index 4fde46988b..ed41742460 100644 --- a/src/frontends/qt4/Dialogs.cpp +++ b/src/frontends/qt4/Dialogs.cpp @@ -28,7 +28,6 @@ #include "GuiPrefs.h" #include "GuiPrint.h" #include "GuiSearch.h" -#include "GuiSendto.h" #include "GuiShowFile.h" #include "GuiToc.h" #include "GuiView.h" @@ -111,7 +110,7 @@ Dialog * createGuiPrefs(LyXView & lv); Dialog * createGuiPrint(LyXView & lv); Dialog * createGuiRef(LyXView & lv); Dialog * createGuiSearch(LyXView & lv); -Dialog * createGuiSendto(LyXView & lv); +Dialog * createGuiSendTo(LyXView & lv); Dialog * createGuiShowFile(LyXView & lv); Dialog * createGuiSpellchecker(LyXView & lv); Dialog * createGuiTabularCreate(LyXView & lv); @@ -204,7 +203,7 @@ Dialog * Dialogs::build(string const & name) if (name == "ref") return createGuiRef(lyxview_); if (name == "sendto") - return new GuiSendtoDialog(lyxview_); + return createGuiSendTo(lyxview_); if (name == "spellchecker") return createGuiSpellchecker(lyxview_); if (name == "tabular") diff --git a/src/frontends/qt4/GuiSendto.cpp b/src/frontends/qt4/GuiSendto.cpp index b89245b77a..798fad0c39 100644 --- a/src/frontends/qt4/GuiSendto.cpp +++ b/src/frontends/qt4/GuiSendto.cpp @@ -3,6 +3,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * + * \author Angus Leeming * \author Jürgen Spitzmüller * * Full author contact details are available in file CREDITS. @@ -12,10 +13,15 @@ #include "GuiSendto.h" -#include "ControlSendto.h" +#include "Buffer.h" +#include "Converter.h" +#include "Format.h" +#include "FuncRequest.h" +#include "LyXRC.h" #include "qt_helpers.h" -#include "Format.h" +#include "support/filetools.h" +#include "support/lstrings.h" #include #include @@ -28,12 +34,14 @@ using std::string; namespace lyx { namespace frontend { -GuiSendtoDialog::GuiSendtoDialog(LyXView & lv) - : GuiDialog(lv, "sendto") +using support::trim; + +GuiSendTo::GuiSendTo(LyXView & lv) + : GuiDialog(lv, "sendto"), Controller(this) { setupUi(this); setViewTitle(_("Send Document to Command")); - setController(new ControlSendto(*this)); + setController(this, false); connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); @@ -45,7 +53,7 @@ GuiSendtoDialog::GuiSendtoDialog(LyXView & lv) this, SLOT(slotFormatSelected(QListWidgetItem *))); connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(changed_adaptor())); - connect(commandCO, SIGNAL(textChanged(const QString&)), + connect(commandCO, SIGNAL(textChanged(QString)), this, SLOT(changed_adaptor())); bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy); @@ -55,28 +63,22 @@ GuiSendtoDialog::GuiSendtoDialog(LyXView & lv) } -ControlSendto & GuiSendtoDialog::controller() -{ - return static_cast(GuiDialog::controller()); -} - - -void GuiSendtoDialog::changed_adaptor() +void GuiSendTo::changed_adaptor() { changed(); } -void GuiSendtoDialog::closeEvent(QCloseEvent * e) +void GuiSendTo::closeEvent(QCloseEvent * e) { slotClose(); e->accept(); } -void GuiSendtoDialog::updateContents() +void GuiSendTo::updateContents() { - all_formats_ = controller().allFormats(); + all_formats_ = allFormats(); // Check whether the current contents of the browser will be // changed by loading the contents of formats @@ -97,23 +99,23 @@ void GuiSendtoDialog::updateContents() formatLW->addItem(toqstr(*it)); } - commandCO->addItem(toqstr(controller().getCommand())); + commandCO->addItem(toqstr(command_)); } -void GuiSendtoDialog::applyView() +void GuiSendTo::applyView() { int const line = formatLW->currentRow(); if (line < 0 || line > int(formatLW->count())) return; - controller().setFormat(all_formats_[line]); - controller().setCommand(fromqstr(commandCO->currentText())); + format_ = all_formats_[line]; + command_ = trim(fromqstr(commandCO->currentText())); } -bool GuiSendtoDialog::isValid() +bool GuiSendTo::isValid() { int const line = formatLW->currentRow(); @@ -124,6 +126,74 @@ bool GuiSendtoDialog::isValid() !commandCO->currentText().isEmpty(); } + +bool GuiSendTo::initialiseParams(std::string const &) +{ + format_ = 0; + command_ = lyxrc.custom_export_command; + return true; +} + + +void GuiSendTo::dispatchParams() +{ + if (command_.empty() || !format_ || format_->name().empty()) + return; + + string const data = format_->name() + " " + command_; + dispatch(FuncRequest(getLfun(), data)); +} + +// FIXME: Move to Converters? +vector GuiSendTo::allFormats() const +{ + // What formats can we output natively? + vector exports; + exports.push_back("lyx"); + exports.push_back("text"); + + if (buffer().isLatex()) + exports.push_back("latex"); + else if (buffer().isDocBook()) + exports.push_back("docbook"); + else if (buffer().isLiterate()) + exports.push_back("literate"); + + // Loop over these native formats and ascertain what formats we + // can convert to + vector to; + + vector::const_iterator ex_it = exports.begin(); + vector::const_iterator ex_end = exports.end(); + for (; ex_it != ex_end; ++ex_it) { + // Start off with the native export format. + // "formats" is LyX's list of recognised formats + to.push_back(formats.getFormat(*ex_it)); + + Formats::const_iterator fo_it = formats.begin(); + Formats::const_iterator fo_end = formats.end(); + for (; fo_it != fo_end; ++fo_it) { + // we need to hide the default graphic export formats + // from the external menu, because we need them only + // for the internal lyx-view and external latex run + string const name = fo_it->name(); + if (name != "eps" && name != "xpm" && name != "png" && + theConverters().isReachable(*ex_it, name)) + to.push_back(&(*fo_it)); + } + } + + // Remove repeated formats. + std::sort(to.begin(), to.end()); + to.erase(std::unique(to.begin(), to.end()), to.end()); + + return to; +} + + +Dialog * createGuiSendTo(LyXView & lv) { return new GuiSendTo(lv); } + + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiSendto.h b/src/frontends/qt4/GuiSendto.h index d69ca02f28..095c249142 100644 --- a/src/frontends/qt4/GuiSendto.h +++ b/src/frontends/qt4/GuiSendto.h @@ -4,6 +4,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * + * \author Angus Leeming * \author Jürgen Spitzmüller * * Full author contact details are available in file CREDITS. @@ -13,7 +14,6 @@ #define GUISENDTO_H #include "GuiDialog.h" -#include "ControlSendto.h" #include "ui_SendtoUi.h" #include @@ -26,12 +26,12 @@ class Format; namespace frontend { -class GuiSendtoDialog : public GuiDialog, public Ui::SendtoUi +class GuiSendTo : public GuiDialog, public Ui::SendtoUi, public Controller { Q_OBJECT public: - GuiSendtoDialog(LyXView & lv); + GuiSendTo(LyXView & lv); private Q_SLOTS: void changed_adaptor(); @@ -41,7 +41,7 @@ private Q_SLOTS: private: void closeEvent(QCloseEvent * e); /// parent controller - ControlSendto & controller(); + Controller & controller() { return *this; } /// bool isValid(); /// Apply from dialog @@ -51,6 +51,25 @@ private: /// std::vector all_formats_; + /// + bool initialiseParams(std::string const & data); + /// + void clearParams() {} + /// + void dispatchParams(); + /// + bool isBufferDependent() const { return true; } + /// + kb_action getLfun() const { return LFUN_BUFFER_EXPORT_CUSTOM; } + + /// Return a vector of those formats that can be exported from "lyx". + std::vector allFormats() const; + +private: + /// + Format const * format_; + /// + std::string command_; }; } // namespace frontend