mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
cosmetics
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21097 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
64bd1b1f38
commit
f934b86850
150
src/Buffer.cpp
150
src/Buffer.cpp
@ -24,6 +24,7 @@
|
|||||||
#include "Counters.h"
|
#include "Counters.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "DocIterator.h"
|
#include "DocIterator.h"
|
||||||
|
#include "EmbeddedFiles.h"
|
||||||
#include "Encoding.h"
|
#include "Encoding.h"
|
||||||
#include "ErrorList.h"
|
#include "ErrorList.h"
|
||||||
#include "Exporter.h"
|
#include "Exporter.h"
|
||||||
@ -33,34 +34,34 @@
|
|||||||
#include "InsetIterator.h"
|
#include "InsetIterator.h"
|
||||||
#include "InsetList.h"
|
#include "InsetList.h"
|
||||||
#include "Language.h"
|
#include "Language.h"
|
||||||
#include "LaTeX.h"
|
|
||||||
#include "LaTeXFeatures.h"
|
#include "LaTeXFeatures.h"
|
||||||
|
#include "LaTeX.h"
|
||||||
#include "Layout.h"
|
#include "Layout.h"
|
||||||
#include "LyXAction.h"
|
|
||||||
#include "Lexer.h"
|
#include "Lexer.h"
|
||||||
#include "Text.h"
|
#include "LyXAction.h"
|
||||||
#include "LyX.h"
|
#include "LyX.h"
|
||||||
#include "LyXRC.h"
|
#include "LyXRC.h"
|
||||||
#include "LyXVC.h"
|
#include "LyXVC.h"
|
||||||
#include "Messages.h"
|
#include "Messages.h"
|
||||||
#include "output.h"
|
|
||||||
#include "output_docbook.h"
|
#include "output_docbook.h"
|
||||||
|
#include "output.h"
|
||||||
#include "output_latex.h"
|
#include "output_latex.h"
|
||||||
#include "output_plaintext.h"
|
#include "output_plaintext.h"
|
||||||
#include "Paragraph.h"
|
|
||||||
#include "paragraph_funcs.h"
|
#include "paragraph_funcs.h"
|
||||||
|
#include "Paragraph.h"
|
||||||
#include "ParagraphParameters.h"
|
#include "ParagraphParameters.h"
|
||||||
#include "ParIterator.h"
|
#include "ParIterator.h"
|
||||||
|
#include "PDFOptions.h"
|
||||||
#include "Session.h"
|
#include "Session.h"
|
||||||
#include "sgml.h"
|
#include "sgml.h"
|
||||||
#include "TexRow.h"
|
#include "TexRow.h"
|
||||||
#include "TextClassList.h"
|
|
||||||
#include "TexStream.h"
|
#include "TexStream.h"
|
||||||
|
#include "TextClassList.h"
|
||||||
|
#include "Text.h"
|
||||||
#include "TocBackend.h"
|
#include "TocBackend.h"
|
||||||
#include "Undo.h"
|
#include "Undo.h"
|
||||||
|
#include "VCBackend.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "EmbeddedFiles.h"
|
|
||||||
#include "PDFOptions.h"
|
|
||||||
|
|
||||||
#include "insets/InsetBibitem.h"
|
#include "insets/InsetBibitem.h"
|
||||||
#include "insets/InsetBibtex.h"
|
#include "insets/InsetBibtex.h"
|
||||||
@ -1309,7 +1310,7 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname,
|
|||||||
// Other flags: -wall -v0 -x
|
// Other flags: -wall -v0 -x
|
||||||
int Buffer::runChktex()
|
int Buffer::runChktex()
|
||||||
{
|
{
|
||||||
busy(true);
|
setBusy(true);
|
||||||
|
|
||||||
// get LaTeX-Filename
|
// get LaTeX-Filename
|
||||||
FileName const path(temppath());
|
FileName const path(temppath());
|
||||||
@ -1333,14 +1334,12 @@ int Buffer::runChktex()
|
|||||||
Alert::error(_("chktex failure"),
|
Alert::error(_("chktex failure"),
|
||||||
_("Could not run chktex successfully."));
|
_("Could not run chktex successfully."));
|
||||||
} else if (res > 0) {
|
} else if (res > 0) {
|
||||||
ErrorList & errorList = pimpl_->errorLists["ChkTeX"];
|
ErrorList & errlist = pimpl_->errorLists["ChkTeX"];
|
||||||
// Clear out old errors
|
errlist.clear();
|
||||||
errorList.clear();
|
bufferErrors(terr, errlist);
|
||||||
// Fill-in the error list with the TeX errors
|
|
||||||
bufferErrors(*this, terr, errorList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
busy(false);
|
setBusy(false);
|
||||||
|
|
||||||
errors("ChkTeX");
|
errors("ChkTeX");
|
||||||
|
|
||||||
@ -1927,7 +1926,7 @@ void Buffer::message(docstring const & msg) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Buffer::busy(bool on) const
|
void Buffer::setBusy(bool on) const
|
||||||
{
|
{
|
||||||
if (gui_)
|
if (gui_)
|
||||||
gui_->busy(on);
|
gui_->busy(on);
|
||||||
@ -2386,4 +2385,123 @@ vector<string> Buffer::backends() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Buffer::readFileHelper(FileName const & s)
|
||||||
|
{
|
||||||
|
// File information about normal file
|
||||||
|
if (!s.exists()) {
|
||||||
|
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);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if emergency save file exists and is newer.
|
||||||
|
FileName const e(s.absFilename() + ".emergency");
|
||||||
|
|
||||||
|
if (e.exists() && s.exists() && e.lastModified() > s.lastModified()) {
|
||||||
|
docstring const file = makeDisplayPath(s.absFilename(), 20);
|
||||||
|
docstring const text =
|
||||||
|
bformat(_("An emergency save of the document "
|
||||||
|
"%1$s exists.\n\n"
|
||||||
|
"Recover emergency save?"), file);
|
||||||
|
switch (Alert::prompt(_("Load emergency save?"), text, 0, 2,
|
||||||
|
_("&Recover"), _("&Load Original"),
|
||||||
|
_("&Cancel")))
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
// the file is not saved if we load the emergency file.
|
||||||
|
markDirty();
|
||||||
|
return readFile(e);
|
||||||
|
case 1:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now check if autosave file is newer.
|
||||||
|
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 text =
|
||||||
|
bformat(_("The backup of the document "
|
||||||
|
"%1$s is newer.\n\nLoad the "
|
||||||
|
"backup instead?"), file);
|
||||||
|
switch (Alert::prompt(_("Load backup?"), text, 0, 2,
|
||||||
|
_("&Load backup"), _("Load &original"),
|
||||||
|
_("&Cancel") ))
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
// the file is not saved if we load the autosave file.
|
||||||
|
markDirty();
|
||||||
|
return readFile(a);
|
||||||
|
case 1:
|
||||||
|
// Here we delete the autosave
|
||||||
|
unlink(a);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return readFile(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Buffer::loadLyXFile(FileName const & s)
|
||||||
|
{
|
||||||
|
if (s.isReadable()) {
|
||||||
|
if (readFileHelper(s)) {
|
||||||
|
lyxvc().file_found_hook(s);
|
||||||
|
if (!s.isWritable())
|
||||||
|
setReadonly(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
docstring const file = makeDisplayPath(s.absFilename(), 20);
|
||||||
|
// Here we probably should run
|
||||||
|
if (LyXVC::file_not_found_hook(s)) {
|
||||||
|
docstring const text =
|
||||||
|
bformat(_("Do you want to retrieve the document"
|
||||||
|
" %1$s from version control?"), file);
|
||||||
|
int const ret = Alert::prompt(_("Retrieve from version control?"),
|
||||||
|
text, 0, 1, _("&Retrieve"), _("&Cancel"));
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
|
// How can we know _how_ to do the checkout?
|
||||||
|
// With the current VC support it has to be,
|
||||||
|
// a RCS file since CVS do not have special ,v files.
|
||||||
|
RCS::retrieve(s);
|
||||||
|
return loadLyXFile(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Buffer::bufferErrors(TeXErrors const & terr, ErrorList & errorList) const
|
||||||
|
{
|
||||||
|
TeXErrors::Errors::const_iterator cit = terr.begin();
|
||||||
|
TeXErrors::Errors::const_iterator end = terr.end();
|
||||||
|
|
||||||
|
for (; cit != end; ++cit) {
|
||||||
|
int id_start = -1;
|
||||||
|
int pos_start = -1;
|
||||||
|
int errorRow = cit->error_in_line;
|
||||||
|
bool found = texrow().getIdFromRow(errorRow, id_start,
|
||||||
|
pos_start);
|
||||||
|
int id_end = -1;
|
||||||
|
int pos_end = -1;
|
||||||
|
do {
|
||||||
|
++errorRow;
|
||||||
|
found = texrow().getIdFromRow(errorRow, id_end, pos_end);
|
||||||
|
} while (found && id_start == id_end && pos_start == pos_end);
|
||||||
|
|
||||||
|
errorList.push_back(ErrorItem(cit->error_desc,
|
||||||
|
cit->error_text, id_start, pos_start, pos_end));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
11
src/Buffer.h
11
src/Buffer.h
@ -155,6 +155,12 @@ public:
|
|||||||
/// Write file. Returns \c false if unsuccesful.
|
/// Write file. Returns \c false if unsuccesful.
|
||||||
bool writeFile(support::FileName const &) const;
|
bool writeFile(support::FileName const &) const;
|
||||||
|
|
||||||
|
/// Loads LyX file \c filename into buffer, * and \return success
|
||||||
|
bool loadLyXFile(support::FileName const & s);
|
||||||
|
|
||||||
|
/// Fill in the ErrorList with the TeXErrors
|
||||||
|
void bufferErrors(TeXErrors const &, ErrorList &) const;
|
||||||
|
|
||||||
/// Just a wrapper for writeLaTeXSource, first creating the ofstream.
|
/// Just a wrapper for writeLaTeXSource, first creating the ofstream.
|
||||||
bool makeLaTeXFile(support::FileName const & filename,
|
bool makeLaTeXFile(support::FileName const & filename,
|
||||||
std::string const & original_path,
|
std::string const & original_path,
|
||||||
@ -393,7 +399,7 @@ public:
|
|||||||
/// This function is called when some parsing error shows up.
|
/// This function is called when some parsing error shows up.
|
||||||
void errors(std::string const & err) const;
|
void errors(std::string const & err) const;
|
||||||
/// This function is called when the buffer busy status change.
|
/// This function is called when the buffer busy status change.
|
||||||
void busy(bool on) const;
|
void setBusy(bool on) const;
|
||||||
/// This function is called when the buffer readonly status change.
|
/// This function is called when the buffer readonly status change.
|
||||||
void readonly(bool on) const;
|
void readonly(bool on) const;
|
||||||
/// Update window titles of all users.
|
/// Update window titles of all users.
|
||||||
@ -428,8 +434,9 @@ public:
|
|||||||
///
|
///
|
||||||
std::vector<Format const *> exportableFormats(bool only_viewable) const;
|
std::vector<Format const *> exportableFormats(bool only_viewable) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
///
|
||||||
|
bool readFileHelper(support::FileName const & s);
|
||||||
///
|
///
|
||||||
std::vector<std::string> backends() const;
|
std::vector<std::string> backends() const;
|
||||||
/** Inserts a file into a document
|
/** Inserts a file into a document
|
||||||
|
@ -1966,7 +1966,7 @@ void BufferView::menuInsertLyXFile(string const & filenm)
|
|||||||
|
|
||||||
docstring res;
|
docstring res;
|
||||||
Buffer buf("", false);
|
Buffer buf("", false);
|
||||||
if (lyx::loadLyXFile(&buf, FileName(filename))) {
|
if (buf.loadLyXFile(FileName(filename))) {
|
||||||
ErrorList & el = buffer_.errorList("Parse");
|
ErrorList & el = buffer_.errorList("Parse");
|
||||||
// Copy the inserted document error list into the current buffer one.
|
// Copy the inserted document error list into the current buffer one.
|
||||||
el = buf.errorList("Parse");
|
el = buf.errorList("Parse");
|
||||||
@ -1974,8 +1974,9 @@ void BufferView::menuInsertLyXFile(string const & filenm)
|
|||||||
cap::pasteParagraphList(d->cursor_, buf.paragraphs(),
|
cap::pasteParagraphList(d->cursor_, buf.paragraphs(),
|
||||||
buf.params().getTextClassPtr(), el);
|
buf.params().getTextClassPtr(), el);
|
||||||
res = _("Document %1$s inserted.");
|
res = _("Document %1$s inserted.");
|
||||||
} else
|
} else {
|
||||||
res = _("Could not insert document %1$s");
|
res = _("Could not insert document %1$s");
|
||||||
|
}
|
||||||
|
|
||||||
// emit message signal.
|
// emit message signal.
|
||||||
message(bformat(res, disp_fn));
|
message(bformat(res, disp_fn));
|
||||||
|
@ -578,7 +578,7 @@ bool Converters::scanLog(Buffer const & buffer, string const & /*command*/,
|
|||||||
int const result = latex.scanLogFile(terr);
|
int const result = latex.scanLogFile(terr);
|
||||||
|
|
||||||
if (result & LaTeX::ERRORS)
|
if (result & LaTeX::ERRORS)
|
||||||
bufferErrors(buffer, terr, errorList);
|
buffer.bufferErrors(terr, errorList);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -589,7 +589,7 @@ namespace {
|
|||||||
class ShowMessage
|
class ShowMessage
|
||||||
: public boost::signals::trackable {
|
: public boost::signals::trackable {
|
||||||
public:
|
public:
|
||||||
ShowMessage(Buffer const & b) : buffer_(b) {};
|
ShowMessage(Buffer const & b) : buffer_(b) {}
|
||||||
void operator()(docstring const & msg) const { buffer_.message(msg); }
|
void operator()(docstring const & msg) const { buffer_.message(msg); }
|
||||||
private:
|
private:
|
||||||
Buffer const & buffer_;
|
Buffer const & buffer_;
|
||||||
@ -601,7 +601,7 @@ private:
|
|||||||
bool Converters::runLaTeX(Buffer const & buffer, string const & command,
|
bool Converters::runLaTeX(Buffer const & buffer, string const & command,
|
||||||
OutputParams const & runparams, ErrorList & errorList)
|
OutputParams const & runparams, ErrorList & errorList)
|
||||||
{
|
{
|
||||||
buffer.busy(true);
|
buffer.setBusy(true);
|
||||||
buffer.message(_("Running LaTeX..."));
|
buffer.message(_("Running LaTeX..."));
|
||||||
|
|
||||||
runparams.document_language = buffer.params().language->babel();
|
runparams.document_language = buffer.params().language->babel();
|
||||||
@ -615,7 +615,7 @@ bool Converters::runLaTeX(Buffer const & buffer, string const & command,
|
|||||||
int const result = latex.run(terr);
|
int const result = latex.run(terr);
|
||||||
|
|
||||||
if (result & LaTeX::ERRORS)
|
if (result & LaTeX::ERRORS)
|
||||||
bufferErrors(buffer, terr, errorList);
|
buffer.bufferErrors(terr, errorList);
|
||||||
|
|
||||||
// check return value from latex.run().
|
// check return value from latex.run().
|
||||||
if ((result & LaTeX::NO_LOGFILE)) {
|
if ((result & LaTeX::NO_LOGFILE)) {
|
||||||
@ -630,7 +630,7 @@ bool Converters::runLaTeX(Buffer const & buffer, string const & command,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
buffer.busy(false);
|
buffer.setBusy(false);
|
||||||
|
|
||||||
int const ERROR_MASK =
|
int const ERROR_MASK =
|
||||||
LaTeX::NO_LOGFILE |
|
LaTeX::NO_LOGFILE |
|
||||||
|
@ -602,7 +602,7 @@ void LyX::loadFiles()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Buffer * buf = pimpl_->buffer_list_.newBuffer(it->absFilename(), false);
|
Buffer * buf = pimpl_->buffer_list_.newBuffer(it->absFilename(), false);
|
||||||
if (loadLyXFile(buf, *it)) {
|
if (buf->loadLyXFile(*it)) {
|
||||||
ErrorList const & el = buf->errorList("Parse");
|
ErrorList const & el = buf->errorList("Parse");
|
||||||
if (!el.empty())
|
if (!el.empty())
|
||||||
for_each(el.begin(), el.end(),
|
for_each(el.begin(), el.end(),
|
||||||
|
@ -2504,4 +2504,18 @@ Inset const * Paragraph::getInset(pos_type pos) const
|
|||||||
return d->insetlist_.get(pos);
|
return d->insetlist_.get(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Paragraph::numberOfOptArgs() const
|
||||||
|
{
|
||||||
|
int num = 0;
|
||||||
|
InsetList::const_iterator it = insetList().begin();
|
||||||
|
InsetList::const_iterator end = insetList().end();
|
||||||
|
for (; it != end ; ++it) {
|
||||||
|
if (it->inset->lyxCode() == OPTARG_CODE)
|
||||||
|
++num;
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -371,8 +371,10 @@ public:
|
|||||||
/// by this author in the paragraph.
|
/// by this author in the paragraph.
|
||||||
void checkAuthors(AuthorList const & authorList);
|
void checkAuthors(AuthorList const & authorList);
|
||||||
|
|
||||||
private:
|
/// return the number of InsetOptArg in a paragraph
|
||||||
|
int numberOfOptArgs() const;
|
||||||
|
|
||||||
|
private:
|
||||||
///
|
///
|
||||||
LayoutPtr layout_;
|
LayoutPtr layout_;
|
||||||
/**
|
/**
|
||||||
|
@ -1708,7 +1708,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|||||||
break;
|
break;
|
||||||
case LFUN_OPTIONAL_INSERT:
|
case LFUN_OPTIONAL_INSERT:
|
||||||
code = OPTARG_CODE;
|
code = OPTARG_CODE;
|
||||||
enable = numberOfOptArgs(cur.paragraph())
|
enable = cur.paragraph().numberOfOptArgs()
|
||||||
< cur.paragraph().layout()->optionalargs;
|
< cur.paragraph().layout()->optionalargs;
|
||||||
break;
|
break;
|
||||||
case LFUN_ENVIRONMENT_INSERT:
|
case LFUN_ENVIRONMENT_INSERT:
|
||||||
|
@ -229,6 +229,17 @@ TextClassList::addTextClass(std::string const & textclass, std::string const & p
|
|||||||
TextClassList textclasslist;
|
TextClassList textclasslist;
|
||||||
|
|
||||||
|
|
||||||
|
textclass_type defaultTextclass()
|
||||||
|
{
|
||||||
|
// We want to return the article class. if `first' is
|
||||||
|
// true in the returned pair, then `second' is the textclass
|
||||||
|
// number; if it is false, second is 0. In both cases, second
|
||||||
|
// is what we want.
|
||||||
|
return textclasslist.numberOfClass("article").second;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Reads the style files
|
// Reads the style files
|
||||||
bool LyXSetStyle()
|
bool LyXSetStyle()
|
||||||
{
|
{
|
||||||
|
@ -68,6 +68,8 @@ private:
|
|||||||
|
|
||||||
///
|
///
|
||||||
extern TextClassList textclasslist;
|
extern TextClassList textclasslist;
|
||||||
|
///
|
||||||
|
textclass_type defaultTextclass();
|
||||||
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -37,11 +37,9 @@
|
|||||||
#include "ParagraphList.h"
|
#include "ParagraphList.h"
|
||||||
#include "ParagraphParameters.h"
|
#include "ParagraphParameters.h"
|
||||||
#include "ParIterator.h"
|
#include "ParIterator.h"
|
||||||
#include "LyXVC.h"
|
|
||||||
#include "TexRow.h"
|
#include "TexRow.h"
|
||||||
#include "Text.h"
|
#include "Text.h"
|
||||||
#include "TocBackend.h"
|
#include "TocBackend.h"
|
||||||
#include "VCBackend.h"
|
|
||||||
|
|
||||||
#include "frontends/alert.h"
|
#include "frontends/alert.h"
|
||||||
|
|
||||||
@ -73,111 +71,6 @@ using support::unlink;
|
|||||||
|
|
||||||
namespace Alert = frontend::Alert;
|
namespace Alert = frontend::Alert;
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
bool readFile(Buffer * const b, FileName const & s)
|
|
||||||
{
|
|
||||||
BOOST_ASSERT(b);
|
|
||||||
|
|
||||||
// File information about normal file
|
|
||||||
if (!s.exists()) {
|
|
||||||
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);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if emergency save file exists and is newer.
|
|
||||||
FileName const e(s.absFilename() + ".emergency");
|
|
||||||
|
|
||||||
if (e.exists() && s.exists() && e.lastModified() > s.lastModified()) {
|
|
||||||
docstring const file = makeDisplayPath(s.absFilename(), 20);
|
|
||||||
docstring const text =
|
|
||||||
bformat(_("An emergency save of the document "
|
|
||||||
"%1$s exists.\n\n"
|
|
||||||
"Recover emergency save?"), file);
|
|
||||||
switch (Alert::prompt(_("Load emergency save?"), text, 0, 2,
|
|
||||||
_("&Recover"), _("&Load Original"),
|
|
||||||
_("&Cancel")))
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
// the file is not saved if we load the emergency file.
|
|
||||||
b->markDirty();
|
|
||||||
return b->readFile(e);
|
|
||||||
case 1:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now check if autosave file is newer.
|
|
||||||
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 text =
|
|
||||||
bformat(_("The backup of the document "
|
|
||||||
"%1$s is newer.\n\nLoad the "
|
|
||||||
"backup instead?"), file);
|
|
||||||
switch (Alert::prompt(_("Load backup?"), text, 0, 2,
|
|
||||||
_("&Load backup"), _("Load &original"),
|
|
||||||
_("&Cancel") ))
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
// the file is not saved if we load the autosave file.
|
|
||||||
b->markDirty();
|
|
||||||
return b->readFile(a);
|
|
||||||
case 1:
|
|
||||||
// Here we delete the autosave
|
|
||||||
unlink(a);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return b->readFile(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace anon
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool loadLyXFile(Buffer * b, FileName const & s)
|
|
||||||
{
|
|
||||||
BOOST_ASSERT(b);
|
|
||||||
|
|
||||||
if (s.isReadable()) {
|
|
||||||
if (readFile(b, s)) {
|
|
||||||
b->lyxvc().file_found_hook(s);
|
|
||||||
if (!s.isWritable())
|
|
||||||
b->setReadonly(true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
docstring const file = makeDisplayPath(s.absFilename(), 20);
|
|
||||||
// Here we probably should run
|
|
||||||
if (LyXVC::file_not_found_hook(s)) {
|
|
||||||
docstring const text =
|
|
||||||
bformat(_("Do you want to retrieve the document"
|
|
||||||
" %1$s from version control?"), file);
|
|
||||||
int const ret = Alert::prompt(_("Retrieve from version control?"),
|
|
||||||
text, 0, 1, _("&Retrieve"), _("&Cancel"));
|
|
||||||
|
|
||||||
if (ret == 0) {
|
|
||||||
// How can we know _how_ to do the checkout?
|
|
||||||
// With the current VC support it has to be,
|
|
||||||
// a RCS file since CVS do not have special ,v files.
|
|
||||||
RCS::retrieve(s);
|
|
||||||
return loadLyXFile(b, s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool checkIfLoaded(FileName const & fn)
|
bool checkIfLoaded(FileName const & fn)
|
||||||
{
|
{
|
||||||
@ -211,7 +104,7 @@ Buffer * checkAndLoadLyXFile(FileName const & filename)
|
|||||||
|
|
||||||
if (filename.isReadable()) {
|
if (filename.isReadable()) {
|
||||||
Buffer * b = theBufferList().newBuffer(filename.absFilename());
|
Buffer * b = theBufferList().newBuffer(filename.absFilename());
|
||||||
if (!lyx::loadLyXFile(b, filename)) {
|
if (!b->loadLyXFile(filename)) {
|
||||||
theBufferList().release(b);
|
theBufferList().release(b);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -228,6 +121,7 @@ Buffer * checkAndLoadLyXFile(FileName const & filename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FIXME newFile() should probably be a member method of Application...
|
// FIXME newFile() should probably be a member method of Application...
|
||||||
Buffer * newFile(string const & filename, string const & templatename,
|
Buffer * newFile(string const & filename, string const & templatename,
|
||||||
bool const isNamed)
|
bool const isNamed)
|
||||||
@ -267,32 +161,6 @@ Buffer * newFile(string const & filename, string const & templatename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void bufferErrors(Buffer const & buf, TeXErrors const & terr,
|
|
||||||
ErrorList & errorList)
|
|
||||||
{
|
|
||||||
TeXErrors::Errors::const_iterator cit = terr.begin();
|
|
||||||
TeXErrors::Errors::const_iterator end = terr.end();
|
|
||||||
|
|
||||||
for (; cit != end; ++cit) {
|
|
||||||
int id_start = -1;
|
|
||||||
int pos_start = -1;
|
|
||||||
int errorrow = cit->error_in_line;
|
|
||||||
bool found = buf.texrow().getIdFromRow(errorrow, id_start,
|
|
||||||
pos_start);
|
|
||||||
int id_end = -1;
|
|
||||||
int pos_end = -1;
|
|
||||||
do {
|
|
||||||
++errorrow;
|
|
||||||
found = buf.texrow().getIdFromRow(errorrow, id_end,
|
|
||||||
pos_end);
|
|
||||||
} while (found && id_start == id_end && pos_start == pos_end);
|
|
||||||
|
|
||||||
errorList.push_back(ErrorItem(cit->error_desc,
|
|
||||||
cit->error_text, id_start, pos_start, pos_end));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int countWords(DocIterator const & from, DocIterator const & to)
|
int countWords(DocIterator const & from, DocIterator const & to)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -623,13 +491,4 @@ void checkBufferStructure(Buffer & buffer, ParIterator const & par_it)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
textclass_type defaultTextclass()
|
|
||||||
{
|
|
||||||
// We want to return the article class. if `first' is
|
|
||||||
// true in the returned pair, then `second' is the textclass
|
|
||||||
// number; if it is false, second is 0. In both cases, second
|
|
||||||
// is what we want.
|
|
||||||
return textclasslist.numberOfClass("article").second;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -12,19 +12,14 @@
|
|||||||
#ifndef BUFFER_FUNCS_H
|
#ifndef BUFFER_FUNCS_H
|
||||||
#define BUFFER_FUNCS_H
|
#define BUFFER_FUNCS_H
|
||||||
|
|
||||||
#include "support/docstring.h"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
namespace support { class FileName; }
|
namespace support { class FileName; }
|
||||||
|
|
||||||
class Buffer;
|
class Buffer;
|
||||||
class DocIterator;
|
class DocIterator;
|
||||||
class ErrorList;
|
|
||||||
class TeXErrors;
|
|
||||||
class ParIterator;
|
class ParIterator;
|
||||||
|
|
||||||
|
|
||||||
@ -33,12 +28,6 @@ class ParIterator;
|
|||||||
*/
|
*/
|
||||||
bool checkIfLoaded(support::FileName const & fn);
|
bool checkIfLoaded(support::FileName const & fn);
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a LyX file \c filename into \c Buffer
|
|
||||||
* and \return success status.
|
|
||||||
*/
|
|
||||||
bool loadLyXFile(Buffer *, support::FileName const & filename);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks and loads a LyX file \param filename.
|
* Checks and loads a LyX file \param filename.
|
||||||
* \retval the newly created \c Buffer pointer if successful or 0.
|
* \retval the newly created \c Buffer pointer if successful or 0.
|
||||||
@ -52,9 +41,6 @@ Buffer * checkAndLoadLyXFile(support::FileName const & filename);
|
|||||||
Buffer * newFile(std::string const & filename, std::string const & templatename,
|
Buffer * newFile(std::string const & filename, std::string const & templatename,
|
||||||
bool isNamed = false);
|
bool isNamed = false);
|
||||||
|
|
||||||
/// Fill in the ErrorList with the TeXErrors
|
|
||||||
void bufferErrors(Buffer const &, TeXErrors const &, ErrorList &);
|
|
||||||
|
|
||||||
/// Count the number of words in the text between these two iterators
|
/// Count the number of words in the text between these two iterators
|
||||||
int countWords(DocIterator const & from, DocIterator const & to);
|
int countWords(DocIterator const & from, DocIterator const & to);
|
||||||
|
|
||||||
@ -67,9 +53,6 @@ void updateLabels(Buffer const &, ParIterator &);
|
|||||||
///
|
///
|
||||||
void checkBufferStructure(Buffer &, ParIterator const &);
|
void checkBufferStructure(Buffer &, ParIterator const &);
|
||||||
|
|
||||||
///
|
|
||||||
textclass_type defaultTextclass();
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
#endif // BUFFER_FUNCS_H
|
#endif // BUFFER_FUNCS_H
|
||||||
|
@ -203,7 +203,7 @@ bool InsetCaption::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case LFUN_OPTIONAL_INSERT:
|
case LFUN_OPTIONAL_INSERT:
|
||||||
status.enabled(numberOfOptArgs(cur.paragraph()) == 0);
|
status.enabled(cur.paragraph().numberOfOptArgs() == 0);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -400,7 +400,7 @@ Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
child = theBufferList().newBuffer(included_file.absFilename());
|
child = theBufferList().newBuffer(included_file.absFilename());
|
||||||
if (!loadLyXFile(child, included_file)) {
|
if (!child->loadLyXFile(included_file)) {
|
||||||
//close the buffer we just opened
|
//close the buffer we just opened
|
||||||
theBufferList().close(child, false);
|
theBufferList().close(child, false);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -308,21 +308,6 @@ Font const outerFont(pit_type par_offset, ParagraphList const & pars)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// return the number of InsetOptArg in a paragraph
|
|
||||||
int numberOfOptArgs(Paragraph const & par)
|
|
||||||
{
|
|
||||||
int num = 0;
|
|
||||||
|
|
||||||
InsetList::const_iterator it = par.insetList().begin();
|
|
||||||
InsetList::const_iterator end = par.insetList().end();
|
|
||||||
for (; it != end ; ++it) {
|
|
||||||
if (it->inset->lyxCode() == OPTARG_CODE)
|
|
||||||
++num;
|
|
||||||
}
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void acceptChanges(ParagraphList & pars, BufferParams const & bparams)
|
void acceptChanges(ParagraphList & pars, BufferParams const & bparams)
|
||||||
{
|
{
|
||||||
pit_type pars_size = static_cast<pit_type>(pars.size());
|
pit_type pars_size = static_cast<pit_type>(pars.size());
|
||||||
|
@ -72,9 +72,6 @@ int getEndLabel(pit_type par, ParagraphList const & plist);
|
|||||||
*/
|
*/
|
||||||
Font const outerFont(pit_type par_offset, ParagraphList const & pars);
|
Font const outerFont(pit_type par_offset, ParagraphList const & pars);
|
||||||
|
|
||||||
/// return the number of InsetOptArg in a paragraph
|
|
||||||
int numberOfOptArgs(Paragraph const & par);
|
|
||||||
|
|
||||||
/// accept the changes within the complete ParagraphList
|
/// accept the changes within the complete ParagraphList
|
||||||
void acceptChanges(ParagraphList & pars, BufferParams const & bparams);
|
void acceptChanges(ParagraphList & pars, BufferParams const & bparams);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user