git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20799 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-06 20:09:40 +00:00
parent bb1c76d479
commit 64e0e5663b
8 changed files with 116 additions and 337 deletions

View File

@ -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 <config.h>
#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<Format const *> const ControlSendto::allFormats() const
{
// What formats can we output natively?
vector<string> 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<Format const *> to;
vector<string>::const_iterator ex_it = exports.begin();
vector<string>::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

View File

@ -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 <vector>
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<Format const *> 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

View File

@ -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 <config.h>
#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

View File

@ -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

View File

@ -19,8 +19,6 @@ SOURCEFILES = \
ControlPrefs.cpp \ ControlPrefs.cpp \
ControlPrint.cpp \ ControlPrint.cpp \
ControlSearch.cpp \ ControlSearch.cpp \
ControlSendto.cpp \
ControlThesaurus.cpp \
ControlToc.cpp \ ControlToc.cpp \
frontend_helpers.cpp frontend_helpers.cpp
@ -36,8 +34,6 @@ HEADERFILES = \
ControlPrefs.h \ ControlPrefs.h \
ControlPrint.h \ ControlPrint.h \
ControlSearch.h \ ControlSearch.h \
ControlSendto.h \
ControlThesaurus.h \
ControlToc.h \ ControlToc.h \
frontend_helpers.h frontend_helpers.h

View File

@ -28,7 +28,6 @@
#include "GuiPrefs.h" #include "GuiPrefs.h"
#include "GuiPrint.h" #include "GuiPrint.h"
#include "GuiSearch.h" #include "GuiSearch.h"
#include "GuiSendto.h"
#include "GuiShowFile.h" #include "GuiShowFile.h"
#include "GuiToc.h" #include "GuiToc.h"
#include "GuiView.h" #include "GuiView.h"
@ -111,7 +110,7 @@ Dialog * createGuiPrefs(LyXView & lv);
Dialog * createGuiPrint(LyXView & lv); Dialog * createGuiPrint(LyXView & lv);
Dialog * createGuiRef(LyXView & lv); Dialog * createGuiRef(LyXView & lv);
Dialog * createGuiSearch(LyXView & lv); Dialog * createGuiSearch(LyXView & lv);
Dialog * createGuiSendto(LyXView & lv); Dialog * createGuiSendTo(LyXView & lv);
Dialog * createGuiShowFile(LyXView & lv); Dialog * createGuiShowFile(LyXView & lv);
Dialog * createGuiSpellchecker(LyXView & lv); Dialog * createGuiSpellchecker(LyXView & lv);
Dialog * createGuiTabularCreate(LyXView & lv); Dialog * createGuiTabularCreate(LyXView & lv);
@ -204,7 +203,7 @@ Dialog * Dialogs::build(string const & name)
if (name == "ref") if (name == "ref")
return createGuiRef(lyxview_); return createGuiRef(lyxview_);
if (name == "sendto") if (name == "sendto")
return new GuiSendtoDialog(lyxview_); return createGuiSendTo(lyxview_);
if (name == "spellchecker") if (name == "spellchecker")
return createGuiSpellchecker(lyxview_); return createGuiSpellchecker(lyxview_);
if (name == "tabular") if (name == "tabular")

View File

@ -3,6 +3,7 @@
* This file is part of LyX, the document processor. * This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Angus Leeming
* \author Jürgen Spitzmüller * \author Jürgen Spitzmüller
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
@ -12,10 +13,15 @@
#include "GuiSendto.h" #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 "qt_helpers.h"
#include "Format.h" #include "support/filetools.h"
#include "support/lstrings.h"
#include <QListWidget> #include <QListWidget>
#include <QPushButton> #include <QPushButton>
@ -28,12 +34,14 @@ using std::string;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
GuiSendtoDialog::GuiSendtoDialog(LyXView & lv) using support::trim;
: GuiDialog(lv, "sendto")
GuiSendTo::GuiSendTo(LyXView & lv)
: GuiDialog(lv, "sendto"), Controller(this)
{ {
setupUi(this); setupUi(this);
setViewTitle(_("Send Document to Command")); setViewTitle(_("Send Document to Command"));
setController(new ControlSendto(*this)); setController(this, false);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
@ -45,7 +53,7 @@ GuiSendtoDialog::GuiSendtoDialog(LyXView & lv)
this, SLOT(slotFormatSelected(QListWidgetItem *))); this, SLOT(slotFormatSelected(QListWidgetItem *)));
connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)), connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
this, SLOT(changed_adaptor())); this, SLOT(changed_adaptor()));
connect(commandCO, SIGNAL(textChanged(const QString&)), connect(commandCO, SIGNAL(textChanged(QString)),
this, SLOT(changed_adaptor())); this, SLOT(changed_adaptor()));
bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy); bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
@ -55,28 +63,22 @@ GuiSendtoDialog::GuiSendtoDialog(LyXView & lv)
} }
ControlSendto & GuiSendtoDialog::controller() void GuiSendTo::changed_adaptor()
{
return static_cast<ControlSendto &>(GuiDialog::controller());
}
void GuiSendtoDialog::changed_adaptor()
{ {
changed(); changed();
} }
void GuiSendtoDialog::closeEvent(QCloseEvent * e) void GuiSendTo::closeEvent(QCloseEvent * e)
{ {
slotClose(); slotClose();
e->accept(); 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 // Check whether the current contents of the browser will be
// changed by loading the contents of formats // changed by loading the contents of formats
@ -97,23 +99,23 @@ void GuiSendtoDialog::updateContents()
formatLW->addItem(toqstr(*it)); formatLW->addItem(toqstr(*it));
} }
commandCO->addItem(toqstr(controller().getCommand())); commandCO->addItem(toqstr(command_));
} }
void GuiSendtoDialog::applyView() void GuiSendTo::applyView()
{ {
int const line = formatLW->currentRow(); int const line = formatLW->currentRow();
if (line < 0 || line > int(formatLW->count())) if (line < 0 || line > int(formatLW->count()))
return; return;
controller().setFormat(all_formats_[line]); format_ = all_formats_[line];
controller().setCommand(fromqstr(commandCO->currentText())); command_ = trim(fromqstr(commandCO->currentText()));
} }
bool GuiSendtoDialog::isValid() bool GuiSendTo::isValid()
{ {
int const line = formatLW->currentRow(); int const line = formatLW->currentRow();
@ -124,6 +126,74 @@ bool GuiSendtoDialog::isValid()
!commandCO->currentText().isEmpty(); !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<Format const *> GuiSendTo::allFormats() const
{
// What formats can we output natively?
vector<string> 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<Format const *> to;
vector<string>::const_iterator ex_it = exports.begin();
vector<string>::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 frontend
} // namespace lyx } // namespace lyx

View File

@ -4,6 +4,7 @@
* This file is part of LyX, the document processor. * This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Angus Leeming
* \author Jürgen Spitzmüller * \author Jürgen Spitzmüller
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
@ -13,7 +14,6 @@
#define GUISENDTO_H #define GUISENDTO_H
#include "GuiDialog.h" #include "GuiDialog.h"
#include "ControlSendto.h"
#include "ui_SendtoUi.h" #include "ui_SendtoUi.h"
#include <vector> #include <vector>
@ -26,12 +26,12 @@ class Format;
namespace frontend { namespace frontend {
class GuiSendtoDialog : public GuiDialog, public Ui::SendtoUi class GuiSendTo : public GuiDialog, public Ui::SendtoUi, public Controller
{ {
Q_OBJECT Q_OBJECT
public: public:
GuiSendtoDialog(LyXView & lv); GuiSendTo(LyXView & lv);
private Q_SLOTS: private Q_SLOTS:
void changed_adaptor(); void changed_adaptor();
@ -41,7 +41,7 @@ private Q_SLOTS:
private: private:
void closeEvent(QCloseEvent * e); void closeEvent(QCloseEvent * e);
/// parent controller /// parent controller
ControlSendto & controller(); Controller & controller() { return *this; }
/// ///
bool isValid(); bool isValid();
/// Apply from dialog /// Apply from dialog
@ -51,6 +51,25 @@ private:
/// ///
std::vector<Format const *> all_formats_; std::vector<Format const *> 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<Format const *> allFormats() const;
private:
///
Format const * format_;
///
std::string command_;
}; };
} // namespace frontend } // namespace frontend