use of org.eclipse.jface.text.IRewriteTarget in project eclipse.platform.text by eclipse.
the class ConvertLineDelimitersAction method run.
@Override
public void run() {
try {
ITextEditor editor = getTextEditor();
if (editor == null)
return;
if (!validateEditorInputState())
return;
Object adapter = editor.getAdapter(IRewriteTarget.class);
if (adapter instanceof IRewriteTarget) {
IRewriteTarget target = (IRewriteTarget) adapter;
IDocument document = target.getDocument();
if (document != null) {
Shell shell = getTextEditor().getSite().getShell();
ConvertRunnable runnable = new ConvertRunnable(target, fLineDelimiter);
if (document.getNumberOfLines() < 40) {
BusyIndicator.showWhile(shell.getDisplay(), runnable);
} else {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
dialog.run(false, true, runnable);
}
}
}
} catch (InterruptedException e) {
// action canceled
} catch (InvocationTargetException e) {
// should not happen
}
}
use of org.eclipse.jface.text.IRewriteTarget in project eclipse.platform.text by eclipse.
the class HippieCompleteAction method clearState.
/**
* Invalidates the cached completions, removes all registered listeners and
* sets the cached document to <code>null</code>.
*/
private void clearState() {
fLastCompletion = null;
ITextEditor editor = getTextEditor();
if (editor != null) {
IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
if (target != null) {
fExitStrategy.disarm();
target.endCompoundChange();
}
}
fDocument = null;
}
use of org.eclipse.jface.text.IRewriteTarget in project eclipse.platform.text by eclipse.
the class HippieCompleteAction method updateState.
/**
* Update the completion state. The completion cache is updated with the
* completions based on the currently displayed document and the current
* selection. To track the validity of the cached state, listeners are
* registered with the editor and document, and the current document is
* cached.
*/
private void updateState() {
Assert.isNotNull(getTextEditor());
clearState();
List<IDocument> documents = HippieCompletionEngine.computeDocuments(getTextEditor());
if (documents.size() > 0) {
fDocument = documents.remove(0);
Iterator<String> suggestions;
try {
String prefix = getCurrentPrefix();
if (prefix == null) {
notifyUser();
return;
}
suggestions = fEngine.getMultipleDocumentsIterator(fDocument, documents, prefix, getSelectionOffset());
} catch (BadLocationException e) {
log(e);
return;
}
CompletionState completionState = new CompletionState(suggestions, getSelectionOffset());
// if it is single empty suggestion
if (completionState.hasOnly1EmptySuggestion) {
notifyUser();
return;
}
IRewriteTarget target = getTextEditor().getAdapter(IRewriteTarget.class);
if (target != null)
target.beginCompoundChange();
fLastCompletion = completionState;
}
}
use of org.eclipse.jface.text.IRewriteTarget in project eclipse.platform.text by eclipse.
the class MoveLinesAction method beginCompoundEdit.
/**
* Ends the compound change.
*/
private void beginCompoundEdit() {
ITextEditor editor = getTextEditor();
if (fEditInProgress || fTextViewer == null || editor == null)
return;
fEditInProgress = true;
fStrategy.arm(fTextViewer);
IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
if (target != null) {
target.beginCompoundChange();
}
}
use of org.eclipse.jface.text.IRewriteTarget in project eclipse.platform.text by eclipse.
the class QuickDiffRestoreAction method run.
@Override
public void run() {
ITextEditor editor = getTextEditor();
if (editor == null || !validateEditorInputState())
return;
IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
if (target != null)
target.beginCompoundChange();
runCompoundChange();
if (target != null)
target.endCompoundChange();
}
Aggregations