Embedding: add embedding support for InsetInclude. (params["embed"] is added)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22441 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2008-01-08 16:35:43 +00:00
parent 569a82cb86
commit c81fd7337d
6 changed files with 70 additions and 39 deletions

View File

@ -286,6 +286,12 @@ bool EmbeddedFile::isReadableFile() const
}
unsigned long EmbeddedFile::checksum() const
{
return availableFile().checksum();
}
bool operator==(EmbeddedFile const & lhs, EmbeddedFile const & rhs)
{
return lhs.absFilename() == rhs.absFilename()

View File

@ -144,6 +144,8 @@ public:
/// Check readability of availableFile
bool isReadableFile() const;
/// Calculate checksum of availableFile
unsigned long checksum() const;
private:
/// filename in zip file

View File

@ -60,6 +60,7 @@ GuiInclude::GuiInclude(GuiView & lv)
this, SLOT(change_adaptor()));
connect(editPB, SIGNAL(clicked()), this, SLOT(edit()));
connect(browsePB, SIGNAL(clicked()), this, SLOT(browse()));
connect(embedCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
connect(typeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
connect(previewCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
@ -178,6 +179,7 @@ void GuiInclude::typeChanged(int v)
void GuiInclude::updateContents()
{
filenameED->setText(toqstr(params_["filename"]));
embedCB->setCheckState(params_["embed"] == _("true") ? Qt::Checked : Qt::Unchecked);
visiblespaceCB->setChecked(false);
visiblespaceCB->setEnabled(false);
@ -247,6 +249,7 @@ void GuiInclude::updateContents()
void GuiInclude::applyView()
{
params_["filename"] = from_utf8(internal_path(fromqstr(filenameED->text())));
params_["embed"] = embedCB->checkState() == Qt::Checked ? _("true") : _("false");
params_.preview(previewCB->isChecked());
int const item = typeCO->currentIndex();

View File

@ -44,6 +44,7 @@
#include "insets/InsetListingsParams.h"
#include "support/docstream.h"
#include "support/ExceptionMessage.h"
#include "support/FileNameList.h"
#include "support/filetools.h"
#include "support/lstrings.h" // contains
@ -116,6 +117,34 @@ bool isInputOrInclude(InsetCommandParams const & params)
return t == INPUT || t == INCLUDE;
}
FileName const masterFileName(Buffer const & buffer)
{
return buffer.masterBuffer()->fileName();
}
void add_preview(RenderMonitoredPreview &, InsetInclude const &, Buffer const &);
string const parentFilename(Buffer const & buffer)
{
return buffer.absFileName();
}
EmbeddedFile const includedFilename(Buffer const & buffer,
InsetCommandParams const & params)
{
// it is not a good idea to create this EmbeddedFile object
// each time, but there seems to be no easy way around.
EmbeddedFile file(to_utf8(params["filename"]),
onlyPath(parentFilename(buffer)));
file.setEmbed(params["embed"] == _("true") ? true : false);
file.enable(buffer.embeddedFiles().enabled(), &buffer);
return file;
}
} // namespace anon
@ -140,9 +169,9 @@ CommandInfo const * InsetInclude::findInfo(string const & /* cmdName */)
// FIXME
// This is only correct for the case of listings, but it'll do for now.
// In the other cases, this second parameter should just be empty.
static const char * const paramnames[] = {"filename", "lstparams", ""};
static const bool isoptional[] = {false, true};
static const CommandInfo info = {2, paramnames, isoptional};
static const char * const paramnames[] = {"filename", "embed", "lstparams", ""};
static const bool isoptional[] = {false, false, true};
static const CommandInfo info = {3, paramnames, isoptional};
return &info;
}
@ -172,6 +201,14 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
from_utf8(par_new.getParamValue("label")),
REF_CODE);
}
try {
// test parameter
includedFilename(cur.buffer(), p);
} catch (ExceptionMessage const & message) {
Alert::error(message.title_, message.details_);
// do not set parameter if an error happens
break;
}
set(p, cur.buffer());
cur.buffer().updateBibfilesCache();
} else
@ -187,33 +224,6 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
}
namespace {
FileName const masterFileName(Buffer const & buffer)
{
return buffer.masterBuffer()->fileName();
}
string const parentFilename(Buffer const & buffer)
{
return buffer.absFileName();
}
FileName const includedFilename(Buffer const & buffer,
InsetCommandParams const & params)
{
return makeAbsPath(to_utf8(params["filename"]),
onlyPath(parentFilename(buffer)));
}
void add_preview(RenderMonitoredPreview &, InsetInclude const &, Buffer const &);
} // namespace anon
void InsetInclude::set(InsetCommandParams const & p, Buffer const & buffer)
{
setParams(p);
@ -264,6 +274,8 @@ docstring const InsetInclude::getScreenLabel(Buffer const & buf) const
else
temp += from_utf8(onlyFilename(to_utf8(params()["filename"])));
if (params()["embed"] == _("true"))
temp += _(" (embedded)");
return temp;
}
@ -362,7 +374,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
if (incfile.empty())
return 0;
FileName const included_file = includedFilename(buffer, params());
FileName const included_file = includedFilename(buffer, params()).availableFile();
//Check we're not trying to include ourselves.
//FIXME RECURSIVE INCLUDE
@ -615,7 +627,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
Buffer const & buffer = features.buffer();
string const included_file = includedFilename(buffer, params()).absFilename();
string const included_file = includedFilename(buffer, params()).availableFile().absFilename();
if (isLyXFilename(included_file))
writefile = changeExtension(included_file, ".sgml");
@ -889,12 +901,18 @@ void InsetInclude::updateLabels(Buffer const & buffer, ParIterator const &)
void InsetInclude::registerEmbeddedFiles(Buffer const & buffer,
EmbeddedFiles & files) const
{
// include and input are temprarily not considered.
/*
if (isVerbatim(params()) || isListings(params()))
files.registerFile(includedFilename(buffer, params()).absFilename(),
false, this);
*/
files.registerFile(includedFilename(buffer, params()), this);
}
void InsetInclude::updateEmbeddedFile(Buffer const & buf,
EmbeddedFile const & file)
{
InsetCommandParams p = params();
p["filename"] = from_utf8(file.outputFilename());
p["embedded"] = file.embedded() ? _("true") : _("false");
set(p, buf);
}
} // namespace lyx

View File

@ -98,6 +98,8 @@ public:
/// child document can be embedded
void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const;
///
void updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & file);
///
static CommandInfo const * findInfo(std::string const &);
///
static std::string defaultCommand() { return "include"; };

View File

@ -75,7 +75,7 @@ public:
/// returns time of last write access
std::time_t lastModified() const;
/// generates a checksum of a file
unsigned long checksum() const;
virtual unsigned long checksum() const;
/// return true when file is readable but not writabel
bool isReadOnly() const;
/// return true when it names a directory