Exemplo n.º 1
0
void ItemDocument::requestStateSave(int actionTicket) {
	if (m_bIsLoading) return;

	cleanClearStack(m_redoStack);

	if ((actionTicket >= 0) && (actionTicket == m_currentActionTicket)) {
		delete m_currentState;
		m_currentState = 0;
	}

	m_currentActionTicket = actionTicket;

	//FIXME: it is possible, that we push something here, also nothing has changed, yet.
	// to reproduce do:
	// 1. select an item -> something is pushed onto undoStack, but nothing changed
	// 2. select Undo -> pushed on redoStack, pop from undoStack
	// 3. deselect item -> there is still something on the redoStack
	//
	// this way you can fill up the redoStack, as you like :-/

	if (m_currentState)
		m_undoStack.push(m_currentState);

	m_currentState = new ItemDocumentData(type());
	m_currentState->saveDocumentState(this);

	if (!m_savedState)
		m_savedState = m_currentState;

	setModified(m_savedState != m_currentState);

	emit undoRedoStateChanged();

	//FIXME To resize undo queue, have to pop and push everything
	// In Qt4 QStack is used and QStack inherits QVector, that should
	// make it a bit more easy
	int maxUndo = KTLConfig::maxUndo();

	if (maxUndo <= 0 || m_undoStack.count() < (unsigned)maxUndo)
		return;

	IDDStack tempStack;
	int pushed = 0;

	while (!m_undoStack.isEmpty() && pushed < maxUndo) {
		tempStack.push(m_undoStack.pop());
		pushed++;
	}

	cleanClearStack(m_undoStack);

	while (!tempStack.isEmpty())
		m_undoStack.push(tempStack.pop());
}
Exemplo n.º 2
0
void ItemDocument::undo() {
	ItemDocumentData *idd = m_undoStack.pop();

	if (!idd) return;

	if (m_currentState) m_redoStack.push(m_currentState);

	idd->restoreDocument(this);

	m_currentState = idd;

	setModified(m_savedState != m_currentState);

	emit undoRedoStateChanged();
}
Exemplo n.º 3
0
void DocManager::slotViewFocused( View *view )
{
	ViewContainer * vc = static_cast<ViewContainer*>(KTechlab::self()->tabWidget()->currentWidget());
	if (!vc)
		view = 0l;
	
	if (!view)
		return;
	
	// This function can get called with a view that is not in the current view
	// container (such as when the user right clicks and then the popup is
	// destroyed - not too sure why, but this is the easiest way to fix it).
	if ( view->viewContainer() != vc )
		view = vc->activeView();
	
	if ( !view || (View*)p_focusedView == view )
		return;
	
	if (p_focusedView)
		slotViewUnfocused();
	
	p_focusedView = view;
	
	if ( TextView * textView = dynamic_cast<TextView*>((View*)p_focusedView) )
		KTechlab::self()->factory()->addClient( textView->kateView() );
	else
		KTechlab::self()->factory()->addClient( p_focusedView );
	
	Document *document = view->document();
	
	connect( document, SIGNAL(undoRedoStateChanged()), KTechlab::self(), SLOT(slotDocUndoRedoChanged()) );
	p_connectedDocument = document;
		
	if ( document->type() == Document::dt_circuit ||
			   document->type() == Document::dt_flowcode ||
			   document->type() == Document::dt_mechanics )
	{
		ItemDocument *cvb = static_cast<ItemDocument*>(view->document());
		ItemInterface::self()->slotItemDocumentChanged(cvb);
	}
	
	KTechlab::self()->slotDocUndoRedoChanged();
	KTechlab::self()->slotDocModifiedChanged();
	KTechlab::self()->requestUpdateCaptions();
}
Exemplo n.º 4
0
void DocManager::slotViewUnfocused()
{
	if ( !KTechlab::self() )
		return;
	
	KTechlab::self()->removeGUIClients();
	disableContextActions();
	
	if (!p_focusedView)
		return;
	
	if (p_connectedDocument)
	{
		disconnect( p_connectedDocument, SIGNAL(undoRedoStateChanged()), KTechlab::self(), SLOT(slotDocUndoRedoChanged()) );
		p_connectedDocument = 0;
	}
	
	ItemInterface::self()->slotItemDocumentChanged(0l);
	p_focusedView = 0;
	
// 	KTechlab::self()->setCaption( 0 );
	KTechlab::self()->requestUpdateCaptions();
}