matthiasblaesing commented on PR #9767:
URL: https://github.com/apache/netbeans/pull/9767#issuecomment-7111973470
This looks better to me. Please have a look at this suggestion:
```diff
--- a/ide/editor/src/org/netbeans/modules/editor/LineWrapAction.java
+++ b/ide/editor/src/org/netbeans/modules/editor/LineWrapAction.java
@@ -27,7 +27,9 @@
import javax.swing.ButtonGroup;
import javax.swing.JComponent;
import javax.swing.JMenu;
+import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JSeparator;
import javax.swing.SwingUtilities;
import javax.swing.text.JTextComponent;
import org.netbeans.api.editor.settings.SimpleValueNames;
@@ -67,9 +69,11 @@
"lineWrapAction.menuItem.off=&Off",
"lineWrapAction.menuItem.anywhere=&Anywhere",
"lineWrapAction.menuItem.afterWords=After &words",
+ "lineWrapAction.menuItem.toggleLineWrap=&Toggle Line Wrap",
"lineWrapAction.wrapOffAction.displayName=Wrap Off",
"lineWrapAction.wrapAfterWordsAction.displayName=Wrap After Words",
- "lineWrapAction.wrapAnywhereAction.displayName=Wrap Anywhere"
+ "lineWrapAction.wrapAnywhereAction.displayName=Wrap Anywhere",
+ "lineWrapAction.toggleLinewrapAction.displayName=Toggle Line Wrap"
})
@ActionID(
category = LineWrapAction.CATEGORY,
@@ -95,6 +99,7 @@
private JRadioButtonMenuItem wrapOffMenuItem;
private JRadioButtonMenuItem wrapAnywhereMenuItem;
private JRadioButtonMenuItem wrapAfterWordsMenuItem;
+ private JMenuItem toggleLinewrapMenuItem;
public LineWrapAction() {
super(Bundle.lineWrapAction_displayName());
@@ -168,6 +173,10 @@
wrapAfterWordsMenuItem = new JRadioButtonMenuItem(action);
Mnemonics.setLocalizedText(wrapAfterWordsMenuItem,
Bundle.lineWrapAction_menuItem_afterWords());
+ action = Actions.forID(LineWrapAction.SUBCATEGORY,
ToggleWrapAction.ID);
+ toggleLinewrapMenuItem = new JMenuItem(action);
+ Mnemonics.setLocalizedText(toggleLinewrapMenuItem,
Bundle.lineWrapAction_menuItem_toggleLineWrap());
+
ButtonGroup group = new ButtonGroup();
group.add(wrapOffMenuItem);
group.add(wrapAnywhereMenuItem);
@@ -178,6 +187,9 @@
menu.add(wrapOffMenuItem);
menu.add(wrapAnywhereMenuItem);
menu.add(wrapAfterWordsMenuItem);
+ menu.add(new JSeparator());
+ menu.add(toggleLinewrapMenuItem);
+
}
private void updateState() {
@@ -280,10 +292,6 @@
@ActionID(
category = LineWrapAction.SUBCATEGORY,
id = WrapAfterWordsAction.ID)
- @ActionReferences({
- @ActionReference(
- path = "Shortcuts",
- name = "O-Z")})
@ActionRegistration(
lazy = false,
iconInMenu = false,
@@ -304,4 +312,39 @@
}
}
+
+ @ActionID(
+ category = LineWrapAction.SUBCATEGORY,
+ id = ToggleWrapAction.ID)
+ @ActionReferences({
+ @ActionReference(
+ path = "Shortcuts",
+ name = "O-Z")})
+ @ActionRegistration(
+ lazy = false,
+ iconInMenu = false,
+ displayName =
"#lineWrapAction.toggleLinewrapAction.displayName")
+ public static final class ToggleWrapAction extends AbstractAction {
+
+ public static final String ID =
"org.netbeans.modules.editor.LineWrapAction.ToogleWrap";
+
+ private static final long serialVersionUID = 1L;
+
+ public ToggleWrapAction() {
+ super(Bundle.lineWrapAction_toggleLinewrapAction_displayName());
}
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String currentLineWrap = getLineWrapTypeForActiveEditor();
+ if
(LineWrapType.WORD_BOUND.getSettingValue().equals(currentLineWrap)) {
+ setLineWrapTypeForActiveEditor(LineWrapType.NONE);
+ } else if
(LineWrapType.NONE.getSettingValue().equals(currentLineWrap)) {
+
setLineWrapTypeForActiveEditor(LineWrapType.CHARACTER_BOUND);
+ } else if
(LineWrapType.CHARACTER_BOUND.getSettingValue().equals(currentLineWrap)) {
+ setLineWrapTypeForActiveEditor(LineWrapType.WORD_BOUND);
+ }
+ }
+
+ }
+}
```
In the committed state Alt-Z is tied to the "Word wrap" action. The
introduction of the toggle action allows us to toggle through the wrapping
options. The addition to the menu of that action is not really necessary, but
allows the shortcut to be better discoverable without loosing screen real
estate.
<img width="533" height="118" alt="grafik"
src="https://github.com/user-attachments/assets/9f96caa0-56f8-407b-b5bb-bbd73362ca15"
/>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists