diff options
author | Andrey Loskutov | 2014-08-05 17:09:27 +0000 |
---|---|---|
committer | Andrey Loskutov | 2015-11-10 08:33:11 +0000 |
commit | a50bb821beaaf193dc9bf412316a0c15b32ac0f1 (patch) | |
tree | ff0a54cea18b30bb67d13ea64a73dc4d57abd303 /org.eclipse.ui.workbench.texteditor | |
parent | b212745ce6ea0079e5876fe77658b174a124c1ae (diff) | |
download | eclipse.platform.text-a50bb821beaaf193dc9bf412316a0c15b32ac0f1.tar.gz eclipse.platform.text-a50bb821beaaf193dc9bf412316a0c15b32ac0f1.tar.xz eclipse.platform.text-a50bb821beaaf193dc9bf412316a0c15b32ac0f1.zip |
Bug 35779 - [misc] Text Viewer and Editor needs to support word wrap
Added "Enable word wrap when opening an editor" preference to "Text
Editors" preference page, "Toggle Word Wrap" text editor action /
toolbar button and ALT+SHIFT+Y shortcut for text editors extending
AbstractTextEditor.
Change-Id: Ibc4d64d0c76a31aff781726336d41b9ee1cbd659
Also-by: Florian Weßling <flo@cdhq.de>
Also-by: Holger Voormann <eclipse@voormann.de>
Also-by: Lars Vogel <Lars.Vogel@vogella.com>
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.ui.workbench.texteditor')
11 files changed, 181 insertions, 7 deletions
diff --git a/org.eclipse.ui.workbench.texteditor/icons/full/dtool16/wordwrap.png b/org.eclipse.ui.workbench.texteditor/icons/full/dtool16/wordwrap.png Binary files differnew file mode 100644 index 00000000000..a446b7d974d --- /dev/null +++ b/org.eclipse.ui.workbench.texteditor/icons/full/dtool16/wordwrap.png diff --git a/org.eclipse.ui.workbench.texteditor/icons/full/etool16/wordwrap.png b/org.eclipse.ui.workbench.texteditor/icons/full/etool16/wordwrap.png Binary files differnew file mode 100644 index 00000000000..69e1839376b --- /dev/null +++ b/org.eclipse.ui.workbench.texteditor/icons/full/etool16/wordwrap.png diff --git a/org.eclipse.ui.workbench.texteditor/plugin.properties b/org.eclipse.ui.workbench.texteditor/plugin.properties index 2812816bb88..f49ffdb045e 100644 --- a/org.eclipse.ui.workbench.texteditor/plugin.properties +++ b/org.eclipse.ui.workbench.texteditor/plugin.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2013 IBM Corporation and others. +# Copyright (c) 2000, 2015 IBM Corporation 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 @@ -38,6 +38,10 @@ toggleBlockSelectionMode.label= Toggle Block Selection toggleBlockSelectionMode.tooltip= Toggle Block Selection toggleBlockSelectionMode.description= Toggle block / column selection in the current text editor +toggleWordWrap.label= Toggle Word Wrap +toggleWordWrap.tooltip= Toggle Word Wrap +toggleWordWrap.description= Toggle word wrap in the current text editor + smartEnter.label= Insert Line Below Current Line smartEnter.description= Adds a new line below the current line smartEnterInverse.label= Insert Line Above Current Line diff --git a/org.eclipse.ui.workbench.texteditor/plugin.xml b/org.eclipse.ui.workbench.texteditor/plugin.xml index f3ed45e0334..f3a897f35a9 100644 --- a/org.eclipse.ui.workbench.texteditor/plugin.xml +++ b/org.eclipse.ui.workbench.texteditor/plugin.xml @@ -405,6 +405,12 @@ categoryId="org.eclipse.ui.category.edit" id="org.eclipse.ui.edit.text.toggleBlockSelectionMode"> </command> + <command + name="%toggleWordWrap.label" + description="%toggleWordWrap.description" + categoryId="org.eclipse.ui.category.edit" + id="org.eclipse.ui.edit.text.toggleWordWrap"> + </command> <command name="%command.toggleInsertMode.name" description="%command.toggleInsertMode.description" @@ -794,6 +800,11 @@ commandId="org.eclipse.ui.edit.text.toggleBlockSelectionMode" schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/> <key + sequence="M2+M3+Y" + contextId="org.eclipse.ui.textEditorScope" + commandId="org.eclipse.ui.edit.text.toggleWordWrap" + schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/> + <key platform="carbon" sequence="M2+M3+A" contextId="org.eclipse.ui.textEditorScope" @@ -1184,6 +1195,19 @@ toolbarPath="Normal/Presentation" tooltip="%toggleBlockSelectionMode.tooltip"> </action> + <action + allowLabelUpdate="true" + definitionId="org.eclipse.ui.edit.text.toggleWordWrap" + disabledIcon="$nl$/icons/full/dtool16/wordwrap.png" + helpContextId="org.eclipse.ui.word_wrap_toggle_action_context" + icon="$nl$/icons/full/etool16/wordwrap.png" + id="org.eclipse.ui.edit.text.toggleWordWrap" + label="%toggleWordWrap.label" + retarget="true" + style="toggle" + toolbarPath="Normal/Presentation" + tooltip="%toggleWordWrap.tooltip"> + </action> </actionSet> </extension> <extension diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java index c83295f9f8e..a2dfb70a1e1 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java @@ -16,6 +16,7 @@ * Nick Sandonato <nsandona@us.ibm.com> - [implementation] AbstractTextEditor does not prompt when out of sync in MultiPageEditorPart - http://bugs.eclipse.org/337719 * Holger Voormann - Word Wrap - https://bugs.eclipse.org/bugs/show_bug.cgi?id=35779 * Florian Weßling <flo@cdhq.de> - Word Wrap - https://bugs.eclipse.org/bugs/show_bug.cgi?id=35779 + * Andrey Loskutov <loskutov@gmx.de> - Word Wrap - https://bugs.eclipse.org/bugs/show_bug.cgi?id=35779 *******************************************************************************/ package org.eclipse.ui.texteditor; @@ -2313,6 +2314,16 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit */ public static final String PREFERENCE_HOVER_ENRICH_MODE= "hoverReplaceMode"; //$NON-NLS-1$ + /** + * A named preference to control the initial word wrap status. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + * + * @since 3.10 + */ + public static final String PREFERENCE_WORD_WRAP_ENABLED= "wordwrap.enabled"; //$NON-NLS-1$ + /** Menu id for the editor context menu. */ public static final String DEFAULT_EDITOR_CONTEXT_MENU_ID= "#EditorContext"; //$NON-NLS-1$ /** Menu id for the ruler context menu. */ @@ -3590,6 +3601,9 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit IVerticalRuler ruler= getVerticalRuler(); if (ruler instanceof CompositeRuler) updateContributedRulerColumns((CompositeRuler) ruler); + + if(isWordWrapSupported()) + setWordWrap(getInitialWordWrapStatus()); } /** @@ -5950,11 +5964,37 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHOW_INFORMATION); setAction(ITextEditorActionConstants.SHOW_INFORMATION, action); - action= new BlockSelectionModeToggleAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ToggleBlockSelectionMode.", this); //$NON-NLS-1$ + final BlockSelectionModeToggleAction blockAction= new BlockSelectionModeToggleAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ToggleBlockSelectionMode.", this); //$NON-NLS-1$ + action = blockAction; action.setHelpContextId(IAbstractTextEditorHelpContextIds.BLOCK_SELECTION_MODE_ACTION); action.setActionDefinitionId(ITextEditorActionDefinitionIds.BLOCK_SELECTION_MODE); setAction(ITextEditorActionConstants.BLOCK_SELECTION_MODE, action); + if(isWordWrapSupported()){ + final WordWrapToggleAction wrapAction= new WordWrapToggleAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ToggleWordWrap.", this, getInitialWordWrapStatus()); //$NON-NLS-1$ + action = wrapAction; + action.setHelpContextId(IAbstractTextEditorHelpContextIds.WORD_WRAP_TOGGLE_ACTION); + action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_WRAP); + setAction(ITextEditorActionConstants.WORD_WRAP, action); + + blockAction.addPropertyChangeListener(new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + if(IAction.CHECKED == event.getProperty() && + Boolean.TRUE.equals(event.getNewValue())){ + wrapAction.setChecked(false); + } + } + }); + wrapAction.addPropertyChangeListener(new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + if(IAction.CHECKED == event.getProperty() && + Boolean.TRUE.equals(event.getNewValue())){ + blockAction.setChecked(false); + } + } + }); + } + action= new TextOperationAction(EditorMessages.getBundleForConstructedKeys(), "Editor.OpenHyperlink.", this, HyperlinkManager.OPEN_HYPERLINK, true); //$NON-NLS-1$; action.setHelpContextId(IAbstractTextEditorHelpContextIds.OPEN_HYPERLINK_ACTION); action.setActionDefinitionId(ITextEditorActionDefinitionIds.OPEN_HYPERLINK); @@ -7465,4 +7505,13 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit } } + /** + * Returns the initial word wrap status. + * + * @return initial word wrap status + * @since 3.10 + */ + protected boolean getInitialWordWrapStatus() { + return getPreferenceStore().getBoolean(PREFERENCE_WORD_WRAP_ENABLED); + } } diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicTextEditorActionContributor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicTextEditorActionContributor.java index 388e05250d3..5627877f930 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicTextEditorActionContributor.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicTextEditorActionContributor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation 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 @@ -214,6 +214,8 @@ public class BasicTextEditorActionContributor extends EditorActionBarContributor actionBars.setGlobalActionHandler(ACTIONS[i], getAction(editor, ACTIONS[i])); actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.SHOW_WHITESPACE_CHARACTERS, getAction(editor, ITextEditorActionConstants.SHOW_WHITESPACE_CHARACTERS)); actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.BLOCK_SELECTION_MODE, getAction(editor, ITextEditorActionConstants.BLOCK_SELECTION_MODE)); + if(editor instanceof AbstractTextEditor && ((AbstractTextEditor)editor).isWordWrapSupported()) + actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.WORD_WRAP, getAction(editor, ITextEditorActionConstants.WORD_WRAP)); fFindNext.setAction(getAction(editor, ITextEditorActionConstants.FIND_NEXT)); fFindPrevious.setAction(getAction(editor, ITextEditorActionConstants.FIND_PREVIOUS)); diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConstructedEditorMessages.properties b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConstructedEditorMessages.properties index cab744bc9f8..9b4a5b5f998 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConstructedEditorMessages.properties +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConstructedEditorMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2010 IBM Corporation and others. +# Copyright (c) 2000, 2015 IBM Corporation 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 @@ -245,6 +245,11 @@ Editor.ToggleBlockSelectionMode.description= Enable block / column selection in Editor.ToggleBlockSelectionMode.image= Editor.ToggleBlockSelectionMode.tooltip= Toggle Block Selection Mode +Editor.ToggleWordWrap.label= Toggle Word Wrap +Editor.ToggleWordWrap.description= Toggle word wrap in the current text editor +Editor.ToggleWordWrap.image= +Editor.ToggleWordWrap.tooltip= Toggle Word Wrap + Editor.OpenHyperlink.label= Open Hyperlin&k Editor.OpenHyperlink.tooltip= Open Hyperlink Editor.OpenHyperlink.image= diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IAbstractTextEditorHelpContextIds.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IAbstractTextEditorHelpContextIds.java index 57b59d5cc98..0ff7f3df6ff 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IAbstractTextEditorHelpContextIds.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IAbstractTextEditorHelpContextIds.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation 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 @@ -397,6 +397,13 @@ public interface IAbstractTextEditorHelpContextIds { String BLOCK_SELECTION_MODE_ACTION= PREFIX + "block_selection_mode" + ACTION_POSTFIX; //$NON-NLS-1$ /** + * Help context id for the word wrap toggle action. Value: + * <code>"org.eclipse.ui.word_wrap_toggle_action_context"</code> + * @since 3.10 + */ + String WORD_WRAP_TOGGLE_ACTION= PREFIX + "word_wrap_toggle" + ACTION_POSTFIX; //$NON-NLS-1$ + + /** * Help context id for the open hyperlink action. * Value: <code>"org.eclipse.ui.open_hyperlink_action_context"</code> * @since 3.7 diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java index d27d3ea70e8..f8b5a855cfd 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation 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 @@ -673,6 +673,13 @@ public interface ITextEditorActionConstants extends IWorkbenchActionConstants { String BLOCK_SELECTION_MODE= "BlockSelectionMode"; //$NON-NLS-1$ /** + * Name of the action for toggling word wrap. Value: + * <code>"WordWrap"</code> + * @since 3.10 + */ + String WORD_WRAP= "WordWrap"; //$NON-NLS-1$ + + /** * Name of the action displaying a sticky ruler hover for the current caret location. * Value: <code>"ShowChangeRulerInformation"</code> * @since 3.6 diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java index 641eebb6fb6..153ae3298cd 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation 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 @@ -579,6 +579,14 @@ public interface ITextEditorActionDefinitionIds extends IWorkbenchActionDefiniti String BLOCK_SELECTION_MODE= "org.eclipse.ui.edit.text.toggleBlockSelectionMode"; //$NON-NLS-1$ /** + * Command ID of the command to toggle word wrap: + * <code>"org.eclipse.ui.edit.text.toggleWordWrap"</code>). + * + * @since 3.10 + */ + String WORD_WRAP= "org.eclipse.ui.edit.text.toggleWordWrap"; //$NON-NLS-1$ + + /** * Command ID of the command to display a sticky ruler hover for the current caret location. * Value <code>"org.eclipse.ui.edit.text.showChangeRulerInformation"</code>. * diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/WordWrapToggleAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/WordWrapToggleAction.java new file mode 100644 index 00000000000..1a5483d4553 --- /dev/null +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/WordWrapToggleAction.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2015 Andrey Loskutov 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: + * Andrey Loskutov <loskutov@gmx.de> - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.texteditor; + +import java.util.ResourceBundle; + +import org.eclipse.jface.action.IAction; + + +/** + * This action toggles the word wrap in the editor. + * + * @since 3.10 + */ +final class WordWrapToggleAction extends TextEditorAction { + + /** + * Construct the action and initialize its state. + * + * @param resourceBundle the resource bundle to construct label and tooltip from + * @param prefix the prefix to use for constructing resource bundle keys + * @param editor the editor this action is associated with + * @param checked initial toggle state + */ + public WordWrapToggleAction(ResourceBundle resourceBundle, String prefix, ITextEditor editor, boolean checked) { + super(resourceBundle, prefix, editor, IAction.AS_CHECK_BOX); + update(checked); + } + + public void run() { + boolean newState = false; + if (isWordWrapPossible()) { + ITextEditorExtension6 ext6= (ITextEditorExtension6) getTextEditor(); + newState= !ext6.isWordWrapEnabled(); + ext6.setWordWrap(newState); + } + update(newState); + } + + private void update(boolean checked) { + setEnabled(isWordWrapPossible()); + setChecked(checked); + } + + public void update() { + setEnabled(isWordWrapPossible()); + setChecked(isWordWrapEnabled()); + } + + private boolean isWordWrapPossible(){ + return getTextEditor() instanceof ITextEditorExtension6; + } + + private boolean isWordWrapEnabled(){ + if (isWordWrapPossible()) { + return ((ITextEditorExtension6)getTextEditor()).isWordWrapEnabled(); + } + return false; + } +} |