This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 180543
Collapse All | Expand All

(-)a/editor/src/org/netbeans/modules/editor/impl/ActionsList.java (+1 lines)
Lines 143-148 Link Here
143
            
143
            
144
            if (toAdd instanceof Action) {
144
            if (toAdd instanceof Action) {
145
                actions.add((Action) toAdd);
145
                actions.add((Action) toAdd);
146
                // XXX
146
            } else if (isSeparator(toAdd)) {
147
            } else if (isSeparator(toAdd)) {
147
                if (prohibitSeparatorsAndActionNames) {
148
                if (prohibitSeparatorsAndActionNames) {
148
                    if (LOG.isLoggable(Level.INFO)) {
149
                    if (LOG.isLoggable(Level.INFO)) {
(-)a/o.n.core/src/org/netbeans/core/NbKeymap.java (-10 / +16 lines)
Lines 59-64 Link Here
59
import javax.swing.Action;
59
import javax.swing.Action;
60
import javax.swing.KeyStroke;
60
import javax.swing.KeyStroke;
61
import javax.swing.text.Keymap;
61
import javax.swing.text.Keymap;
62
import org.openide.awt.AcceleratorBinding;
62
import org.openide.awt.StatusDisplayer;
63
import org.openide.awt.StatusDisplayer;
63
import org.openide.cookies.InstanceCookie;
64
import org.openide.cookies.InstanceCookie;
64
import org.openide.filesystems.FileAttributeEvent;
65
import org.openide.filesystems.FileAttributeEvent;
Lines 71-76 Link Here
71
import org.openide.loaders.DataObject;
72
import org.openide.loaders.DataObject;
72
import org.openide.loaders.DataObjectNotFoundException;
73
import org.openide.loaders.DataObjectNotFoundException;
73
import org.openide.loaders.DataShadow;
74
import org.openide.loaders.DataShadow;
75
import org.openide.util.Lookup;
74
import org.openide.util.Utilities;
76
import org.openide.util.Utilities;
75
import org.openide.util.actions.SystemAction;
77
import org.openide.util.actions.SystemAction;
76
import org.openide.util.lookup.ServiceProvider;
78
import org.openide.util.lookup.ServiceProvider;
Lines 334-351 Link Here
334
    }
336
    }
335
337
336
    public KeyStroke[] getKeyStrokesForAction(Action a) {
338
    public KeyStroke[] getKeyStrokesForAction(Action a) {
337
        FileObject definingFile = (FileObject) a.getValue("definingFile"); // cf. o.o.awt.Toolbar.setAccelerator
339
        return new KeyStroke[0];
338
        if (definingFile == null) {
340
    }
339
            LOG.log(Level.FINE, "no defining file known for {0}", id(a));
341
340
            return new KeyStroke[0];
342
    @ServiceProvider(service=AcceleratorBinding.class)
343
    public static final class AcceleratorBindingImpl extends AcceleratorBinding {
344
        public @Override KeyStroke keyStrokeForAction(Action a, FileObject definingFile) {
345
            String id = idForFile(definingFile);
346
            NbKeymap km = Lookup.getDefault().lookup(NbKeymap.class);
347
            km.bindings();
348
            km.action2Id.put(a, id);
349
            KeyStroke k = km.id2Stroke.get(id);
350
            LOG.log(Level.FINE, "found keystroke {0} for {1} with ID {2}", new Object[] {k, id(a), id});
351
            return k;
341
        }
352
        }
342
        String id = idForFile(definingFile);
343
        bindings();
344
        action2Id.put(a, id);
345
        KeyStroke k = id2Stroke.get(id);
346
        LOG.log(Level.FINE, "found keystroke {0} for {1} with ID {2}", new Object[] {k, id(a), id});
347
        return k != null ? new KeyStroke[] {k} : new KeyStroke[0];
348
    }
353
    }
354
349
    /**
355
    /**
350
     * Traverses shadow files to origin.
356
     * Traverses shadow files to origin.
351
     * Returns impl class name if that is obvious (common for SystemAction's);
357
     * Returns impl class name if that is obvious (common for SystemAction's);
(-)a/o.n.core/test/unit/src/org/netbeans/core/NbKeymapTest.java (-2 / +2 lines)
Lines 96-102 Link Here
96
        Action a = km.getAction(stroke);
96
        Action a = km.getAction(stroke);
97
        assertNotNull("for " + stroke, a);
97
        assertNotNull("for " + stroke, a);
98
        assertEquals(actionName, a.getValue(Action.NAME));
98
        assertEquals(actionName, a.getValue(Action.NAME));
99
        a.putValue("definingFile", presenterDefinition);
99
        a.putValue("definingFile", presenterDefinition);//XXX
100
        assertEquals("for " + stroke + " from " + presenterDefinition.getPath(),
100
        assertEquals("for " + stroke + " from " + presenterDefinition.getPath(),
101
                Collections.singletonList(stroke), Arrays.asList(km.getKeyStrokesForAction(a)));
101
                Collections.singletonList(stroke), Arrays.asList(km.getKeyStrokesForAction(a)));
102
    }
102
    }
Lines 264-270 Link Here
264
        FileObject def = make("Menu/x.shadow");
264
        FileObject def = make("Menu/x.shadow");
265
        def.setAttribute("originalFile", "Action/nonexistent.instance");
265
        def.setAttribute("originalFile", "Action/nonexistent.instance");
266
        Action a = new DummyAction("x");
266
        Action a = new DummyAction("x");
267
        a.putValue("definingFile", def);
267
        a.putValue("definingFile", def);//XXX
268
        new NbKeymap().getKeyStrokesForAction(a);
268
        new NbKeymap().getKeyStrokesForAction(a);
269
    }
269
    }
270
270
(-)a/openide.loaders/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.loaders
2
OpenIDE-Module: org.openide.loaders
3
OpenIDE-Module-Specification-Version: 7.12
3
OpenIDE-Module-Specification-Version: 7.13
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
5
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
5
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
(-)a/openide.loaders/src/org/openide/awt/AcceleratorBinding.java (+85 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
40
package org.openide.awt;
41
42
import javax.swing.Action;
43
import javax.swing.KeyStroke;
44
import javax.swing.text.Keymap;
45
import org.openide.filesystems.FileObject;
46
import org.openide.util.Lookup;
47
48
/**
49
 * Permits accelerators to be set on actions based on global registrations.
50
 * This class is only intended for use from NetBeans infrastructure code:
51
 * that which either reads shortcut definitions (i.e. the global {@link Keymap});
52
 * or which loads actions into presenters (e.g. {@link Toolbar}).
53
 * @since org.openide.loaders 7.13
54
 */
55
public abstract class AcceleratorBinding {
56
57
    protected AcceleratorBinding() {}
58
59
    /**
60
     * XXX
61
     * @param a XXX
62
     * @param definingFile XXX
63
     * @return XXX
64
     */
65
    public abstract KeyStroke keyStrokeForAction(Action a, FileObject definingFile);
66
67
    /**
68
     * Associates an {@link Action#ACCELERATOR_KEY} with an action based on a declared shortcut.
69
     * If an instance of {@link AcceleratorBinding} can be found in default lookup,
70
     * it will be used to determine the binding. Otherwise nothing is done.
71
     * @param a an action defined in layers
72
     * @param definingFile instance file defining the action
73
     */
74
    public static void setAccelerator(Action a, FileObject definingFile) {
75
        AcceleratorBinding bnd = Lookup.getDefault().lookup(AcceleratorBinding.class);
76
        if (bnd == null) {
77
            return;
78
        }
79
        KeyStroke key = bnd.keyStrokeForAction(a, definingFile);
80
        if (key != null) {
81
            a.putValue(Action.ACCELERATOR_KEY, key);
82
        }
83
    }
84
85
}
(-)a/openide.loaders/src/org/openide/awt/DynaMenuModel.java (-1 / +4 lines)
Lines 86-92 Link Here
86
        while (it.hasNext()) {
86
        while (it.hasNext()) {
87
            Object obj = it.next();
87
            Object obj = it.next();
88
            if (obj instanceof Action) {
88
            if (obj instanceof Action) {
89
                Toolbar.setAccelerator((Action) obj, cookiesToFiles.get(obj));
89
                FileObject file = cookiesToFiles.get(obj);
90
                if (file != null) {
91
                    AcceleratorBinding.setAccelerator((Action) obj, file);
92
                }
90
            }
93
            }
91
            if (obj instanceof Presenter.Menu) {
94
            if (obj instanceof Presenter.Menu) {
92
                // does this still apply??
95
                // does this still apply??
(-)a/openide.loaders/src/org/openide/awt/Toolbar.java (-25 / +2 lines)
Lines 58-75 Link Here
58
import javax.swing.JComponent;
58
import javax.swing.JComponent;
59
import javax.swing.JSeparator;
59
import javax.swing.JSeparator;
60
import javax.swing.JToolBar;
60
import javax.swing.JToolBar;
61
import javax.swing.KeyStroke;
62
import javax.swing.UIManager;
61
import javax.swing.UIManager;
63
import javax.swing.plaf.metal.MetalLookAndFeel;
62
import javax.swing.plaf.metal.MetalLookAndFeel;
64
import javax.swing.text.Keymap;
65
import org.netbeans.modules.openide.loaders.DataObjectAccessor;
63
import org.netbeans.modules.openide.loaders.DataObjectAccessor;
66
import org.openide.cookies.InstanceCookie;
64
import org.openide.cookies.InstanceCookie;
67
import org.openide.filesystems.FileObject;
68
import org.openide.loaders.DataFolder;
65
import org.openide.loaders.DataFolder;
69
import org.openide.loaders.DataObject;
66
import org.openide.loaders.DataObject;
70
import org.openide.loaders.FolderInstance;
67
import org.openide.loaders.FolderInstance;
71
import org.openide.util.ImageUtilities;
68
import org.openide.util.ImageUtilities;
72
import org.openide.util.Lookup;
73
import org.openide.util.Task;
69
import org.openide.util.Task;
74
import org.openide.util.actions.Presenter;
70
import org.openide.util.actions.Presenter;
75
71
Lines 411-417 Link Here
411
407
412
                    if (obj instanceof Presenter.Toolbar) {
408
                    if (obj instanceof Presenter.Toolbar) {
413
                        if (obj instanceof Action && file != null) {
409
                        if (obj instanceof Action && file != null) {
414
                            setAccelerator((Action)obj, file.getPrimaryFile());
410
                            AcceleratorBinding.setAccelerator((Action)obj, file.getPrimaryFile());
415
                        }
411
                        }
416
                        obj = ((Presenter.Toolbar) obj).getToolbarPresenter();
412
                        obj = ((Presenter.Toolbar) obj).getToolbarPresenter();
417
                    }
413
                    }
Lines 447-453 Link Here
447
                        b.putClientProperty("file", file);
443
                        b.putClientProperty("file", file);
448
                        org.openide.awt.Toolbar.this.add(b);
444
                        org.openide.awt.Toolbar.this.add(b);
449
                        if (file != null) {
445
                        if (file != null) {
450
                            setAccelerator(a, file.getPrimaryFile());
446
                            AcceleratorBinding.setAccelerator(a, file.getPrimaryFile());
451
                        }
447
                        }
452
                        continue;
448
                        continue;
453
                    }
449
                    }
Lines 481-505 Link Here
481
477
482
    } // end of inner class Folder
478
    } // end of inner class Folder
483
479
484
    static void setAccelerator(Action a, FileObject file) {
485
        if (file == null) {
486
            return;
487
        }
488
        a.putValue("definingFile", file); // cf. o.n.core.NbKeymap.getKeyStrokesForAction
489
        KeyStroke[] keys;
490
        try {
491
            assert a.getValue("definingFile") == file : a.getClass() + " violated Action.putValue contract";
492
            Keymap keymap = Lookup.getDefault().lookup(Keymap.class);
493
            keys = keymap != null ? keymap.getKeyStrokesForAction(a) : new KeyStroke[0];
494
            assert keys != null : keymap;
495
        } finally {
496
            a.putValue("definingFile", null);
497
        }
498
        if (keys.length > 0) {
499
            a.putValue(Action.ACCELERATOR_KEY, keys[0]);
500
        }
501
    }
502
503
    @Override
480
    @Override
504
    public void setUI(javax.swing.plaf.ToolBarUI ui) {
481
    public void setUI(javax.swing.plaf.ToolBarUI ui) {
505
        super.setUI(ui);
482
        super.setUI(ui);

Return to bug 180543