]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetGraphics.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[features.git] / src / insets / InsetGraphics.cpp
index 8e592b8e3b0b7f533d8f47f5cfc9a73d007d70a6..51a527fa0c02408b3a4bc7e1b480fdb29035901b 100644 (file)
@@ -66,9 +66,10 @@ TODO
 #include "Mover.h"
 #include "OutputParams.h"
 #include "sgml.h"
-#include "EmbeddedFiles.h"
+#include "TocBackend.h"
 
 #include "frontends/alert.h"
+#include "frontends/Application.h"
 
 #include "support/convert.h"
 #include "support/debug.h"
@@ -122,13 +123,40 @@ string findTargetFormat(string const & format, OutputParams const & runparams)
        return format;
 }
 
+
+void readInsetGraphics(Lexer & lex, string const & bufpath,
+       InsetGraphicsParams & params)
+{
+       bool finished = false;
+
+       while (lex.isOK() && !finished) {
+               lex.next();
+
+               string const token = lex.getString();
+               LYXERR(Debug::GRAPHICS, "Token: '" << token << '\'');
+
+               if (token.empty())
+                       continue;
+
+               if (token == "\\end_inset") {
+                       finished = true;
+               } else {
+                       if (!params.Read(lex, token, bufpath))
+                               lyxerr << "Unknown token, " << token << ", skipping."
+                                       << endl;
+               }
+       }
+}
+
 } // namespace anon
 
 
-InsetGraphics::InsetGraphics()
+InsetGraphics::InsetGraphics(Buffer & buf)
        : graphic_label(sgml::uniqueID(from_ascii("graph"))),
          graphic_(new RenderGraphic(this))
-{}
+{
+       Inset::setBuffer(buf);
+}
 
 
 InsetGraphics::InsetGraphics(InsetGraphics const & ig)
@@ -149,7 +177,7 @@ Inset * InsetGraphics::clone() const
 
 InsetGraphics::~InsetGraphics()
 {
-       InsetGraphicsMailer(*this).hideDialog();
+       hideDialogs("graphics", this);
 }
 
 
@@ -157,36 +185,32 @@ 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())
+                       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;
-                       }
+               string2params(to_utf8(cmd.argument()), buffer(), p);
+               if (!p.filename.empty())
                        setParams(p);
-               else
+               else
                        cur.noUpdate();
                break;
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetGraphicsMailer(*this).updateDialog(&cur.bv());
+               cur.bv().updateDialog("graphics", params2string(params(),
+cur.bv().buffer()));
                break;
 
        case LFUN_MOUSE_RELEASE:
-               if (!cur.selection())
-                       InsetGraphicsMailer(*this).showDialog(&cur.bv());
+               if (!cur.selection() && cmd.button() == mouse_button::button1)
+                       cur.bv().showDialog("graphics", params2string(params(),
+cur.bv().buffer()), this);
                break;
 
        default:
@@ -212,30 +236,10 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-void InsetGraphics::registerEmbeddedFiles(EmbeddedFileList & files) const
-{
-       files.registerFile(params().filename, this, buffer());
-}
-
-
-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());
-}
-
-
 void InsetGraphics::edit(Cursor & cur, bool, EntryDirection)
 {
-       InsetGraphicsMailer(*this).showDialog(&cur.bv());
+       cur.bv().showDialog("graphics", params2string(params(),
+               cur.bv().buffer()), this);
 }
 
 
@@ -266,43 +270,14 @@ void InsetGraphics::write(ostream & os) const
 
 void InsetGraphics::read(Lexer & lex)
 {
-       string const token = lex.getString();
-
-       if (token == "Graphics")
-               readInsetGraphics(lex, buffer().filePath());
-       else
-               LYXERR(Debug::GRAPHICS, "Not a Graphics inset!");
-
-       params_.filename.enable(buffer().embedded(), &buffer());
+       lex.setContext("InsetGraphics::read");
+       //lex >> "Graphics";
+       readInsetGraphics(lex, buffer().filePath(), params_);
        graphic_->update(params().as_grfxParams());
 }
 
 
