Search in sources :

Example 6 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project xtext-eclipse by eclipse.

the class ImportsAwareClipboardAction method run.

@Override
public void run() {
    if (textOperationTarget == null)
        return;
    ITextEditor editor = getTextEditor();
    if (editor == null)
        return;
    if (isModifyOperation() && !validateEditorInputState())
        return;
    BusyIndicator.showWhile(getDisplay(), new Runnable() {

        @Override
        public void run() {
            internalDoOperation();
        }
    });
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor)

Example 7 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project xtext-eclipse by eclipse.

the class ImportsAwareClipboardAction method getShell.

private Shell getShell() {
    ITextEditor editor = getTextEditor();
    if (editor != null) {
        IWorkbenchPartSite site = editor.getSite();
        Shell shell = site.getShell();
        if (shell != null && !shell.isDisposed()) {
            return shell;
        }
    }
    return null;
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Shell(org.eclipse.swt.widgets.Shell) ITextEditor(org.eclipse.ui.texteditor.ITextEditor)

Example 8 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project xtext-eclipse by eclipse.

the class TextChangeCombinerTest method testMixedChanges.

@Test
public void testMixedChanges() throws Exception {
    IFile file1 = IResourcesSetupUtil.createFile(PROJECT + "/file1.txt", MODEL);
    ITextEditor editor1 = openInEditor(file1);
    CompositeChange compositeChange = new CompositeChange("test");
    compositeChange.add(createEditorDocumentChange(editor1, 1, 1, "foo"));
    compositeChange.add(createTextFileChange(file0, 1, 1, "foo"));
    CompositeChange compositeChange1 = new CompositeChange("test");
    compositeChange.add(compositeChange1);
    compositeChange1.add(createEditorDocumentChange(editor1, 3, 1, "baz"));
    compositeChange1.add(createTextFileChange(file0, 1, 1, "foo"));
    compositeChange1.add(createTextFileChange(file0, 3, 1, "baz"));
    Change combined = combiner.combineChanges(compositeChange);
    Change undo = combined.perform(new NullProgressMonitor());
    IDocument document1 = getDocument(editor1);
    assertEquals(MODEL.replace("123", "foo2baz"), document1.get());
    assertEquals(MODEL.replace("123", "foo2baz"), getContents(file0));
    undo.perform(new NullProgressMonitor());
    assertEquals(MODEL, document1.get());
    assertEquals(MODEL, getContents(file0));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) EditorDocumentChange(org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 9 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project xtext-eclipse by eclipse.

the class TextChangeCombinerTest method testSingleDocumentChange.

@Test
public void testSingleDocumentChange() throws Exception {
    ITextEditor editor = openInEditor(file0);
    Change docChange = createEditorDocumentChange(editor, 1, 1, "foo");
    Change combined = combiner.combineChanges(docChange);
    assertEquals(docChange, combined);
    assertTextType(combined);
    Change undo = combined.perform(new NullProgressMonitor());
    IDocument document = getDocument(editor);
    assertEquals(MODEL.replace("1", "foo"), document.get());
    undo.perform(new NullProgressMonitor());
    assertEquals(MODEL, document.get());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) EditorDocumentChange(org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 10 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project xtext-eclipse by eclipse.

the class ToggleSLCommentAction method run.

/**
 * Implementation of the <code>IAction</code> prototype. Checks if the selected
 * lines are all commented or not and uncomments/comments them respectively.
 */
@Override
public void run() {
    if (fOperationTarget == null || fDocumentPartitioning == null || fPrefixesMap == null)
        return;
    ITextEditor editor = getTextEditor();
    if (editor == null)
        return;
    if (!validateEditorInputState())
        return;
    final int operationCode;
    if (isSelectionCommented(editor.getSelectionProvider().getSelection()))
        operationCode = ITextOperationTarget.STRIP_PREFIX;
    else
        operationCode = ITextOperationTarget.PREFIX;
    Shell shell = editor.getSite().getShell();
    if (!fOperationTarget.canDoOperation(operationCode)) {
        if (shell != null)
            MessageDialog.openError(shell, Messages.ToggleSLCommentAction_0, Messages.ToggleSLCommentAction_1);
        return;
    }
    Display display = null;
    if (shell != null && !shell.isDisposed())
        display = shell.getDisplay();
    BusyIndicator.showWhile(display, new Runnable() {

        @Override
        public void run() {
            fOperationTarget.doOperation(operationCode);
        }
    });
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Display(org.eclipse.swt.widgets.Display)

Aggregations

ITextEditor (org.eclipse.ui.texteditor.ITextEditor)233 IEditorPart (org.eclipse.ui.IEditorPart)91 IDocument (org.eclipse.jface.text.IDocument)73 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)39 ITextSelection (org.eclipse.jface.text.ITextSelection)34 IFile (org.eclipse.core.resources.IFile)33 Test (org.junit.Test)31 BadLocationException (org.eclipse.jface.text.BadLocationException)27 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)25 PartInitException (org.eclipse.ui.PartInitException)23 ISelection (org.eclipse.jface.viewers.ISelection)19 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)17 IRegion (org.eclipse.jface.text.IRegion)16 Annotation (org.eclipse.jface.text.source.Annotation)16 ArrayList (java.util.ArrayList)15 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)15 IResource (org.eclipse.core.resources.IResource)14 IEditorInput (org.eclipse.ui.IEditorInput)14 CoreException (org.eclipse.core.runtime.CoreException)13 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)12