]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetGraphics.cpp
Move isMultiCell() to Cursor, and use it.
[lyx.git] / src / insets / InsetGraphics.cpp
index 39e5fb5875494a7a6409e0c5eb49eedde6a1dba0..2bd0cae1118a9aff97be69506576ac5a0dda2480 100644 (file)
@@ -15,7 +15,6 @@ TODO
     * 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
@@ -23,8 +22,6 @@ TODO
       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:
@@ -56,14 +53,13 @@ TODO
 #include "BufferView.h"
 #include "Converter.h"
 #include "Cursor.h"
-#include "support/debug.h"
 #include "DispatchResult.h"
 #include "ErrorList.h"
 #include "Exporter.h"
 #include "Format.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "support/gettext.h"
+#include "InsetIterator.h"
 #include "LaTeXFeatures.h"
 #include "Length.h"
 #include "Lexer.h"
@@ -71,13 +67,17 @@ 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"
 #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"
@@ -90,28 +90,11 @@ TODO
 #include <sstream>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
-using support::bformat;
-using support::changeExtension;
-using support::compare_timestamps;
-using support::contains;
-using support::DocFileName;
-using support::FileName;
-using support::float_equal;
-using support::getExtension;
-using support::isValidLaTeXFilename;
-using support::latex_path;
-using support::onlyFilename;
-using support::removeExtension;
-using support::rtrim;
-using support::subst;
-using support::suffixIs;
-using support::Systemcall;
-using support::unzipFile;
-using support::unzippedFileName;
-
+namespace Alert = frontend::Alert;
 
 namespace {
 
@@ -141,13 +124,42 @@ 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)
@@ -168,25 +180,24 @@ Inset * InsetGraphics::clone() const
 
 InsetGraphics::~InsetGraphics()
 {
-       InsetGraphicsMailer(*this).hideDialog();
+       hideDialogs("graphics", this);
 }
 
 
 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);
+       case LFUN_INSET_EDIT: {
+               InsetGraphicsParams p = params();
+               if (!cmd.argument().empty())
+                       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);
+               string2params(to_utf8(cmd.argument()), buffer(), p);
                if (!p.filename.empty())
                        setParams(p);
                else
@@ -195,12 +206,14 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        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:
@@ -214,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:
@@ -226,28 +239,10 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-void InsetGraphics::registerEmbeddedFiles(Buffer const &, 
-       EmbeddedFiles & files) const
-{
-       files.registerFile(params().filename.absFilename(), 
-               false, this);
-}
-
-
-void InsetGraphics::updateEmbeddedFile(Buffer const & buf,
-       EmbeddedFile const & file)
-{
-       BOOST_ASSERT(buf.embeddedFiles().enabled());
-       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());
+       cur.bv().showDialog("graphics", params2string(params(),
+               cur.bv().buffer()), this);
 }
 
 
@@ -269,61 +264,23 @@ Inset::EDITABLE InsetGraphics::editable() const
 }
 
 
-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());
-       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;
-       }
+       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."
-                                       << std::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
@@ -382,7 +339,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()) {
@@ -439,7 +396,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() ;-)
@@ -487,7 +445,7 @@ enum GraphicsCopyStatus {
 };
 
 
