2003-06-20 12:46:28 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file buffer_funcs.cpp
|
2003-06-20 12:46:28 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2003-06-20 12:46:28 +00:00
|
|
|
|
* \author Alfredo Braunstein
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-06-20 12:46:28 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "buffer_funcs.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
|
|
|
|
#include "BufferList.h"
|
|
|
|
|
#include "BufferParams.h"
|
|
|
|
|
#include "DocIterator.h"
|
|
|
|
|
#include "Counters.h"
|
|
|
|
|
#include "ErrorList.h"
|
2005-02-25 11:55:36 +00:00
|
|
|
|
#include "Floating.h"
|
|
|
|
|
#include "FloatList.h"
|
2007-10-18 15:29:51 +00:00
|
|
|
|
#include "InsetList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Language.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "LaTeX.h"
|
2007-09-29 20:02:32 +00:00
|
|
|
|
#include "Layout.h"
|
2007-08-13 18:11:43 +00:00
|
|
|
|
#include "LyX.h"
|
2007-04-29 19:53:54 +00:00
|
|
|
|
#include "TextClass.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Paragraph.h"
|
2005-04-19 09:04:25 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2006-03-23 20:11:06 +00:00
|
|
|
|
#include "ParagraphList.h"
|
2005-02-25 11:55:36 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "ParIterator.h"
|
|
|
|
|
#include "TexRow.h"
|
2007-08-15 13:47:32 +00:00
|
|
|
|
#include "Text.h"
|
2006-11-11 00:35:14 +00:00
|
|
|
|
#include "TocBackend.h"
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "frontends/alert.h"
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetBibitem.h"
|
|
|
|
|
#include "insets/InsetInclude.h"
|
2005-02-25 11:55:36 +00:00
|
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
|
#include "support/lassert.h"
|
2007-12-07 11:57:13 +00:00
|
|
|
|
#include "support/convert.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "support/filetools.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/gettext.h"
|
2007-11-13 23:50:28 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2008-01-08 15:18:00 +00:00
|
|
|
|
#include "support/textutils.h"
|
2007-07-17 17:40:44 +00:00
|
|
|
|
|
2006-04-16 14:19:25 +00:00
|
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
|
using namespace lyx::support;
|
2006-04-16 14:19:25 +00:00
|
|
|
|
|
2007-12-12 18:57:56 +00:00
|
|
|
|
namespace lyx {
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace Alert = frontend::Alert;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2007-06-19 16:03:47 +00:00
|
|
|
|
|
|
|
|
|
Buffer * checkAndLoadLyXFile(FileName const & filename)
|
|
|
|
|
{
|
|
|
|
|
// File already open?
|
2007-08-06 04:14:26 +00:00
|
|
|
|
Buffer * checkBuffer = theBufferList().getBuffer(filename.absFilename());
|
|
|
|
|
if (checkBuffer) {
|
|
|
|
|
if (checkBuffer->isClean())
|
|
|
|
|
return checkBuffer;
|
2007-06-19 16:03:47 +00:00
|
|
|
|
docstring const file = makeDisplayPath(filename.absFilename(), 20);
|
2007-08-06 04:14:26 +00:00
|
|
|
|
docstring text = bformat(_(
|
|
|
|
|
"The document %1$s is already loaded and has unsaved changes.\n"
|
|
|
|
|
"Do you want to abandon your changes and reload the version on disk?"), file);
|
|
|
|
|
if (Alert::prompt(_("Reload saved document?"),
|
|
|
|
|
text, 0, 1, _("&Reload"), _("&Keep Changes")))
|
|
|
|
|
return checkBuffer;
|
2007-06-19 16:03:47 +00:00
|
|
|
|
|
|
|
|
|
// FIXME: should be LFUN_REVERT
|
2007-12-04 22:21:25 +00:00
|
|
|
|
theBufferList().release(checkBuffer);
|
|
|
|
|
// Load it again.
|
|
|
|
|
return checkAndLoadLyXFile(filename);
|
2007-06-19 16:03:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-26 20:37:54 +00:00
|
|
|
|
if (filename.exists()) {
|
|
|
|
|
if (!filename.isReadableFile()) {
|
|
|
|
|
docstring text = bformat(_("The file %1$s exists but is not "
|
|
|
|
|
"readable by the current user."),
|
|
|
|
|
from_utf8(filename.absFilename()));
|
|
|
|
|
Alert::error(_("File not readable!"), text);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2007-06-19 16:03:47 +00:00
|
|
|
|
Buffer * b = theBufferList().newBuffer(filename.absFilename());
|
2007-12-17 18:37:13 +00:00
|
|
|
|
if (!b)
|
|
|
|
|
// Buffer creation is not possible.
|
|
|
|
|
return 0;
|
2007-10-21 10:50:56 +00:00
|
|
|
|
if (!b->loadLyXFile(filename)) {
|
2007-06-19 16:03:47 +00:00
|
|
|
|
theBufferList().release(b);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
docstring text = bformat(_("The document %1$s does not yet "
|
|
|
|
|
"exist.\n\nDo you want to create a new document?"),
|
|
|
|
|
from_utf8(filename.absFilename()));
|
2007-06-20 21:07:32 +00:00
|
|
|
|
if (!Alert::prompt(_("Create new document?"),
|
2007-06-19 16:03:47 +00:00
|
|
|
|
text, 0, 1, _("&Create"), _("Cancel")))
|
|
|
|
|
return newFile(filename.absFilename(), string(), true);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-21 10:50:56 +00:00
|
|
|
|
|
2006-09-27 10:24:13 +00:00
|
|
|
|
// FIXME newFile() should probably be a member method of Application...
|
2003-06-30 23:56:22 +00:00
|
|
|
|
Buffer * newFile(string const & filename, string const & templatename,
|
2005-01-05 20:21:27 +00:00
|
|
|
|
bool const isNamed)
|
2003-06-20 12:46:28 +00:00
|
|
|
|
{
|
|
|
|
|
// get a free buffer
|
2006-10-11 17:24:46 +00:00
|
|
|
|
Buffer * b = theBufferList().newBuffer(filename);
|
2007-12-17 18:37:13 +00:00
|
|
|
|
if (!b)
|
|
|
|
|
// Buffer creation is not possible.
|
|
|
|
|
return 0;
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
2006-12-17 12:12:17 +00:00
|
|
|
|
FileName tname;
|
2003-06-20 12:46:28 +00:00
|
|
|
|
// use defaults.lyx as a default template if it exists.
|
|
|
|
|
if (templatename.empty())
|
2006-12-17 12:12:17 +00:00
|
|
|
|
tname = libFileSearch("templates", "defaults.lyx");
|
2003-06-20 12:46:28 +00:00
|
|
|
|
else
|
2006-12-27 10:56:11 +00:00
|
|
|
|
tname = makeAbsPath(templatename);
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
|
|
|
|
if (!tname.empty()) {
|
2003-07-28 14:40:29 +00:00
|
|
|
|
if (!b->readFile(tname)) {
|
2006-12-17 12:12:17 +00:00
|
|
|
|
docstring const file = makeDisplayPath(tname.absFilename(), 50);
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring const text = bformat(
|
|
|
|
|
_("The specified document template\n%1$s\ncould not be read."),
|
|
|
|
|
file);
|
|
|
|
|
Alert::error(_("Could not read template"), text);
|
2006-10-11 17:24:46 +00:00
|
|
|
|
theBufferList().release(b);
|
2006-07-17 15:13:49 +00:00
|
|
|
|
return 0;
|
2003-06-20 12:46:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isNamed) {
|
|
|
|
|
b->setUnnamed();
|
|
|
|
|
b->setFileName(filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b->setReadonly(false);
|
2007-10-20 10:03:45 +00:00
|
|
|
|
b->setFullyLoaded(true);
|
2003-06-20 12:46:28 +00:00
|
|
|
|
|
|
|
|
|
return b;
|
|
|
|
|
}
|
2003-06-24 20:42:15 +00:00
|
|
|
|
|
|
|
|
|
|
2007-12-07 11:57:13 +00:00
|
|
|
|
Buffer * newUnnamedFile(string const & templatename, FileName const & path)
|
|
|
|
|
{
|
|
|
|
|
static int newfile_number;
|
|
|
|
|
|
|
|
|
|
string document_path = path.absFilename();
|
|
|
|
|
string filename = addName(document_path,
|
|
|
|
|
"newfile" + convert<string>(++newfile_number) + ".lyx");
|
|
|
|
|
while (theBufferList().exists(filename)
|
|
|
|
|
|| FileName(filename).isReadableFile()) {
|
|
|
|
|
++newfile_number;
|
|
|
|
|
filename = addName(document_path,
|
|
|
|
|
"newfile" + convert<string>(newfile_number) + ".lyx");
|
|
|
|
|
}
|
|
|
|
|
return newFile(filename, templatename, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-12-27 16:30:27 +00:00
|
|
|
|
int countWords(DocIterator const & from, DocIterator const & to)
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
bool inword = false;
|
|
|
|
|
for (DocIterator dit = from ; dit != to ; dit.forwardPos()) {
|
|
|
|
|
// Copied and adapted from isLetter() in ControlSpellChecker
|
|
|
|
|
if (dit.inTexted()
|
|
|
|
|
&& dit.pos() != dit.lastpos()
|
|
|
|
|
&& dit.paragraph().isLetter(dit.pos())
|
2006-10-19 12:49:11 +00:00
|
|
|
|
&& !dit.paragraph().isDeleted(dit.pos())) {
|
2004-12-27 16:30:27 +00:00
|
|
|
|
if (!inword) {
|
|
|
|
|
++count;
|
|
|
|
|
inword = true;
|
|
|
|
|
}
|
|
|
|
|
} else if (inword)
|
|
|
|
|
inword = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
2005-02-25 11:55:36 +00:00
|
|
|
|
|
|
|
|
|
|
2008-01-08 15:18:00 +00:00
|
|
|
|
int countChars(DocIterator const & from, DocIterator const & to, bool with_blanks)
|
|
|
|
|
{
|
|
|
|
|
int chars = 0;
|
|
|
|
|
int blanks = 0;
|
|
|
|
|
for (DocIterator dit = from ; dit != to ; dit.forwardPos()) {
|
2008-01-15 22:30:19 +00:00
|
|
|
|
|
|
|
|
|
if (!dit.inTexted()) continue;
|
2008-01-12 16:34:02 +00:00
|
|
|
|
Paragraph const & par = dit.paragraph();
|
2008-01-12 13:34:10 +00:00
|
|
|
|
pos_type const pos = dit.pos();
|
|
|
|
|
|
2008-01-15 22:30:19 +00:00
|
|
|
|
if (pos != dit.lastpos() && !par.isDeleted(pos)) {
|
2008-02-09 10:41:49 +00:00
|
|
|
|
if (Inset const * ins = par.getInset(pos)) {
|
2008-01-12 13:34:10 +00:00
|
|
|
|
if (ins->isLetter())
|
2008-01-08 15:18:00 +00:00
|
|
|
|
++chars;
|
2008-01-12 16:34:02 +00:00
|
|
|
|
else if (with_blanks && ins->isSpace())
|
2008-01-08 15:18:00 +00:00
|
|
|
|
++blanks;
|
|
|
|
|
} else {
|
2008-01-12 16:34:02 +00:00
|
|
|
|
char_type const c = par.getChar(pos);
|
2008-01-08 15:18:00 +00:00
|
|
|
|
if (isPrintableNonspace(c))
|
|
|
|
|
++chars;
|
|
|
|
|
else if (isSpace(c) && with_blanks)
|
|
|
|
|
++blanks;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return chars + blanks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-25 11:55:36 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
depth_type getDepth(DocIterator const & it)
|
2005-02-25 11:55:36 +00:00
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
|
depth_type depth = 0;
|
2006-04-05 23:56:29 +00:00
|
|
|
|
for (size_t i = 0 ; i < it.depth() ; ++i)
|
2005-08-03 20:21:11 +00:00
|
|
|
|
if (!it[i].inset().inMathed())
|
|
|
|
|
depth += it[i].paragraph().getDepth() + 1;
|
|
|
|
|
// remove 1 since the outer inset does not count
|
|
|
|
|
return depth - 1;
|
|
|
|
|
}
|
2005-02-25 11:55:36 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
depth_type getItemDepth(ParIterator const & it)
|
2006-04-05 23:56:29 +00:00
|
|
|
|
{
|
2005-08-03 20:21:11 +00:00
|
|
|
|
Paragraph const & par = *it;
|
2008-03-06 21:31:27 +00:00
|
|
|
|
LabelType const labeltype = par.layout().labeltype;
|
2005-02-25 11:55:36 +00:00
|
|
|
|
|
2005-08-03 20:21:11 +00:00
|
|
|
|
if (labeltype != LABEL_ENUMERATE && labeltype != LABEL_ITEMIZE)
|
2006-04-05 23:56:29 +00:00
|
|
|
|
return 0;
|
2005-02-25 11:55:36 +00:00
|
|
|
|
|
2005-08-03 20:21:11 +00:00
|
|
|
|
// this will hold the lowest depth encountered up to now.
|
2006-10-21 00:16:43 +00:00
|
|
|
|
depth_type min_depth = getDepth(it);
|
2005-08-03 20:21:11 +00:00
|
|
|
|
ParIterator prev_it = it;
|
2005-02-25 11:55:36 +00:00
|
|
|
|
while (true) {
|
2005-08-03 20:21:11 +00:00
|
|
|
|
if (prev_it.pit())
|
|
|
|
|
--prev_it.top().pit();
|
|
|
|
|
else {
|
|
|
|
|
// start of nested inset: go to outer par
|
|
|
|
|
prev_it.pop_back();
|
|
|
|
|
if (prev_it.empty()) {
|
|
|
|
|
// start of document: nothing to do
|
|
|
|
|
return 0;
|
2005-02-25 11:55:36 +00:00
|
|
|
|
}
|
2005-08-03 20:21:11 +00:00
|
|
|
|
}
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2005-08-03 20:21:11 +00:00
|
|
|
|
// We search for the first paragraph with same label
|
|
|
|
|
// that is not more deeply nested.
|
|
|
|
|
Paragraph & prev_par = *prev_it;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
depth_type const prev_depth = getDepth(prev_it);
|
2008-03-06 21:31:27 +00:00
|
|
|
|
if (labeltype == prev_par.layout().labeltype) {
|
2007-11-07 19:52:11 +00:00
|
|
|
|
if (prev_depth < min_depth)
|
2005-08-03 20:21:11 +00:00
|
|
|
|
return prev_par.itemdepth + 1;
|
2007-11-07 19:52:11 +00:00
|
|
|
|
if (prev_depth == min_depth)
|
2005-08-03 20:21:11 +00:00
|
|
|
|
return prev_par.itemdepth;
|
2005-02-25 11:55:36 +00:00
|
|
|
|
}
|
2007-12-12 19:28:07 +00:00
|
|
|
|
min_depth = min(min_depth, prev_depth);
|
2005-08-03 20:21:11 +00:00
|
|
|
|
// small optimization: if we are at depth 0, we won't
|
|
|
|
|
// find anything else
|
2007-11-07 19:52:11 +00:00
|
|
|
|
if (prev_depth == 0)
|
2005-08-03 20:21:11 +00:00
|
|
|
|
return 0;
|
2005-02-25 11:55:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-08-03 20:21:11 +00:00
|
|
|
|
bool needEnumCounterReset(ParIterator const & it)
|
2005-02-25 11:55:36 +00:00
|
|
|
|
{
|
2005-08-03 20:21:11 +00:00
|
|
|
|
Paragraph const & par = *it;
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(par.layout().labeltype == LABEL_ENUMERATE, /**/);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
depth_type const cur_depth = par.getDepth();
|
2005-08-03 20:21:11 +00:00
|
|
|
|
ParIterator prev_it = it;
|
|
|
|
|
while (prev_it.pit()) {
|
|
|
|
|
--prev_it.top().pit();
|
|
|
|
|
Paragraph const & prev_par = *prev_it;
|
|
|
|
|
if (prev_par.getDepth() <= cur_depth)
|
2008-03-06 21:31:27 +00:00
|
|
|
|
return prev_par.layout().labeltype != LABEL_ENUMERATE;
|
2005-02-25 11:55:36 +00:00
|
|
|
|
}
|
2005-08-03 20:21:11 +00:00
|
|
|
|
// start of nested inset: reset
|
|
|
|
|
return true;
|
2005-02-25 11:55:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-04-16 14:19:25 +00:00
|
|
|
|
// set the label of a paragraph. This includes the counters.
|
2007-08-12 21:43:58 +00:00
|
|
|
|
void setLabel(Buffer const & buf, ParIterator & it)
|
2005-02-25 11:55:36 +00:00
|
|
|
|
{
|
2008-05-20 11:25:29 +00:00
|
|
|
|
BufferParams const & bp = buf.masterBuffer()->params();
|
|
|
|
|
DocumentClass const & textclass = bp.documentClass();
|
2007-08-12 21:43:58 +00:00
|
|
|
|
Paragraph & par = it.paragraph();
|
2008-03-06 21:31:27 +00:00
|
|
|
|
Layout const & layout = par.layout();
|
2005-02-25 11:55:36 +00:00
|
|
|
|
Counters & counters = textclass.counters();
|
|
|
|
|
|
2007-07-11 12:52:50 +00:00
|
|
|
|
if (par.params().startOfAppendix()) {
|
|
|
|
|
// FIXME: only the counter corresponding to toplevel
|
|
|
|
|
// sectionning should be reset
|
|
|
|
|
counters.reset();
|
|
|
|
|
counters.appendix(true);
|
2005-02-25 11:55:36 +00:00
|
|
|
|
}
|
2007-07-11 12:52:50 +00:00
|
|
|
|
par.params().appendix(counters.appendix());
|
2005-02-25 11:55:36 +00:00
|
|
|
|
|
2005-08-03 20:21:11 +00:00
|
|
|
|
// Compute the item depth of the paragraph
|
|
|
|
|
par.itemdepth = getItemDepth(it);
|
|
|
|
|
|
2008-03-06 21:31:27 +00:00
|
|
|
|
if (layout.margintype == MARGIN_MANUAL) {
|
2005-02-25 11:55:36 +00:00
|
|
|
|
if (par.params().labelWidthString().empty())
|
2008-05-20 11:25:29 +00:00
|
|
|
|
par.params().labelWidthString(par.translateIfPossible(layout.labelstring(), bp));
|
2005-02-25 11:55:36 +00:00
|
|
|
|
} else {
|
2007-01-15 16:58:14 +00:00
|
|
|
|
par.params().labelWidthString(docstring());
|
2005-02-25 11:55:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-03-06 21:31:27 +00:00
|
|
|
|
switch(layout.labeltype) {
|
2007-08-17 09:15:04 +00:00
|
|
|
|
case LABEL_COUNTER:
|
2008-05-20 11:25:29 +00:00
|
|
|
|
if (layout.toclevel <= bp.secnumdepth
|
2008-03-06 21:31:27 +00:00
|
|
|
|
&& (layout.latextype != LATEX_ENVIRONMENT
|
2005-04-19 09:04:25 +00:00
|
|
|
|
|| isFirstInSequence(it.pit(), it.plist()))) {
|
2008-03-06 21:31:27 +00:00
|
|
|
|
counters.step(layout.counter);
|
2007-01-15 16:58:14 +00:00
|
|
|
|
par.params().labelString(
|
2008-05-20 11:25:29 +00:00
|
|
|
|
par.expandLabel(layout, bp));
|
2007-01-11 16:38:08 +00:00
|
|
|
|
} else
|
2007-01-15 16:58:14 +00:00
|
|
|
|
par.params().labelString(docstring());
|
2007-08-17 09:15:04 +00:00
|
|
|
|
break;
|
2007-01-11 16:38:08 +00:00
|
|
|
|
|
2007-08-17 09:15:04 +00:00
|
|
|
|
case LABEL_ITEMIZE: {
|
2005-02-25 11:55:36 +00:00
|
|
|
|
// At some point of time we should do something more
|
|
|
|
|
// clever here, like:
|
|
|
|
|
// par.params().labelString(
|
2008-05-20 11:25:29 +00:00
|
|
|
|
// bp.user_defined_bullet(par.itemdepth).getText());
|
2005-02-25 11:55:36 +00:00
|
|
|
|
// for now, use a simple hardcoded label
|
2007-08-12 21:43:58 +00:00
|
|
|
|
docstring itemlabel;
|
2005-02-25 11:55:36 +00:00
|
|
|
|
switch (par.itemdepth) {
|
|
|
|
|
case 0:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
itemlabel = char_type(0x2022);
|
2005-02-25 11:55:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
itemlabel = char_type(0x2013);
|
2005-02-25 11:55:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2006-10-21 00:16:43 +00:00
|
|
|
|
itemlabel = char_type(0x2217);
|
2005-02-25 11:55:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2007-01-11 16:38:08 +00:00
|
|
|
|
itemlabel = char_type(0x2219); // or 0x00b7
|
2005-02-25 11:55:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-01-15 16:58:14 +00:00
|
|
|
|
par.params().labelString(itemlabel);
|
2007-08-17 09:15:04 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-25 11:55:36 +00:00
|
|
|
|
|
2007-08-17 09:15:04 +00:00
|
|
|
|
case LABEL_ENUMERATE: {
|
|
|
|
|
// FIXME: Yes I know this is a really, really! bad solution
|
2005-02-25 11:55:36 +00:00
|
|
|
|
// (Lgb)
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring enumcounter = from_ascii("enum");
|
2005-02-25 11:55:36 +00:00
|
|
|
|
|
|
|
|
|
switch (par.itemdepth) {
|
|
|
|
|
case 2:
|
|
|
|
|
enumcounter += 'i';
|
|
|
|
|
case 1:
|
|
|
|
|
enumcounter += 'i';
|
|
|
|
|
case 0:
|
|
|
|
|
enumcounter += 'i';
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
enumcounter += "iv";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// not a valid enumdepth...
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-03 20:21:11 +00:00
|
|
|
|
// Maybe we have to reset the enumeration counter.
|
|
|
|
|
if (needEnumCounterReset(it))
|
|
|
|
|
counters.reset(enumcounter);
|
|
|
|
|
|
2005-02-25 11:55:36 +00:00
|
|
|
|
counters.step(enumcounter);
|
|
|
|
|
|
2005-09-09 14:52:55 +00:00
|
|
|
|
string format;
|
|
|
|
|
|
|
|
|
|
switch (par.itemdepth) {
|
|
|
|
|
case 0:
|
|
|
|
|
format = N_("\\arabic{enumi}.");
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
format = N_("(\\alph{enumii})");
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
format = N_("\\roman{enumiii}.");
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
format = N_("\\Alph{enumiv}.");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// not a valid enumdepth...
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-15 16:58:14 +00:00
|
|
|
|
par.params().labelString(counters.counterLabel(
|
2008-05-20 11:25:29 +00:00
|
|
|
|
par.translateIfPossible(from_ascii(format), bp)));
|
2007-01-11 16:38:08 +00:00
|
|
|
|
|
2007-08-17 09:15:04 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LABEL_SENSITIVE: {
|
2007-08-12 21:43:58 +00:00
|
|
|
|
string const & type = counters.current_float();
|
|
|
|
|
docstring full_label;
|
|
|
|
|
if (type.empty())
|
|
|
|
|
full_label = buf.B_("Senseless!!! ");
|
|
|
|
|
else {
|
|
|
|
|
docstring name = buf.B_(textclass.floats().getType(type).name());
|
|
|
|
|
if (counters.hasCounter(from_utf8(type))) {
|
|
|
|
|
counters.step(from_utf8(type));
|
|
|
|
|
full_label = bformat(from_ascii("%1$s %2$s:"),
|
|
|
|
|
name,
|
2007-08-16 11:12:56 +00:00
|
|
|
|
counters.theCounter(from_utf8(type)));
|
2007-08-12 21:43:58 +00:00
|
|
|
|
} else
|
|
|
|
|
full_label = bformat(from_ascii("%1$s #:"), name);
|
2005-02-25 11:55:36 +00:00
|
|
|
|
}
|
2007-08-12 21:43:58 +00:00
|
|
|
|
par.params().labelString(full_label);
|
2007-08-17 09:15:04 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-25 11:55:36 +00:00
|
|
|
|
|
2007-08-17 09:15:04 +00:00
|
|
|
|
case LABEL_NO_LABEL:
|
2007-01-15 16:58:14 +00:00
|
|
|
|
par.params().labelString(docstring());
|
2007-08-17 09:15:04 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LABEL_MANUAL:
|
|
|
|
|
case LABEL_TOP_ENVIRONMENT:
|
|
|
|
|
case LABEL_CENTERED_TOP_ENVIRONMENT:
|
|
|
|
|
case LABEL_STATIC:
|
|
|
|
|
case LABEL_BIBLIO:
|
2007-01-15 16:58:14 +00:00
|
|
|
|
par.params().labelString(
|
2008-05-20 11:25:29 +00:00
|
|
|
|
par.translateIfPossible(layout.labelstring(), bp));
|
2007-08-17 09:15:04 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-25 11:55:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
2007-08-12 21:43:58 +00:00
|
|
|
|
void updateLabels(Buffer const & buf, ParIterator & parit)
|
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(parit.pit() == 0, /**/);
|
2007-08-12 21:43:58 +00:00
|
|
|
|
|
2007-12-21 20:42:46 +00:00
|
|
|
|
// set the position of the text in the buffer to be able
|
|
|
|
|
// to resolve macros in it. This has nothing to do with
|
|
|
|
|
// labels, but by putting it here we avoid implementing
|
|
|
|
|
// a whole bunch of traversal routines just for this call.
|
|
|
|
|
parit.text()->setMacrocontextPosition(parit);
|
|
|
|
|
|
2007-08-12 21:43:58 +00:00
|
|
|
|
depth_type maxdepth = 0;
|
|
|
|
|
pit_type const lastpit = parit.lastpit();
|
|
|
|
|
for ( ; parit.pit() <= lastpit ; ++parit.pit()) {
|
|
|
|
|
// reduce depth if necessary
|
|
|
|
|
parit->params().depth(min(parit->params().depth(), maxdepth));
|
|
|
|
|
maxdepth = parit->getMaxDepthAfter();
|
|
|
|
|
|
|
|
|
|
// set the counter for this paragraph
|
|
|
|
|
setLabel(buf, parit);
|
|
|
|
|
|
|
|
|
|
// Now the insets
|
2007-10-18 15:29:51 +00:00
|
|
|
|
InsetList::const_iterator iit = parit->insetList().begin();
|
|
|
|
|
InsetList::const_iterator end = parit->insetList().end();
|
2007-08-12 21:43:58 +00:00
|
|
|
|
for (; iit != end; ++iit) {
|
|
|
|
|
parit.pos() = iit->pos;
|
2008-02-27 20:43:16 +00:00
|
|
|
|
iit->inset->updateLabels(parit);
|
2007-08-12 21:43:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-25 11:55:36 +00:00
|
|
|
|
|
2007-08-14 16:59:59 +00:00
|
|
|
|
// FIXME: buf should should be const because updateLabels() modifies
|
|
|
|
|
// the contents of the paragraphs.
|
2006-11-13 16:53:49 +00:00
|
|
|
|
void updateLabels(Buffer const & buf, bool childonly)
|
2005-02-25 11:55:36 +00:00
|
|
|
|
{
|
2007-10-20 10:03:45 +00:00
|
|
|
|
Buffer const * const master = buf.masterBuffer();
|
2006-11-13 16:53:49 +00:00
|
|
|
|
// Use the master text class also for child documents
|
2008-02-28 01:42:02 +00:00
|
|
|
|
DocumentClass const & textclass = master->params().documentClass();
|
2006-11-13 16:53:49 +00:00
|
|
|
|
|
|
|
|
|
if (!childonly) {
|
|
|
|
|
// If this is a child document start with the master
|
|
|
|
|
if (master != &buf) {
|
|
|
|
|
updateLabels(*master);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// start over the counters
|
|
|
|
|
textclass.counters().reset();
|
2008-03-02 15:27:35 +00:00
|
|
|
|
buf.clearReferenceCache();
|
2008-03-06 18:13:04 +00:00
|
|
|
|
buf.updateMacros();
|
2006-11-13 16:53:49 +00:00
|
|
|
|
}
|
2006-09-09 11:16:28 +00:00
|
|
|
|
|
2007-08-14 16:59:59 +00:00
|
|
|
|
Buffer & cbuf = const_cast<Buffer &>(buf);
|
|
|
|
|
|
|
|
|
|
if (buf.text().empty()) {
|
2007-08-15 13:47:32 +00:00
|
|
|
|
// FIXME: we don't call continue with updateLabels()
|
|
|
|
|
// here because it crashes on newly created documents.
|
|
|
|
|
// But the TocBackend needs to be initialised
|
|
|
|
|
// nonetheless so we update the tocBackend manually.
|
2007-08-14 16:59:59 +00:00
|
|
|
|
cbuf.tocBackend().update();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-12 21:43:58 +00:00
|
|
|
|
// do the real work
|
|
|
|
|
ParIterator parit = par_iterator_begin(buf.inset());
|
|
|
|
|
updateLabels(buf, parit);
|
2006-04-22 18:48:28 +00:00
|
|
|
|
|
2007-03-12 11:23:41 +00:00
|
|
|
|
cbuf.tocBackend().update();
|
2007-05-17 19:19:37 +00:00
|
|
|
|
if (!childonly)
|
|
|
|
|
cbuf.structureChanged();
|
2005-02-25 11:55:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|