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(); }
void SidebarToolbar::btDownClicked(GtkToolButton* toolbutton, SidebarToolbar* toolbar) { XOJ_CHECK_TYPE_OBJ(toolbar, SidebarToolbar); Document* doc = toolbar->control->getDocument(); PageRef swapped_page, other_page; doc->lock(); size_t page = doc->indexOf(toolbar->currentPage); swapped_page = toolbar->currentPage; other_page = doc->getPage(page + 1); if (page != size_t_npos) { doc->deletePage(page); doc->insertPage(toolbar->currentPage, page + 1); } doc->unlock(); UndoRedoHandler* undo = toolbar->control->getUndoRedoHandler(); undo->addUndoAction(new SwapUndoAction(page, false, swapped_page, other_page)); toolbar->control->firePageDeleted(page); toolbar->control->firePageInserted(page + 1); toolbar->control->firePageSelected(page + 1); toolbar->control->getScrollHandler()->scrollToPage(page + 1); }
static PyObject * PyUndoRedoHandler_canRedo(PyUndoRedoHandler * self) { UndoRedoHandler * undo = self->control->getUndoRedoHandler(); if (undo->canRedo()) { Py_RETURN_TRUE; } Py_RETURN_FALSE; }
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(); }
static PyObject * PyUndoRedoHandler_getRedoItemTypeOnStack(PyUndoRedoHandler * self) { UndoRedoHandler * undo = self->control->getUndoRedoHandler(); const char * name = undo->getRedoStackTopTypeName(); if(name) { return PyString_FromString(name); } Py_RETURN_NONE; }
void SidebarToolbar::btCopyClicked(GtkToolButton* toolbutton, SidebarToolbar* toolbar) { XOJ_CHECK_TYPE_OBJ(toolbar, SidebarToolbar); Document* doc = toolbar->control->getDocument(); doc->lock(); int page = doc->indexOf(toolbar->currentPage); PageRef newPage = toolbar->currentPage.clone(); doc->insertPage(newPage, page + 1); doc->unlock(); UndoRedoHandler* undo = toolbar->control->getUndoRedoHandler(); undo->addUndoAction(new CopyUndoAction(newPage, page + 1)); toolbar->control->firePageInserted(page + 1); toolbar->control->firePageSelected(page + 1); toolbar->control->getScrollHandler()->scrollToPage(page + 1); }
void InputHandler::onButtonReleaseEvent(GdkEventButton * event, PageRef page) { XOJ_CHECK_TYPE(InputHandler); if (!this->tmpStroke) { return; } // Backward compatibility and also easier to handle for me;-) // I cannot draw a line with one point, to draw a visible line I need two points, // twice the same Point is also OK if (this->tmpStroke->getPointCount() == 1) { ArrayIterator<Point> it = this->tmpStroke->pointIterator(); if (it.hasNext()) { this->tmpStroke->addPoint(it.next()); } // No pressure sensitivity this->tmpStroke->clearPressure(); } this->tmpStroke->freeUnusedPointItems(); if (page.getSelectedLayerId() < 1) { // This creates a layer if none exists page.getSelectedLayer(); page.setSelectedLayerId(1); xournal->getControl()->getWindow()->updateLayerCombobox(); } Layer * layer = page.getSelectedLayer(); UndoRedoHandler * undo = xournal->getControl()->getUndoRedoHandler(); undo->addUndoAction(new InsertUndoAction(page, layer, this->tmpStroke, this->redrawable)); ToolHandler * h = xournal->getControl()->getToolHandler(); if (h->isShapeRecognizer()) { if (this->reco == NULL) { this->reco = new ShapeRecognizer(); } ShapeRecognizerResult * result = this->reco->recognizePatterns(this->tmpStroke); if (result != NULL) { UndoRedoHandler * undo = xournal->getControl()->getUndoRedoHandler(); Stroke * recognized = result->getRecognized(); RecognizerUndoAction * recognizerUndo = new RecognizerUndoAction(page, this->redrawable, layer, this->tmpStroke, recognized); undo->addUndoAction(recognizerUndo); layer->addElement(result->getRecognized()); Range range(recognized->getX(), recognized->getY()); range.addPoint(recognized->getX() + recognized->getElementWidth(), recognized->getY() + recognized->getElementHeight()); range.addPoint(this->tmpStroke->getX(), this->tmpStroke->getY()); range.addPoint(this->tmpStroke->getX() + this->tmpStroke->getElementWidth(), this->tmpStroke->getY() + this->tmpStroke->getElementHeight()); ListIterator<Stroke *> l = result->getSources(); while (l.hasNext()) { Stroke * s = l.next(); layer->removeElement(s, false); recognizerUndo->addSourceElement(s); range.addPoint(s->getX(), s->getY()); range.addPoint(s->getX() + s->getElementWidth(), s->getY() + s->getElementHeight()); } this->redrawable->rerenderRange(range); // delete the result object, this is not needed anymore, the stroke are not deleted with this delete result; } else { layer->addElement(this->tmpStroke); this->redrawable->rerenderElement(this->tmpStroke); } } else { layer->addElement(this->tmpStroke); this->redrawable->rerenderElement(this->tmpStroke); } this->tmpStroke = NULL; if (currentInputDevice == event->device) { currentInputDevice = NULL; INPUTDBG("currentInputDevice = NULL\n", 0); } this->tmpStrokeDrawElem = 0; }
static PyObject * PyUndoRedoHandler_redo(PyUndoRedoHandler * self) { UndoRedoHandler * undo = self->control->getUndoRedoHandler(); undo->redo(); Py_RETURN_NONE; }