-void InsetGraphics::readInsetGraphics(Lexer & lex, string const & bufpath)
-{
-       bool finished = false;
-
-       while (lex.isOK() && !finished) {
-               lex.next();
-
-               string const token = lex.getString();
-               LYXERR(Debug::GRAPHICS, "Token: '" << token << '\'');
-
-               if (token.empty())
-                       continue;
-
-               if (token == "\\end_inset") {
-                       finished = true;
-               } else {
-                       if (!params_.Read(lex, token, bufpath))
-                               lyxerr << "Unknown token, " << token << ", skipping."
-                                       << endl;
-               }
-       }
-}
-
-
-string const InsetGraphics::createLatexOptions() const
+string InsetGraphics::createLatexOptions() const
 {
        // Calculate the options part of the command, we must do it to a string
        // stream since we might have a trailing comma that we would like to remove
@@ -361,7 +336,7 @@ string const InsetGraphics::createLatexOptions() const
 }
 
 
-docstring const InsetGraphics::toDocbookLength(Length const & len) const
+docstring InsetGraphics::toDocbookLength(Length const & len) const
 {
        odocstringstream result;
        switch (len.unit()) {
@@ -418,7 +393,8 @@ docstring const InsetGraphics::toDocbookLength(Length const & len) const
        return result.str();
 }
 
-docstring const InsetGraphics::createDocBookAttributes() const
+
+docstring InsetGraphics::createDocBookAttributes() const
 {
        // Calculate the options part of the command, we must do it to a string
        // stream since we copied the code from createLatexParams() ;-)
@@ -561,7 +537,7 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
        if (params().filename.empty())
                return string();
 
-       string const orig_file = params().filename.availableFile().absFilename();
+       string const orig_file = params().filename.absFilename();
        // this is for dryrun and display purposes, do not use latexFilename
        string const rel_file = params().filename.relFilename(buffer().filePath());
 
@@ -571,7 +547,7 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
 
        // 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.availableFile();
+       FileName temp_file = params().filename;
 
        // The master buffer. This is useful when there are multiple levels
        // of include files
@@ -591,7 +567,7 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
 
        GraphicsCopyStatus status;
        boost::tie(status, temp_file) =
-                       copyToDirIfNeeded(params().filename.availableFile(), temp_path);
+                       copyToDirIfNeeded(params().filename, temp_path);
 
        if (status == FAILURE)
                return orig_file;
@@ -923,48 +899,42 @@ void InsetGraphics::editGraphics(InsetGraphicsParams const & p,
 }
 
 
-string const InsetGraphicsMailer::name_("graphics");
+void InsetGraphics::addToToc(ParConstIterator const & cpit) const
+{
+       TocBackend & backend = buffer().tocBackend();
 
-InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset)
-       : inset_(inset)
-{}
+       docstring const str = params_.filename.displayName();
+       backend.toc("graphics").push_back(TocItem(cpit, 0, str));
+}
 
 
-string const InsetGraphicsMailer::inset2string(Buffer const & buffer) const
+docstring InsetGraphics::contextMenu(BufferView const &, int, int) const
 {
-       return params2string(inset_.params(), buffer);
+       return from_ascii("context-graphics");
 }
 
 
-void InsetGraphicsMailer::string2params(string const & in,
-                                       Buffer const & buffer,
-                                       InsetGraphicsParams & params)
+void InsetGraphics::string2params(string const & in, Buffer const & buffer,
+       InsetGraphicsParams & params)
 {
-       params = InsetGraphicsParams();
        if (in.empty())
                return;
 
        istringstream data(in);
-       Lexer lex(0,0);
+       Lexer lex;
        lex.setStream(data);
-
-       string name;
-       lex >> name;
-       if (!lex || name != name_)
-               return print_mailer_error("InsetGraphicsMailer", in, 1, name_);
-
-       InsetGraphics inset;
-       inset.readInsetGraphics(lex, buffer.filePath());
-       params = inset.params();
+       lex.setContext("InsetGraphics::string2params");
+       lex >> "graphics";
+       params = InsetGraphicsParams();
+       readInsetGraphics(lex, buffer.filePath(), params);
 }
 
 
-string const
-InsetGraphicsMailer::params2string(InsetGraphicsParams const & params,
-                                  Buffer const & buffer)
+string InsetGraphics::params2string(InsetGraphicsParams const & params,
+       Buffer const & buffer)
 {
        ostringstream data;
-       data << name_ << ' ';
+       data << "graphics" << ' ';
        params.Write(data, buffer);
        data << "\\end_inset\n";
        return data.str();