org.eclipse.jface.text.source.ISourceViewer Java Examples

The following examples show how to use org.eclipse.jface.text.source.ISourceViewer. 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: JsonSourceViewerConfiguration.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
    ContentAssistant ca = new ContentAssistant();
    JsonContentAssistProcessor processor = createContentAssistProcessor(ca);

    ca.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
    ca.setInformationControlCreator(getInformationControlCreator(sourceViewer));

    ca.enableAutoInsert(false);
    ca.enablePrefixCompletion(false);
    ca.enableAutoActivation(true);
    ca.setAutoActivationDelay(100);
    ca.enableColoredLabels(true);
    ca.setShowEmptyList(true);
    ca.setRepeatedInvocationMode(true);
    ca.addCompletionListener(processor);
    ca.setStatusLineVisible(true);

    return ca;
}
 
Example #2
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void setCaretPosition(final int position) {
	final ISourceViewer viewer= getSourceViewer();

	final StyledText text= viewer.getTextWidget();
	if (text != null && !text.isDisposed()) {

		final Point selection= text.getSelection();
		final int caret= text.getCaretOffset();
		final int offset= modelOffset2WidgetOffset(viewer, position);

		if (caret == selection.x)
			text.setSelectionRange(selection.y, offset - selection.y);
		else
			text.setSelectionRange(selection.x, offset - selection.x);
	}
}
 
Example #3
Source File: FormatterPreviewUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public static void updatePreview(ISourceViewer viewer, URL previewContent, String[] substitutions,
		IScriptFormatterFactory factory, Map<String, String> preferences)
{
	String content = null;
	if (previewContent != null)
	{
		try
		{
			final String c = new String(Util.getInputStreamAsCharArray(previewContent.openConnection()
					.getInputStream(), -1, ENCODING));
			content = Util.concatenate(Util.splitLines(c), LINE_SEPARATOR);
			if (content != null && substitutions != null && substitutions.length > 0)
			{
				content = substitute(content, substitutions);
			}
		}
		catch (IOException e)
		{
			IdeLog.logError(FormatterUIEplPlugin.getDefault(), e, IDebugScopes.DEBUG);
			disablePreview(viewer);
			return;
		}
	}

	updatePreview(viewer, content, substitutions, factory, preferences);
}
 
Example #4
Source File: OpenDeclarationHandler.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
	if (xtextEditor != null) {
		ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection();

		IRegion region = new Region(selection.getOffset(), selection.getLength());

		ISourceViewer internalSourceViewer = xtextEditor.getInternalSourceViewer();

		IHyperlink[] hyperlinks = getDetector().detectHyperlinks(internalSourceViewer, region, false);
		if (hyperlinks != null && hyperlinks.length > 0) {
			IHyperlink hyperlink = hyperlinks[0];
			hyperlink.open();
		}
	}		
	return null;
}
 
Example #5
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void doSetInput(IEditorInput input) throws CoreException {
	ISourceViewer sourceViewer= getSourceViewer();
	if (!(sourceViewer instanceof ISourceViewerExtension2)) {
		setPreferenceStore(createCombinedPreferenceStore(input));
		internalDoSetInput(input);
		return;
	}

	// uninstall & unregister preference store listener
	getSourceViewerDecorationSupport(sourceViewer).uninstall();
	((ISourceViewerExtension2)sourceViewer).unconfigure();

	setPreferenceStore(createCombinedPreferenceStore(input));

	// install & register preference store listener
	sourceViewer.configure(getSourceViewerConfiguration());
	getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore());

	internalDoSetInput(input);
}
 
