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();
}
});
}
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;
}
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));
}
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());
}
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);
}
});
}
Aggregations