use of org.eclipse.jface.text.ITextSelection in project eclipse.platform.text by eclipse.
the class AddMarkerAction method getInitialAttributes.
/**
* Returns the attributes the new marker will be initialized with.
* <p>
* Subclasses may extend or replace this method.</p>
*
* @return the attributes the new marker will be initialized with
*/
protected Map<String, Object> getInitialAttributes() {
Map<String, Object> attributes = new HashMap<>(11);
ITextSelection selection = (ITextSelection) getTextEditor().getSelectionProvider().getSelection();
if (!selection.isEmpty()) {
int start = selection.getOffset();
int length = selection.getLength();
if (length < 0) {
length = -length;
start -= length;
}
MarkerUtilities.setCharStart(attributes, start);
MarkerUtilities.setCharEnd(attributes, start + length);
// marker line numbers are 1-based
int line = selection.getStartLine();
MarkerUtilities.setLineNumber(attributes, line == -1 ? -1 : line + 1);
IDocument document = getTextEditor().getDocumentProvider().getDocument(getTextEditor().getEditorInput());
MarkerUtilities.setMessage(attributes, getLabelProposal(document, start, length));
}
return attributes;
}
use of org.eclipse.jface.text.ITextSelection in project eclipse.platform.text by eclipse.
the class JoinLinesAction method run.
@Override
public void run() {
ITextEditor editor = getTextEditor();
if (editor == null)
return;
if (!validateEditorInputState())
return;
IDocument document = getDocument(editor);
if (document == null)
return;
ITextSelection selection = getSelection(editor);
if (selection == null)
return;
int startLine = selection.getStartLine();
int endLine = selection.getEndLine();
try {
int caretOffset = joinLines(document, startLine, endLine);
if (caretOffset > -1)
editor.selectAndReveal(caretOffset, 0);
} catch (BadLocationException e) {
// should not happen
}
}
use of org.eclipse.jface.text.ITextSelection in project eclipse.platform.text by eclipse.
the class JoinLinesAction method getSelection.
/**
* Returns the editor's selection.
*
* @param editor the editor
* @return the editor's selection
*/
private static ITextSelection getSelection(ITextEditor editor) {
ISelectionProvider selectionProvider = editor.getSelectionProvider();
if (selectionProvider == null)
return null;
ISelection selection = selectionProvider.getSelection();
if (!(selection instanceof ITextSelection))
return null;
return (ITextSelection) selection;
}
use of org.eclipse.jface.text.ITextSelection in project eclipse.platform.text by eclipse.
the class TextSelectionNavigationLocation method update.
/**
* Updates the this location.
*/
@Override
public void update() {
IEditorPart part = getEditorPart();
if (part instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) getEditorPart();
if (equalsLocationOf(textEditor))
return;
ISelection s = textEditor.getSelectionProvider().getSelection();
if (s == null || s.isEmpty())
return;
ITextSelection selection = (ITextSelection) s;
if (selection.getOffset() == 0 && selection.getLength() == 0)
return;
fPosition.offset = selection.getOffset();
fPosition.length = selection.getLength();
fPosition.isDeleted = false;
if (!part.isDirty())
fSavedPosition = new Position(fPosition.offset, fPosition.length);
}
}
use of org.eclipse.jface.text.ITextSelection in project eclipse.platform.text by eclipse.
the class QuickDiffRestoreAction method getSelection.
/**
* Returns the selection of the editor this action belongs to.
*
* @return the editor's selection, or <code>null</code>
*/
protected ITextSelection getSelection() {
if (getTextEditor() == null)
return null;
ISelectionProvider sp = getTextEditor().getSelectionProvider();
if (sp == null)
return null;
ISelection s = sp.getSelection();
if (s instanceof ITextSelection)
return (ITextSelection) s;
return null;
}
Aggregations