예제 #1
0
bool UndoStack::redo(uint steps, int objectId)
{
	for (uint i = 0; i < steps && !redoActions_.empty(); ++i) {
		UndoState *tmpRedoState = 0;
		if (objectId == Um::GLOBAL_UNDO_MODE)
		{
			tmpRedoState = redoActions_[0];
			redoActions_.erase(redoActions_.begin());
		}
		else
		{ // object specific mode (search the correct state)
			StateList::iterator it;
			for (it = redoActions_.begin(); it != redoActions_.end(); ++it)
			{
				UndoObject *tmp = (*it)->undoObject();
				if (tmp && tmp->getUId() == static_cast<ulong>(objectId))
				{
					tmpRedoState = *it;
					redoActions_.erase(it);
					break;
				}
			}
		}
		
		undoActions_.insert(undoActions_.begin(), tmpRedoState); // push to the undo actions
		tmpRedoState->redo();
	}
	
	return true;
}
예제 #2
0
UndoObject* Controller::createRedoObject()
{
	version_t version = _model->getFileVersion();
	bool preview = _model->getProjectSettings().getSavePreview();
	// temporarily set to the latest fileversion so no data will be lost
	UndoObject* rd = new UndoObject(_model,
                                    _model->getFilename(),
									_model->getEditMode(),
                                    _model->isFileChanged(),
                                    _model->isFilenameSet(),
									true);
	try {
		_model->setFileVersion(k_current_version);
		_model->getProjectSettings().setSavePreview(false);
		_model->saveBinary(rd->getUndoData());
		rd->accept();
		emit updateUndoData();
	} catch(...) {
		// restore the original version
		_model->setFileVersion(version);
		_model->getProjectSettings().setSavePreview(preview);
		delete rd;
		rd = 0;
	}
	return rd;
}
예제 #3
0
파일: undostack.cpp 프로젝트: JLuc/scribus
bool UndoStack::undo(uint steps, int objectId)
{
	for (uint i = 0; i < steps && !undoActions_.empty(); ++i) {
		UndoState *tmpUndoState = 0;
		if (objectId == Um::GLOBAL_UNDO_MODE)
		{
			tmpUndoState = undoActions_[0];
			undoActions_.erase(undoActions_.begin());
		}
		else
		{ // object specific mode (search the correct state)
			StateList::iterator it;
			for (it = undoActions_.begin(); it != undoActions_.end(); ++it)
			{
				UndoObject *tmp = (*it)->undoObject();
				if (tmp && tmp->getUId() == static_cast<ulong>(objectId))
				{
					tmpUndoState = *it;
					undoActions_.erase(it);
					break;
				}
				else if((*it)->isTransaction())
				{
					TransactionState *ts = dynamic_cast<TransactionState*>(*it);
					if(ts->containsOnly(objectId))
					{
						tmpUndoState = *it;
						undoActions_.erase(it);
						break;
					}
				}
			}
		}

		redoActions_.insert(redoActions_.begin(), tmpUndoState); // push to the redo actions
		tmpUndoState->undo();
	}

	return true;
}
예제 #4
0
void UndoManager::setState(UndoGui* gui, int uid)
{
	gui->clear();

	if ( stacks_[currentDoc_].size() == 0 )
		return;

	UndoStack& currentStack = stacks_[currentDoc_];

	StateList::iterator itstartU = currentStack.undoActions_.begin(); // undo actions
	StateList::iterator itendU   = currentStack.undoActions_.end();

	StateList::iterator itstartR = currentStack.redoActions_.begin(); // redo actions
	StateList::iterator itendR   = currentStack.redoActions_.end();

	if (uid > -1)
	{ // find the range from where actions are added when in obj. spec. mode
		StateList::iterator it2;
		for (it2  = currentStack.undoActions_.begin();
		     it2 != currentStack.undoActions_.end(); ++it2)
		{
			UndoState*  tmp  = *it2;
			TransactionState *ts = dynamic_cast<TransactionState*>(tmp);
			if (ts && !ts->containsOnly(uid))
			{
				if (it2 != currentStack.undoActions_.begin())
					itendU = --it2;
				break;
			}
		}
		StateList::iterator it3;
		for (it3  = currentStack.redoActions_.begin();
		     it3 != currentStack.redoActions_.end(); ++it3)
		{
			UndoState*  tmp  = *it3;
			TransactionState *ts = dynamic_cast<TransactionState*>(tmp);
			if (ts && !ts->containsOnly(uid))
			{
				itendR = it3;
				break;
			}
		}
	}

	if (currentStack.undoItems() > 0)
	{
		if (itendU == currentStack.undoActions_.end())
			--itendU;
		for (; itendU >= itstartU; --itendU) // insert undo actions
		{
			UndoState*  state  = *itendU;
			UndoObject* target = state->undoObject();

			if (target && (uid == -1 || target->getUId() == static_cast<uint>(uid)))
				gui->insertUndoItem(target, state);
			if (itendU == itstartU)
				break;
		}
	}

	if (currentStack.redoItems() > 0)
	{
		if (itendR > itstartR)
			--itendR;
		for (; itstartR <= itendR; ++itstartR) // insert redo actions
		{
			UndoState*  state  = *itstartR;
			UndoObject* target = state->undoObject();

			if (target && (uid == -1 || target->getUId() == static_cast<uint>(uid)))
				gui->insertRedoItem(target, state);
			if (itendR == itstartR)
				break;
		}
	}
}