]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetGraphics.cpp
Stupid bug fix.
[lyx.git] / src / insets / InsetGraphics.cpp
index 51a527fa0c02408b3a4bc7e1b480fdb29035901b..2bd0cae1118a9aff97be69506576ac5a0dda2480 100644 (file)
@@ -59,6 +59,7 @@ TODO
 #include "Format.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "InsetIterator.h"
 #include "LaTeXFeatures.h"
 #include "Length.h"
 #include "Lexer.h"
@@ -142,8 +143,10 @@ void readInsetGraphics(Lexer & lex, string const & bufpath,
                        finished = true;
                } else {
                        if (!params.Read(lex, token, bufpath))
-                               lyxerr << "Unknown token, " << token << ", skipping."
-                                       << endl;
+                               lyxerr << "Unknown token, "
+                                      << token
+                                      << ", skipping."
+                                      << endl;
                }
        }
 }
@@ -184,7 +187,7 @@ InsetGraphics::~InsetGraphics()
 void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
-       case LFUN_GRAPHICS_EDIT: {
+       case LFUN_INSET_EDIT: {
                InsetGraphicsParams p = params();
                if (!cmd.argument().empty())
                        string2params(to_utf8(cmd.argument()), buffer(), p);
@@ -204,13 +207,13 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_DIALOG_UPDATE:
                cur.bv().updateDialog("graphics", params2string(params(),
-cur.bv().buffer()));
+                                     cur.bv().buffer()));
                break;
 
        case LFUN_MOUSE_RELEASE:
                if (!cur.selection() && cmd.button() == mouse_button::button1)
                        cur.bv().showDialog("graphics", params2string(params(),
-cur.bv().buffer()), this);
+                                           cur.bv().buffer()), this);
                break;
 
        default:
@@ -224,10 +227,10 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
                FuncStatus & flag) const
 {
        switch (cmd.action) {
-       case LFUN_GRAPHICS_EDIT:
+       case LFUN_INSET_EDIT:
        case LFUN_INSET_MODIFY:
        case LFUN_INSET_DIALOG_UPDATE:
-               flag.enabled(true);
+               flag.setEnabled(true);
                return true;
 
        default:
@@ -601,7 +604,8 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
                        // noUnzip parameter meaningless.
                        LYXERR(Debug::GRAPHICS, "\tpass zipped file to LaTeX.");
 
-                       FileName const bb_orig_file = FileName(changeExtension(orig_file, "bb"));
+                       FileName const bb_orig_file =
+                               FileName(changeExtension(orig_file, "bb"));
                        if (runparams.nice) {
                                runparams.exportdata->addExternalFile(tex_format,
                                                bb_orig_file,
@@ -609,7 +613,8 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
                        } else {
                                // LaTeX needs the bounding box file in the
                                // tmp dir
-                               FileName bb_file = FileName(changeExtension(temp_file.absFilename(), "bb"));
+                               FileName bb_file =
+                                       FileName(changeExtension(temp_file.absFilename(), "bb"));
                                boost::tie(status, bb_file) =
                                        copyFileIfNeeded(bb_orig_file, bb_file);
                                if (status == FAILURE)
@@ -661,11 +666,13 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
                        // The LaTeX compiler will not be able to determine
                        // the file format from the extension, so we must
                        // change it.
-                       FileName const new_file = FileName(changeExtension(temp_file.absFilename(), ext));
+                       FileName const new_file = 
+                               FileName(changeExtension(temp_file.absFilename(), ext));
                        if (temp_file.moveTo(new_file)) {
                                temp_file = new_file;
                                output_file = changeExtension(output_file, ext);
-                               source_file = FileName(changeExtension(source_file.absFilename(), ext));
+                               source_file = 
+                                       FileName(changeExtension(source_file.absFilename(), ext));
                        } else {
                                LYXERR(Debug::GRAPHICS, "Could not rename file `"
                                        << temp_file << "' to `" << new_file << "'.");
@@ -861,7 +868,8 @@ void InsetGraphics::validate(LaTeXFeatures & features) const
 
        if (features.runparams().nice) {
                Buffer const * masterBuffer = features.buffer().masterBuffer();
-               string const rel_file = removeExtension(params().filename.relFilename(masterBuffer->filePath()));
+               string const rel_file = removeExtension(
+                       params().filename.relFilename(masterBuffer->filePath()));
                if (contains(rel_file, "."))
                        features.require("lyxdot");
        }
@@ -899,11 +907,12 @@ void InsetGraphics::editGraphics(InsetGraphicsParams const & p,
 }
 
 
-void InsetGraphics::addToToc(ParConstIterator const & cpit) const
+void InsetGraphics::addToToc(DocIterator const & cpit)
 {
        TocBackend & backend = buffer().tocBackend();
 
-       docstring const str = params_.filename.displayName();
+       //FIXME UNICODE
+       docstring const str = from_utf8(params_.filename.onlyFileName());
        backend.toc("graphics").push_back(TocItem(cpit, 0, str));
 }
 
@@ -940,5 +949,77 @@ string InsetGraphics::params2string(InsetGraphicsParams const & params,
        return data.str();
 }
 
+namespace graphics {
+
+void getGraphicsGroups(Buffer const & b, set<string> & ids)
+{
+       Inset & inset = b.inset();
+       InsetIterator it  = inset_iterator_begin(inset);
+       InsetIterator const end = inset_iterator_end(inset);
+       for (; it != end; ++it)
+               if (it->lyxCode() == GRAPHICS_CODE) {
+                       InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
+                       InsetGraphicsParams inspar = ins.getParams();
+                       if (!inspar.groupId.empty())
+                               ids.insert(inspar.groupId);
+               }
+}
+
+
+string getGroupParams(Buffer const & b, string const & groupId)
+{
+       if (groupId.empty())
+               return string();
+       Inset & inset = b.inset();
+       InsetIterator it  = inset_iterator_begin(inset);
+       InsetIterator const end = inset_iterator_end(inset);
+       for (; it != end; ++it)
+               if (it->lyxCode() == GRAPHICS_CODE) {
+                       InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
+                       InsetGraphicsParams inspar = ins.getParams();
+                       if (inspar.groupId == groupId) {
+                               InsetGraphicsParams tmp = inspar;
+                               tmp.filename.erase();
+                               return InsetGraphics::params2string(tmp, b);
+                       }
+               }
+       return string();
+}
+
+
+void unifyGraphicsGroups(Buffer const & b, string const & argument)
+{
+       InsetGraphicsParams params;
+       InsetGraphics::string2params(argument, b, params);
+
+       Inset & inset = b.inset();
+       InsetIterator it  = inset_iterator_begin(inset);
+       InsetIterator const end = inset_iterator_end(inset);
+       for (; it != end; ++it) {
+               if (it->lyxCode() == GRAPHICS_CODE) {
+                       InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
+                       InsetGraphicsParams inspar = ins.getParams();
+                       if (params.groupId == inspar.groupId) {
+                               params.filename = inspar.filename;
+                               ins.setParams(params);
+                       }
+               }
+       }
+
+}
+
+
+InsetGraphics * getCurrentGraphicsInset(Cursor const & cur)
+{
+       Inset * instmp = &cur.inset();
+       if (instmp->lyxCode() != GRAPHICS_CODE)
+               instmp = cur.nextInset();
+       if (!instmp || instmp->lyxCode() != GRAPHICS_CODE)
+               return 0;
+
+       return static_cast<InsetGraphics *>(instmp);
+}
+
+} // namespace graphics
 
 } // namespace lyx