Example #6
Source File: XMLConfiguration.java    From http4e with Apache License 2.0 6 votes vote down vote up
public IContentFormatter getContentFormatter( ISourceViewer sourceViewer){
    ContentFormatter formatter = new ContentFormatter();
    XMLFormattingStrategy formattingStrategy = new XMLFormattingStrategy();
    DefaultFormattingStrategy defaultStrategy = new DefaultFormattingStrategy();
    TextFormattingStrategy textStrategy = new TextFormattingStrategy();
    DocTypeFormattingStrategy doctypeStrategy = new DocTypeFormattingStrategy();
    PIFormattingStrategy piStrategy = new PIFormattingStrategy();
    formatter.setFormattingStrategy(defaultStrategy,
            IDocument.DEFAULT_CONTENT_TYPE);
    formatter.setFormattingStrategy(textStrategy,
            XMLPartitionScanner.XML_TEXT);
    formatter.setFormattingStrategy(doctypeStrategy,
            XMLPartitionScanner.XML_DOCTYPE);
    formatter.setFormattingStrategy(piStrategy, XMLPartitionScanner.XML_PI);
    formatter.setFormattingStrategy(textStrategy,
            XMLPartitionScanner.XML_CDATA);
    formatter.setFormattingStrategy(formattingStrategy,
            XMLPartitionScanner.XML_START_TAG);
    formatter.setFormattingStrategy(formattingStrategy,
            XMLPartitionScanner.XML_END_TAG);
    
    return formatter;
}
 
Example #7
Source File: PyEditConfigurationWithoutEditor.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IReconciler getReconciler(ISourceViewer sourceViewer) {
    if (fPreferenceStore == null || !fPreferenceStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) {
        return null;
    }

    SpellingService spellingService = EditorsUI.getSpellingService();
    if (spellingService.getActiveSpellingEngineDescriptor(fPreferenceStore) == null) {
        return null;
    }

    //Overridden (just) to return a PyReconciler!
    IReconcilingStrategy strategy = new PyReconciler(sourceViewer, spellingService);

    MonoReconciler reconciler = new MonoReconciler(strategy, false);
    reconciler.setIsIncrementalReconciler(false);
    reconciler.setProgressMonitor(new NullProgressMonitor());
    reconciler.setDelay(500);
    return reconciler;
}
 
Example #8
Source File: TypeScriptMergeViewer.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
protected ISourceViewer createTypeScriptSourceViewer(Composite parent, IVerticalRuler verticalRuler,
		IOverviewRuler overviewRuler, boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
	return new AdaptedSourceViewer(parent, verticalRuler, overviewRuler, isOverviewRulerVisible, styles,
			store) {
		@Override
		protected void handleDispose() {
			super.handleDispose();

			// dispose the compilation unit adapter
			dispose();

			fEditor.remove(this);
			if (fEditor.isEmpty()) {
				fEditor = null;
				fSite = null;
			}

			fSourceViewer.remove(this);
			if (fSourceViewer.isEmpty())
				fSourceViewer = null;

		}
	};
}
 
Example #9
Source File: CompilationUnitEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void installTabsToSpacesConverter() {
	ISourceViewer sourceViewer= getSourceViewer();
	SourceViewerConfiguration config= getSourceViewerConfiguration();
	if (config != null && sourceViewer instanceof ITextViewerExtension7) {
		int tabWidth= config.getTabWidth(sourceViewer);
		TabsToSpacesConverter tabToSpacesConverter= new TabsToSpacesConverter();
		tabToSpacesConverter.setNumberOfSpacesPerTab(tabWidth);
		IDocumentProvider provider= getDocumentProvider();
		if (provider instanceof ICompilationUnitDocumentProvider) {
			ICompilationUnitDocumentProvider cup= (ICompilationUnitDocumentProvider) provider;
			tabToSpacesConverter.setLineTracker(cup.createLineTracker(getEditorInput()));
		} else
			tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
		((ITextViewerExtension7)sourceViewer).setTabsToSpacesConverter(tabToSpacesConverter);
		updateIndentPrefixes();
	}
}
 
Example #10
Source File: XtextQuickAssistProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.3
 */
