Search in sources :

Example 1 with IStructuredTextUndoManager

use of org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager in project webtools.sourceediting by eclipse.

the class ExtendedEditorActionProxy method endRecording.

private void endRecording() {
    if (fRecorder != null) {
        IStructuredTextUndoManager um = fRecorder.getUndoManager();
        if (um != null) {
            um.endRecording(this);
        }
        fRecorder.releaseFromEdit();
        fRecorder = null;
    }
}
Also used : IStructuredTextUndoManager(org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager)

Example 2 with IStructuredTextUndoManager

use of org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager in project webtools.sourceediting by eclipse.

the class DropActionProxy method endRecording.

private void endRecording() {
    if (fRecorder != null) {
        IStructuredTextUndoManager um = fRecorder.getUndoManager();
        if (um != null)
            um.endRecording(this);
        fRecorder.releaseFromEdit();
        fRecorder = null;
    }
}
Also used : IStructuredTextUndoManager(org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager)

Example 3 with IStructuredTextUndoManager

use of org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager in project webtools.sourceediting by eclipse.

the class StructuredTextEditor method updateMenuText.

private void updateMenuText() {
    ITextViewer viewer = getTextViewer();
    StyledText widget = null;
    if (viewer != null)
        widget = viewer.getTextWidget();
    if (fStructuredModel != null && !fStructuredModel.isModelStateChanging() && viewer != null && widget != null && !widget.isDisposed()) {
        // performance: don't force an update of the action bars unless
        // required as it is expensive
        String previousUndoText = null;
        String previousUndoDesc = null;
        String previousRedoText = null;
        String previousRedoDesc = null;
        boolean updateActions = false;
        IAction undoAction = getAction(ITextEditorActionConstants.UNDO);
        IAction redoAction = getAction(ITextEditorActionConstants.REDO);
        if (undoAction != null) {
            previousUndoText = undoAction.getText();
            previousUndoDesc = undoAction.getDescription();
            updateActions = updateActions || previousUndoText == null || previousUndoDesc == null;
            undoAction.setText(UNDO_ACTION_TEXT_DEFAULT);
            undoAction.setDescription(UNDO_ACTION_DESC_DEFAULT);
        }
        if (redoAction != null) {
            previousRedoText = redoAction.getText();
            previousRedoDesc = redoAction.getDescription();
            updateActions = updateActions || previousRedoText == null || previousRedoDesc == null;
            redoAction.setText(REDO_ACTION_TEXT_DEFAULT);
            redoAction.setDescription(REDO_ACTION_DESC_DEFAULT);
        }
        if (fStructuredModel.getUndoManager() != null) {
            IStructuredTextUndoManager undoManager = fStructuredModel.getUndoManager();
            // get undo command
            Command undoCommand = undoManager.getUndoCommand();
            // set undo label and description
            if (undoAction != null) {
                undoAction.setEnabled(undoManager.undoable());
                if (undoCommand != null) {
                    String label = undoCommand.getLabel();
                    if (label != null) {
                        String customText = MessageFormat.format(UNDO_ACTION_TEXT, new String[] { label });
                        updateActions = updateActions || customText == null || previousUndoText == null || !customText.equals(previousUndoText);
                        undoAction.setText(customText);
                    }
                    String desc = undoCommand.getDescription();
                    if (desc != null) {
                        String customDesc = MessageFormat.format(UNDO_ACTION_DESC, new String[] { desc });
                        updateActions = updateActions || customDesc == null || previousRedoDesc == null || !customDesc.equals(previousUndoDesc);
                        undoAction.setDescription(customDesc);
                    }
                }
            }
            // get redo command
            Command redoCommand = undoManager.getRedoCommand();
            // set redo label and description
            if (redoAction != null) {
                redoAction.setEnabled(undoManager.redoable());
                if (redoCommand != null) {
                    String label = redoCommand.getLabel();
                    if (label != null) {
                        String customText = MessageFormat.format(REDO_ACTION_TEXT, new String[] { label });
                        updateActions = updateActions || customText == null || previousRedoText == null || !customText.equals(previousRedoText);
                        redoAction.setText(customText);
                    }
                    String desc = redoCommand.getDescription();
                    if (desc != null) {
                        String customDesc = MessageFormat.format(REDO_ACTION_DESC, new String[] { desc });
                        updateActions = updateActions || customDesc == null || previousRedoDesc == null || !customDesc.equals(previousRedoDesc);
                        redoAction.setDescription(customDesc);
                    }
                }
            }
        }
        // tell the action bars to update
        if (updateActions) {
            if (getEditorSite().getActionBars() != null) {
                getEditorSite().getActionBars().updateActionBars();
            } else if (getEditorPart() != null && getEditorPart().getEditorSite().getActionBars() != null) {
                getEditorPart().getEditorSite().getActionBars().updateActionBars();
            }
        }
    }
}
Also used : IStructuredTextUndoManager(org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager) StyledText(org.eclipse.swt.custom.StyledText) IAction(org.eclipse.jface.action.IAction) Command(org.eclipse.emf.common.command.Command) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 4 with IStructuredTextUndoManager

use of org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager in project webtools.sourceediting by eclipse.

the class AbstractStructuredModel method getUndoManager.

public IStructuredTextUndoManager getUndoManager() {
    IStructuredTextUndoManager structuredTextUndoManager = null;
    IStructuredDocument structuredDocument = getStructuredDocument();
    if (structuredDocument == null) {
        structuredTextUndoManager = null;
    } else {
        structuredTextUndoManager = structuredDocument.getUndoManager();
    }
    return structuredTextUndoManager;
}
Also used : IStructuredTextUndoManager(org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 5 with IStructuredTextUndoManager

use of org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager in project webtools.sourceediting by eclipse.

the class StructuredTextViewer method beginRecording.

private void beginRecording(String label, String description, int cursorPosition, int selectionLength) {
    IDocument doc = getDocument();
    if (doc instanceof IStructuredDocument) {
        IStructuredDocument structuredDocument = (IStructuredDocument) doc;
        IStructuredTextUndoManager undoManager = structuredDocument.getUndoManager();
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=198617
        // undo after paste in document with folds - wrong behavior
        IRegion widgetSelection = new Region(cursorPosition, selectionLength);
        IRegion documentSelection = widgetRange2ModelRange(widgetSelection);
        if (documentSelection == null)
            documentSelection = widgetSelection;
        undoManager.beginRecording(this, label, description, documentSelection.getOffset(), documentSelection.getLength());
    } else {
    // TODO: how to handle other document types?
    }
}
Also used : IStructuredTextUndoManager(org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager) IRegion(org.eclipse.jface.text.IRegion) Region(org.eclipse.jface.text.Region) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

IStructuredTextUndoManager (org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager)7 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 IDocument (org.eclipse.jface.text.IDocument)2 IRegion (org.eclipse.jface.text.IRegion)2 Region (org.eclipse.jface.text.Region)2 Command (org.eclipse.emf.common.command.Command)1 IAction (org.eclipse.jface.action.IAction)1 DocumentRewriteSession (org.eclipse.jface.text.DocumentRewriteSession)1 IDocumentExtension4 (org.eclipse.jface.text.IDocumentExtension4)1 ITextViewer (org.eclipse.jface.text.ITextViewer)1 StyledText (org.eclipse.swt.custom.StyledText)1 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1