* What advanced features the users want to do?
Implement them in a non latex dependent way, but a logical way.
LyX should translate it to latex or any other fitting format.
- * Add a way to roll the image file into the file format.
* When loading, if the image is not found in the expected place, try
to find it in the clipart, or in the same directory with the image.
* The image choosing dialog could show thumbnails of the image formats
filename.
* Add support for the 'picins' package.
* Add support for the 'picinpar' package.
- * Improve support for 'subfigure' - Allow to set the various options
- that are possible.
*/
/* NOTES:
#include "BufferView.h"
#include "Converter.h"
#include "Cursor.h"
-#include "support/debug.h"
#include "DispatchResult.h"
+#include "EmbeddedFiles.h"
#include "ErrorList.h"
#include "Exporter.h"
#include "Format.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
-#include "support/gettext.h"
#include "LaTeXFeatures.h"
#include "Length.h"
#include "Lexer.h"
#include "Mover.h"
#include "OutputParams.h"
#include "sgml.h"
-#include "EmbeddedFiles.h"
+#include "TocBackend.h"
#include "frontends/alert.h"
#include "support/convert.h"
+#include "support/debug.h"
#include "support/docstream.h"
+#include "support/ExceptionMessage.h"
#include "support/filetools.h"
+#include "support/gettext.h"
#include "support/lyxlib.h"
#include "support/lstrings.h"
#include "support/os.h"
namespace lyx {
+namespace Alert = frontend::Alert;
+
namespace {
/// Find the most suitable image format for images in \p format
}
+void InsetGraphics::setBuffer(Buffer & buffer)
+{
+ if (buffer_) {
+ try {
+ // a file may not be copied successfully when, e.g. buffer_
+ // has already been closed.
+ params_.filename = params_.filename.copyTo(&buffer);
+ } catch (ExceptionMessage const & message) {
+ Alert::error(message.title_, message.details_);
+ // failed to embed
+ params_.filename.setEmbed(false);
+ }
+ }
+ Inset::setBuffer(buffer);
+}
+
+
void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
case LFUN_GRAPHICS_EDIT: {
- Buffer const & buffer = cur.bv().buffer();
- InsetGraphicsParams p;
- InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, p);
- editGraphics(p, buffer);
+ InsetGraphicsParams p = params();
+ if (!cmd.argument().empty())
+ InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
+ editGraphics(p, buffer());
break;
}
case LFUN_INSET_MODIFY: {
- Buffer const & buffer = cur.buffer();
InsetGraphicsParams p;
- InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, p);
+ InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
if (!p.filename.empty())
setParams(p);
else
break;
case LFUN_MOUSE_RELEASE:
- if (!cur.selection())
+ if (!cur.selection() && cmd.button() == mouse_button::button1)
InsetGraphicsMailer(*this).showDialog(&cur.bv());
break;
}
-void InsetGraphics::registerEmbeddedFiles(Buffer const &,
- EmbeddedFiles & files) const
+void InsetGraphics::registerEmbeddedFiles(EmbeddedFileList & files) const
{
- files.registerFile(params().filename.absFilename(),
- false, this);
+ files.registerFile(params().filename, this, buffer());
}
-void InsetGraphics::updateEmbeddedFile(Buffer const & buf,
- EmbeddedFile const & file)
+void InsetGraphics::updateEmbeddedFile(EmbeddedFile const & file)
{
- BOOST_ASSERT(buf.embeddedFiles().enabled());
+ // only properties of an embedded file can be changed here.
params_.filename = file;
- LYXERR(Debug::FILES, "Update InsetGraphic with File "
- << params_.filename.toFilesystemEncoding()
- << ", embedding status: " << params_.filename.embedded());
}
-void InsetGraphics::edit(Cursor & cur, bool)
+void InsetGraphics::edit(Cursor & cur, bool, EntryDirection)
{
InsetGraphicsMailer(*this).showDialog(&cur.bv());
}
}
-void InsetGraphics::write(Buffer const & buf, ostream & os) const
+void InsetGraphics::write(ostream & os) const
{
os << "Graphics\n";
- params().Write(os, buf);
+ params().Write(os, buffer());
}
-void InsetGraphics::read(Buffer const & buf, Lexer & lex)
+void InsetGraphics::read(Lexer & lex)
{
string const token = lex.getString();
if (token == "Graphics")
- readInsetGraphics(lex, buf.filePath());
+ readInsetGraphics(lex, buffer().filePath());
else
LYXERR(Debug::GRAPHICS, "Not a Graphics inset!");
- // InsetGraphics is read, with filename in params_. We do not know if this file actually
- // exists or is embedded so we need to get the 'availableFile' from buf.embeddedFiles()
- if (buf.embeddedFiles().enabled()) {
- EmbeddedFiles::EmbeddedFileList::const_iterator it =
- buf.embeddedFiles().find(params_.filename.toFilesystemEncoding());
- if (it != buf.embeddedFiles().end())
- // using available file, embedded or external, depending on file availability and
- // embedding status.
- params_.filename = *it;
- }
+ params_.filename.enable(buffer().embedded(), &buffer(), false);
graphic_->update(params().as_grfxParams());
}
} // namespace anon
-string const InsetGraphics::prepareFile(Buffer const & buf,
- OutputParams const & runparams) const
+string InsetGraphics::prepareFile(OutputParams const & runparams) const
{
// The following code depends on non-empty filenames
if (params().filename.empty())
return string();
- string const orig_file = params().filename.absFilename();
- string const rel_file = params().filename.relFilename(buf.filePath());
+ string const orig_file = params().filename.availableFile().absFilename();
+ // this is for dryrun and display purposes, do not use latexFilename
+ string const rel_file = params().filename.relFilename(buffer().filePath());
// previewing source code, no file copying or file format conversion
if (runparams.dryrun)
// temp_file will contain the file for LaTeX to act on if, for example,
// we move it to a temp dir or uncompress it.
- FileName temp_file = params().filename;
+ FileName temp_file = params().filename.availableFile();
// The master buffer. This is useful when there are multiple levels
// of include files
- Buffer const * masterBuffer = buf.masterBuffer();
+ Buffer const * masterBuffer = buffer().masterBuffer();
// Return the output name if we are inside a comment or the file does
// not exist.
GraphicsCopyStatus status;
boost::tie(status, temp_file) =
- copyToDirIfNeeded(params().filename, temp_path);
+ copyToDirIfNeeded(params().filename.availableFile(), temp_path);
if (status == FAILURE)
return orig_file;
// the file format from the extension, so we must
// change it.
FileName const new_file = FileName(changeExtension(temp_file.absFilename(), ext));
- if (rename(temp_file, new_file)) {
+ if (temp_file.moveTo(new_file)) {
temp_file = new_file;
output_file = changeExtension(output_file, ext);
source_file = FileName(changeExtension(source_file.absFilename(), ext));
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
ErrorList el;
- if (theConverters().convert(&buf, temp_file, to_file, params().filename,
+ if (theConverters().convert(&buffer(), temp_file, to_file, params().filename,
from, to, el,
Converters::try_default | Converters::try_cache)) {
runparams.exportdata->addExternalFile(tex_format,
}
-int InsetGraphics::latex(Buffer const & buf, odocstream & os,
+int InsetGraphics::latex(odocstream & os,
OutputParams const & runparams) const
{
// If there is no file specified or not existing,
LYXERR(Debug::GRAPHICS, "insetgraphics::latex: Filename = "
<< params().filename.absFilename());
- string const relative_file =
- params().filename.relFilename(buf.filePath());
-
bool const file_exists = !params().filename.empty()
&& params().filename.isReadableFile();
string const message = file_exists ?
// after the actual includegraphics command.
string before;
string after;
- // Do we want subcaptions?
- if (params().subcaption) {
- if (runparams.moving_arg)
- before += "\\protect";
- before += "\\subfigure[" + params().subcaptionText + "]{";
- after = '}';
- }
if (runparams.moving_arg)
before += "\\protect";
// Convert the file if necessary.
// Remove the extension so LaTeX will use whatever is appropriate
// (when there are several versions in different formats)
- latex_str += prepareFile(buf, runparams);
+ latex_str += prepareFile(runparams);
latex_str += '}' + after;
// FIXME UNICODE
os << from_utf8(latex_str);
}
-int InsetGraphics::plaintext(Buffer const & buf, odocstream & os,
- OutputParams const &) const
+int InsetGraphics::plaintext(odocstream & os, OutputParams const &) const
{
// No graphics in ascii output. Possible to use gifscii to convert
// images to ascii approximation.
// FIXME UNICODE
// FIXME: We have no idea what the encoding of the filename is
- docstring const str = bformat(buf.B_("Graphics file: %1$s"),
+ docstring const str = bformat(buffer().B_("Graphics file: %1$s"),
from_utf8(params().filename.absFilename()));
os << '<' << str << '>';
// For explanation on inserting graphics into DocBook checkout:
// http://en.tldp.org/LDP/LDP-Author-Guide/html/inserting-pictures.html
// See also the docbook guide at http://www.docbook.org/
-int InsetGraphics::docbook(Buffer const &, odocstream & os,
+int InsetGraphics::docbook(odocstream & os,
OutputParams const & runparams) const
{
// In DocBook v5.0, the graphic tag will be eliminated from DocBook, will
if (contains(rel_file, "."))
features.require("lyxdot");
}
-
- if (params().subcaption)
- features.require("subfigure");
}
}
+void InsetGraphics::addToToc(ParConstIterator const & cpit) const
+{
+ TocBackend & backend = buffer().tocBackend();
+
+ docstring str = params_.filename.displayName();
+ if (params_.filename.embedded()) {
+ backend.toc("embedded").push_back(TocItem(cpit, 0, str));
+ str += _(" (embedded)");
+ }
+ backend.toc("graphics").push_back(TocItem(cpit, 0, str));
+}
+
+
+docstring InsetGraphics::contextMenu(BufferView const &, int, int) const
+{
+ return from_ascii("context-graphics");
+}
+
+
string const InsetGraphicsMailer::name_("graphics");
InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset)