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 152576
Collapse All | Expand All

(-)a/o.n.core/src/org/netbeans/core/NbKeymap.java (-126 / +221 lines)
Lines 43-66 Link Here
43
43
44
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionEvent;
45
import java.awt.event.KeyEvent;
45
import java.awt.event.KeyEvent;
46
import java.io.IOException;
46
import java.util.ArrayList;
47
import java.util.ArrayList;
47
import java.util.Arrays;
48
import java.util.Collections;
48
import java.util.Collections;
49
import java.util.Comparator;
49
import java.util.Comparator;
50
import java.util.HashMap;
50
import java.util.HashMap;
51
import java.util.HashSet;
52
import java.util.Iterator;
53
import java.util.List;
51
import java.util.List;
54
import java.util.Map;
52
import java.util.Map;
55
import java.util.Map.Entry;
56
import java.util.Observable;
53
import java.util.Observable;
57
import java.util.Set;
54
import java.util.TreeMap;
58
import javax.swing.AbstractAction;
55
import javax.swing.AbstractAction;
59
import javax.swing.Action;
56
import javax.swing.Action;
60
import javax.swing.KeyStroke;
57
import javax.swing.KeyStroke;
61
import javax.swing.text.Keymap;
58
import javax.swing.text.Keymap;
62
import org.openide.awt.StatusDisplayer;
59
import org.openide.awt.StatusDisplayer;
63
import org.openide.util.Mutex;
60
import org.openide.cookies.InstanceCookie;
61
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.Repository;
63
import org.openide.loaders.DataObject;
64
import org.openide.util.Exceptions;
65
import org.openide.util.Utilities;
64
import org.openide.util.lookup.ServiceProvider;
66
import org.openide.util.lookup.ServiceProvider;
65
67
66
/** Implementation of standard key - action mappings.
68
/** Implementation of standard key - action mappings.
Lines 74-80 Link Here
74
    /** Parent keymap */
76
    /** Parent keymap */
75
    Keymap parent;
77
    Keymap parent;
76
    /** Hashtable holding KeyStroke > Action mappings */
78
    /** Hashtable holding KeyStroke > Action mappings */
77
    Map<KeyStroke,Action> bindings;
79
    //Map<KeyStroke,Action> bindings;
78
    /** Default action */
80
    /** Default action */
79
    Action defaultAction;
81
    Action defaultAction;
80
    /** hash table to map (Action -> ArrayList of KeyStrokes) */
82
    /** hash table to map (Action -> ArrayList of KeyStrokes) */
Lines 126-132 Link Here
126
    NbKeymap(final String name, final Keymap parent) {
128
    NbKeymap(final String name, final Keymap parent) {
127
        this.name = name;
129
        this.name = name;
128
        this.parent = parent;
130
        this.parent = parent;
129
        bindings = new HashMap<KeyStroke,Action>();
131
//        bindings = new HashMap<KeyStroke,Action>();
130
    }
132
    }