protected void selectAndRevealQuickfix(IQuickAssistInvocationContext invocationContext, Set<Annotation> applicableAnnotations, List<ICompletionProposal> completionProposals) {
       if (completionProposals.isEmpty()) {
       	return;
       }
	if (!(invocationContext instanceof QuickAssistInvocationContext && ((QuickAssistInvocationContext) invocationContext).isSuppressSelection())) {
		ISourceViewer sourceViewer = invocationContext.getSourceViewer();
		IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
		Iterator<Annotation> iterator = applicableAnnotations.iterator();
		while (iterator.hasNext()) {
			Position pos = annotationModel.getPosition(iterator.next());
			if (pos != null) {
				sourceViewer.setSelectedRange(pos.getOffset(), pos.getLength());
				sourceViewer.revealRange(pos.getOffset(), pos.getLength());
				break;
			}
		}
	}
}
 
Example #11
Source File: PyEditConfiguration.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) {
    // create a content assistant:
    PyCorrectionAssistant assistant = new PyCorrectionAssistant();

    // next create a content assistant processor to populate the completions window
    IQuickAssistProcessor processor = new PythonCorrectionProcessor(this.getEdit());

    // Correction assist works on all
    assistant.setQuickAssistProcessor(processor);
    assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));

    //delay and auto activate set on PyContentAssistant constructor.

    return assistant;
}
 
Example #12
Source File: EditTemplateDialog.java    From typescript.java with MIT License 6 votes vote down vote up
private void handleVerifyKeyPressed(VerifyEvent event) {
	if (!event.doit)
		return;

	if (event.stateMask != SWT.MOD1)
		return;

	switch (event.character) {
	case ' ':
		fPatternEditor.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
		event.doit = false;
		break;

	// CTRL-Z
	case 'z' - 'a' + 1:
		fPatternEditor.doOperation(ITextOperationTarget.UNDO);
		event.doit = false;
		break;
	}
}
 
Example #13
Source File: CompilationUnitEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void createPartControl(Composite parent) {

	super.createPartControl(parent);

	IPreferenceStore preferenceStore= getPreferenceStore();
	boolean closeBrackets= preferenceStore.getBoolean(CLOSE_BRACKETS);
	boolean closeStrings= preferenceStore.getBoolean(CLOSE_STRINGS);
	boolean closeAngularBrackets= JavaCore.VERSION_1_5.compareTo(preferenceStore.getString(JavaCore.COMPILER_SOURCE)) <= 0;

	fBracketInserter.setCloseBracketsEnabled(closeBrackets);
	fBracketInserter.setCloseStringsEnabled(closeStrings);
	fBracketInserter.setCloseAngularBracketsEnabled(closeAngularBrackets);

	ISourceViewer sourceViewer= getSourceViewer();
	if (sourceViewer instanceof ITextViewerExtension)
		((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(fBracketInserter);

	if (isMarkingOccurrences())
		installOccurrencesFinder(false);
}
 
Example #14
Source File: AbstractLangSourceViewerConfiguration.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
	return new HTMLAnnotationHover(true) {
		@Override
		protected boolean isIncluded(Annotation annotation) {
			return isShowInOverviewRuler(annotation);
		}
	};
}
 
Example #15
Source File: XMLConfiguration.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public String[] getConfiguredContentTypes( ISourceViewer sourceViewer )
{
	return new String[]{
			IDocument.DEFAULT_CONTENT_TYPE,
			XMLPartitionScanner.XML_COMMENT,
			XMLPartitionScanner.XML_TAG
	};
}
 
Example #16
Source File: ContentAssistantFactory.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void setContentAssistProcessor(ContentAssistant assistant, SourceViewerConfiguration configuration,
		ISourceViewer sourceViewer) {
	super.setContentAssistProcessor(assistant, configuration, sourceViewer);
	assistant.setContentAssistProcessor(jsDocContentAssistProcessor, TokenTypeToPartitionMapper.JS_DOC_PARTITION);
	assistant.setContentAssistProcessor(null, TokenTypeToPartitionMapper.REG_EX_PARTITION);
	assistant.setContentAssistProcessor(null, TokenTypeToPartitionMapper.TEMPLATE_LITERAL_PARTITION);
	assistant.setContentAssistProcessor(null, TerminalsTokenTypeToPartitionMapper.SL_COMMENT_PARTITION);
	assistant.setContentAssistProcessor(null, TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
}
 
Example #17
Source File: AcfContentAssistProcessorTestBuilder.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc} Code copied from parent. Override required to run in UI because of getSourceViewer, which creates a new Shell.
 */
@Override
public ContentAssistProcessorTestBuilder assertMatchString(final String matchString) throws Exception {
  BadLocationException exception = UiThreadDispatcher.dispatchAndWait(new Function<BadLocationException>() {
    @Override
    public BadLocationException run() {
      String currentModelToParse = getModel();
      final XtextResource xtextResource = loadHelper.getResourceFor(new StringInputStream(currentModelToParse));
      final IXtextDocument xtextDocument = getDocument(xtextResource, currentModelToParse);
      XtextSourceViewerConfiguration configuration = get(XtextSourceViewerConfiguration.class);
      Shell shell = new Shell();
      try {
        ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument, configuration);
        IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
        String contentType = xtextDocument.getContentType(currentModelToParse.length());
        if (contentAssistant.getContentAssistProcessor(contentType) != null) {
          ContentAssistContext.Factory factory = get(ContentAssistContext.Factory.class);
          ContentAssistContext[] contexts = factory.create(sourceViewer, currentModelToParse.length(), xtextResource);
          for (ContentAssistContext context : contexts) {
            Assert.assertTrue("matchString = '" + matchString + "', actual: '" + context.getPrefix() + "'", "".equals(context.getPrefix())
                || matchString.equals(context.getPrefix()));
          }
        } else {
          Assert.fail("No content assistant for content type " + contentType);
        }
      } catch (BadLocationException e) {
        return e;
      } finally {
        shell.dispose();
      }
      return null;
    }
  });
  if (exception != null) {
    throw exception;
  }
  return this;
}
 
