#include "Converter.h"
#include "Cursor.h"
#include "DispatchResult.h"
+#include "EmbeddedFiles.h"
#include "ErrorList.h"
#include "Exporter.h"
#include "Format.h"
#include "Mover.h"
#include "OutputParams.h"
#include "sgml.h"
-#include "EmbeddedFiles.h"
+#include "TocBackend.h"
#include "frontends/alert.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: {
- InsetGraphicsParams p;
- InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
+ InsetGraphicsParams p = params();
+ if (!cmd.argument().empty())
+ InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
editGraphics(p, buffer());
break;
}
case LFUN_INSET_MODIFY: {
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;
- }
+ 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::updateEmbeddedFile(EmbeddedFile const & file)
{
- // when embedding is enabled, change of embedding status leads to actions
- EmbeddedFile temp = file;
- temp.enable(buffer().embedded(), &buffer());
- // 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;
}
else
LYXERR(Debug::GRAPHICS, "Not a Graphics inset!");
- params_.filename.enable(buffer().embedded(), &buffer());
+ params_.filename.enable(buffer().embedded(), &buffer(), false);
graphic_->update(params().as_grfxParams());
}
}
+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)