-std::pair<GraphicsCopyStatus, FileName> const
+pair<GraphicsCopyStatus, FileName> const
 copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
 {
        LYXERR(Debug::FILES, "Comparing " << file_in << " and " << file_out);
@@ -496,32 +454,30 @@ copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
 
        if (checksum_in == checksum_out)
                // Nothing to do...
-               return std::make_pair(IDENTICAL_CONTENTS, file_out);
+               return make_pair(IDENTICAL_CONTENTS, file_out);
 
        Mover const & mover = getMover(formats.getFormatFromFile(file_in));
        bool const success = mover.copy(file_in, file_out);
        if (!success) {
                // FIXME UNICODE
                LYXERR(Debug::GRAPHICS,
-                       to_utf8(support::bformat(_("Could not copy the file\n%1$s\n"
+                       to_utf8(bformat(_("Could not copy the file\n%1$s\n"
                                                           "into the temporary directory."),
                                                from_utf8(file_in.absFilename()))));
        }
 
        GraphicsCopyStatus status = success ? SUCCESS : FAILURE;
-       return std::make_pair(status, file_out);
+       return make_pair(status, file_out);
 }
 
 
-std::pair<GraphicsCopyStatus, FileName> const
+pair<GraphicsCopyStatus, FileName> const
 copyToDirIfNeeded(DocFileName const & file, string const & dir)
 {
-       using support::rtrim;
-
        string const file_in = file.absFilename();
-       string const only_path = support::onlyPath(file_in);
-       if (rtrim(support::onlyPath(file_in) , "/") == rtrim(dir, "/"))
-               return std::make_pair(IDENTICAL_PATHS, file_in);
+       string const only_path = onlyPath(file_in);
+       if (rtrim(onlyPath(file_in) , "/") == rtrim(dir, "/"))
+               return make_pair(IDENTICAL_PATHS, file_in);
 
        string mangled = file.mangledFilename();
        if (file.isZipped()) {
@@ -535,7 +491,7 @@ copyToDirIfNeeded(DocFileName const & file, string const & dir)
                string::size_type const ext_len = file_in.length() - base.length();
                mangled[mangled.length() - ext_len] = '.';
        }
-       FileName const file_out(support::makeAbsPath(mangled, dir));
+       FileName const file_out(makeAbsPath(mangled, dir));
 
        return copyFileIfNeeded(file, file_out);
 }
@@ -554,13 +510,10 @@ string const stripExtensionIfPossible(string const & file, bool nice)
        // dots with a macro whose definition is just a dot ;-)
        // The automatic format selection does not work if the file
        // name is escaped.
-       string const latex_name = latex_path(file,
-                                            support::EXCLUDE_EXTENSION);
+       string const latex_name = latex_path(file, EXCLUDE_EXTENSION);
        if (!nice || contains(latex_name, '"'))
                return latex_name;
-       return latex_path(removeExtension(file),
-                         support::PROTECT_EXTENSION,
-                         support::ESCAPE_DOTS);
+       return latex_path(removeExtension(file), PROTECT_EXTENSION, ESCAPE_DOTS);
 }
 
 
@@ -575,21 +528,21 @@ string const stripExtensionIfPossible(string const & file, string const & to, bo
            (to_format == "eps" && file_format ==  "ps") ||
            (to_format ==  "ps" && file_format == "eps"))
                return stripExtensionIfPossible(file, nice);
-       return latex_path(file, support::EXCLUDE_EXTENSION);
+       return latex_path(file, EXCLUDE_EXTENSION);
 }
 
 } // 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());
+       // 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)
@@ -601,7 +554,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
 
        // 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.
@@ -651,7 +604,8 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
                        // 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,
@@ -659,7 +613,8 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
                        } 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)
@@ -673,8 +628,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
                                        source_file, output_file);
                        // We can't strip the extension, because we don't know
                        // the unzipped file format
-                       return latex_path(output_file,
-                                         support::EXCLUDE_EXTENSION);
+                       return latex_path(output_file, EXCLUDE_EXTENSION);
                }
 
                FileName const unzipped_temp_file =
@@ -712,11 +666,13 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
                        // 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));
-                       if (support::rename(temp_file, new_file)) {
+                       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 << "'.");
@@ -754,7 +710,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
 
        // 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,
@@ -767,7 +723,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
 }
 
 
-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,
@@ -775,9 +731,6 @@ int InsetGraphics::latex(Buffer const & buf, odocstream & os,
        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 ?
@@ -792,13 +745,6 @@ int InsetGraphics::latex(Buffer const & buf, odocstream & os,
        // 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";
@@ -821,19 +767,18 @@ int InsetGraphics::latex(Buffer const & buf, odocstream & os,
        // 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);
 
        LYXERR(Debug::GRAPHICS, "InsetGraphics::latex outputting:\n" << latex_str);
        // Return how many newlines we issued.
-       return int(std::count(latex_str.begin(), latex_str.end(),'\n'));
+       return int(count(latex_str.begin(), latex_str.end(),'\n'));
 }
 
 
-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.
@@ -843,7 +788,7 @@ int InsetGraphics::plaintext(Buffer const & buf, odocstream & os,
        // 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 << '>';
 
@@ -857,7 +802,7 @@ static int writeImageObject(char const * format, odocstream & os,
 {
        if (runparams.flavor != OutputParams::XML)
                os << "<![ %output.print." << format
-                        << "; [" << std::endl;
+                        << "; [" << endl;
 
        os <<"<imageobject><imagedata fileref=\"&"
                 << graphic_label
@@ -874,7 +819,7 @@ static int writeImageObject(char const * format, odocstream & os,
        os << "</imageobject>";
 
        if (runparams.flavor != OutputParams::XML)
-               os << std::endl << "]]>" ;
+               os << endl << "]]>" ;
 
        return runparams.flavor == OutputParams::XML ? 0 : 2;
 }
@@ -883,7 +828,7 @@ static int writeImageObject(char const * format, odocstream & os,
 // 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
@@ -923,13 +868,11 @@ 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");
        }
-
-       if (params().subcaption)
-               features.require("subfigure");
 }
 
 
@@ -964,52 +907,119 @@ void InsetGraphics::editGraphics(InsetGraphicsParams const & p,
 }
 
 
-string const InsetGraphicsMailer::name_("graphics");
+void InsetGraphics::addToToc(DocIterator const & cpit)
+{
+       TocBackend & backend = buffer().tocBackend();
 
-InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset)
-       : inset_(inset)
-{}
+       //FIXME UNICODE
+       docstring const str = from_utf8(params_.filename.onlyFileName());
+       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();
 }
 
+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