Example #18
Source File: AbstractLangBasicSourceViewerConfiguration.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected void setupPresentationReconciler(PresentationReconciler reconciler, ISourceViewer sourceViewer) {
	// Must be called from UI thread
	assertTrue(Display.getCurrent() != null);
	
	// Create a token registry for given sourceViewer
	TokenRegistry tokenRegistry = new TokenRegistry(colorManager, stylingPrefs) {
		@Override
		protected void handleTokenModified(Token token) {
			sourceViewer.invalidateTextPresentation();
		}
	};
	addConfigurationScopedOwned(sourceViewer, tokenRegistry);
	
	ArrayList2<AbstractLangScanner> scanners = new ArrayList2<>();
	
	for(LangPartitionTypes partitionType : getPartitionTypes()) {
		
		String contentType = partitionType.getId();
		AbstractLangScanner scanner = createScannerFor(Display.getCurrent(), partitionType, tokenRegistry);
		scanners.add(scanner);
		
		DefaultDamagerRepairer dr = getDamagerRepairer(scanner, contentType);
		reconciler.setDamager(dr, contentType);
		reconciler.setRepairer(dr, contentType);
	}
	
}
 
Example #19
Source File: ScriptSourceViewerConfiguration.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public IReconciler getReconciler( ISourceViewer sourceViewer )
{
	// Creates an instance of MonoReconciler with the specified strategy,
	// and is not incremental.
	return new MonoReconciler( new ScriptReconcilingStrategy( sourceViewer ),
			false );
}
 
Example #20
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void uninstall() {
	ISourceViewer sourceViewer= getSourceViewer();
	if (sourceViewer != null)
		sourceViewer.removeTextInputListener(this);

	IDocumentProvider documentProvider= getDocumentProvider();
	if (documentProvider != null) {
		IDocument document= documentProvider.getDocument(getEditorInput());
		if (document != null)
			document.removeDocumentListener(this);
	}
}
 
Example #21
Source File: JsniMethodBodyCompletionProposalComputerTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static void assertNoProposals(IProgressMonitor monitor,
    JsniMethodBodyCompletionProposalComputer jcpc,
    CompilationUnitEditor cuEditor, ISourceViewer viewer, int offset) {
  assertEquals(0, jcpc.computeCompletionProposals(
      new JavaContentAssistInvocationContext(viewer, offset, cuEditor),
      monitor).size());
}
 
