use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class AbstractIndentAction method doIndent.
/**
* Do the actual indentation work.
*/
private void doIndent() {
if (targetEditor == null) {
return;
}
final IDocument document = getDocument();
if (null == document) {
return;
}
Interval rootInterval = GlobalIntervalHandler.getInterval(document);
if (rootInterval == null) {
rootInterval = (new HeuristicalIntervalDetector()).buildIntervals(document);
GlobalIntervalHandler.putInterval(document, rootInterval);
}
if (rootInterval == null) {
return;
}
int startLine = -1;
int endLine = -1;
if (!selection.isEmpty()) {
if (selection instanceof TextSelection) {
final TextSelection tSelection = (TextSelection) selection;
if (tSelection.getLength() != 0) {
startLine = tSelection.getStartLine();
endLine = tSelection.getEndLine();
}
}
}
if (startLine == -1 || endLine == -1) {
startLine = 0;
endLine = document.getNumberOfLines() - 1;
}
indentArray.clear();
indentArray.add("");
final int nofLines = endLine - startLine;
int offset;
int realOffset;
int lineLength;
Interval interval;
try {
final int regionStartOffset = document.getLineOffset(startLine);
final int regionLength = document.getLineOffset(endLine) + document.getLineLength(endLine) - regionStartOffset;
multiEdit = new MultiTextEdit(regionStartOffset, regionLength);
final RewriteSessionEditProcessor processor = new RewriteSessionEditProcessor(document, multiEdit, TextEdit.UPDATE_REGIONS | TextEdit.CREATE_UNDO);
for (int i = nofLines; i >= 0; i--) {
lineLength = document.getLineLength(startLine + i);
offset = document.getLineOffset(startLine + i);
realOffset = getRealLineStart(document, offset, lineLength);
interval = rootInterval.getSmallestEnclosingInterval(realOffset);
final int indentLevel = lineIndentationLevel(document, realOffset, offset + lineLength, interval);
setIndentLevel(document, document.getLineOffset(startLine + i), indentLevel);
}
performEdits(processor);
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
}
return;
}
use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class ASN1Editor method createPartControl.
@Override
public void createPartControl(final Composite parent) {
super.createPartControl(parent);
projectionViewer = (ProjectionViewer) getSourceViewer();
projectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
projectionSupport.install();
projectionViewer.doOperation(ProjectionViewer.TOGGLE);
annotationModel = projectionViewer.getProjectionAnnotationModel();
getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
ASN1Editor.this.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
}
});
getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection.isEmpty() || !(selection instanceof TextSelection) || "".equals(((TextSelection) selection).getText())) {
return;
}
final TextSelection textSelection = (TextSelection) selection;
final int offset = textSelection.getOffset() + textSelection.getLength();
occurrencesMarker.markOccurences(getDocument(), offset);
}
});
IFile file = (IFile) getEditorInput().getAdapter(IFile.class);
if (file != null) {
EditorTracker.put(file, this);
}
}
use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class ReferenceSearch method runAction.
/**
* Helper function used by FindReferences classes for TTCN-3, ASN.1 and
* TTCNPP editors
*/
public static void runAction(final IEditorPart targetEditor, final ISelection selection) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
return;
}
if (!TITANNature.hasTITANNature(file.getProject())) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
return;
}
IPreferencesService prefs = Platform.getPreferencesService();
boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
int offset;
if (selection instanceof TextSelection && !selection.isEmpty() && !"".equals(((TextSelection) selection).getText())) {
if (reportDebugInformation) {
TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
}
TextSelection tSelection = (TextSelection) selection;
offset = tSelection.getOffset() + tSelection.getLength();
} else {
offset = ((IEditorWithCarretOffset) targetEditor).getCarretOffset();
}
// find the module
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
if (ResourceExclusionHelper.isExcluded(file)) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(EXCLUDEDFROMBUILD, file.getFullPath()));
return;
}
final Module module = projectSourceParser.containedModule(file);
if (module == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(NOTFOUNDMODULE, file.getName()));
return;
}
final ReferenceFinder rf = new ReferenceFinder();
boolean isDetected = rf.detectAssignmentDataByOffset(module, offset, targetEditor, true, reportDebugInformation);
if (!isDetected) {
return;
}
final ReferenceSearchQuery query = new ReferenceSearchQuery(rf, module, file.getProject());
for (ISearchQuery runningQuery : NewSearchUI.getQueries()) {
NewSearchUI.cancelQuery(runningQuery);
}
NewSearchUI.runQueryInBackground(query);
}
use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class GotoMatchingBracketAction method run.
@Override
public final void run(final IAction action) {
if (targetEditor == null) {
return;
}
if (targetEditor.getActiveEditor() != targetEditor.getEditor()) {
return;
}
if (!selection.isEmpty()) {
if (selection instanceof TextSelection) {
TextSelection tSelection = (TextSelection) selection;
if (tSelection.getLength() != 0) {
return;
}
}
}
ConfigTextEditor textEditor = targetEditor.getEditor();
IDocument document = textEditor.getDocument();
int carretOffset = textEditor.getCarretOffset();
PairMatcher pairMatcher = new PairMatcher();
IRegion region = pairMatcher.match(document, carretOffset);
if (region == null) {
return;
}
int targetOffset;
if (region.getOffset() + 1 == carretOffset) {
targetOffset = region.getOffset() + region.getLength();
} else {
targetOffset = region.getOffset() + 1;
}
textEditor.setCarretOffset(targetOffset);
textEditor.selectAndReveal(targetOffset, 0);
}
use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.
the class GotoMatchingBracketAction method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (activeEditor instanceof ConfigEditor) {
this.targetEditor = (ConfigEditor) activeEditor;
} else {
this.targetEditor = null;
}
if (activeEditor == null) {
return null;
}
if (this.targetEditor.getActiveEditor() != this.targetEditor.getEditor()) {
return null;
}
if (!selection.isEmpty()) {
if (selection instanceof TextSelection) {
TextSelection tSelection = (TextSelection) selection;
if (tSelection.getLength() != 0) {
return null;
}
}
}
ConfigTextEditor textEditor = this.targetEditor.getEditor();
IDocument document = textEditor.getDocument();
int carretOffset = textEditor.getCarretOffset();
PairMatcher pairMatcher = new PairMatcher();
IRegion region = pairMatcher.match(document, carretOffset);
if (region == null) {
return null;
}
int targetOffset;
if (region.getOffset() + 1 == carretOffset) {
targetOffset = region.getOffset() + region.getLength();
} else {
targetOffset = region.getOffset() + 1;
}
textEditor.setCarretOffset(targetOffset);
textEditor.selectAndReveal(targetOffset, 0);
return null;
}
Aggregations