Search in sources :

Example 1 with ITextEditorExtension

use of org.eclipse.ui.texteditor.ITextEditorExtension 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)

Example 2 with ITextEditorExtension

use of org.eclipse.ui.texteditor.ITextEditorExtension in project webtools.sourceediting by eclipse.

the class ActionContributor method setActiveEditor.

/**
 * @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(IEditorPart)
 */
public void setActiveEditor(IEditorPart activeEditor) {
    if (getActiveEditorPart() == activeEditor)
        return;
    super.setActiveEditor(activeEditor);
    ITextEditor textEditor = getTextEditor(activeEditor);
    /*		IActionBars actionBars = getActionBars();
		if (actionBars != null) {
			actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNextAnnotation);
			actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPreviousAnnotation);
			actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), fPreviousAnnotation);
			actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), fNextAnnotation);

			if (textEditor != null) {
				actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId()));
				actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId()));
			}
		}

		fStructureSelectEnclosingAction.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_STRUCTURE_SELECT_ENCLOSING));
		fStructureSelectNextAction.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_STRUCTURE_SELECT_NEXT));
		fStructureSelectPreviousAction.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_STRUCTURE_SELECT_PREVIOUS));
		fStructureSelectHistoryAction.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_STRUCTURE_SELECT_HISTORY));

		fShiftRight.setAction(getAction(textEditor, ITextEditorActionConstants.SHIFT_RIGHT));
		fShiftLeft.setAction(getAction(textEditor, ITextEditorActionConstants.SHIFT_LEFT));

		fToggleComment.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_TOGGLE_COMMENT));
		fAddBlockComment.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_ADD_BLOCK_COMMENT));
		fRemoveBlockComment.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_REMOVE_BLOCK_COMMENT));

		// go to prev/next error
		// CMVC 249017 for JavaEditor consistancy
		fPreviousAnnotation.setEditor(textEditor);
		fNextAnnotation.setEditor(textEditor);
		fGotoMatchingBracketAction.setAction(getAction(textEditor, StructuredTextEditorActionConstants.ACTION_NAME_GOTO_MATCHING_BRACKET));
*/
    fToggleInsertModeAction.setAction(getAction(textEditor, ITextEditorActionConstants.TOGGLE_INSERT_MODE));
    if (extendedContributor != null) {
        extendedContributor.setActiveEditor(activeEditor);
    }
    if (_showDebugStatus && textEditor instanceof ITextEditorExtension) {
        ((ITextEditorExtension) textEditor).setStatusField(fDebugStatusOffset, StructuredTextEditorActionConstants.STATUS_CATEGORY_OFFSET);
        fDebugStatusOffset.setActiveEditor(textEditor);
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ITextEditorExtension(org.eclipse.ui.texteditor.ITextEditorExtension)

Example 3 with ITextEditorExtension

use of org.eclipse.ui.texteditor.ITextEditorExtension in project xtext-eclipse by eclipse.

the class DefaultRefactoringDocumentProvider method get.

@Override
public IRefactoringDocument get(URI uri, final StatusWrapper status) {
    URI resourceURI = uri.trimFragment();
    final IFileEditorInput fileEditorInput = getEditorInput(resourceURI, status);
    if (fileEditorInput != null) {
        IFile file = fileEditorInput.getFile();
        IPath redirectedPath = changeRedirector.getRedirectedPath(file.getFullPath());
        IFile redirectedFile = file.getWorkspace().getRoot().getFile(redirectedPath);
        if (redirectedFile.equals(file)) {
            if (workbench != null) {
                ITextEditor editor = new DisplayRunnableWithResult<ITextEditor>() {

                    @Override
                    protected ITextEditor run() throws Exception {
                        IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
                        IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
                        ITextEditor editor = Adapters.adapt(activePage.findEditor(fileEditorInput), ITextEditor.class);
                        if (editor != null) {
                            if (editor instanceof ITextEditorExtension && ((ITextEditorExtension) editor).isEditorInputReadOnly())
                                status.add(ERROR, "Editor for {0} is read only", fileEditorInput.getName());
                            return (editor);
                        }
                        return null;
                    }
                }.syncExec();
                if (editor != null) {
                    IDocument document = editor.getDocumentProvider().getDocument(fileEditorInput);
                    if (document != null)
                        return new EditorDocument(resourceURI, editor, document, preferences.isSaveAllBeforeRefactoring() || !editor.isDirty());
                }
            }
            return new FileDocument(resourceURI, file, getEncodingProvider(resourceURI));
        } else {
            return new RedirectedFileDocument(resourceURI, file, redirectedFile, getEncodingProvider(resourceURI));
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IPath(org.eclipse.core.runtime.IPath) URI(org.eclipse.emf.common.util.URI) WrappedException(org.eclipse.emf.common.util.WrappedException) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ITextEditorExtension(org.eclipse.ui.texteditor.ITextEditorExtension) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

ITextEditor (org.eclipse.ui.texteditor.ITextEditor)3 ITextEditorExtension (org.eclipse.ui.texteditor.ITextEditorExtension)3 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 URI (org.eclipse.emf.common.util.URI)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 IDocument (org.eclipse.jface.text.IDocument)1 IFileEditorInput (org.eclipse.ui.IFileEditorInput)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 ITextEditorExtension2 (org.eclipse.ui.texteditor.ITextEditorExtension2)1