Example #22
Source File: DebugScriptSourceViewerConfiguration.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public ITextHover getTextHover( ISourceViewer sourceViewer,
		String contentType, int stateMask )
{

	if ( !( JSPartitionScanner.JS_COMMENT.equals( contentType )
			//|| JSPartitionScanner.JS_KEYWORD.equals( contentType ) 
			|| JSPartitionScanner.JS_STRING.equals( contentType ) ) )
	{
		return new ScriptDebugHover( );
	}
	return super.getTextHover( sourceViewer, contentType, stateMask );
}
 
Example #23
Source File: XMLSourceConfiguration.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void setupPresentationReconciler(PresentationReconciler reconciler, ISourceViewer sourceViewer)
{
	DTDSourceConfiguration.getDefault().setupPresentationReconciler(reconciler, sourceViewer);

	DefaultDamagerRepairer dr = new ThemeingDamagerRepairer(getXMLScanner());
	reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
	reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);

	reconciler.setDamager(dr, DEFAULT);
	reconciler.setRepairer(dr, DEFAULT);

	dr = new ThemeingDamagerRepairer(getPreProcessorScanner());
	reconciler.setDamager(dr, PRE_PROCESSOR);
	reconciler.setRepairer(dr, PRE_PROCESSOR);

	dr = new ThemeingDamagerRepairer(getCDATAScanner());
	reconciler.setDamager(dr, CDATA);
	reconciler.setRepairer(dr, CDATA);

	dr = new ThemeingDamagerRepairer(getXMLTagScanner());
	reconciler.setDamager(dr, TAG);
	reconciler.setRepairer(dr, TAG);

	dr = new ThemeingDamagerRepairer(getCommentScanner());
	reconciler.setDamager(dr, COMMENT);
	reconciler.setRepairer(dr, COMMENT);
}
 
Example #24
Source File: DotProposalProviderDelegator.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private ICompletionProposal[] computeCompletionProposals(
		final IXtextDocument xtextDocument, int cursorPosition, Shell shell)
		throws BadLocationException {
	XtextSourceViewerConfiguration configuration = get(
			XtextSourceViewerConfiguration.class);
	ISourceViewer sourceViewer = getSourceViewer(shell, xtextDocument,
			configuration);
	return computeCompletionProposals(xtextDocument, cursorPosition,
			configuration, sourceViewer);
}
 
Example #25
Source File: GWTSourceViewerConfiguration.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IPresentationReconciler getPresentationReconciler(
    ISourceViewer sourceViewer) {
  PresentationReconciler reconciler = (PresentationReconciler) super.getPresentationReconciler(sourceViewer);

  DefaultDamagerRepairer dr = new DefaultDamagerRepairer(jsniScanner);
  reconciler.setDamager(dr, GWTPartitions.JSNI_METHOD);
  reconciler.setRepairer(dr, GWTPartitions.JSNI_METHOD);

  return reconciler;
}
 
Example #26
Source File: RenameRefactoringHandler.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private RenameRefactoringInfo getRenameRefactoringInfo() {
	ITextSelection textSelection = WorkbenchUtils.getActiveTextSelection();
	if (textSelection == null) {
		return null;
	}
	
	IEditorPart editor = WorkbenchUtils.getActiveEditor(false);
	if (editor == null) {
		return null;
	}
	ISourceViewer textViewer = (ISourceViewer)editor.getAdapter(ISourceViewer.class);
	SourceCodeTextEditor textEditor = null;
	if (editor instanceof SourceCodeTextEditor) {
		textEditor = (SourceCodeTextEditor) editor;
	}
	else{
		return null;
	}
	
	PstLeafNode pstLeafNode = ModulaEditorSymbolUtils.getIdentifierPstLeafNode(textEditor, textSelection.getOffset());
	IModulaSymbol symbol = ModulaEditorSymbolUtils.getModulaSymbol(
			textViewer.getDocument(), pstLeafNode);
	WordAndRegion wordUnderCursor = SelectionUtils.getWordUnderCursor(false);
	
	if (symbol == null || wordUnderCursor == null) {
		return null;
	}
	
	IFile ifileEdited = WorkbenchUtils.getIFileFrom(editor.getEditorInput());
	if (ifileEdited == null) {
		return null;
	}
	
    return new RenameRefactoringInfo(ifileEdited, wordUnderCursor.word, symbol);
}
 
