Search in sources :

Example 21 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class LineAnnotationManagerTest method testLineBasedQuery.

@Test
public void testLineBasedQuery() throws Exception {
    NewSearchUI.runQueryInForeground(null, fLineQuery);
    AbstractTextSearchResult result = (AbstractTextSearchResult) fLineQuery.getSearchResult();
    Object[] files = result.getElements();
    try {
        for (int i = 0; i < files.length; i++) {
            IFile file = (IFile) files[0];
            ITextEditor editor = (ITextEditor) SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
            IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
            IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
            annotationModel.getAnnotationIterator();
            ArrayList<Position> positions = new ArrayList<>();
            for (Iterator<Annotation> iter = annotationModel.getAnnotationIterator(); iter.hasNext(); ) {
                Annotation annotation = iter.next();
                if (annotation.getType().equals(fAnnotationTypeLookup.getAnnotationType(NewSearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO))) {
                    positions.add(annotationModel.getPosition(annotation));
                }
            }
            Match[] matches = result.getMatches(file);
            for (int j = 0; j < matches.length; j++) {
                Position position = computeDocumentPositionFromLineMatch(document, matches[j]);
                assertTrue("position not found at: " + j, positions.remove(position));
            }
            assertEquals(0, positions.size());
        }
    } finally {
        SearchPlugin.getActivePage().closeAllEditors(false);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractTextSearchResult(org.eclipse.search.ui.text.AbstractTextSearchResult) Annotation(org.eclipse.jface.text.source.Annotation) Match(org.eclipse.search.ui.text.Match) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 22 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class JavaActionContributor method doSetActiveEditor.

private void doSetActiveEditor(IEditorPart part) {
    super.setActiveEditor(part);
    ITextEditor editor = null;
    if (part instanceof ITextEditor)
        editor = (ITextEditor) part;
    fContentAssistProposal.setAction(getAction(editor, ITextEditorActionConstants.CONTENT_ASSIST));
    fContentAssistTip.setAction(getAction(editor, ITextEditorActionConstants.CONTENT_ASSIST_CONTEXT_INFORMATION));
    fTogglePresentation.setEditor(editor);
    fTogglePresentation.update();
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor)

Example 23 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class PresentationAction method run.

@Override
public void run() {
    ITextEditor editor = getTextEditor();
    editor.resetHighlightRange();
    boolean show = editor.showsHighlightRangeOnly();
    setChecked(!show);
    editor.showHighlightRangeOnly(!show);
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor)

Example 24 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class ProjectHyperlinkDetector method detectHyperlinks.

@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    ITextEditor textEditor = getAdapter(ITextEditor.class);
    IResource resource = textEditor.getEditorInput().getAdapter(IResource.class);
    String fileLocation = TextProcessor.process(IDEResourceInfoUtils.getLocationText(resource));
    ShowInSystemExplorerHyperlink showInSystemExplorerHyperlink = new ShowInSystemExplorerHyperlink(fileLocation, region);
    URLHyperlink fileUrlHyperlink = new URLHyperlink(region, fileLocation);
    URLHyperlink projectFileHelpLink = new URLHyperlink(region, "https://help.eclipse.org/oxygen/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fproject_description_file.html");
    return new IHyperlink[] { showInSystemExplorerHyperlink, fileUrlHyperlink, projectFileHelpLink };
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IResource(org.eclipse.core.resources.IResource)

Example 25 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class LineNumberColumn method getQuickDiffPreference.

/**
 * Returns whether quick diff info should be visible upon opening an editor
 * according to the preference store settings.
 *
 * @return <code>true</code> if the line numbers should be visible
 */
private boolean getQuickDiffPreference() {
    if (fForwarder != null)
        return fForwarder.isQuickDiffEnabled();
    IPreferenceStore store = getPreferenceStore();
    boolean setting = store != null ? store.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON) : false;
    if (!setting)
        return false;
    boolean modifiable;
    ITextEditor editor = getEditor();
    if (editor instanceof ITextEditorExtension2) {
        ITextEditorExtension2 ext = (ITextEditorExtension2) editor;
        modifiable = ext.isEditorInputModifiable();
    } else if (editor instanceof ITextEditorExtension) {
        ITextEditorExtension ext = (ITextEditorExtension) editor;
        modifiable = ext.isEditorInputReadOnly();
    } else if (editor != null) {
        modifiable = editor.isEditable();
    } else {
        modifiable = true;
    }
    return modifiable;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ITextEditorExtension2(org.eclipse.ui.texteditor.ITextEditorExtension2) ITextEditorExtension(org.eclipse.ui.texteditor.ITextEditorExtension) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

ITextEditor (org.eclipse.ui.texteditor.ITextEditor)233 IEditorPart (org.eclipse.ui.IEditorPart)91 IDocument (org.eclipse.jface.text.IDocument)73 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)39 ITextSelection (org.eclipse.jface.text.ITextSelection)34 IFile (org.eclipse.core.resources.IFile)33 Test (org.junit.Test)31 BadLocationException (org.eclipse.jface.text.BadLocationException)27 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)25 PartInitException (org.eclipse.ui.PartInitException)23 ISelection (org.eclipse.jface.viewers.ISelection)19 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)17 IRegion (org.eclipse.jface.text.IRegion)16 Annotation (org.eclipse.jface.text.source.Annotation)16 ArrayList (java.util.ArrayList)15 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)15 IResource (org.eclipse.core.resources.IResource)14 IEditorInput (org.eclipse.ui.IEditorInput)14 CoreException (org.eclipse.core.runtime.CoreException)13 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)12