mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Embedding: add embedding support for InsetExternal. (params["embed"] is added)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22442 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c81fd7337d
commit
09a6f725d0
@ -110,6 +110,8 @@ GuiExternal::GuiExternal(GuiView & lv)
|
||||
this, SLOT(change_adaptor()));
|
||||
connect(browsePB, SIGNAL(clicked()),
|
||||
this, SLOT(browseClicked()));
|
||||
connect(embedCB, SIGNAL(toggled(bool)),
|
||||
this, SLOT(change_adaptor()));
|
||||
connect(editPB, SIGNAL(clicked()),
|
||||
this, SLOT(editClicked()));
|
||||
connect(externalCO, SIGNAL(activated(QString)),
|
||||
@ -557,6 +559,7 @@ void GuiExternal::updateContents()
|
||||
string const name =
|
||||
params_.filename.outputFilename(bufferFilepath());
|
||||
fileED->setText(toqstr(name));
|
||||
embedCB->setCheckState(params_.filename.embedded() ? Qt::Checked : Qt::Unchecked);
|
||||
|
||||
externalCO->setCurrentIndex(getTemplateNumber(params_.templatename()));
|
||||
updateTemplate();
|
||||
@ -639,6 +642,7 @@ void GuiExternal::updateTemplate()
|
||||
void GuiExternal::applyView()
|
||||
{
|
||||
params_.filename.set(fromqstr(fileED->text()), bufferFilepath());
|
||||
params_.filename.setEmbed(embedCB->checkState() == Qt::Checked);
|
||||
|
||||
params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName);
|
||||
|
||||
|
@ -50,7 +50,7 @@ Template const * getTemplatePtr(InsetExternalParams const & params)
|
||||
|
||||
void editExternal(InsetExternalParams const & params, Buffer const & buffer)
|
||||
{
|
||||
formats.edit(buffer, params.filename,
|
||||
formats.edit(buffer, params.filename.availableFile(),
|
||||
formats.getFormatFromFile(params.filename));
|
||||
}
|
||||
|
||||
@ -254,7 +254,7 @@ void updateExternal(InsetExternalParams const & params,
|
||||
|
||||
if (from_checksum != temp_checksum) {
|
||||
Mover const & mover = getMover(from_format);
|
||||
if (!mover.copy(params.filename, temp_file)) {
|
||||
if (!mover.copy(params.filename.availableFile(), temp_file)) {
|
||||
LYXERR(Debug::EXTERNAL, "external::updateExternal. "
|
||||
<< "Unable to copy " << params.filename << " to " << temp_file);
|
||||
return; // FAILURE
|
||||
@ -310,7 +310,7 @@ void updateExternal(InsetExternalParams const & params,
|
||||
ErrorList el;
|
||||
bool const success =
|
||||
theConverters().convert(&buffer, temp_file, abs_to_file,
|
||||
params.filename, from_format, to_format, el,
|
||||
params.filename.availableFile(), from_format, to_format, el,
|
||||
Converters::try_default | Converters::try_cache);
|
||||
|
||||
if (!success) {
|
||||
|
@ -31,8 +31,11 @@
|
||||
#include "MetricsInfo.h"
|
||||
#include "OutputParams.h"
|
||||
|
||||
#include "frontends/alert.h"
|
||||
|
||||
#include "graphics/PreviewLoader.h"
|
||||
|
||||
#include "support/ExceptionMessage.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxlib.h"
|
||||
@ -59,6 +62,8 @@ string defaultTemplateName;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
namespace Alert = frontend::Alert;
|
||||
|
||||
extern bool use_gui;
|
||||
|
||||
namespace external {
|
||||
@ -182,9 +187,10 @@ void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
|
||||
os << "External\n"
|
||||
<< "\ttemplate " << templatename() << '\n';
|
||||
|
||||
if (!filename.empty())
|
||||
if (!filename.empty()) {
|
||||
os << "\tfilename " << filename.outputFilename(buffer.filePath()) << '\n';
|
||||
|
||||
os << "\tembed " << (filename.embedded() ? "true" : "false") << '\n';
|
||||
}
|
||||
if (display != defaultDisplayType)
|
||||
os << "\tdisplay "
|
||||
<< external::displayTranslator().find(display)
|
||||
@ -241,6 +247,7 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
|
||||
enum ExternalTags {
|
||||
EX_TEMPLATE = 1,
|
||||
EX_FILENAME,
|
||||
EX_EMBED,
|
||||
EX_DISPLAY,
|
||||
EX_LYXSCALE,
|
||||
EX_DRAFT,
|
||||
@ -264,6 +271,7 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
|
||||
{ "draft", EX_DRAFT},
|
||||
{ "extra", EX_EXTRA },
|
||||
{ "filename", EX_FILENAME},
|
||||
{ "embed", EX_EMBED},
|
||||
{ "height", EX_HEIGHT },
|
||||
{ "keepAspectRatio", EX_KEEPASPECTRATIO },
|
||||
{ "lyxscale", EX_LYXSCALE},
|
||||
@ -292,6 +300,12 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
|
||||
filename.set(name, buffer.filePath());
|
||||
break;
|
||||
}
|
||||
|
||||
case EX_EMBED: {
|
||||
lex.next();
|
||||
filename.setEmbed(lex.getBool());
|
||||
break;
|
||||
}
|
||||
|
||||
case EX_DISPLAY: {
|
||||
lex.next();
|
||||
@ -437,6 +451,15 @@ void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
Buffer const & buffer = cur.buffer();
|
||||
InsetExternalParams p;
|
||||
InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer, p);
|
||||
if (!p.filename.empty()) {
|
||||
try {
|
||||
p.filename.enable(buffer.embeddedFiles().enabled(), &buffer);
|
||||
} catch (ExceptionMessage const & message) {
|
||||
Alert::error(message.title_, message.details_);
|
||||
// do not set parameter if an error happens
|
||||
break;
|
||||
}
|
||||
}
|
||||
setParams(p, buffer);
|
||||
break;
|
||||
}
|
||||
@ -476,8 +499,18 @@ bool InsetExternal::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
void InsetExternal::registerEmbeddedFiles(Buffer const &,
|
||||
EmbeddedFiles & files) const
|
||||
{
|
||||
// temporarily disable embedding for this inset
|
||||
/* files.registerFile(params_.filename, this); */
|
||||
files.registerFile(params_.filename, this);
|
||||
}
|
||||
|
||||
|
||||
void InsetExternal::updateEmbeddedFile(Buffer const & buf,
|
||||
EmbeddedFile const & file)
|
||||
{
|
||||
// when embedding is enabled, change of embedding status leads to actions
|
||||
EmbeddedFile temp = file;
|
||||
temp.enable(buf.embeddedFiles().enabled(), &buf);
|
||||
// this will not be set if an exception is thorwn in enable()
|
||||
params_.filename = temp;
|
||||
}
|
||||
|
||||
|
||||
@ -532,7 +565,8 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams)
|
||||
{
|
||||
graphics::Params gparams;
|
||||
|
||||
gparams.filename = eparams.filename;
|
||||
gparams.filename = eparams.filename.availableFile();
|
||||
gparams.icon = eparams.filename.embedded() ? "pin.png" : "";
|
||||
gparams.scale = eparams.lyxscale;
|
||||
if (eparams.clipdata.clip)
|
||||
gparams.bb = eparams.clipdata.bbox;
|
||||
@ -671,8 +705,11 @@ void InsetExternal::write(Buffer const & buffer, ostream & os) const
|
||||
void InsetExternal::read(Buffer const & buffer, Lexer & lex)
|
||||
{
|
||||
InsetExternalParams params;
|
||||
if (params.read(buffer, lex))
|
||||
if (params.read(buffer, lex)) {
|
||||
// exception handling is not needed as long as embedded files are in place.
|
||||
params.filename.enable(buffer.embeddedFiles().enabled(), & buffer);
|
||||
setParams(params, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,7 +80,7 @@ public:
|
||||
std::string const & templatename() const { return templatename_; }
|
||||
|
||||
/// The external file.
|
||||
support::DocFileName filename;
|
||||
EmbeddedFile filename;
|
||||
/// How the inset is to be displayed by LyX.
|
||||
external::DisplayType display;
|
||||
/// The scale of the displayed graphic (if shown).
|
||||
@ -150,6 +150,8 @@ public:
|
||||
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
|
||||
/// external file can be embedded
|
||||
void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const;
|
||||
///
|
||||
void updateEmbeddedFile(Buffer const &, EmbeddedFile const &);
|
||||
|
||||
protected:
|
||||
InsetExternal(InsetExternal const &);
|
||||
|
Loading…
Reference in New Issue
Block a user