Example #27
Source File: SubWordActions.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds the previous position before the given position.
 *
 * @param position the current position
 * @return the previous position
 */
protected int findPreviousPosition(int position) {
    ISourceViewer viewer = getSourceViewer();
    int widget = -1;
    int previous = position;
    while (previous != BreakIterator.DONE && widget == -1) { // XXX: optimize
        previous = fIterator.preceding(previous);
        if (previous != BreakIterator.DONE) {
            widget = modelOffset2WidgetOffset(viewer, previous);
        }
    }

    IDocument document = viewer.getDocument();
    LinkedModeModel model = LinkedModeModel.getModel(document, position);
    if (model != null && previous != BreakIterator.DONE) {
        LinkedPosition linkedPosition = model.findPosition(new LinkedPosition(document, position, 0));
        if (linkedPosition != null) {
            int linkedPositionOffset = linkedPosition.getOffset();
            if (position != linkedPositionOffset && previous < linkedPositionOffset) {
                previous = linkedPositionOffset;
            }
        } else {
            LinkedPosition previousLinkedPosition = model
                    .findPosition(new LinkedPosition(document, previous, 0));
            if (previousLinkedPosition != null) {
                int previousLinkedPositionEnd = previousLinkedPosition.getOffset()
                        + previousLinkedPosition.getLength();
                if (position != previousLinkedPositionEnd && previous < previousLinkedPositionEnd) {
                    previous = previousLinkedPositionEnd;
                }
            }
        }
    }

    return previous;
}
 
Example #28
Source File: RenameInformationPopup.java    From typescript.java with MIT License 5 votes vote down vote up
private void updateVisibility() {
	if (fPopup != null && !fPopup.isDisposed() && fDelayJobFinished) {
		boolean visible= false;
		//TODO: Check for visibility of linked position, not whether popup is outside of editor?
		if (fRenameLinkedMode.isCaretInLinkedPosition()) {
			StyledText textWidget= fEditor.getViewer().getTextWidget();
			Rectangle eArea= Geometry.toDisplay(textWidget, textWidget.getClientArea());
			Rectangle pBounds= fPopup.getBounds();
			pBounds.x-= GAP;
			pBounds.y-= GAP;
			pBounds.width+= 2 * GAP;
			pBounds.height+= 2 * GAP;
			if (eArea.intersects(pBounds)) {
				visible= true;
			}
		}
		if (visible && ! fPopup.isVisible()) {
			ISourceViewer viewer= fEditor.getViewer();
			if (viewer instanceof IWidgetTokenOwnerExtension) {
				IWidgetTokenOwnerExtension widgetTokenOwnerExtension= (IWidgetTokenOwnerExtension) viewer;
				visible= widgetTokenOwnerExtension.requestWidgetToken(this, WIDGET_PRIORITY);
			}
		} else if (! visible && fPopup.isVisible()) {
			releaseWidgetToken();
		}
		fPopup.setVisible(visible);
	}
}
 
Example #29
Source File: KbdMacroSupport.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private void setRedraw(ISourceViewer view, boolean value) {
	if (view != null) {
		try {
			// some viewers may not have a text widget
			view.getTextWidget().setRedraw(value);
		} catch (Exception e) {}
	}
}
 
Example #30
Source File: ImpexSourceViewerConfig.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
	
	return new String[] { 
			IDocument.DEFAULT_CONTENT_TYPE,
			ImpexDocumentPartitioner.IMPEX_COMMENT,
			ImpexDocumentPartitioner.IMPEX_DATA,
			ImpexDocumentPartitioner.IMPEX_HEADER,
			ImpexDocumentPartitioner.IMPEX_INSTRUCTION };
}