131
133
132
    public Action getDefaultAction() {
134
    public Action getDefaultAction() {
Lines 153-159 Link Here
153
        Keymap activ = this;
155
        Keymap activ = this;
154
        for (int i=0; i<ctx.length; i++) {
156
        for (int i=0; i<ctx.length; i++) {
155
            if (activ == this) {
157
            if (activ == this) {
156
                a = bindings.get(ctx[i]);
158
//                a = bindings.get(ctx[i]);
159
                a = find(ctx[i]);
157
                if ((a == null) && (parent != null)) {
160
                if ((a == null) && (parent != null)) {
158
                    a = parent.getAction(ctx[i]);
161
                    a = parent.getAction(ctx[i]);
159
                }
162
                }
Lines 175-181 Link Here
175
        }
178
        }
176
        
179
        
177
        if (activ == this) {
180
        if (activ == this) {
178
            a = bindings.get(key);
181
//            a = bindings.get(key);
182
            a = find(key);
179
            if ((a == null) && (parent != null)) {
183
            if ((a == null) && (parent != null)) {
180
                a = parent.getAction(key);
184
                a = parent.getAction(key);
181
            }
185
            }
Lines 210-290 Link Here
210
    }
214
    }
211
215
212
    public KeyStroke[] getBoundKeyStrokes() {
216
    public KeyStroke[] getBoundKeyStrokes() {
213
        int i = 0;
217
//        int i = 0;
214
        KeyStroke[] keys = null;
218
//        KeyStroke[] keys = null;
215
        synchronized (this) {
219
//        synchronized (this) {
216
            keys = new KeyStroke[bindings.size()];
220
//            keys = new KeyStroke[bindings.size()];
217
            for (KeyStroke ks: bindings.keySet()) {
221
//            for (KeyStroke ks: bindings.keySet()) {
218
                keys[i++] = ks;
222
//                keys[i++] = ks;
219
            }
223
//            }
220
        }
224
//        }
221
        return keys;
225
//        return keys;
226
        assert false;
227
        return null;
222
    }
228
    }
223
229
224
    public Action[] getBoundActions() {
230
    public Action[] getBoundActions() {
225
        int i = 0;
231
//        int i = 0;
226
        Action[] actionsArray = null;
232
//        Action[] actionsArray = null;
227
        synchronized (this) {
233
//        synchronized (this) {
228
            actionsArray = new Action[bindings.size()];
234
//            actionsArray = new Action[bindings.size()];
229
            for (Iterator iter = bindings.values().iterator(); iter.hasNext(); ) {
235
//            for (Iterator iter = bindings.values().iterator(); iter.hasNext(); ) {
230
                actionsArray[i++] = (Action) iter.next();
236
//                actionsArray[i++] = (Action) iter.next();
231
            }
237
//            }
232
        }
238
//        }
233
        return actionsArray;
239
//        return actionsArray;
240
        assert false;
241
        return null;
234
    }
242
    }
235
243
236
    public KeyStroke[] getKeyStrokesForAction(Action a) {
244
    public KeyStroke[] getKeyStrokesForAction(Action a) {
237
        Map<Action,List<KeyStroke>> localActions = actions;
245
//        Map<Action,List<KeyStroke>> localActions = actions;
238
        if (localActions == null) {
246
//        if (localActions == null) {
239
            localActions = buildReverseMapping ();
247
//            localActions = buildReverseMapping ();
240
        }
248
//        }
241
249
//
242
        List<KeyStroke> strokes = localActions.get (a);
250
//        List<KeyStroke> strokes = localActions.get (a);
243
        if (strokes != null) {
251
//        if (strokes != null) {
244
            return strokes.toArray(new KeyStroke[strokes.size ()]);
252
//            return strokes.toArray(new KeyStroke[strokes.size ()]);
245
        } else {
253
//        } else {
254
//            return new KeyStroke[0];
255
//        }
256
        FileObject definingFile = (FileObject) a.getValue("definingFile"); // cf. o.o.awt.Toolbar.setAccelerator
257
        if (definingFile == null) {
258
            System.err.println("XXX no defining file known for " + a);
246
            return new KeyStroke[0];
259
            return new KeyStroke[0];
247
        }
260
        }
261
        synchronized (this) {
262
            if (id2Stroke == null) {
263
                id2Stroke = new TreeMap<String,String>();
264
                FileObject shortcuts = Repository.getDefault().getDefaultFileSystem().findResource("Shortcuts");
265
                for (FileObject f : shortcuts.getChildren()) {
266
                    id2Stroke.put(idForFile(f), f.getName());
267
                }
268
                shortcuts = Repository.getDefault().getDefaultFileSystem().findResource("Keymaps/NetBeans");
269
                for (FileObject f : shortcuts.getChildren()) {
270
                    id2Stroke.put(idForFile(f), f.getName());
271
                }
272
                { // XXX for debugging
273
                    for (Map.Entry<String,String> entry : id2Stroke.entrySet()) {
274
                        System.err.println(entry.getValue() + " => " + entry.getKey());
275
                    }
276
                }
277
            }
278
        }
279
        String id = idForFile(definingFile);
280
        String k = id2Stroke.get(id);
281
        System.err.println("XXX found keystroke " + k + " for " + a + " with ID " + id);
282
        // XXX return all available keystrokes, or make Toolbar.setAccelerator pick the most common, e.g. C-V over PASTE
283
        return k != null ? new KeyStroke[] {Utilities.stringToKey(k)} : new KeyStroke[0];
284
    }
285
    private Map<String,String> id2Stroke;
286
    /**
287
     * Traverses shadow files to origin.
288
     * Returns impl class name if that is obvious (common for SystemAction's);
289
     * else just returns file path (usual for more modern registrations).
290
     */
291
    private static String idForFile(FileObject f) {
292
        if (f.hasExt("shadow")) {
293
            String path = (String) f.getAttribute("originalFile");
294
            f = Repository.getDefault().getDefaultFileSystem().findResource(path);
295
        }
296
        // Cannot actually load instanceCreate methodvalue=... attribute; just want to see if it is there.
297
        if (f.hasExt("instance") && !Collections.list(f.getAttributes()).contains("instanceCreate")) {
298
            String clazz = (String) f.getAttribute("instanceClass");
299
            if (clazz != null) {
300
                return clazz;
301
            } else {
302
                return f.getName().replace('-', '.');
303
            }
304
        }
305
        return f.getPath();
248
    }
306
    }
249
307
250
    private Map<Action,List<KeyStroke>> buildReverseMapping () {
308
    private Action find(KeyStroke key) {
251
        Map<Action,List<KeyStroke>> localActions = actions = new HashMap<Action,List<KeyStroke>> ();
309
        FileObject shortcuts = Repository.getDefault().getDefaultFileSystem().findResource("Keymaps/NetBeans");
252
310
        String nm = Utilities.keyToString(key);
253
        synchronized (this) {
311
        FileObject def = shortcuts.getFileObject(nm + ".shadow");
254
            for (Map.Entry<KeyStroke,Action> curEntry: bindings.entrySet()) {
312
        if (def == null) {
255
                Action curAction = curEntry.getValue();
313
            def = shortcuts.getFileObject(nm + ".instance");
256
                KeyStroke curKey = curEntry.getKey();
314
        }
257
315
        if (def == null) {
258
                List<KeyStroke> keysForAction = localActions.get (curAction);
316
            shortcuts = Repository.getDefault().getDefaultFileSystem().findResource("Shortcuts");
259
                if (keysForAction == null) {
317
            def = shortcuts.getFileObject(nm + ".shadow");
260
                    keysForAction = Collections.synchronizedList (new ArrayList<KeyStroke> (1));
318
            if (def == null) {
261
                    localActions.put (curAction, keysForAction);
319
                def = shortcuts.getFileObject(nm + ".instance");
262
                }
320
            }
263
                keysForAction.add (curKey);
321
            if (def == null) {
322
                return null;
264
            }
323
            }
265
        }
324
        }
266
325
        try {
267
        return localActions;
326
            DataObject d = DataObject.find(def);
327
            InstanceCookie ic = d.getLookup().lookup(InstanceCookie.class);
328
            if (ic == null) {
329
                return null;
330
            }
331
            return (Action) ic.instanceCreate();
332
        } catch (ClassNotFoundException x) {
333
            Exceptions.printStackTrace(x);
334
        } catch (IOException x) {
335
            Exceptions.printStackTrace(x);
336
        }
337
        return null;
268
    }
338
    }
269
339
340
//    private Map<Action,List<KeyStroke>> buildReverseMapping () {
341
//        Map<Action,List<KeyStroke>> localActions = actions = new HashMap<Action,List<KeyStroke>> ();
342
//
343
//        synchronized (this) {
344
//            for (Map.Entry<KeyStroke,Action> curEntry: bindings.entrySet()) {
345
//                Action curAction = curEntry.getValue();
346
//                KeyStroke curKey = curEntry.getKey();
347
//
348
//                List<KeyStroke> keysForAction = localActions.get (curAction);
349
//                if (keysForAction == null) {
350
//                    keysForAction = Collections.synchronizedList (new ArrayList<KeyStroke> (1));
351
//                    localActions.put (curAction, keysForAction);
352
//                }
353
//                keysForAction.add (curKey);
354
//            }
355
//        }
356
//
357
//        return localActions;
358
//    }
359
270
    public synchronized boolean isLocallyDefined(KeyStroke key) {
360
    public synchronized boolean isLocallyDefined(KeyStroke key) {
271
        return bindings.containsKey(key);
361
//        return bindings.containsKey(key);
362
        assert false;
363
        return false;
272
    }
364
    }
273
365
274
    /** Updates action accelerator. */
366
//    /** Updates action accelerator. */
275
    private void updateActionAccelerator(final Action a) {
367
//    private void updateActionAccelerator(final Action a) {
276
        if(a == null) {
368
//        if(a == null) {
277
            return;
369
//            return;
278
        }
370
//        }
279
        
371
//
280
        Mutex.EVENT.writeAccess(new Runnable() {
372
//        Mutex.EVENT.writeAccess(new Runnable() {
281
            public void run() {
373
//            public void run() {
282
                KeyStroke[] keystrokes = getKeyStrokesForAction(a);
374
//                KeyStroke[] keystrokes = getKeyStrokesForAction(a);
283
                Arrays.sort (keystrokes, NbKeymap.this);
375
//                Arrays.sort (keystrokes, NbKeymap.this);
284
                a.putValue(Action.ACCELERATOR_KEY, keystrokes.length > 0 ? keystrokes[0] : null);
376
//                a.putValue(Action.ACCELERATOR_KEY, keystrokes.length > 0 ? keystrokes[0] : null);
285
            }
377
//            }
286
        });
378
//        });
287
    }
379
//    }
288
    
380
    
289
    public int compare(KeyStroke k1, KeyStroke k2) {
381
    public int compare(KeyStroke k1, KeyStroke k2) {
290
        //#47024 and 32733 - "Find" should not be shown as an accelerator,
382
        //#47024 and 32733 - "Find" should not be shown as an accelerator,
Lines 295-359 Link Here
295
    
387
    
296
    
388
    
297
    public void addActionForKeyStroke(KeyStroke key, Action a) {
389
    public void addActionForKeyStroke(KeyStroke key, Action a) {
298
        // Update reverse binding for old action too (#30455):
390
//        // Update reverse binding for old action too (#30455):
299
        Action old;
391
//        Action old;
300
        synchronized (this) {
392
//        synchronized (this) {
301
            old = bindings.put(key, a);
393
//            old = bindings.put(key, a);
302
            actions = null;
394
//            actions = null;
303
        }
395
//        }
304
        
396
//
305
        updateActionAccelerator(a);
397
//        updateActionAccelerator(a);
306
        updateActionAccelerator(old);
398
//        updateActionAccelerator(old);
307
        setChanged();
399
//        setChanged();
308
        notifyObservers();
400
//        notifyObservers();
401
        assert false;
309
    }
402
    }
310
403
311
    void addActionForKeyStrokeMap(Map<KeyStroke,Action> map) {
404
//    void addActionForKeyStrokeMap(Map<KeyStroke,Action> map) {
312
        Set<Action> actionsSet = new HashSet<Action>();
405
//        Set<Action> actionsSet = new HashSet<Action>();
313
        synchronized (this) {
406
//        synchronized (this) {
314
            for (Entry<KeyStroke,Action> entry: map.entrySet ()) {
407
//            for (Entry<KeyStroke,Action> entry: map.entrySet ()) {
315
                KeyStroke key = entry.getKey();
408
//                KeyStroke key = entry.getKey();
316
                Action value = entry.getValue();
409
//                Action value = entry.getValue();
317
                // Add both old and new action:
410
//                // Add both old and new action:
318
                actionsSet.add(value);
411
//                actionsSet.add(value);
319
                actionsSet.add(bindings.put(key, value));
412
//                actionsSet.add(bindings.put(key, value));
320
            }
413
//            }
321
            actions = null;
414
//            actions = null;
322
        }
415
//        }
323
        
416
//
324
        for(Action a: actionsSet) {
417
//        for(Action a: actionsSet) {
325
            updateActionAccelerator(a);
418
//            updateActionAccelerator(a);
326
        }
419
//        }
327
        
420
//
328
        setChanged();
421
//        setChanged();
329
        notifyObservers();
422
//        notifyObservers();
330
    }
423
//    }
331
424
332
    public void removeKeyStrokeBinding(KeyStroke key) {
425
    public void removeKeyStrokeBinding(KeyStroke key) {
333
        Action a;
426
//        Action a;
334
        synchronized (this) {
427
//        synchronized (this) {
335
            a = bindings.remove(key);
428
//            a = bindings.remove(key);
336
            actions = null;
429
//            actions = null;
337
        }
430
//        }
338
        updateActionAccelerator(a);
431
//        updateActionAccelerator(a);
339
        setChanged();
432
//        setChanged();
340
        notifyObservers();
433
//        notifyObservers();
434
        assert false;
341
    }
435
    }
342
436
343
    public void removeBindings() {
437
    public void removeBindings() {
344
        Set<Action> actionsSet;
438
//        Set<Action> actionsSet;
345
        synchronized (this) {
439
//        synchronized (this) {
346
            actionsSet = new HashSet<Action>(bindings.values());
440
//            actionsSet = new HashSet<Action>(bindings.values());
347
            bindings.clear();
441
//            bindings.clear();
348
            actions = null;
442
//            actions = null;
349
        }
443
//        }
350
        
444
//
351
        for(Action a: actionsSet) {
445
//        for(Action a: actionsSet) {
352
            updateActionAccelerator(a);
446
//            updateActionAccelerator(a);
353
        }
447
//        }
354
        
448
//
355
        setChanged();
449
//        setChanged();
356
        notifyObservers();
450
//        notifyObservers();
451
        assert false;
357
    }
452
    }
358
453
359
    public Keymap getResolveParent() {
454
    public Keymap getResolveParent() {
Lines 366-377 Link Here
366
        notifyObservers();
461
        notifyObservers();
367
    }
462
    }
368
463
369
    /** Returns string representation - can be looong.
464
//    /** Returns string representation - can be looong.
370
    */
465
//    */
371
    @Override
466
//    @Override
372
    public String toString() {
467
//    public String toString() {
373
        return "Keymap[" + name + "]" + bindings; // NOI18N
468
//        return "Keymap[" + name + "]" + bindings; // NOI18N
374
    }
469
//    }
375
    
470
    
376
    public static class SubKeymap implements Keymap {
471
    public static class SubKeymap implements Keymap {
377
        Object hold;
472
        Object hold;
(-)a/o.n.core/src/org/netbeans/core/ShortcutsFolder.java (-7 / +7 lines)
Lines 86-98 Link Here
86
    
86
    
87
    
87
    
88
    static void initShortcuts () {
88
    static void initShortcuts () {
89
        StartLog.logStart("initShortcuts");
89
//        StartLog.logStart("initShortcuts");
90
        try {
90
//        try {
91
            if (shortcutsFolder != null) return;
91
//            if (shortcutsFolder != null) return;
92
            shortcutsFolder = new ShortcutsFolder ();
92
//            shortcutsFolder = new ShortcutsFolder ();
93
        } finally {
93
//        } finally {
94
            StartLog.logEnd("initShortcuts");
94
//            StartLog.logEnd("initShortcuts");
95
        }
95
//        }
96
    }
96
    }
97
    
97
    
98
    private ShortcutsFolder () {
98
    private ShortcutsFolder () {
(-)a/openide.awt/src/org/openide/awt/AlwaysEnabledAction.java (-10 / +3 lines)
Lines 97-104 Link Here
97
                return ret;
97
                return ret;
98
            }
98
            }
99
        }
99
        }
100
100
        Object o = extractCommonAttribute(map, this, name);
101
        return extractCommonAttribute(map, this, name);
101
        // cf. #137709 JG18:
102
        return o != null ? o : super.getValue(name);
102
    }
103
    }
103
104
104
    static final Object extractCommonAttribute(Map fo, Action action, String name) {
105
    static final Object extractCommonAttribute(Map fo, Action action, String name) {
Lines 136-149 Link Here
136
        if ("noIconInMenu".equals(name)) { // NOI18N
137
        if ("noIconInMenu".equals(name)) { // NOI18N
137
            return fo == null ? null : fo.get("noIconInMenu"); // NOI18N
138
            return fo == null ? null : fo.get("noIconInMenu"); // NOI18N
138
        }
139
        }
139
        if (Action.ACCELERATOR_KEY.equals(name)) {
140
            Keymap map = Lookup.getDefault().lookup(Keymap.class);
141
            if (map != null) {
142
                KeyStroke[] arr = map.getKeyStrokesForAction(action);
143
                return arr.length > 0 ? arr[0] : null;
144
            }
145
        }
146
147
        return null;
140
        return null;
148
    }
141
    }
149
142
(-)a/openide.loaders/src/org/openide/awt/DynaMenuModel.java (-1 / +5 lines)
Lines 60-65 Link Here
60
import org.openide.util.ImageUtilities;
60
import org.openide.util.ImageUtilities;
61
import org.openide.util.Utilities;
61
import org.openide.util.Utilities;
62
import org.openide.awt.DynamicMenuContent;
62
import org.openide.awt.DynamicMenuContent;
63
import org.openide.filesystems.FileObject;
63
import org.openide.util.actions.Presenter;
64
import org.openide.util.actions.Presenter;
64
65
65
/**
66
/**
Lines 78-84 Link Here
78
        actionToMenuMap = new HashMap<DynamicMenuContent, JComponent[]>();
79
        actionToMenuMap = new HashMap<DynamicMenuContent, JComponent[]>();
79
    }
80
    }
80
    
81
    
81
    public void loadSubmenu(List cInstances, JMenu m) {
82
    public void loadSubmenu(List cInstances, JMenu m, Map<Object,FileObject> cookiesToFiles) {
82
        // clear first - refresh the menu's content
83
        // clear first - refresh the menu's content
83
        boolean addSeparator = false;
84
        boolean addSeparator = false;
84
        Icon curIcon = null;
85
        Icon curIcon = null;
Lines 87-92 Link Here
87
        actionToMenuMap.clear();
88
        actionToMenuMap.clear();
88
        while (it.hasNext()) {
89
        while (it.hasNext()) {
89
            Object obj = it.next();
90
            Object obj = it.next();
91
            if (obj instanceof Action) {
92
                Toolbar.setAccelerator((Action) obj, cookiesToFiles.get(obj));
93
            }
90
            if (obj instanceof Presenter.Menu) {
94
            if (obj instanceof Presenter.Menu) {
91
                // does this still apply??
95
                // does this still apply??
92
                obj = ((Presenter.Menu)obj).getMenuPresenter();
96
                obj = ((Presenter.Menu)obj).getMenuPresenter();
(-)a/openide.loaders/src/org/openide/awt/MenuBar.java (-1 / +11 lines)
Lines 50-57 Link Here
50
import java.io.ObjectOutput;
50
import java.io.ObjectOutput;
51
import java.util.ArrayList;
51
import java.util.ArrayList;
52
import java.util.Arrays;
52
import java.util.Arrays;
53
import java.util.HashMap;
53
import java.util.Iterator;
54
import java.util.Iterator;
54
import java.util.LinkedList;
55
import java.util.LinkedList;
56
import java.util.Map;
55
import javax.swing.Action;
57
import javax.swing.Action;
56
import javax.swing.BorderFactory;
58
import javax.swing.BorderFactory;
57
import javax.swing.ImageIcon;
59
import javax.swing.ImageIcon;
Lines 614-619 Link Here
614
                super.waitFinished();
616
                super.waitFinished();
615
            }
617
            }
616
            
618
            
619
        private Map<Object,FileObject> cookiesToFiles = new HashMap<Object,FileObject>();
620
621
        @Override
622
        protected Object instanceForCookie(DataObject obj, InstanceCookie cookie) throws IOException, ClassNotFoundException {
623
            Object result = super.instanceForCookie(obj, cookie);
624
            cookiesToFiles.put(result, obj.getPrimaryFile());
625
            return result;
626
        }
617
627
618
    	    /**
628
    	    /**
619
             * Accepts only cookies that can provide <code>Menu</code>.
629
             * Accepts only cookies that can provide <code>Menu</code>.
Lines 671-677 Link Here
671
		    m.add(item);
681
		    m.add(item);
672
		}
682
		}
673
683
674
                m.dynaModel.loadSubmenu(cInstances, m);
684
                m.dynaModel.loadSubmenu(cInstances, m, cookiesToFiles);
675
                
685
                
676
        	return m;
686
        	return m;
677
    	    }
687
    	    }
(-)a/openide.loaders/src/org/openide/awt/Toolbar.java (-2 / +26 lines)
Lines 65-71 Link Here
65
import javax.swing.plaf.synth.SynthLookAndFeel;
65
import javax.swing.plaf.synth.SynthLookAndFeel;
66
import javax.swing.plaf.synth.SynthStyle;
66
import javax.swing.plaf.synth.SynthStyle;
67
import javax.swing.plaf.synth.SynthStyleFactory;
67
import javax.swing.plaf.synth.SynthStyleFactory;
68
import javax.swing.text.Keymap;
68
import org.openide.cookies.InstanceCookie;
69
import org.openide.cookies.InstanceCookie;
70
import org.openide.filesystems.FileObject;
69
import org.openide.loaders.*;
71
import org.openide.loaders.*;
70
import org.openide.nodes.Node;
72
import org.openide.nodes.Node;
71
import org.openide.util.*;
73
import org.openide.util.*;
Lines 994-1000 Link Here
994
            return Toolbar.this.getClass();
996
            return Toolbar.this.getClass();
995
        }
997
        }
996
998
997
    private Map<Object, Object> cookiesToObjects = new HashMap<Object, Object>();
999
    private Map<Object,DataObject> cookiesToObjects = new HashMap<Object,DataObject>();
998
    
1000
    
999
        @Override
1001
        @Override
1000
    protected Object instanceForCookie (DataObject obj, InstanceCookie cookie)
1002
    protected Object instanceForCookie (DataObject obj, InstanceCookie cookie)
Lines 1053-1059 Link Here
1053
            for (int i = 0; i < cookies.length; i++) {
1055
            for (int i = 0; i < cookies.length; i++) {
1054
                try {
1056
                try {
1055
                    java.lang.Object obj = cookies[i].instanceCreate();
1057
                    java.lang.Object obj = cookies[i].instanceCreate();
1056
                    java.lang.Object file = cookiesToObjects.get(obj);
1058
                    DataObject file = cookiesToObjects.get(obj);
1059
1060
                    if (obj instanceof Action) {
1061
                        setAccelerator((Action) obj, file.getPrimaryFile());
1062
                    }
1057
1063
1058
                    if (obj instanceof org.openide.util.actions.Presenter.Toolbar) {
1064
                    if (obj instanceof org.openide.util.actions.Presenter.Toolbar) {
1059
                        obj = ((org.openide.util.actions.Presenter.Toolbar) obj).getToolbarPresenter();
1065
                        obj = ((org.openide.util.actions.Presenter.Toolbar) obj).getToolbarPresenter();
Lines 1125-1130 Link Here
1125
        }
1131
        }
1126
1132
1127
    } // end of inner class Folder
1133
    } // end of inner class Folder
1134
1135
    static void setAccelerator(Action a, FileObject file) {
1136
        if (file == null) {
1137
            return;
1138
        }
1139
        a.putValue("definingFile", file); // cf. o.n.core.NbKeymap.getKeyStrokesForAction
1140
        KeyStroke[] keys;
1141
        try {
1142
            Keymap keymap = Lookup.getDefault().lookup(Keymap.class);
1143
            keys = keymap != null ? keymap.getKeyStrokesForAction(a) : new KeyStroke[0];
1144
            assert keys != null : keymap;
1145
        } finally {
1146
            a.putValue("definingFile", null);
1147
        }
1148
        if (keys.length > 0) {
1149
            a.putValue(Action.ACCELERATOR_KEY, keys[0]);
1150
        }
1151
    }
1128
1152
1129
    /** Bumps for floatable toolbar */
1153
    /** Bumps for floatable toolbar */
1130
    private final class ToolbarBump extends JPanel {
1154
    private final class ToolbarBump extends JPanel {

Return to bug 152576