Exemplo n.º 1
0
QDocumentCursor CursorHistory::back(const QDocumentCursor &currentCursor) {
	if (currentEntry == history.begin()) {
		updateNavActions();
		return QDocumentCursor();
	}

	// insert currentCursor to be able to go back
	if (currentCursor.isValid() && insertPos(currentCursor, false)) {
		currentEntry--;
	}

	CursorPosition pos(currentCursor);
	if (pos.isValid() && !pos.equals(*currentEntry)) {
		updateNavActions();
		return currentPos();
	}

	currentEntry = prevValidEntry(currentEntry);
	updateNavActions();
	return currentPos();
}
Exemplo n.º 2
0
/*!
  Inserts the cursor behind the current entry
*/
bool CursorHistory::insertPos(QDocumentCursor cur, bool deleteBehindCurrent) {
	if (!m_insertionEnabled) return false;
	if (!cur.isValid()) return false;

	CursorPosition pos(cur);
	connectUnique(pos.doc(), SIGNAL(destroyed(QObject*)), this, SLOT(documentClosed(QObject*)));
	// TODO destroyed() may be duplicate to aboutToDeleteDocument() - needs more testing. anyway it does not harm
	connectUnique(pos.doc(), SIGNAL(lineDeleted(QDocumentLineHandle*)), this, SLOT(lineDeleted(QDocumentLineHandle*)));
	connectUnique(pos.doc(), SIGNAL(lineRemoved(QDocumentLineHandle*)), this, SLOT(lineDeleted(QDocumentLineHandle*)));

	if (deleteBehindCurrent && currentEntry != history.end()) {
		currentEntry++;
		currentEntry = history.erase(currentEntry, history.end());
	}
	if (currentEntry == history.end() && currentEntry != history.begin()) currentEntry--;

	// do not insert neighboring duplicates
	if (currentEntryValid() && (*currentEntry).equals(pos)) {
		updateNavActions();
		return false;
	}
	CursorPosList::iterator it = prevValidEntry(currentEntry);
	if (it != history.end() && (*it).isValid() && (*it).equals(pos)) {
		updateNavActions();
		return false;
	}

	if (history.count() >= m_maxLength) {
		if (currentEntry == history.begin()) {
			history.removeLast();
		} else {
			history.removeFirst();
		}
	}

	currentEntry++;
	history.insert(currentEntry, pos);
	updateNavActions();
	return true;
}