abelhafi commented on code in PR #9767: URL: https://github.com/apache/netbeans/pull/9767#discussion_r4684777640
########## ide/editor/src/org/netbeans/modules/editor/LineWrapAction.java: ########## @@ -0,0 +1,353 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.editor; + +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import javax.swing.AbstractAction; +import javax.swing.Action; +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; +import org.netbeans.editor.Utilities; +import org.netbeans.modules.editor.lib2.view.DocumentViewOp; +import org.netbeans.modules.editor.lib2.view.LineWrapType; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.awt.Actions; +import org.openide.awt.DynamicMenuContent; +import org.openide.awt.Mnemonics; +import org.openide.util.NbBundle.Messages; +import org.openide.util.WeakListeners; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +/** + * Registers a {@code Line Wrap} submenu under the {@code View} menu to control + * editor line wrapping. + * + * <p> + * The {@code Line Wrap} submenu contains four actions: the first three activate + * each of the three wrapping modes individually, and the fourth cycles through + * the modes sequentially. + * + * <p> + * Each of these four actions supports customizable keyboard shortcuts + * configured under {@code Tools > Options > Keymap}. By default, only the + * {@code Toggle Line Wrap} action is bound to {@code ALT-Z}.</p> + * + * @author Alejandro L. Belhafi + * @author Matthias Bläsing + * @see LineWrapType + */ +@Messages({ + "lineWrapAction.displayName=Line Wrap", + "lineWrapAction.menu=Line &Wrap", + "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.toggleLineWrapAction.displayName=Toggle Line Wrap" +}) +@ActionID( + category = LineWrapAction.CATEGORY, + id = LineWrapAction.ID) +@ActionReferences({ + @ActionReference( + path = "Menu/View", + position = 215)}) +@ActionRegistration( + lazy = false, + iconInMenu = false, + displayName = "#lineWrapAction.displayName") +public final class LineWrapAction extends AbstractAction + implements PropertyChangeListener, Runnable, DynamicMenuContent { + + public static final String ID = "org.netbeans.modules.editor.LineWrapAction"; + public static final String CATEGORY = "View"; + public static final String SUBCATEGORY = CATEGORY + "/Line Wrap"; + + private static final long serialVersionUID = 1L; + + private JMenu menu; + private JRadioButtonMenuItem wrapOffMenuItem; + private JRadioButtonMenuItem wrapAnywhereMenuItem; + private JRadioButtonMenuItem wrapAfterWordsMenuItem; + private JMenuItem toggleLinewrapMenuItem; + + public LineWrapAction() { + super(Bundle.lineWrapAction_displayName()); + + TopComponent.getRegistry().addPropertyChangeListener( Review Comment: Hello, I understand your preference for `Lookup`, and I did test it during development. However, I moved away from using `Lookup` (and `ContextAwareAction`, `Actions.context`, etc) because it causes inconsistencies in the menu (the menu would remain enabled when selecting a node in the treeview, or stay disabled when returning to the editor). That is why I use `TopComponent`, as is done with other NetBeans actions. -- 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
