#include "insets/InsetInclude.h"
#include "insets/InsetText.h"
+#include "mathed/InsetMathHull.h"
#include "mathed/MacroTable.h"
#include "mathed/MathMacroTemplate.h"
#include "mathed/MathSupport.h"
#include "support/textutils.h"
#include "support/types.h"
-#include <boost/bind.hpp>
-#include <boost/shared_ptr.hpp>
+#include "support/bind.h"
+#include "support/shared_ptr.h"
#include <algorithm>
#include <fstream>
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-int const LYX_FORMAT = 386; // rgh: LyX version for InsetInfo
+int const LYX_FORMAT = 398; // uwestoehr: support for \mathscr
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
}
delete inset;
}
-
+
/// search for macro in local (buffer) table or in children
MacroData const * getBufferMacro(docstring const & name,
DocIterator const & pos) const;
/// If non zero, this buffer is a clone of existing buffer \p cloned_buffer_
/// This one is useful for preview detached in a thread.
Buffer const * cloned_buffer_;
-
+ /// are we in the process of exporting this buffer?
+ mutable bool doing_export;
+
private:
/// So we can force access via the accessors.
mutable Buffer const * parent_buffer;
// We are in our own directory. Why bother to mangle name?
// In fact I wrote this code to circumvent a problematic behaviour
// (bug?) of EMX mkstemp().
- FileName tmpfl(package().temp_dir().absFilename() + "/lyx_tmpbuf" +
+ FileName tmpfl(package().temp_dir().absFileName() + "/lyx_tmpbuf" +
convert<string>(count++));
if (!tmpfl.createDirectory(0777)) {
throw ExceptionMessage(WarningException, _("Disk Error: "), bformat(
_("LyX could not create the temporary directory '%1$s' (Disk is full maybe?)"),
- from_utf8(tmpfl.absFilename())));
+ from_utf8(tmpfl.absFileName())));
}
return tmpfl;
}
read_only(readonly_), filename(file), file_fully_loaded(false),
toc_backend(owner), macro_lock(false), timestamp_(0),
checksum_(0), wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false),
- cloned_buffer_(cloned_buffer), parent_buffer(0)
+ cloned_buffer_(cloned_buffer), doing_export(false), parent_buffer(0)
{
if (!cloned_buffer_) {
temppath = createBufferTmpDir();
if (!d->cloned_buffer_ && !d->temppath.destroyDirectory()) {
Alert::warning(_("Could not remove temporary directory"),
bformat(_("Could not remove the temporary directory %1$s"),
- from_utf8(d->temppath.absFilename())));
+ from_utf8(d->temppath.absFileName())));
}
// Remove any previewed LaTeX snippets associated with this buffer.
- thePreviews().removeLoader(*this);
+ if (!isClone())
+ thePreviews().removeLoader(*this);
delete d;
}
Buffer * Buffer::clone() const
{
- Buffer * buffer_clone = new Buffer(fileName().absFilename(), false, this);
+ Buffer * buffer_clone = new Buffer(fileName().absFileName(), false, this);
buffer_clone->d->macro_lock = true;
buffer_clone->d->children_positions.clear();
// FIXME (Abdel 09/01/2010): this is too complicated. The whole children_positions and
string const Buffer::temppath() const
{
- return d->temppath.absFilename();
+ return d->temppath.absFileName();
}
FileName latex_name =
makeLatexName(d->exportFileName());
return no_path ? latex_name.onlyFileName()
- : latex_name.absFilename();
+ : latex_name.absFileName();
}
FileName Buffer::Impl::exportFileName() const
{
docstring const branch_suffix =
- params.branchlist().getFilenameSuffix();
+ params.branchlist().getFileNameSuffix();
if (branch_suffix.empty())
return filename;
string const name = filename.onlyFileNameWithoutExt()
+ to_utf8(branch_suffix);
- FileName res(filename.onlyPath().absFilename() + "/" + name);
+ FileName res(filename.onlyPath().absFileName() + "/" + name);
res.changeExtension(filename.extension());
return res;
string const path = temppath();
FileName const fname(addName(temppath(),
- onlyFilename(changeExtension(filename,
+ onlyFileName(changeExtension(filename,
".log"))));
// FIXME: how do we know this is the name of the build log?
FileName const bname(
- addName(path, onlyFilename(
+ addName(path, onlyFileName(
changeExtension(filename,
formats.extension(bufferFormat()) + ".out"))));
LYXERR(Debug::FILES, "Log name calculated as: " << bname);
if (type)
*type = buildlog;
- return bname.absFilename();
+ return bname.absFileName();
// If we have a newer master file log or only a master log, show this
} else if (fname != masterfname
&& (!fname.exists() && (masterfname.exists()
LYXERR(Debug::FILES, "Log name calculated as: " << masterfname);
if (type)
*type = mtype;
- return masterfname.absFilename();
+ return masterfname.absFileName();
}
LYXERR(Debug::FILES, "Log name calculated as: " << fname);
if (type)
*type = latexlog;
- return fname.absFilename();
+ return fname.absFileName();
}
params().isfontcolor = false;
params().notefontcolor = lyx::rgbFromHexName("#cccccc");
params().boxbgcolor = lyx::rgbFromHexName("#ff0000");
+ params().html_latex_start.clear();
+ params().html_latex_end.clear();
+ params().html_math_img_scale = 1.0;
+ params().output_sync_macro.erase();
for (int i = 0; i < 4; ++i) {
params().user_defined_bullet(i) = ITEMIZE_DEFAULTS[i];
if (!params().master.empty()) {
FileName const master_file = makeAbsPath(params().master,
onlyPath(absFileName()));
- if (isLyXFilename(master_file.absFilename())) {
+ if (isLyXFileName(master_file.absFileName())) {
Buffer * master =
checkAndLoadLyXFile(master_file, true);
if (master) {
if (!lex.checkFor("\\lyxformat")) {
Alert::error(_("Document format failure"),
bformat(_("%1$s is not a readable LyX document."),
- from_utf8(filename.absFilename())));
+ from_utf8(filename.absFileName())));
return failure;
}
// Save the timestamp and checksum of disk file. If filename is an
// emergency file, save the timestamp and checksum of the original lyx file
// because isExternallyModified will check for this file. (BUG4193)
- string diskfile = filename.absFilename();
+ string diskfile = filename.absFileName();
if (suffixIs(diskfile, ".emergency"))
diskfile = diskfile.substr(0, diskfile.size() - 10);
saveCheckSum(FileName(diskfile));
" version of LyX, but a temporary"
" file for converting it could"
" not be created."),
- from_utf8(filename.absFilename())));
+ from_utf8(filename.absFileName())));
return failure;
}
FileName const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
" version of LyX, but the"
" conversion script lyx2lyx"
" could not be found."),
- from_utf8(filename.absFilename())));
+ from_utf8(filename.absFileName())));
return failure;
}
ostringstream command;
bformat(_("%1$s is from an older version"
" of LyX, but the lyx2lyx script"
" failed to convert it."),
- from_utf8(filename.absFilename())));
+ from_utf8(filename.absFileName())));
else
Alert::error(_("Conversion script failed"),
bformat(_("%1$s is from a newer version"
" of LyX and cannot be converted by the"
" lyx2lyx script."),
- from_utf8(filename.absFilename())));
+ from_utf8(filename.absFileName())));
return failure;
} else {
bool const ret = readFile(tmpfile);
Alert::error(_("Document format failure"),
bformat(_("%1$s ended unexpectedly, which means"
" that it is probably corrupted."),
- from_utf8(filename.absFilename())));
+ from_utf8(filename.absFileName())));
return failure;
}
backupName = FileName(absFileName() + '~');
if (!lyxrc.backupdir_path.empty()) {
string const mangledName =
- subst(subst(backupName.absFilename(), '/', '!'), ':', '!');
+ subst(subst(backupName.absFileName(), '/', '!'), ':', '!');
backupName = FileName(addName(lyxrc.backupdir_path,
mangledName));
}
+ // do not copy because of #6587
if (fileName().moveTo(backupName)) {
madeBackup = true;
} else {
Alert::error(_("Backup failure"),
bformat(_("Cannot create backup file %1$s.\n"
"Please check whether the directory exists and is writeable."),
- from_utf8(backupName.absFilename())));
+ from_utf8(backupName.absFileName())));
//LYXERR(Debug::DEBUG, "Fs error: " << fe.what());
}
}
bool retval = false;
docstring const str = bformat(_("Saving document %1$s..."),
- makeDisplayPath(fname.absFilename()));
+ makeDisplayPath(fname.absFileName()));
message(str);
string const encoded_fname = fname.toSafeFilesystemEncoding(os::CREATE);
if (isClean())
return docstring();
- string const doc = isUnnamed() ? onlyFilename(absFileName()) : absFileName();
+ string const doc = isUnnamed() ? onlyFileName(absFileName()) : absFileName();
docstring user_message = bformat(
_("LyX: Attempting to save document %1$s\n"), from_utf8(doc));
}
// 2) In HOME directory.
- string s = addName(package().home_dir().absFilename(), absFileName());
+ string s = addName(package().home_dir().absFileName(), absFileName());
s += ".emergency";
lyxerr << ' ' << s << endl;
if (writeFile(FileName(s))) {
// 3) In "/tmp" directory.
// MakeAbsPath to prepend the current
// drive letter on OS/2
- s = addName(package().temp_dir().absFilename(), absFileName());
+ s = addName(package().temp_dir().absFileName(), absFileName());
s += ".emergency";
lyxerr << ' ' << s << endl;
if (writeFile(FileName(s))) {
if (!openFileWrite(ofs, fname))
return;
- writeDocBookSource(ofs, fname.absFilename(), runparams, body_only);
+ writeDocBookSource(ofs, fname.absFileName(), runparams, body_only);
ofs.close();
if (ofs.fail())
// get LaTeX-Filename
FileName const path(temppath());
- string const name = addName(path.absFilename(), latexName());
+ string const name = addName(path.absFileName(), latexName());
string const org_path = filePath();
PathChanger p(path); // path to LaTeX file
makeLaTeXFile(FileName(name), org_path, runparams);
TeXErrors terr;
- Chktex chktex(lyxrc.chktex_command, onlyFilename(name), filePath());
+ Chktex chktex(lyxrc.chktex_command, onlyFileName(name), filePath());
int const res = chktex.run(terr); // run chktex
if (res == -1) {
updateMacros();
for_each(paragraphs().begin(), paragraphs().end(),
- boost::bind(&Paragraph::validate, _1, boost::ref(features)));
+ bind(&Paragraph::validate, _1, ref(features)));
if (lyxerr.debugging(Debug::LATEX)) {
features.showStruct();
break;
case LFUN_BRANCH_ADD: {
- docstring const branch_name = func.argument();
+ docstring branch_name = func.argument();
if (branch_name.empty()) {
dispatched = false;
break;
}
BranchList & branch_list = params().branchlist();
- Branch * branch = branch_list.find(branch_name);
- if (branch) {
- LYXERR0("Branch " << branch_name << " already exists.");
- dr.setError(true);
- docstring const msg =
- bformat(_("Branch \"%1$s\" already exists."), branch_name);
- dr.setMessage(msg);
- } else {
- branch_list.add(branch_name);
- branch = branch_list.find(branch_name);
- string const x11hexname = X11hexname(branch->color());
- docstring const str = branch_name + ' ' + from_ascii(x11hexname);
- lyx::dispatch(FuncRequest(LFUN_SET_COLOR, str));
- dr.setError(false);
- dr.update(Update::Force);
+ vector<docstring> const branches =
+ getVectorFromString(branch_name, branch_list.separator());
+ docstring msg;
+ for (vector<docstring>::const_iterator it = branches.begin();
+ it != branches.end(); ++it) {
+ branch_name = *it;
+ Branch * branch = branch_list.find(branch_name);
+ if (branch) {
+ LYXERR0("Branch " << branch_name << " already exists.");
+ dr.setError(true);
+ if (!msg.empty())
+ msg += ("\n");
+ msg += bformat(_("Branch \"%1$s\" already exists."), branch_name);
+ } else {
+ branch_list.add(branch_name);
+ branch = branch_list.find(branch_name);
+ string const x11hexname = X11hexname(branch->color());
+ docstring const str = branch_name + ' ' + from_ascii(x11hexname);
+ lyx::dispatch(FuncRequest(LFUN_SET_COLOR, str));
+ dr.setError(false);
+ dr.update(Update::Force);
+ }
}
+ if (!msg.empty())
+ dr.setMessage(msg);
break;
}
branch->setSelected(func.action() == LFUN_BRANCH_ACTIVATE);
dr.setError(false);
dr.update(Update::Force);
+ dr.forceBufferUpdate();
}
break;
}
}
}
- if (success)
+ if (success) {
dr.update(Update::Force);
+ dr.forceBufferUpdate();
+ }
break;
}
docstring text = bformat(
_("The file %1$s already exists.\n\n"
"Do you want to overwrite that file?"),
- makeDisplayPath(filename.absFilename()));
+ makeDisplayPath(filename.absFileName()));
if (Alert::prompt(_("Overwrite file?"),
text, 0, 1, _("&Overwrite"), _("&Cancel")) != 0)
break;
Language const * newL = languages.getLanguage(argument);
if (!newL || oldL == newL)
break;
- if (oldL->rightToLeft() == newL->rightToLeft() && !isMultiLingual())
+ if (oldL->rightToLeft() == newL->rightToLeft() && !isMultiLingual()) {
changeLanguage(oldL, newL);
+ dr.forceBufferUpdate();
+ }
break;
}
// if the .lyx file has been saved, we don't need an
// autosave
d->bak_clean = true;
+ d->undo_.markDirty();
}
string Buffer::absFileName() const
{
- return d->filename.absFilename();
+ return d->filename.absFileName();
}
string Buffer::filePath() const
{
- return d->filename.onlyPath().absFilename() + "/";
+ return d->filename.onlyPath().absFileName() + "/";
}
continue;
}
+ if (doing_export && iit->inset->asInsetMath()) {
+ InsetMath * im = static_cast<InsetMath *>(iit->inset);
+ if (im->asHullInset()) {
+ InsetMathHull * hull = static_cast<InsetMathHull *>(im);
+ hull->recordLocation(it);
+ }
+ }
+
if (iit->inset->lyxCode() != MATHMACRO_CODE)
continue;
AutoSaveBuffer(Buffer const & buffer, FileName const & fname)
: buffer_(buffer), fname_(fname) {}
///
- virtual boost::shared_ptr<ForkedProcess> clone() const
+ virtual shared_ptr<ForkedProcess> clone() const
{
- return boost::shared_ptr<ForkedProcess>(new AutoSaveBuffer(*this));
+ return shared_ptr<ForkedProcess>(new AutoSaveBuffer(*this));
}
///
int start()
{
command_ = to_utf8(bformat(_("Auto-saving %1$s"),
- from_utf8(fname_.absFilename())));
+ from_utf8(fname_.absFileName())));
return run(DontWait);
}
private:
} // namespace anon
-FileName Buffer::getAutosaveFilename() const
+FileName Buffer::getAutosaveFileName() const
{
// if the document is unnamed try to save in the backup dir, else
// in the default document path, and as a last try in the filePath,
void Buffer::removeAutosaveFile() const
{
- FileName const f = getAutosaveFilename();
+ FileName const f = getAutosaveFileName();
if (f.exists())
f.removeFile();
}
void Buffer::moveAutosaveFile(support::FileName const & oldauto) const
{
- FileName const newauto = getAutosaveFilename();
+ FileName const newauto = getAutosaveFileName();
oldauto.refresh();
if (newauto != oldauto && oldauto.exists())
if (!oldauto.moveTo(newauto))
// emit message signal.
message(_("Autosaving current document..."));
- AutoSaveBuffer autosave(*this, getAutosaveFilename());
+ AutoSaveBuffer autosave(*this, getAutosaveFileName());
autosave.start();
d->bak_clean = true;
}
+namespace {
+ // helper class, to guarantee this gets reset properly
+ class MarkAsExporting {
+ public:
+ MarkAsExporting(Buffer const * buf) : buf_(buf)
+ {
+ LASSERT(buf_, /* */);
+ buf_->setExportStatus(true);
+ }
+ ~MarkAsExporting()
+ {
+ buf_->setExportStatus(false);
+ }
+ private:
+ Buffer const * const buf_;
+ };
+}
+
+
+void Buffer::setExportStatus(bool e) const
+{
+ d->doing_export = e;
+}
+
+
+bool Buffer::isExporting() const
+{
+ return d->doing_export;
+}
+
bool Buffer::doExport(string const & format, bool put_in_tempdir,
bool includeall, string & result_file) const
{
+ MarkAsExporting exporting(this);
string backend_format;
OutputParams runparams(¶ms().encoding());
runparams.flavor = OutputParams::LATEX;
return false;
if (put_in_tempdir) {
- result_file = tmp_result_file.absFilename();
+ result_file = tmp_result_file.absFileName();
return true;
}
- result_file = changeExtension(d->exportFileName().absFilename(), ext);
+ result_file = changeExtension(d->exportFileName().absFileName(), ext);
// We need to copy referenced files (e. g. included graphics
// if format == "dvi") to the result dir.
vector<ExportedFile> const files =
runparams.exportdata->externalFiles(format);
string const dest = onlyPath(result_file);
- CopyStatus status = SUCCESS;
+ bool use_force = use_gui ? lyxrc.export_overwrite == ALL_FILES
+ : force_overwrite == ALL_FILES;
+ CopyStatus status = use_force ? FORCE : SUCCESS;
vector<ExportedFile>::const_iterator it = files.begin();
vector<ExportedFile>::const_iterator const en = files.end();
message(_("Document export cancelled."));
} else if (tmp_result_file.exists()) {
// Finally copy the main file
+ use_force = use_gui ? lyxrc.export_overwrite != NO_FILES
+ : force_overwrite != NO_FILES;
+ if (status == SUCCESS && use_force)
+ status = FORCE;
status = copyFile(format, tmp_result_file,
FileName(result_file), result_file,
status == FORCE);
bool Buffer::preview(string const & format, bool includeall) const
{
+ MarkAsExporting exporting(this);
string result_file;
// (1) export with all included children (omit \includeonly)
if (includeall && !doExport(format, true, true))
{
// File information about normal file
if (!s.exists()) {
- docstring const file = makeDisplayPath(s.absFilename(), 50);
+ docstring const file = makeDisplayPath(s.absFileName(), 50);
docstring text = bformat(_("The specified document\n%1$s"
"\ncould not be read."), file);
Alert::error(_("Could not read document"), text);
}
// Check if emergency save file exists and is newer.
- FileName const e(s.absFilename() + ".emergency");
+ FileName const e(s.absFileName() + ".emergency");
if (e.exists() && s.exists() && e.lastModified() > s.lastModified()) {
- docstring const file = makeDisplayPath(s.absFilename(), 20);
+ docstring const file = makeDisplayPath(s.absFileName(), 20);
docstring const text =
bformat(_("An emergency save of the document "
"%1$s exists.\n\n"
else
str = _("Document was NOT successfully recovered.");
str += "\n\n" + bformat(_("Remove emergency file now?\n(%1$s)"),
- makeDisplayPath(e.absFilename()));
+ makeDisplayPath(e.absFileName()));
if (!Alert::prompt(_("Delete emergency file?"), str, 1, 1,
_("&Remove"), _("&Keep it"))) {
}
// Now check if autosave file is newer.
- FileName const a(onlyPath(s.absFilename()) + '#' + onlyFilename(s.absFilename()) + '#');
+ FileName const a(onlyPath(s.absFileName()) + '#' + onlyFileName(s.absFileName()) + '#');
if (a.exists() && s.exists() && a.lastModified() > s.lastModified()) {
- docstring const file = makeDisplayPath(s.absFilename(), 20);
+ docstring const file = makeDisplayPath(s.absFileName(), 20);
docstring const text =
bformat(_("The backup of the document "
"%1$s is newer.\n\nLoad the "
if (from == end)
break;
to = from;
- if (from.paragraph().spellCheck(from.pos(), to.pos(), wl, suggestions)) {
+ SpellChecker::Result res = from.paragraph().spellCheck(from.pos(), to.pos(), wl, suggestions);
+ if (SpellChecker::misspelled(res)) {
word_lang = wl;
break;
}
removeAutosaveFile();
// e.g., read-only status could have changed due to version control
d->filename.refresh();
- docstring const disp_fn = makeDisplayPath(d->filename.absFilename());
+ docstring const disp_fn = makeDisplayPath(d->filename.absFileName());
bool const success = loadLyXFile(d->filename);
if (success) {
updateBuffer();
changed(true);
+ updateTitles();
markClean();
message(bformat(_("Document %1$s reloaded."), disp_fn));
} else {
docstring const & incfile = inset_inc->getParam("filename");
string oldloc = cbuf->absFileName();
string newloc = makeAbsPath(to_utf8(incfile),
- onlyPath(absFileName())).absFilename();
+ onlyPath(absFileName())).absFileName();
if (oldloc == newloc)
continue;
// the location of the child file is incorrect.