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"
}
+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);
- if (!p.filename.empty()) {
- try {
- p.filename.enable(buffer.embedded(), &buffer);
- } catch (ExceptionMessage const & message) {
- Alert::error(message.title_, message.details_);
- // do not set parameter if an error happens
- break;
- }
+ InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
+ if (!p.filename.empty())
setParams(p);
- } else
+ else
cur.noUpdate();
break;
}
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 & buffer,
- EmbeddedFiles & files) const
+void InsetGraphics::registerEmbeddedFiles(EmbeddedFileList & files) const
{
- files.registerFile(params().filename, this, buffer);
+ files.registerFile(params().filename, this, buffer());
}
-void InsetGraphics::updateEmbeddedFile(Buffer const & buf,
- EmbeddedFile const & file)
+void InsetGraphics::updateEmbeddedFile(EmbeddedFile const & file)
{
- // when embedding is enabled, change of embedding status leads to actions
- EmbeddedFile temp = file;
- temp.enable(buf.embedded(), &buf);
- // this will not be set if an exception is thorwn in enable()
- params_.filename = temp;
-
- LYXERR(Debug::FILES, "Update InsetGraphic with File "
- << params_.filename.toFilesystemEncoding()
- << ", embedding status: " << params_.filename.embedded()
- << ", enabled: " << params_.filename.enabled());
+ // only properties of an embedded file can be changed here.
+ params_.filename = file;
}
-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!");
- params_.filename.enable(buf.embedded(), &buf);
+ 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())
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(buf.filePath());
+ string const rel_file = params().filename.relFilename(buffer().filePath());
// previewing source code, no file copying or file format conversion
if (runparams.dryrun)
// 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.
// 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,
// 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)