Java Code Examples for org.eclipse.jface.text.ITextViewer#getTextWidget()
The following examples show how to use
org.eclipse.jface.text.ITextViewer#getTextWidget() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndentGuidePainter.java From IndentGuide with MIT License | 6 votes |
/** * Creates a new painter for the given text viewer. * * @param textViewer * the text viewer the painter should be attached to */ public IndentGuidePainter(ITextViewer textViewer) { super(); fTextViewer = textViewer; fTextWidget = textViewer.getTextWidget(); GC gc = new GC(fTextWidget); gc.setAdvanced(true); fIsAdvancedGraphicsPresent = gc.getAdvanced(); gc.dispose(); IPreferenceStore store = Activator.getDefault().getPreferenceStore(); lineAlpha = store.getInt(PreferenceConstants.LINE_ALPHA); lineStyle = store.getInt(PreferenceConstants.LINE_STYLE); lineWidth = store.getInt(PreferenceConstants.LINE_WIDTH); lineShift = store.getInt(PreferenceConstants.LINE_SHIFT); drawLeftEnd = store.getBoolean(PreferenceConstants.DRAW_LEFT_END); drawBlankLine = store.getBoolean(PreferenceConstants.DRAW_BLANK_LINE); skipCommentBlock = store .getBoolean(PreferenceConstants.SKIP_COMMENT_BLOCK); }
Example 2
Source File: AbstractJavaCompletionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void updateStyle(ITextViewer viewer) { StyledText text= viewer.getTextWidget(); int widgetOffset= getWidgetOffset(viewer, fRememberedStyleRange.start); StyleRange range= new StyleRange(fRememberedStyleRange); range.start= widgetOffset; range.length= fRememberedStyleRange.length; StyleRange currentRange= text.getStyleRangeAtOffset(widgetOffset); if (currentRange != null) { range.strikeout= currentRange.strikeout; range.underline= currentRange.underline; range.fontStyle= currentRange.fontStyle; } // http://dev.eclipse.org/bugs/show_bug.cgi?id=34754 try { text.setStyleRange(range); } catch (IllegalArgumentException x) { // catching exception as offset + length might be outside of the text widget fRememberedStyleRange= null; } }
Example 3
Source File: AbstractJavaCompletionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a style range for the text viewer. * * @param viewer the text viewer * @return the new style range for the text viewer or <code>null</code> * @since 3.6 */ private StyleRange createStyleRange(ITextViewer viewer) { StyledText text= viewer.getTextWidget(); if (text == null || text.isDisposed()) return null; int widgetCaret= text.getCaretOffset(); int modelCaret= 0; if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) viewer; modelCaret= extension.widgetOffset2ModelOffset(widgetCaret); } else { IRegion visibleRegion= viewer.getVisibleRegion(); modelCaret= widgetCaret + visibleRegion.getOffset(); } if (modelCaret >= getReplacementOffset() + getReplacementLength()) return null; int length= getReplacementOffset() + getReplacementLength() - modelCaret; Color foreground= getForegroundColor(); Color background= getBackgroundColor(); return new StyleRange(modelCaret, length, foreground, background); }
Example 4
Source File: EditorUtils.java From goclipse with Eclipse Public License 1.0 | 5 votes |
/** * Copy of {@link org.eclipse.jface.text.source.MatchingCharacterPainter#getSignedSelection()} */ public static final IRegion getSignedSelection(ITextViewer sourceViewer) { Point viewerSelection= sourceViewer.getSelectedRange(); StyledText text= sourceViewer.getTextWidget(); Point selection= text.getSelectionRange(); if (text.getCaretOffset() == selection.x) { viewerSelection.x= viewerSelection.x + viewerSelection.y; viewerSelection.y= -viewerSelection.y; } return new Region(viewerSelection.x, viewerSelection.y); }
Example 5
Source File: EditorListener.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Connects all selection listeners to the given {@linkplain IEditorPart editor part}. If an * editor part was already bound it will be unbound and replaced with the given editor part. * * @see #unbind() * @param part the editor part to observe * @return <code>true</code> if the selection listeners were successfully installed, <code>false * </code> if the selection listeners could not be installed */ public boolean bind(final IEditorPart part) { if (this.part != null) unbind(); final ITextViewer viewer = EditorAPI.getViewer(part); if (viewer == null) { log.warn( "could not attach selection listeners to editor part:" + part + " , could not retrieve text widget"); return false; } this.part = part; this.viewer = viewer; final StyledText textWidget = viewer.getTextWidget(); textWidget.addControlListener(controlListener); textWidget.addMouseListener(mouseListener); textWidget.addKeyListener(keyListener); viewer.addTextListener(textListener); viewer.getSelectionProvider().addSelectionChangedListener(selectionChangedListener); viewer.addViewportListener(viewportListener); return true; }
Example 6
Source File: PyMoveLineAction.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Performs similar to AbstractTextEditor.selectAndReveal, but does not update * the viewers highlight area. * * @param viewer the viewer that we want to select on * @param offset the offset of the selection * @param length the length of the selection */ private void selectAndReveal(ITextViewer viewer, int offset, int length) { if (viewer == null) { return; // in tests } // invert selection to avoid jumping to the end of the selection in st.showSelection() viewer.setSelectedRange(offset + length, -length); //viewer.revealRange(offset, length); // will trigger jumping StyledText st = viewer.getTextWidget(); if (st != null) { st.showSelection(); // only minimal scrolling } }
Example 7
Source File: PyCompletionPresentationUpdater.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private StyleRange createStyleRange(ITextViewer viewer, int initialOffset, int len) { StyledText text = viewer.getTextWidget(); if (text == null || text.isDisposed()) { return null; } int widgetCaret = text.getCaretOffset(); int modelCaret = 0; if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; modelCaret = extension.widgetOffset2ModelOffset(widgetCaret); } else { IRegion visibleRegion = viewer.getVisibleRegion(); modelCaret = widgetCaret + visibleRegion.getOffset(); } if (modelCaret >= initialOffset + len) { return null; } int length = initialOffset + len - modelCaret; Color foreground = getForegroundColor(); Color background = getBackgroundColor(); return new StyleRange(modelCaret, length, foreground, background); }
Example 8
Source File: JavaReconciler.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void install(ITextViewer textViewer) { super.install(textViewer); fPartListener= new PartListener(); IWorkbenchPartSite site= fTextEditor.getSite(); IWorkbenchWindow window= site.getWorkbenchWindow(); window.getPartService().addPartListener(fPartListener); fActivationListener= new ActivationListener(textViewer.getTextWidget()); Shell shell= window.getShell(); shell.addShellListener(fActivationListener); fJavaElementChangedListener= new ElementChangedListener(); JavaCore.addElementChangedListener(fJavaElementChangedListener); fResourceChangeListener= new ResourceChangeListener(); IWorkspace workspace= JavaPlugin.getWorkspace(); workspace.addResourceChangeListener(fResourceChangeListener); fPropertyChangeListener= new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (SpellingService.PREFERENCE_SPELLING_ENABLED.equals(event.getProperty()) || SpellingService.PREFERENCE_SPELLING_ENGINE.equals(event.getProperty())) forceReconciling(); } }; JavaPlugin.getDefault().getCombinedPreferenceStore().addPropertyChangeListener(fPropertyChangeListener); fReconciledElement= EditorUtility.getEditorInputJavaElement(fTextEditor, false); }
Example 9
Source File: JavaMoveLinesAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Performs similar to AbstractTextEditor.selectAndReveal, but does not update * the viewers highlight area. * * @param viewer the viewer that we want to select on * @param offset the offset of the selection * @param length the length of the selection */ private void selectAndReveal(ITextViewer viewer, int offset, int length) { // invert selection to avoid jumping to the end of the selection in st.showSelection() viewer.setSelectedRange(offset + length, -length); //viewer.revealRange(offset, length); // will trigger jumping StyledText st= viewer.getTextWidget(); if (st != null) st.showSelection(); // only minimal scrolling }
Example 10
Source File: CommandExecutionUtils.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private static int getCaretOffset(ITextViewer textViewer) { StyledText textWidget = textViewer.getTextWidget(); int caretOffset = textWidget.getCaretOffset(); if (textViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) textViewer; return extension.widgetOffset2ModelOffset(caretOffset); } return caretOffset; }
Example 11
Source File: WhitespaceCharacterPainter.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Creates a new painter for the given text viewer. * * @param textViewer * the text viewer the painter should be attached to */ public WhitespaceCharacterPainter(ITextViewer textViewer) { super(); fTextViewer = textViewer; fTextWidget = textViewer.getTextWidget(); GC gc = new GC(fTextWidget); gc.setAdvanced(true); fIsAdvancedGraphicsPresent = gc.getAdvanced(); gc.dispose(); }
Example 12
Source File: IndentGuidesPainter.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
/** * Creates a new painter for the given text viewer. * * @param textViewer * the text viewer the painter should be attached to * @param iXdsModuleIndentModel */ private IndentGuidesPainter(ITextViewer textViewer, IndentGuidesModel indentsModel) { super(); fTextViewer = textViewer; fTextWidget = textViewer.getTextWidget(); GC gc = new GC(fTextWidget); try { gc.setAdvanced(true); fIsAdvancedGraphicsPresent = gc.getAdvanced(); } finally { gc.dispose(); } this.indentsModel = indentsModel; }
Example 13
Source File: TextViewerJoinLinesAction.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void run() { ITextViewer viewer= getTextViewer(); if (viewer == null) return; if (!canModifyViewer()) return; IDocument document= viewer.getDocument(); if (document == null) return; ITextSelection selection= getSelection(viewer); if (selection == null) return; int startLine= selection.getStartLine(); int endLine= selection.getEndLine(); try { int caretOffset= joinLines(document, startLine, endLine); if (caretOffset > -1) { StyledText widget= viewer.getTextWidget(); widget.setRedraw(false); adjustHighlightRange(viewer, caretOffset, 0); viewer.revealRange(caretOffset, 0); viewer.setSelectedRange(caretOffset, 0); widget.setRedraw(true); } } catch (BadLocationException e) { // should not happen } }
Example 14
Source File: TextViewerMoveLinesAction.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Performs similar to AbstractTextEditor.selectAndReveal, but does not update * the viewers highlight area. * * @param viewer the viewer that we want to select on * @param offset the offset of the selection * @param length the length of the selection */ private void selectAndReveal(ITextViewer viewer, int offset, int length) { // invert selection to avoid jumping to the end of the selection in st.showSelection() viewer.setSelectedRange(offset + length, -length); //viewer.revealRange(offset, length); // will trigger jumping StyledText st= viewer.getTextWidget(); if (st != null) st.showSelection(); // only minimal scrolling }
Example 15
Source File: TextViewerMoveLinesAction.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public void runWithEvent(Event event) { ITextViewer viewer = getTextViewer(); if (viewer == null) return; if (!canModifyViewer()) return; // get involved objects IDocument document= viewer.getDocument(); if (document == null) return; StyledText widget= viewer.getTextWidget(); if (widget == null) return; // get selection ITextSelection sel= (ITextSelection) viewer.getSelectionProvider().getSelection(); if (sel.isEmpty()) return; ITextSelection skippedLine= getSkippedLine(document, sel); if (skippedLine == null) return; try { ITextSelection movingArea= getMovingSelection(document, sel, viewer); // if either the skipped line or the moving lines are outside the widget's // visible area, bail out if (!containedByVisibleRegion(movingArea, viewer) || !containedByVisibleRegion(skippedLine, viewer)) return; // get the content to be moved around: the moving (selected) area and the skipped line String moving= movingArea.getText(); String skipped= skippedLine.getText(); if (moving == null || skipped == null || document.getLength() == 0) return; String delim; String insertion; int offset, deviation; if (fUpwards) { delim= document.getLineDelimiter(skippedLine.getEndLine()); if (fCopy) { delim= TextUtilities.getDefaultLineDelimiter(document); insertion= moving + delim; offset= movingArea.getOffset(); deviation= 0; } else { Assert.isNotNull(delim); insertion= moving + delim + skipped; offset= skippedLine.getOffset(); deviation= -skippedLine.getLength() - delim.length(); } } else { delim= document.getLineDelimiter(movingArea.getEndLine()); if (fCopy) { if (delim == null) { delim= TextUtilities.getDefaultLineDelimiter(document); insertion= delim + moving; } else { insertion= moving + delim; } offset= skippedLine.getOffset(); deviation= movingArea.getLength() + delim.length(); } else { Assert.isNotNull(delim); insertion= skipped + delim + moving; offset= movingArea.getOffset(); deviation= skipped.length() + delim.length(); } } // modify the document beginCompoundEdit(); if (fCopy) { document.replace(offset, 0, insertion); } else { document.replace(offset, insertion.length(), insertion); } // move the selection along int selOffset= movingArea.getOffset() + deviation; int selLength= movingArea.getLength() + (fAddDelimiter ? delim.length() : 0); if (! (viewer instanceof ITextViewerExtension5)) selLength= Math.min(selLength, viewer.getVisibleRegion().getOffset() + viewer.getVisibleRegion().getLength() - selOffset); else { // TODO need to check what is necessary in the projection case } selectAndReveal(viewer, selOffset, selLength); } catch (BadLocationException x) { // won't happen without concurrent modification - bail out return; } }
Example 16
Source File: TextViewerThemer.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
public TextViewerThemer(ITextViewer viewer) { super(viewer.getTextWidget()); }
Example 17
Source File: SimpleAssistProcessor.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * Computes the proposals (may forward for simple or 'complete' proposals) * * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int) */ @Override public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { try { IDocument doc = viewer.getDocument(); String[] strs = PySelection.getActivationTokenAndQual(doc, offset, false); String activationToken = strs[0]; String qualifier = strs[1]; IPythonNature pythonNature = edit.getPythonNature(); this.sorter.setQualifier(qualifier); this.sorter.setCompareContext(new CompareContext(pythonNature)); if (this.keepSynched != null) { this.keepSynched.dispose(); this.keepSynched = null; } if (viewer.getTextWidget() != null) { this.keepSynched = new KeepProposalsComparatorSynched(viewer, doc, offset, this.sorter); } if (showDefault()) { ICompletionProposal[] ret = defaultPythonProcessor.computeCompletionProposals(viewer, offset); return ret; } else { updateStatus(); PySelection ps = edit.createPySelection(); if (ps == null) { ps = new PySelection(doc, offset); } List<ICompletionProposalHandle> results = new ArrayList<ICompletionProposalHandle>(); for (ISimpleAssistParticipant participant : participants) { results.addAll( participant.computeCompletionProposals(activationToken, qualifier, ps, edit, offset)); } //don't matter the result... next time we won't ask for simple stuff doCycle(); if (results.size() == 0) { if (!lastCompletionAutoActivated || defaultAutoActivated(viewer, offset) || useAutocompleteOnAllAsciiCharsCache) { return defaultPythonProcessor.computeCompletionProposals(viewer, offset); } return new ICompletionProposal[0]; } else { Collections.sort(results, this.sorter); return results.toArray(new ICompletionProposal[0]); } } } catch (Exception e) { Log.log(e); CompletionError completionError = new CompletionError(e); this.lastError = completionError.getErrorMessage(); //Make the error visible to the user! return new ICompletionProposal[] { completionError }; } }
Example 18
Source File: AbstractCompletionProposalExtension.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * Called when Ctrl is selected during the completions * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, boolean) */ @Override public void selected(ITextViewer viewer, boolean smartToggle) { if (smartToggle) { StyledText text = viewer.getTextWidget(); if (text == null || text.isDisposed()) { return; } int widgetCaret = text.getCaretOffset(); IDocument document = viewer.getDocument(); int finalOffset = widgetCaret; try { if (finalOffset >= document.getLength()) { unselected(viewer); return; } char c; do { c = document.getChar(finalOffset); finalOffset++; } while (isValidChar(c) && finalOffset < document.getLength()); if (c == '(') { fLastIsPar = true; } else { fLastIsPar = false; } if (!isValidChar(c)) { finalOffset--; } this.fLen = finalOffset - widgetCaret; this.getPresentationUpdater().selected(viewer, widgetCaret, this.fLen); } catch (BadLocationException e) { Log.log(e); } } else { unselected(viewer); } }