Merge branch 'master' of git.lyx.org:lyx

This commit is contained in:
Uwe Stöhr 2015-05-04 01:51:21 +02:00
commit f5648006fb
8 changed files with 74 additions and 16 deletions

View File

@ -249,6 +249,9 @@ public:
/// map from children inclusion positions to their scope and their buffer /// map from children inclusion positions to their scope and their buffer
PositionScopeBufferMap position_to_children; PositionScopeBufferMap position_to_children;
/// Keeps track of old buffer filePath() for save-as operations
string old_position;
/// Container for all sort of Buffer dependant errors. /// Container for all sort of Buffer dependant errors.
map<string, ErrorList> errorLists; map<string, ErrorList> errorLists;
@ -4926,6 +4929,8 @@ bool Buffer::saveAs(FileName const & fn)
FileName const old_name = fileName(); FileName const old_name = fileName();
FileName const old_auto = getAutosaveFileName(); FileName const old_auto = getAutosaveFileName();
bool const old_unnamed = isUnnamed(); bool const old_unnamed = isUnnamed();
bool success = true;
d->old_position = filePath();
setFileName(fn); setFileName(fn);
markDirty(); markDirty();
@ -4943,22 +4948,19 @@ bool Buffer::saveAs(FileName const & fn)
// are still valid. // are still valid.
checkChildBuffers(); checkChildBuffers();
checkMasterBuffer(); checkMasterBuffer();
return true;
} else { } else {
// save failed // save failed
// reset the old filename and unnamed state // reset the old filename and unnamed state
setFileName(old_name); setFileName(old_name);
setUnnamed(old_unnamed); setUnnamed(old_unnamed);
return false; success = false;
} }
d->old_position.clear();
return success;
} }
// FIXME We could do better here, but it is complicated. What would be
// nice is to offer either (a) to save the child buffer to an appropriate
// location, so that it would "move with the master", or else (b) to update
// the InsetInclude so that it pointed to the same file. But (a) is a bit
// complicated, because the code for this lives in GuiView.
void Buffer::checkChildBuffers() void Buffer::checkChildBuffers()
{ {
Impl::BufferPositionMap::iterator it = d->children_positions.begin(); Impl::BufferPositionMap::iterator it = d->children_positions.begin();
@ -4978,11 +4980,6 @@ void Buffer::checkChildBuffers()
if (oldloc == newloc) if (oldloc == newloc)
continue; continue;
// the location of the child file is incorrect. // the location of the child file is incorrect.
Alert::warning(_("Included File Invalid"),
bformat(_("Saving this document to a new location has made the file:\n"
" %1$s\n"
"inaccessible. You will need to update the included filename."),
from_utf8(oldloc)));
cbuf->setParent(0); cbuf->setParent(0);
inset_inc->setChildBuffer(0); inset_inc->setChildBuffer(0);
} }
@ -5012,4 +5009,18 @@ void Buffer::checkMasterBuffer()
setParent(0); setParent(0);
} }
string Buffer::includedFilePath(string const & name) const
{
if (d->old_position.empty() || d->old_position == filePath())
return name;
if (FileName::isAbsolute(name))
return to_utf8(makeRelPath(from_utf8(name), from_utf8(filePath())));
// old_position already contains a trailing path separator
string const cleanpath = FileName(d->old_position + name).realPath();
return to_utf8(makeRelPath(from_utf8(cleanpath), from_utf8(filePath())));
}
} // namespace lyx } // namespace lyx

View File

@ -710,6 +710,12 @@ public:
/// ///
void checkMasterBuffer(); void checkMasterBuffer();
/// If the document is being saved to a new location, return the
/// updated path of an included file relative to the new buffer path
/// if possible, otherwise return its absolute path.
/// In all other cases, this is a no-op and name is returned unchanged.
std::string includedFilePath(std::string const & name) const;
/// compute statistics between \p from and \p to /// compute statistics between \p from and \p to
/// \p from initial position /// \p from initial position
/// \p to points to the end position /// \p to points to the end position

