diff options
Diffstat (limited to 'org.eclipse.ui.workbench.texteditor/src/org')
7 files changed, 152 insertions, 6 deletions
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; + } +} |