Exemplo n.º 1
0
void InsetText::addToToc(DocIterator const & cdit, bool output_active,
						 UpdateType utype, TocBackend & backend) const
{
	DocIterator dit = cdit;
	dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
	iterateForToc(dit, output_active, utype, backend);
}
Exemplo n.º 2
0
bool SpellcheckerWidget::Private::atLastPos(DocIterator const & cursor) const
{
	bool const valid_end = !end_.empty();
	return cursor.depth() <= 1 && (
		cursor.atEnd() ||
		(valid_end && isCurrentBuffer(cursor) && cursor >= end_));
}
Exemplo n.º 3
0
void RowPainter::paintMisspelledMark(Row::Element const & e) const
{
	if (e.font.fontInfo().nospellcheck() == FONT_ON)
		return;
	// if changed the misspelled marker gets placed slightly lower than normal
	// to avoid drawing at the same vertical offset
	FontMetrics const & fm = theFontMetrics(e.font);
	int const thickness = max(fm.lineWidth(), 2);
	int const y = yo_ + pi_.base.solidLineOffset() + pi_.base.solidLineThickness()
		+ (e.change.changed() ? pi_.base.solidLineThickness() + 1 : 0)
		+ 1 + thickness / 2;

	//FIXME: this could be computed only once, it is probably not costly.
	// check for cursor position
	// don't draw misspelled marker for words at cursor position
	// we don't want to disturb the process of text editing
	DocIterator const nw = pi_.base.bv->cursor().newWord();
	pos_type cpos = -1;
	if (!nw.empty() && par_.id() == nw.paragraph().id()) {
		cpos = nw.pos();
		if (cpos > 0 && cpos == par_.size() && !par_.isWordSeparator(cpos-1))
			--cpos;
		else if (cpos > 0 && par_.isWordSeparator(cpos))
			--cpos;
	}

	pos_type pos = e.pos;
	while (pos < e.pos + pos_type(e.str.length())) {
		if (!par_.isMisspelled(pos)) {
			++pos;
			continue;
		}

		FontSpan const & range = par_.getSpellRange(pos);

		// Skip element which are being edited
		if (range.contains(cpos)) {
			// the range includes the last element
			pos = range.last + 1;
			continue;
		}

		int x1 = fm.pos2x(e.str, range.first - e.pos,
		                  e.isRTL(), e.extra);
		int x2 = fm.pos2x(e.str, min(range.last - e.pos + 1,
									 pos_type(e.str.length())),
									 e.isRTL(), e.extra);
		if (x1 > x2)
			swap(x1, x2);

		pi_.pain.line(int(x_ + x1), y, int(x_ + x2), y,
		              Color_error,
		              Painter::line_onoffdash, thickness);
		pos = range.last + 1;
	}
}
Exemplo n.º 4
0
void InsetPreview::preparePreview(DocIterator const & pos) const  
{
	TexRow texrow;
	odocstringstream str;  
	otexstream os(str, texrow);
	OutputParams runparams(&pos.buffer()->params().encoding());
	latex(os, runparams);
	docstring const snippet = str.str();
	preview_->addPreview(snippet, *pos.buffer());  
}
Exemplo n.º 5
0
void Row::setSelectionAndMargins(DocIterator const & beg, 
		DocIterator const & end) const
{
	setSelection(beg.pos(), end.pos());
	
	if (selection()) {
		end_margin_sel = isMarginSelected(false, beg, end);
		begin_margin_sel = isMarginSelected(true, beg, end);
	}
}
Exemplo n.º 6
0
void MacroData::expand(vector<MathData> const & args, MathData & to) const
{
	updateData();

	// Hack. Any inset with a cell would do.
	static InsetMathSqrt inset(0);
	inset.setBuffer(const_cast<Buffer &>(*buffer_));

	// FIXME UNICODE
	asArray(display_.empty() ? definition_ : display_, inset.cell(0));
	//lyxerr << "MathData::expand: args: " << args << endl;
	//lyxerr << "MathData::expand: ar: " << inset.cell(0) << endl;
	for (DocIterator it = doc_iterator_begin(buffer_, &inset); it; it.forwardChar()) {
		if (!it.nextInset())
			continue;
		if (it.nextInset()->lyxCode() != MATH_MACROARG_CODE)
			continue;
		//it.cell().erase(it.pos());
		//it.cell().insert(it.pos(), it.nextInset()->asInsetMath()
		size_t n = static_cast<MathMacroArgument*>(it.nextInset())->number();
		if (n <= args.size()) {
			it.cell().erase(it.pos());
			it.cell().insert(it.pos(), args[n - 1]);
		}
	}
	//lyxerr << "MathData::expand: res: " << inset.cell(0) << endl;
	to = inset.cell(0);
}
Exemplo n.º 7
0
void InsetBranch::addToToc(DocIterator const & cpit) const
{
	DocIterator pit = cpit;
	pit.push_back(CursorSlice(const_cast<InsetBranch &>(*this)));

	Toc & toc = buffer().tocBackend().toc("branch");
	docstring str = params_.branch + ": ";
	text().forToc(str, TOC_ENTRY_LENGTH);
	toc.push_back(TocItem(pit, 0, str, toolTipText(docstring(), 3, 60)));
	// Proceed with the rest of the inset.
	InsetCollapsable::addToToc(cpit);
}
Exemplo n.º 8
0
void GuiSpellchecker::check()
{
	LYXERR(Debug::GUI, "Check the spelling of a word");

	DocIterator from = bufferview()->cursor();
	DocIterator to;
	WordLangTuple word_lang;
	docstring_list suggestions;

	int progress;
	try {
		progress = buffer().spellCheck(from, to, word_lang, suggestions);
	} catch (ExceptionMessage const & message) {
		if (message.type_ == WarningException) {
			Alert::warning(message.title_, message.details_);
			close();
			return;
		}
		throw message;
	}
	LYXERR(Debug::GUI, "Found word \"" << word_lang.word() << "\"");
	d->count_ += progress;
	d->progress_ += progress;

	// end of document
	if (from == doc_iterator_end(&buffer())) {
		showSummary();
		return;
	}
	if (!isVisible())
		show();

	d->word_ = word_lang;

	int const progress_bar = d->total_
		? int(100.0 * float(d->progress_)/d->total_) : 100;
	LYXERR(Debug::GUI, "Updating spell progress.");
	// set progress bar
	d->ui.spellcheckPR->setValue(progress_bar);
	// set suggestions
	updateSuggestions(suggestions);
	// set language
	int const pos = d->ui.languageCO->findData(toqstr(word_lang.lang()->lang()));
	if (pos != -1)
		d->ui.languageCO->setCurrentIndex(pos);

	// FIXME: if we used a lfun like in find/replace, dispatch would do
	// that for us
	int const size = to.pos() - from.pos();
	BufferView * bv = const_cast<BufferView *>(bufferview());
	bv->putSelectionAt(from, size, false);
}
Exemplo n.º 9
0
void InsetText::iterateForToc(DocIterator const & cdit, bool output_active) const
{
	DocIterator dit = cdit;
	Toc & toc = buffer().tocBackend().toc("tableofcontents");

	BufferParams const & bufparams = buffer_->params();
	int const min_toclevel = bufparams.documentClass().min_toclevel();
	// we really should have done this before we got here, but it
	// can't hurt too much to do it again
	bool const doing_output = output_active && producesOutput();

	// For each paragraph, traverse its insets and let them add
	// their toc items
	ParagraphList const & pars = paragraphs();
	pit_type pend = paragraphs().size();
	for (pit_type pit = 0; pit != pend; ++pit) {
		Paragraph const & par = pars[pit];
		dit.pit() = pit;
		// if we find an optarg, we'll save it for use later.
		InsetText const * arginset = 0;
		InsetList::const_iterator it  = par.insetList().begin();
		InsetList::const_iterator end = par.insetList().end();
		for (; it != end; ++it) {
			Inset & inset = *it->inset;
			dit.pos() = it->pos;
			//lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
			inset.addToToc(dit, doing_output);
			if (inset.lyxCode() == ARG_CODE)
				arginset = inset.asInsetText();
		}
		// now the toc entry for the paragraph
		int const toclevel = text().getTocLevel(pit);
		if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
			// insert this into the table of contents
			docstring tocstring;
			int const length = doing_output ? INT_MAX : TOC_ENTRY_LENGTH;
			if (arginset) {
				tocstring = par.labelString();
				if (!tocstring.empty())
					tocstring += ' ';
				arginset->text().forToc(tocstring, length);
			} else
				par.forToc(tocstring, length);
			dit.pos() = 0;
			toc.push_back(TocItem(dit, toclevel - min_toclevel,
				tocstring, doing_output, tocstring));
		}
		
		// And now the list of changes.
		par.addChangesToToc(dit, buffer(), doing_output);
	}
}
Exemplo n.º 10
0
void InsetNote::addToToc(DocIterator const & cpit) const
{
	DocIterator pit = cpit;
	pit.push_back(CursorSlice(const_cast<InsetNote &>(*this)));

	Toc & toc = buffer().tocBackend().toc("note");
	InsetLayout const & il = getLayout();
	docstring str = translateIfPossible(il.labelstring()) + from_ascii(": ");
	text().forToc(str, TOC_ENTRY_LENGTH);
	toc.push_back(TocItem(pit, 0, str, toolTipText(docstring(), 3, 60)));
	// Proceed with the rest of the inset.
	InsetCollapsable::addToToc(cpit);
}
Exemplo n.º 11
0
bool Row::isMarginSelected(bool left_margin, DocIterator const & beg,
		DocIterator const & end) const
{
	pos_type const sel_pos = left_margin ? sel_beg : sel_end;
	pos_type const margin_pos = left_margin ? pos_ : end_;

	// Is the chosen margin selected ?
	if (sel_pos == margin_pos) {
		if (beg.pos() == end.pos())
			// This is a special case in which the space between after 
			// pos i-1 and before pos i is selected, i.e. the margins
			// (see DocIterator::boundary_).
			return beg.boundary() && !end.boundary();
		else if (end.pos() == margin_pos)
			// If the selection ends around the margin, it is only
			// drawn if the cursor is after the margin.
			return !end.boundary();
		else if (beg.pos() == margin_pos)
			// If the selection begins around the margin, it is 
			// only drawn if the cursor is before the margin.
			return beg.boundary();
		else 
			return true;
	}
	return false;
}
Exemplo n.º 12
0
void InsetText::addToToc(DocIterator const & cdit) const
{
	DocIterator dit = cdit;
	dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
	Toc & toc = buffer().tocBackend().toc("tableofcontents");

	BufferParams const & bufparams = buffer_->params();
	int const min_toclevel = bufparams.documentClass().min_toclevel();

	// For each paragraph, traverse its insets and let them add
	// their toc items
	ParagraphList const & pars = paragraphs();
	pit_type pend = paragraphs().size();
	for (pit_type pit = 0; pit != pend; ++pit) {
		Paragraph const & par = pars[pit];
		dit.pit() = pit;
		// if we find an optarg, we'll save it for use later.
		InsetText const * arginset = 0;
		InsetList::const_iterator it  = par.insetList().begin();
		InsetList::const_iterator end = par.insetList().end();
		for (; it != end; ++it) {
			Inset & inset = *it->inset;
			dit.pos() = it->pos;
			//lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
			inset.addToToc(dit);
			if (inset.lyxCode() == ARG_CODE)
				arginset = inset.asInsetText();
		}
		// now the toc entry for the paragraph
		int const toclevel = par.layout().toclevel;
		if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
			// insert this into the table of contents
			docstring tocstring;
			if (arginset) {
				tocstring = par.labelString();
				if (!tocstring.empty())
					tocstring += ' ';
				arginset->text().forToc(tocstring, TOC_ENTRY_LENGTH);
			} else
				par.forToc(tocstring, TOC_ENTRY_LENGTH);
			dit.pos() = 0;
			toc.push_back(TocItem(dit, toclevel - min_toclevel,
				tocstring, tocstring));
		}
		
		// And now the list of changes.
		par.addChangesToToc(dit, buffer());
	}
}
Exemplo n.º 13
0
void DocumentManager::onFileChanged( const QString & path )
{
    DocIterator it;
    for( it = mDocHash.begin(); it != mDocHash.end(); ++it )
    {
        Document *doc = it.value();
        if (doc->mFilePath == path) {
            QFileInfo info(doc->mFilePath);
            if (doc->mSaveTime < info.lastModified()) {
                doc->mDoc->setModified(true);
                emit changedExternally(doc);
            }
        }
    }
}
Exemplo n.º 14
0
void DocumentManager::open( const QString & path, int initialCursorPosition, bool toRecent )
{
    QFileInfo info(path);
    QString cpath = info.canonicalFilePath();
    info.setFile(cpath);

    if (cpath.isEmpty()) {
        qWarning() << "DocumentManager: Can not open file: canonical path is empty.";
        return;
    }

    // Check if file already opened

    DocIterator it;
    for( it = mDocHash.begin(); it != mDocHash.end(); ++it )
    {
        Document *doc = it.value();
        if(doc->mFilePath == cpath) {
            Q_EMIT( showRequest(doc, initialCursorPosition) );
            if (toRecent) addToRecent(doc);
            return;
        }
    }

    // Open the file

    QFile file(cpath);
    if(!file.open(QIODevice::ReadOnly)) {
        qWarning() << "DocumentManager: the file" << cpath << "could not be opened for reading.";
        return;
    }
    QByteArray bytes( file.readAll() );
    file.close();

    Document *doc = new Document();
    doc->mDoc->setPlainText( QString::fromUtf8( bytes.data(), bytes.size() ) );
    doc->mDoc->setModified(false);
    doc->mFilePath = cpath;
    doc->mTitle = info.fileName();

    mDocHash.insert( doc->id(), doc );

    mFsWatcher.addPath(cpath);

    Q_EMIT( opened(doc, initialCursorPosition) );

    if (toRecent) this->addToRecent(doc);
}
Exemplo n.º 15
0
void InsetCaption::addToToc(DocIterator const & cpit, bool output_active) const
{
	if (floattype_.empty())
		return;

	DocIterator pit = cpit;
	pit.push_back(CursorSlice(const_cast<InsetCaption &>(*this)));

	Toc & toc = buffer().tocBackend().toc(floattype_);
	docstring str = full_label_;
	int length = output_active ? INT_MAX : TOC_ENTRY_LENGTH;
	text().forToc(str, length);
	toc.push_back(TocItem(pit, 0, str, output_active));

	// Proceed with the rest of the inset.
	InsetText::addToToc(cpit, output_active);
}
Exemplo n.º 16
0
void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active,
								UpdateType utype, TocBackend & backend) const
{
	DocIterator pit = cpit;
	pit.push_back(CursorSlice(const_cast<InsetCaptionable &>(*this)));
	docstring str;
	// Leave str empty if we generate for output (e.g. xhtml lists of figures).
	// This ensures that there is a caption if and only if the string is
	// non-empty.
	if (utype != OutputUpdate)
		text().forOutliner(str, TOC_ENTRY_LENGTH);
	TocBuilder & b = backend.builder(caption_type_);
	b.pushItem(pit, str, output_active);
	// Proceed with the rest of the inset.
	InsetCollapsible::addToToc(cpit, output_active, utype, backend);
	b.pop();
}
Exemplo n.º 17
0
void InsetCaption::addToToc(DocIterator const & cpit, bool output_active,
							UpdateType utype, TocBackend & backend) const
{
	string const & type = floattype_.empty() ? "senseless" : floattype_;
	DocIterator pit = cpit;
	pit.push_back(CursorSlice(const_cast<InsetCaption &>(*this)));
	int length = (utype == OutputUpdate) ?
		// For output (e.g. xhtml) all (bug #8603) or nothing
		(output_active ? INT_MAX : 0) :
		// TOC for LyX interface
		TOC_ENTRY_LENGTH;
	docstring str;
	if (length > 0) {
		str = full_label_;
		text().forOutliner(str, length);
	}
	backend.builder(type).captionItem(pit, str, output_active);
	// Proceed with the rest of the inset.
	InsetText::addToToc(cpit, output_active, utype, backend);
}
Exemplo n.º 18
0
void SpellcheckerWidget::Private::setSelection(
	DocIterator const & from, DocIterator const & to) const
{
	BufferView * bv = gv_->documentBufferView();
	DocIterator end = to;

	if (from.pit() != end.pit()) {
		// there are multiple paragraphs in selection 
		Cursor & bvcur = bv->cursor();
		bvcur.setCursor(from);
		bvcur.clearSelection();
		bvcur.setSelection(true);
		bvcur.setCursor(end);
		bvcur.setSelection(true);
	} else {
		// FIXME LFUN
		// If we used a LFUN, dispatch would do all of this for us
		int const size = end.pos() - from.pos();
		bv->putSelectionAt(from, size, false);
	}
	bv->processUpdateFlags(Update::Force | Update::FitCursor);	
}
Exemplo n.º 19
0
bool GuiErrorList::goTo(int item)
{
    if (&buffer() != buf_) {
        if (!theBufferList().isLoaded(buf_))
            return false;
        FuncRequest fr(LFUN_BUFFER_SWITCH, buf_->absFileName());
        dispatch(fr);
    }
    ErrorItem const & err = errorList()[item];

    if (err.par_id == -1)
        return false;

    if (from_master_)
        // FIXME: implement
        return false;

    DocIterator dit = buf_->getParFromID(err.par_id);

    if (dit == doc_iterator_end(buf_)) {
        // FIXME: Happens when loading a read-only doc with
        // unknown layout. Should this be the case?
        LYXERR0("par id " << err.par_id << " not found");
        return false;
    }

    // Now make the selection.
    // if pos_end is 0, this means it is end-of-paragraph
    pos_type const s = dit.paragraph().size();
    pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
    pos_type const start = min(err.pos_start, end);
    pos_type const range = end - start;
    dit.pos() = start;
    BufferView * bv = const_cast<BufferView *>(bufferview());
    // FIXME: If we used an LFUN, we would not need this line:
    bv->putSelectionAt(dit, range, false);
    bv->processUpdateFlags(Update::Force | Update::FitCursor);
    return true;
}
Exemplo n.º 20
0
bool TocBackend::updateItem(DocIterator const & dit)
{
	if (dit.paragraph().layout().toclevel == Layout::NOT_IN_TOC)
		return false;

	if (toc("tableofcontents").empty()) {
		// FIXME: should not happen, 
		// a call to TocBackend::update() is missing somewhere
		LYXERR0("TocBackend::updateItem called but the TOC is empty!");
		return false;
	}

	BufferParams const & bufparams = buffer_->params();
	const int min_toclevel = bufparams.documentClass().min_toclevel();

	TocIterator toc_item = item("tableofcontents", dit);

	docstring tocstring;

	// For each paragraph, traverse its insets and let them add
	// their toc items
	Paragraph & par = toc_item->dit_.paragraph();
	InsetList::const_iterator it = par.insetList().begin();
	InsetList::const_iterator end = par.insetList().end();
	for (; it != end; ++it) {
		Inset & inset = *it->inset;
		if (inset.lyxCode() == ARG_CODE) {
			if (!tocstring.empty())
				break;
			Paragraph const & inset_par =
				*static_cast<InsetArgument&>(inset).paragraphs().begin();
			if (!par.labelString().empty())
				tocstring = par.labelString() + ' ';
			tocstring += inset_par.asString(AS_STR_INSETS);
			break;
		}
	}

	int const toclevel = par.layout().toclevel;
	if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel
		&& tocstring.empty())
			tocstring = par.asString(AS_STR_LABEL | AS_STR_INSETS);

	const_cast<TocItem &>(*toc_item).str_ = tocstring;

	buffer_->updateTocItem("tableofcontents", dit);
	return true;
}
Exemplo n.º 21
0
Document *DocumentManager::open( const QString & path, int initialCursorPosition, int selectionLength, bool toRecent )
{
    QFileInfo info(path);
    QString cpath = info.canonicalFilePath();
    info.setFile(cpath);

    if (cpath.isEmpty()) {
        MainWindow::instance()->showStatusMessage (
                    tr("Cannot open file: %1 (file does not exist)").arg(path) );
        return 0;
    }

    // Check if file already opened
    for( DocIterator it = mDocHash.begin(); it != mDocHash.end(); ++it ) {
        Document *doc = it.value();
        if(doc->mFilePath == cpath) {
            Q_EMIT( showRequest(doc, initialCursorPosition, selectionLength) );
            if (toRecent) addToRecent(doc);
            return doc;
        }
    }

    // Open the file
    QFile file(cpath);
    if(!file.open(QIODevice::ReadOnly)) {
        MainWindow::instance()->showStatusMessage(
                    tr("Cannot open file for reading: %1").arg(cpath));
        return 0;
    }
    QByteArray bytes( file.readAll() );
    file.close();

    // strip .rtf
    bool isRTF = false;
    QString filePath = cpath;
    if (info.suffix() == QString("rtf")) {
        isRTF = true;

        filePath += QString(".scd");
        int result = rtf2txt(bytes.data());
        bytes = bytes.left(result);
        QMessageBox::warning(NULL, QString(tr("Opening RTF File")),
                             QString(tr("Warning: RTF file will be converted to plain-text scd file.")));
    }

    closeSingleUntitledIfUnmodified();

    const bool fileIsPlainText = !(info.suffix() == QString("sc") ||
                                   (info.suffix() == QString("scd")));

    Document *doc = createDocument( fileIsPlainText );
    doc->mDoc->setPlainText( decodeDocument(bytes) );
    doc->mDoc->setModified(false);
    doc->mFilePath = filePath;
    doc->mTitle = info.fileName();
    doc->mSaveTime = info.lastModified();

    if (!isRTF)
        mFsWatcher.addPath(cpath);

    syncLangDocument(doc);
    Q_EMIT( opened(doc, initialCursorPosition, selectionLength) );

    if (toRecent) this->addToRecent(doc);

    return doc;
}
Exemplo n.º 22
0
void InsetText::iterateForToc(DocIterator const & cdit, bool output_active,
							  UpdateType utype, TocBackend & backend) const
{
	DocIterator dit = cdit;
	// This also ensures that any document has a table of contents
	shared_ptr<Toc> toc = backend.toc("tableofcontents");

	BufferParams const & bufparams = buffer_->params();
	int const min_toclevel = bufparams.documentClass().min_toclevel();
	// we really should have done this before we got here, but it
	// can't hurt too much to do it again
	bool const doing_output = output_active && producesOutput();

	// For each paragraph,
	// * Add a toc item for the paragraph if it is AddToToc--merging adjacent
	//   paragraphs as needed.
	// * Traverse its insets and let them add their toc items
	// * Compute the main table of contents (this is hardcoded)
	// * Add the list of changes
	ParagraphList const & pars = paragraphs();
	pit_type pend = paragraphs().size();
	// Record pairs {start,end} of where a toc item was opened for a paragraph
	// and where it must be closed
	stack<pair<pit_type, pit_type>> addtotoc_stack;

	for (pit_type pit = 0; pit != pend; ++pit) {
		Paragraph const & par = pars[pit];
		dit.pit() = pit;
		dit.pos() = 0;

		// Custom AddToToc in paragraph layouts (i.e. theorems)
		if (par.layout().addToToc() && text().isFirstInSequence(pit)) {
			pit_type end =
				openAddToTocForParagraph(pit, dit, output_active, backend);
			addtotoc_stack.push({pit, end});
		}

		// If we find an InsetArgument that is supposed to provide the TOC caption,
		// we'll save it for use later.
		InsetArgument const * arginset = nullptr;
		for (auto const & table : par.insetList()) {
			dit.pos() = table.pos;
			table.inset->addToToc(dit, doing_output, utype, backend);
			if (InsetArgument const * x = table.inset->asInsetArgument())
				if (x->isTocCaption())
					arginset = x;
		}

		// End custom AddToToc in paragraph layouts
		while (!addtotoc_stack.empty() && addtotoc_stack.top().second == pit) {
			// execute the closing function
			closeAddToTocForParagraph(addtotoc_stack.top().first,
			                          addtotoc_stack.top().second, backend);
			addtotoc_stack.pop();
		}

		// now the toc entry for the paragraph in the main table of contents
		int const toclevel = text().getTocLevel(pit);
		if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
			// insert this into the table of contents
			docstring tocstring;
			int const length = (doing_output && utype == OutputUpdate) ?
				INT_MAX : TOC_ENTRY_LENGTH;
			if (arginset) {
				tocstring = par.labelString();
				if (!tocstring.empty())
					tocstring += ' ';
				arginset->text().forOutliner(tocstring, length);
			} else
				par.forOutliner(tocstring, length);
			dit.pos() = 0;
			toc->push_back(TocItem(dit, toclevel - min_toclevel,
			                       tocstring, doing_output));
		}

		// And now the list of changes.
		par.addChangesToToc(dit, buffer(), doing_output, backend);
	}
}
Exemplo n.º 23
0
bool SpellcheckerWidget::Private::isCurrentBuffer(DocIterator const & cursor) const
{
	return start_.buffer() == cursor.buffer();
}
Exemplo n.º 24
0
static bool equal(DocIterator & o, DocIterator & n)
{
	// Explicitly check for this, so we won't call
	// Paragraph::getChar for the last pos.
	bool const o_lastpos = o.pos() == o.lastpos();
	bool const n_lastpos = n.pos() == n.lastpos();
	if (o_lastpos || n_lastpos)
		return o_lastpos && n_lastpos;

	Paragraph const & old_par = o.text()->getPar(o.pit());
	Paragraph const & new_par = n.text()->getPar(n.pit());

	char_type const c_o = old_par.getChar(o.pos());
	char_type const c_n = new_par.getChar(n.pos());
	if (c_o != c_n)
		return false;

	if (old_par.isInset(o.pos())) {
		Inset const * i_o = old_par.getInset(o.pos());
		Inset const * i_n = new_par.getInset(n.pos());

		if (i_o && i_n)
			return equal(i_o, i_n);
	}

	Font fo = old_par.getFontSettings(o.buffer()->params(), o.pos());
	Font fn = new_par.getFontSettings(n.buffer()->params(), n.pos());
	return fo == fn;
}
Exemplo n.º 25
0
void Undo::Private::doRecordUndo(UndoKind kind,
	DocIterator const & cell,
	pit_type first_pit, pit_type last_pit,
	CursorData const & cur_before,
	bool isFullBuffer,
	UndoElementStack & stack)
{
	if (!group_level) {
		LYXERR0("There is no group open (creating one)");
		++group_id;
	}

	if (first_pit > last_pit)
		swap(first_pit, last_pit);

	// Undo::ATOMIC are always recorded (no overlapping there).
	// As nobody wants all removed character appear one by one when undoing,
	// we want combine 'similar' non-ATOMIC undo recordings to one.
	pit_type from = first_pit;
	pit_type end = cell.lastpit() - last_pit;
	if (!undo_finished_
	    && kind != ATOMIC_UNDO
	    && !stack.empty()
	    && samePar(stack.top().cell, cell)
	    && stack.top().kind == kind
	    && stack.top().from == from
	    && stack.top().end == end) {
		// reset cur_after; it will be filled correctly by endUndoGroup.
		stack.top().cur_after = CursorData();
		return;
	}

	if (isFullBuffer)
		LYXERR(Debug::UNDO, "Create full buffer undo element of group " << group_id);
	else
		LYXERR(Debug::UNDO, "Create undo element of group " << group_id);
	// create the position information of the Undo entry
	UndoElement undo(kind, cur_before, cell, from, end, 0, 0,
	                 buffer_.params(), isFullBuffer, buffer_.isClean(), group_id);

	// fill in the real data to be saved
	if (cell.inMathed()) {
		// simply use the whole cell
		MathData & ar = cell.cell();
		undo.array = new MathData(ar.buffer(), ar.begin(), ar.end());
	} else {
		// some more effort needed here as 'the whole cell' of the
		// main Text _is_ the whole document.
		// record the relevant paragraphs
		Text const * text = cell.text();
		LBUFERR(text);
		ParagraphList const & plist = text->paragraphs();
		ParagraphList::const_iterator first = plist.begin();
		advance(first, first_pit);
		ParagraphList::const_iterator last = plist.begin();
		advance(last, last_pit + 1);
		undo.pars = new ParagraphList(first, last);
	}

	// push the undo entry to undo stack
	stack.push(undo);
	//lyxerr << "undo record: " << stack.top() << endl;
}
Exemplo n.º 26
0
void InsetText::addToToc(DocIterator const & cdit, bool output_active) const
{
	DocIterator dit = cdit;
	dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
	iterateForToc(dit, output_active);
}
Exemplo n.º 27
0
void InsetPreview::reloadPreview(DocIterator const & pos) const
{
	preparePreview(pos);
	preview_->startLoading(*pos.buffer());
}