View File

@ -1025,6 +1025,12 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
} }
void InsetBibtex::write(ostream & os) const
{
params().Write(os, &buffer());
}
string InsetBibtex::contextMenuName() const string InsetBibtex::contextMenuName() const
{ {
return "context-bibtex"; return "context-bibtex";

View File

@ -38,6 +38,8 @@ public:
bool addDatabase(docstring const &); bool addDatabase(docstring const &);
/// ///
bool delDatabase(docstring const &); bool delDatabase(docstring const &);
///
void write(std::ostream &) const;
/// \name Public functions inherited from Inset class /// \name Public functions inherited from Inset class
//@{ //@{

View File

@ -28,6 +28,7 @@
#include "InsetRef.h" #include "InsetRef.h"
#include "InsetTOC.h" #include "InsetTOC.h"
#include "Buffer.h"
#include "Encoding.h" #include "Encoding.h"
#include "Lexer.h" #include "Lexer.h"
#include "OutputParams.h" #include "OutputParams.h"
@ -320,6 +321,12 @@ void InsetCommandParams::read(Lexer & lex)
void InsetCommandParams::write(ostream & os) const void InsetCommandParams::write(ostream & os) const
{
Write(os, 0);
}
void InsetCommandParams::Write(ostream & os, Buffer const * buffer) const
{ {
os << "CommandInset " << insetType() << '\n'; os << "CommandInset " << insetType() << '\n';
os << "LatexCommand " << cmdName_ << '\n'; os << "LatexCommand " << cmdName_ << '\n';
@ -328,12 +335,27 @@ void InsetCommandParams::write(ostream & os) const
ParamInfo::const_iterator it = info_.begin(); ParamInfo::const_iterator it = info_.begin();
ParamInfo::const_iterator end = info_.end(); ParamInfo::const_iterator end = info_.end();
for (; it != end; ++it) { for (; it != end; ++it) {
std::string const & name = it->name(); string const & name = it->name();
docstring const & data = (*this)[name]; string data = to_utf8((*this)[name]);
if (!data.empty()) { if (!data.empty()) {
// FIXME UNICODE // Adjust path of files if document was moved
if (buffer && name == "filename") {
data = buffer->includedFilePath(data);
} else if (buffer && name == "bibfiles") {
int i = 0;
string newdata;
string bib = token(data, ',', i);
while (!bib.empty()) {
bib = buffer->includedFilePath(bib);
if (!newdata.empty())
newdata.append(1, ',');
newdata.append(bib);
bib = token(data, ',', ++i);
}
data = newdata;
}
os << name << ' ' os << name << ' '
<< Lexer::quoteString(to_utf8(data)) << Lexer::quoteString(data)
<< '\n'; << '\n';
} }
} }

View File

@ -28,6 +28,7 @@
namespace lyx { namespace lyx {
class Lexer; class Lexer;
class Buffer;
class ParamInfo { class ParamInfo {
public: public:
@ -117,6 +118,8 @@ public:
/// Parse the command /// Parse the command
/// ///
void write(std::ostream &) const; void write(std::ostream &) const;
///
void Write(std::ostream & os, Buffer const * buf) const;
/// Build the complete LaTeX command /// Build the complete LaTeX command
docstring getCommand(OutputParams const &) const; docstring getCommand(OutputParams const &) const;
/// Return the command name /// Return the command name

View File

@ -1029,6 +1029,12 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
} }
void InsetInclude::write(ostream & os) const
{
params().Write(os, &buffer());
}
string InsetInclude::contextMenuName() const string InsetInclude::contextMenuName() const
{ {
return "context-include"; return "context-include";

View File

@ -64,6 +64,8 @@ public:
/// ///
void updateCommand(); void updateCommand();
///
void write(std::ostream &) const;
/// \name Public functions inherited from Inset class /// \name Public functions inherited from Inset class
//@{ //@{