mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Remove show invisible characters action (moved to Platform)
This commit is contained in:
parent
6ec58803b9
commit
b778c94164
4 changed files with 1 additions and 293 deletions
Binary file not shown.
Before Width: | Height: | Size: 123 B |
|
@ -148,11 +148,6 @@ todoTaskPrefName=Task Tags
|
|||
Editors.DefaultTextEditor = Default Text Editor
|
||||
AsmEditor.name = Assembly Editor
|
||||
|
||||
# Show Invisble Characters
|
||||
ShowInvisibleCharactersAction.label=Show Invisible Characters
|
||||
ShowInvisibleCharactersAction.tooltip=Show Invisible Characters
|
||||
ShowInvisibleCharactersAction.description=Show invisible (whitespace) characters CR, LF, TAB and SPACE
|
||||
|
||||
# Task Action
|
||||
DeleteTaskAction.label=Delete C/C++ Markers
|
||||
DeleteIProblemMarkerAction.label=Delete IProblem Markers
|
||||
|
|
|
@ -221,7 +221,7 @@
|
|||
</actionSet>
|
||||
<showInPart id="org.eclipse.cdt.ui.includeBrowser"/>
|
||||
<showInPart id="org.eclipse.cdt.ui.CView"/>
|
||||
<actionSet id="org.eclipse.cdt.ui.CEditorPresentationActionSet"/>
|
||||
<actionSet id="org.eclipse.ui.edit.text.actionSet.presentation"/>
|
||||
<showInPart id="org.eclipse.ui.navigator.ProjectExplorer"/>
|
||||
<viewShortcut id="org.eclipse.ui.navigator.ProjectExplorer"/>
|
||||
<!--perspectiveShortcut
|
||||
|
@ -852,24 +852,6 @@
|
|||
tooltip="%NewProjectDropDownAction.tooltip">
|
||||
</action>
|
||||
</actionSet>
|
||||
<actionSet
|
||||
description="%CEditorPresentationActionSet.description"
|
||||
id="org.eclipse.cdt.ui.CEditorPresentationActionSet"
|
||||
label="%CEditorPresentationActionSet.label">
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.ShowInvisibleCharactersAction"
|
||||
definitionId="org.eclipse.cdt.ui.edit.text.c.show.invisible.chars"
|
||||
icon="icons/etool16/show_invisible_chars.gif"
|
||||
id="org.eclipse.cdt.ui.ShowInvisibleCharactersAction"
|
||||
label="%ShowInvisibleCharactersAction.label"
|
||||
style="toggle"
|
||||
toolbarPath="org.eclipse.ui.edit.text.actionSet.presentation/Presentation"
|
||||
tooltip="%ShowInvisibleCharactersAction.tooltip">
|
||||
<enablement>
|
||||
<objectClass name="org.eclipse.jface.text.ITextSelection"/>
|
||||
</enablement>
|
||||
</action>
|
||||
</actionSet>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.ide.projectNatureImages">
|
||||
|
@ -1131,12 +1113,6 @@
|
|||
categoryId="org.eclipse.cdt.ui.category.source"
|
||||
id="org.eclipse.cdt.ui.edit.text.c.show.tooltip">
|
||||
</command>
|
||||
<command
|
||||
name="%ShowInvisibleCharactersAction.label"
|
||||
description="%ShowInvisibleCharactersAction.description"
|
||||
categoryId="org.eclipse.cdt.ui.category.source"
|
||||
id="org.eclipse.cdt.ui.edit.text.c.show.invisible.chars">
|
||||
</command>
|
||||
</extension>
|
||||
<extension
|
||||
id="pdomSearchPage"
|
||||
|
|
|
@ -1,263 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.text.IPainter;
|
||||
import org.eclipse.jface.text.ITextOperationTarget;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.ITextViewerExtension2;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IEditorActionDelegate;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IPartListener2;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchPartReference;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
import org.eclipse.ui.texteditor.IUpdate;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.InvisibleCharacterPainter;
|
||||
|
||||
/**
|
||||
* This action toggles the visibility of whitespace characters by
|
||||
* attaching/detaching an {@link InvisibleCharacterPainter} to the
|
||||
* active (text-)editor.
|
||||
*
|
||||
* @author anton.leherbauer@windriver.com
|
||||
*/
|
||||
public class ShowInvisibleCharactersAction implements IEditorActionDelegate, IWorkbenchWindowActionDelegate, IUpdate {
|
||||
|
||||
/**
|
||||
* The PartListener to act on changes of the active editor.
|
||||
*/
|
||||
private class PartListener implements IPartListener2 {
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.IWorkbenchPartReference)
|
||||
*/
|
||||
public void partActivated(IWorkbenchPartReference partRef) {
|
||||
if (partRef.getPart(false) instanceof IEditorPart) {
|
||||
updateActiveEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IPartListener2#partBroughtToTop(org.eclipse.ui.IWorkbenchPartReference)
|
||||
*/
|
||||
public void partBroughtToTop(IWorkbenchPartReference partRef) {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
|
||||
*/
|
||||
public void partClosed(IWorkbenchPartReference partRef) {
|
||||
if (partRef.getPart(false) instanceof IEditorPart) {
|
||||
updateActiveEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference)
|
||||
*/
|
||||
public void partDeactivated(IWorkbenchPartReference partRef) {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
|
||||
*/
|
||||
public void partOpened(IWorkbenchPartReference partRef) {
|
||||
if (partRef.getPart(false) instanceof IEditorPart) {
|
||||
updateActiveEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IPartListener2#partHidden(org.eclipse.ui.IWorkbenchPartReference)
|
||||
*/
|
||||
public void partHidden(IWorkbenchPartReference partRef) {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IPartListener2#partVisible(org.eclipse.ui.IWorkbenchPartReference)
|
||||
*/
|
||||
public void partVisible(IWorkbenchPartReference partRef) {
|
||||
if (partRef.getPart(false) instanceof IEditorPart) {
|
||||
updateActiveEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IPartListener2#partInputChanged(org.eclipse.ui.IWorkbenchPartReference)
|
||||
*/
|
||||
public void partInputChanged(IWorkbenchPartReference partRef) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private IPainter fInvisibleCharPainter;
|
||||
private IWorkbenchWindow fWindow;
|
||||
private IPartListener2 fPartListener;
|
||||
private ITextEditor fTextEditor;
|
||||
private boolean fIsChecked;
|
||||
private IAction fAction;
|
||||
|
||||
public ShowInvisibleCharactersAction() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the painter to the current editor.
|
||||
*/
|
||||
private void addPainter() {
|
||||
ITextEditor editor= getTextEditor();
|
||||
ITextViewer viewer= getTextViewer(editor);
|
||||
if (viewer instanceof ITextViewerExtension2) {
|
||||
ITextViewerExtension2 viewerExt2= (ITextViewerExtension2)viewer;
|
||||
if (fInvisibleCharPainter == null) {
|
||||
fInvisibleCharPainter= new InvisibleCharacterPainter(viewer);
|
||||
}
|
||||
viewerExt2.addPainter(fInvisibleCharPainter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ITextViewer from an ITextEditor by adapting
|
||||
* it to a ITextOperationTarget.
|
||||
* @param editor the ITextEditor
|
||||
* @return the text viewer or <code>null</code>
|
||||
*/
|
||||
private ITextViewer getTextViewer(ITextEditor editor) {
|
||||
Object target= editor.getAdapter(ITextOperationTarget.class);
|
||||
if (target instanceof ITextViewer) {
|
||||
return (ITextViewer)target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the painter from the current editor.
|
||||
*/
|
||||
private void removePainter() {
|
||||
ITextEditor editor= getTextEditor();
|
||||
ITextViewer viewer= getTextViewer(editor);
|
||||
if (viewer instanceof ITextViewerExtension2) {
|
||||
ITextViewerExtension2 viewerExt2= (ITextViewerExtension2)viewer;
|
||||
viewerExt2.removePainter(fInvisibleCharPainter);
|
||||
}
|
||||
}
|
||||
|
||||
private void setEditor(ITextEditor editor) {
|
||||
if (editor != null && editor == getTextEditor()) {
|
||||
return;
|
||||
}
|
||||
if (fInvisibleCharPainter != null) {
|
||||
removePainter();
|
||||
fInvisibleCharPainter.deactivate(false);
|
||||
fInvisibleCharPainter.dispose();
|
||||
fInvisibleCharPainter= null;
|
||||
}
|
||||
fTextEditor= editor;
|
||||
update();
|
||||
if (fTextEditor != null && fIsChecked) {
|
||||
addPainter();
|
||||
}
|
||||
}
|
||||
|
||||
private ITextEditor getTextEditor() {
|
||||
return fTextEditor;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
|
||||
*/
|
||||
public void setActiveEditor(IAction action, IEditorPart targetEditor) {
|
||||
fAction= action;
|
||||
if (targetEditor instanceof ITextEditor) {
|
||||
setEditor((ITextEditor)targetEditor);
|
||||
} else {
|
||||
setEditor(null);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
|
||||
*/
|
||||
public void init(IWorkbenchWindow window) {
|
||||
fWindow= window;
|
||||
fPartListener= new PartListener();
|
||||
fWindow.getActivePage().addPartListener(fPartListener);
|
||||
updateActiveEditor();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
if (fWindow != null) {
|
||||
IWorkbenchPage activePage= fWindow.getActivePage();
|
||||
if (activePage != null) {
|
||||
activePage.removePartListener(fPartListener);
|
||||
}
|
||||
fPartListener= null;
|
||||
fWindow= null;
|
||||
}
|
||||
fAction= null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
|
||||
*/
|
||||
public void run(IAction action) {
|
||||
fAction= action;
|
||||
fIsChecked= action.isChecked();
|
||||
if (fIsChecked) {
|
||||
addPainter();
|
||||
} else if (fInvisibleCharPainter != null) {
|
||||
removePainter();
|
||||
fInvisibleCharPainter.deactivate(true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
|
||||
*/
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
fAction= action;
|
||||
fIsChecked= action.isChecked();
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the active editor.
|
||||
*/
|
||||
protected void updateActiveEditor() {
|
||||
IWorkbenchPage page= fWindow.getActivePage();
|
||||
if (page != null) {
|
||||
IEditorPart editorPart= page.getActiveEditor();
|
||||
if (editorPart instanceof ITextEditor) {
|
||||
setEditor((ITextEditor)editorPart);
|
||||
} else {
|
||||
setEditor(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.texteditor.IUpdate#update()
|
||||
*/
|
||||
public void update() {
|
||||
if (fAction != null) {
|
||||
fAction.setEnabled(getTextEditor() != null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue