Ignore:
Timestamp:
2015-02-03T21:53:19+01:00 (9 years ago)
Author:
Don-vip
Message:

fix #11064 - disable undo/redo feature for table cell editors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java

    r8002 r8005  
    4646
    4747    protected JTextComponent component = null;
     48    protected boolean undoRedo;
    4849    protected final UndoAction undoAction = new UndoAction();
    4950    protected final RedoAction redoAction = new RedoAction();
     
    8283     * @see #detach()
    8384     */
    84     protected TextContextualPopupMenu attach(JTextComponent component) {
     85    protected TextContextualPopupMenu attach(JTextComponent component, boolean undoRedo) {
    8586        if (component != null && !isAttached()) {
    8687            this.component = component;
    87             if (component.isEditable()) {
     88            this.undoRedo = undoRedo;
     89            if (undoRedo && component.isEditable()) {
    8890                component.getDocument().addUndoableEditListener(undoEditListener);
    8991                if (!GraphicsEnvironment.isHeadless()) {
     
    102104    private void addMenuEntries() {
    103105        if (component.isEditable()) {
    104             add(new JMenuItem(undoAction));
    105             add(new JMenuItem(redoAction));
    106             addSeparator();
     106            if (undoRedo) {
     107                add(new JMenuItem(undoAction));
     108                add(new JMenuItem(redoAction));
     109                addSeparator();
     110            }
    107111            addMenuEntry(component, tr("Cut"), DefaultEditorKit.cutAction, null);
    108112        }
     
    125129            component.removePropertyChangeListener(EDITABLE, propertyChangeListener);
    126130            removeAll();
    127             component.getDocument().removeUndoableEditListener(undoEditListener);
     131            if (undoRedo) {
     132                component.getDocument().removeUndoableEditListener(undoEditListener);
     133            }
    128134            component = null;
    129135        }
     
    134140     * Creates a new {@link TextContextualPopupMenu} and enables it for the given text component.
    135141     * @param component The component that will display the menu and handle its actions.
     142     * @param undoRedo Enables or not Undo/Redo feature. Not recommended for table cell editors, unless each cell provides its own editor
    136143     * @return The {@link PopupMenuLauncher} responsible of displaying the popup menu.
    137144     *         Call {@link #disableMenuFor} with this object if you want to disable the menu later.
    138      * @see #disableMenuFor(JTextComponent, PopupMenuLauncher)
    139      */
    140     public static PopupMenuLauncher enableMenuFor(JTextComponent component) {
    141         PopupMenuLauncher launcher = new PopupMenuLauncher(new TextContextualPopupMenu().attach(component), true);
     145     * @see #disableMenuFor
     146     */
     147    public static PopupMenuLauncher enableMenuFor(JTextComponent component, boolean undoRedo) {
     148        PopupMenuLauncher launcher = new PopupMenuLauncher(new TextContextualPopupMenu().attach(component, undoRedo), true);
    142149        component.addMouseListener(launcher);
    143150        return launcher;
     
    148155     * @param component The component that currently displays the menu and handles its actions.
    149156     * @param launcher The {@link PopupMenuLauncher} obtained via {@link #enableMenuFor}.
    150      * @see #enableMenuFor(JTextComponent)
     157     * @see #enableMenuFor
    151158     */
    152159    public static void disableMenuFor(JTextComponent component, PopupMenuLauncher launcher) {
Note: See TracChangeset for help on using the changeset viewer.