Exemple #1
0
void PageView::endText() {
	XOJ_CHECK_TYPE(PageView);

	if (!this->textEditor) {
		return;
	}
	Text * txt = this->textEditor->getText();
	Layer * layer = this->page.getSelectedLayer();
	UndoRedoHandler * undo = xournal->getControl()->getUndoRedoHandler();

	// Text deleted
	if (txt->getText().isEmpty()) {
		// old element
		int pos = layer->indexOf(txt);
		if (pos != -1) {
			DeleteUndoAction * eraseDeleteUndoAction = new DeleteUndoAction(page, this, true);
			layer->removeElement(txt, false);
			eraseDeleteUndoAction->addElement(layer, txt, pos);
			undo->addUndoAction(eraseDeleteUndoAction);
		}
	} else {
		// new element
		if (layer->indexOf(txt) == -1) {
			undo->addUndoActionBefore(new InsertUndoAction(page, layer, txt, this), this->textEditor->getFirstUndoAction());
			layer->addElement(txt);
			this->textEditor->textCopyed();
		}
	}

	delete this->textEditor;
	this->textEditor = NULL;
	this->rerenderPage();
}
Exemple #2
0
void PageView::endText()
{
	XOJ_CHECK_TYPE(PageView);

	if (!this->textEditor)
	{
		return;
	}
	Text* txt = this->textEditor->getText();
	Layer* layer = this->page->getSelectedLayer();
	UndoRedoHandler* undo = xournal->getControl()->getUndoRedoHandler();

	// Text deleted
	if (txt->getText().isEmpty())
	{
		// old element
		int pos = layer->indexOf(txt);
		if (pos != -1)
		{
			DeleteUndoAction* eraseDeleteUndoAction = new DeleteUndoAction(page,
			                                                               true);
			layer->removeElement(txt, false);
			eraseDeleteUndoAction->addElement(layer, txt, pos);
			undo->addUndoAction(eraseDeleteUndoAction);
		}
	}
	else
	{
		// new element
		if (layer->indexOf(txt) == -1)
		{
			undo->addUndoActionBefore(new InsertUndoAction(page, layer, txt),
			                          this->textEditor->getFirstUndoAction());
			layer->addElement(txt);
			this->textEditor->textCopyed();
		}
		//or if the file was saved and reopened
		//and/or if we click away from the text window
		else
		{
			//TextUndoAction does not work because the textEdit object is destroyed
			//after endText() so we need to instead copy the information between an
			//old and new element that we can push and pop to recover.
			undo->addUndoAction(new TextBoxUndoAction(page, layer,
			                                          txt, this->oldtext));

		}


	}

	delete this->textEditor;
	this->textEditor = NULL;
	this->rerenderPage();
}