]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinclude.C
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[lyx.git] / src / insets / insetinclude.C
index f395ec700a2366a0d0b5691b524a804bdcf7a12f..36d745ffaab50d50390a14dbced97131035e6018 100644 (file)
@@ -217,7 +217,7 @@ string const parentFilename(Buffer const & buffer)
 }
 
 
-string const includedFilename(Buffer const & buffer,
+FileName const includedFilename(Buffer const & buffer,
                              InsetCommandParams const & params)
 {
        return makeAbsPath(to_utf8(params["filename"]),
@@ -318,8 +318,7 @@ docstring const InsetInclude::getScreenLabel(Buffer const &) const
        if (params_["filename"].empty())
                temp += "???";
        else
-               // FIXME: We don't know the encoding of the filename
-               temp += from_ascii(onlyFilename(to_utf8(params_["filename"])));
+               temp += from_utf8(onlyFilename(to_utf8(params_["filename"])));
 
        return temp;
 }
@@ -333,7 +332,7 @@ Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params
        if (isVerbatim(params))
                return 0;
 
-       string const included_file = includedFilename(buffer, params);
+       string const included_file = includedFilename(buffer, params).absFilename();
        if (!isLyXFilename(included_file))
                return 0;
 
@@ -347,16 +346,16 @@ bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
        if (isVerbatim(params))
                return false;
 
-       string const included_file = includedFilename(buffer, params);
-       if (!isLyXFilename(included_file))
+       FileName const included_file = includedFilename(buffer, params);
+       if (!isLyXFilename(included_file.absFilename()))
                return false;
 
-       Buffer * buf = theBufferList().getBuffer(included_file);
+       Buffer * buf = theBufferList().getBuffer(included_file.absFilename());
        if (!buf) {
                // the readonly flag can/will be wrong, not anymore I think.
-               if (!fs::exists(included_file))
+               if (!fs::exists(included_file.toFilesystemEncoding()))
                        return false;
-               buf = theBufferList().newBuffer(included_file);
+               buf = theBufferList().newBuffer(included_file.absFilename());
                if (!loadLyXFile(buf, included_file))
                        return false;
        }
@@ -427,7 +426,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
 // argument. Should we set it to string(), or should makeLaTeXFile
 // make use of it somehow? (JMarc 20031002)
 #endif
-               tmp->makeLaTeXFile(writefile.absFilename(),
+               tmp->makeLaTeXFile(writefile,
                                   onlyPath(masterFilename(buffer)),
                                   runparams, false);
        } else {
@@ -497,7 +496,7 @@ int InsetInclude::plaintext(Buffer const & buffer, odocstream & os,
        if (isVerbatim(params_)) {
                // FIXME: We don't know the encoding of the file
                docstring const str = from_utf8(
-                       getFileContents(FileName(includedFilename(buffer, params_))));
+                       getFileContents(includedFilename(buffer, params_)));
                os << str;
                // Return how many newlines we issued.
                return int(lyx::count(str.begin(), str.end(), '\n'));
@@ -515,7 +514,7 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
        if (incfile.empty())
                return 0;
 
-       string const included_file = includedFilename(buffer, params_);
+       string const included_file = includedFilename(buffer, params_).absFilename();
 
        // write it to a file (so far the complete file)
        string const exportfile = changeExtension(incfile, ".sgml");
@@ -534,7 +533,7 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
                lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
                lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
-               tmp->makeDocBookFile(writefile.absFilename(), runparams, true);
+               tmp->makeDocBookFile(writefile, runparams, true);
        }
 
        runparams.exportdata->addExternalFile("docbook", writefile,
@@ -560,7 +559,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
 
        Buffer const & buffer = features.buffer();
 
-       string const included_file = includedFilename(buffer, params_);
+       string const included_file = includedFilename(buffer, params_).absFilename();
 
        if (isLyXFilename(included_file))
                writefile = changeExtension(included_file, ".sgml");
@@ -570,7 +569,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
        if (!features.runparams().nice && !isVerbatim(params_)) {
                incfile = DocFileName(writefile).mangledFilename();
                writefile = makeAbsPath(incfile,
-                                       buffer.getMasterBuffer()->temppath());
+                                       buffer.getMasterBuffer()->temppath()).absFilename();
        }
 
        features.includeFile(include_label, writefile);
@@ -600,7 +599,7 @@ void InsetInclude::getLabelList(Buffer const & buffer,
                                std::vector<docstring> & list) const
 {
        if (loadIfNeeded(buffer, params_)) {
-               string const included_file = includedFilename(buffer, params_);
+               string const included_file = includedFilename(buffer, params_).absFilename();
                Buffer * tmp = theBufferList().getBuffer(included_file);
                tmp->setParentName("");
                tmp->getLabelList(list);
@@ -610,10 +609,10 @@ void InsetInclude::getLabelList(Buffer const & buffer,
 
 
 void InsetInclude::fillWithBibKeys(Buffer const & buffer,
-                                  std::vector<std::pair<string,string> > & keys) const
+               std::vector<std::pair<string, docstring> > & keys) const
 {
        if (loadIfNeeded(buffer, params_)) {
-               string const included_file = includedFilename(buffer, params_);
+               string const included_file = includedFilename(buffer, params_).absFilename();
                Buffer * tmp = theBufferList().getBuffer(included_file);
                tmp->setParentName("");
                tmp->fillWithBibKeys(keys);
@@ -633,22 +632,22 @@ void InsetInclude::updateBibfilesCache(Buffer const & buffer)
 }
 
 
-std::vector<string> const &
+std::vector<FileName> const &
 InsetInclude::getBibfilesCache(Buffer const & buffer) const
 {
        Buffer * const tmp = getChildBuffer(buffer, params_);
        if (tmp) {
                tmp->setParentName("");
-               std::vector<string> const & cache = tmp->getBibfilesCache();
+               std::vector<FileName> const & cache = tmp->getBibfilesCache();
                tmp->setParentName(parentFilename(buffer));
                return cache;
        }
-       static std::vector<string> const empty;
+       static std::vector<FileName> const empty;
        return empty;
 }
 
 
-void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
+bool InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
 
@@ -673,7 +672,9 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
        Box b(0, dim.wid, -dim.asc, dim.des);
        button_.setBox(b);
 
+       bool const changed = dim_ != dim;
        dim_ = dim;
+       return changed;
 }
 
 
@@ -724,10 +725,10 @@ namespace {
 
 bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
 {
-       string const included_file = includedFilename(buffer, params);
+       FileName const included_file = includedFilename(buffer, params);
 
        return type(params) == INPUT && params.preview() &&
-               isFileReadable(FileName(included_file));
+               isFileReadable(included_file);
 }
 
 
@@ -748,7 +749,7 @@ void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
        InsetCommandParams const & params = inset.params();
        if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
            preview_wanted(params, buffer)) {
-               renderer.setAbsFile(FileName(includedFilename(buffer, params)));
+               renderer.setAbsFile(includedFilename(buffer, params));
                docstring const snippet = latex_string(inset, buffer);
                renderer.addPreview(snippet, buffer);
        }
@@ -761,7 +762,7 @@ void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const
 {
        Buffer const & buffer = ploader.buffer();
        if (preview_wanted(params(), buffer)) {
-               preview_->setAbsFile(FileName(includedFilename(buffer, params())));
+               preview_->setAbsFile(includedFilename(buffer, params()));
                docstring const snippet = latex_string(*this, buffer);
                preview_->addPreview(snippet, ploader);
        }