+ Added a new class to help with action accelerators.
+ Should not be used by typical modules.
+
+
+
+
+ New constructor of XMLDataObject
diff --git a/openide.loaders/manifest.mf b/openide.loaders/manifest.mf
--- a/openide.loaders/manifest.mf
+++ b/openide.loaders/manifest.mf
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
OpenIDE-Module: org.openide.loaders
-OpenIDE-Module-Specification-Version: 7.12
+OpenIDE-Module-Specification-Version: 7.13
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
AutoUpdate-Essential-Module: true
diff --git a/openide.loaders/src/org/openide/awt/AcceleratorBinding.java b/openide.loaders/src/org/openide/awt/AcceleratorBinding.java
new file mode 100644
--- /dev/null
+++ b/openide.loaders/src/org/openide/awt/AcceleratorBinding.java
@@ -0,0 +1,89 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2010 Sun Microsystems, Inc.
+ */
+
+package org.openide.awt;
+
+import javax.swing.Action;
+import javax.swing.KeyStroke;
+import javax.swing.text.Keymap;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Lookup;
+
+/**
+ * Permits accelerators to be set on actions based on global registrations.
+ * This class is only intended for use from NetBeans infrastructure code:
+ * that which either reads shortcut definitions (i.e. the global {@link Keymap});
+ * or which loads actions into presenters (e.g. {@link Toolbar}).
+ * @since org.openide.loaders 7.13
+ */
+public abstract class AcceleratorBinding {
+
+ /**
+ * Subclass constructor. Only certain implementations are permitted.
+ */
+ protected AcceleratorBinding() {
+ assert getClass().getName().equals("org.netbeans.core.NbKeymap$AcceleratorBindingImpl") : this;
+ }
+
+ /**
+ * Finds a keystroke for an action.
+ * @param action an action
+ * @param definingFile an instance file which defines the action
+ * @return a keystroke or null
+ */
+ protected abstract KeyStroke keyStrokeForAction(Action action, FileObject definingFile);
+
+ /**
+ * Associates an {@link Action#ACCELERATOR_KEY} with an action based on a declared shortcut.
+ * If an instance of {@link AcceleratorBinding} can be found in default lookup,
+ * it will be used to determine the binding. Otherwise nothing is done.
+ * @param action an action defined in layers
+ * @param definingFile instance file defining the action
+ */
+ public static void setAccelerator(Action action, FileObject definingFile) {
+ for (AcceleratorBinding bnd : Lookup.getDefault().lookupAll(AcceleratorBinding.class)) {
+ KeyStroke key = bnd.keyStrokeForAction(action, definingFile);
+ if (key != null) {
+ action.putValue(Action.ACCELERATOR_KEY, key);
+ break;
+ }
+ }
+ }
+
+}
diff --git a/openide.loaders/src/org/openide/awt/DynaMenuModel.java b/openide.loaders/src/org/openide/awt/DynaMenuModel.java
--- a/openide.loaders/src/org/openide/awt/DynaMenuModel.java
+++ b/openide.loaders/src/org/openide/awt/DynaMenuModel.java
@@ -86,7 +86,10 @@
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof Action) {
- Toolbar.setAccelerator((Action) obj, cookiesToFiles.get(obj));
+ FileObject file = cookiesToFiles.get(obj);
+ if (file != null) {
+ AcceleratorBinding.setAccelerator((Action) obj, file);
+ }
}
if (obj instanceof Presenter.Menu) {
// does this still apply??
diff --git a/openide.loaders/src/org/openide/awt/Toolbar.java b/openide.loaders/src/org/openide/awt/Toolbar.java
--- a/openide.loaders/src/org/openide/awt/Toolbar.java
+++ b/openide.loaders/src/org/openide/awt/Toolbar.java
@@ -58,18 +58,14 @@
import javax.swing.JComponent;
import javax.swing.JSeparator;
import javax.swing.JToolBar;
-import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalLookAndFeel;
-import javax.swing.text.Keymap;
import org.netbeans.modules.openide.loaders.DataObjectAccessor;
import org.openide.cookies.InstanceCookie;
-import org.openide.filesystems.FileObject;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObject;
import org.openide.loaders.FolderInstance;
import org.openide.util.ImageUtilities;
-import org.openide.util.Lookup;
import org.openide.util.Task;
import org.openide.util.actions.Presenter;
@@ -411,7 +407,7 @@
if (obj instanceof Presenter.Toolbar) {
if (obj instanceof Action && file != null) {
- setAccelerator((Action)obj, file.getPrimaryFile());
+ AcceleratorBinding.setAccelerator((Action)obj, file.getPrimaryFile());
}
obj = ((Presenter.Toolbar) obj).getToolbarPresenter();
}
@@ -447,7 +443,7 @@
b.putClientProperty("file", file);
org.openide.awt.Toolbar.this.add(b);
if (file != null) {
- setAccelerator(a, file.getPrimaryFile());
+ AcceleratorBinding.setAccelerator(a, file.getPrimaryFile());
}
continue;
}
@@ -481,25 +477,6 @@
} // end of inner class Folder
- static void setAccelerator(Action a, FileObject file) {
- if (file == null) {
- return;
- }
- a.putValue("definingFile", file); // cf. o.n.core.NbKeymap.getKeyStrokesForAction
- KeyStroke[] keys;
- try {
- assert a.getValue("definingFile") == file : a.getClass() + " violated Action.putValue contract";
- Keymap keymap = Lookup.getDefault().lookup(Keymap.class);
- keys = keymap != null ? keymap.getKeyStrokesForAction(a) : new KeyStroke[0];
- assert keys != null : keymap;
- } finally {
- a.putValue("definingFile", null);
- }
- if (keys.length > 0) {
- a.putValue(Action.ACCELERATOR_KEY, keys[0]);
- }
- }
-
@Override
public void setUI(javax.swing.plaf.ToolBarUI ui) {
super.setUI(ui);