diff --git a/editor/apichanges.xml b/editor/apichanges.xml --- a/editor/apichanges.xml +++ b/editor/apichanges.xml @@ -104,6 +104,25 @@ is the proper place. + + + + Editor Actions can be supplied in 'Actions' folder + + + + + +

+ The editor actions (ie. actions that are installed in JEditorPanes + for Netbeans editors) can now be registered in XML layers under + the Actions subfolder. For example adding an action to the java editor + can be achieved by adding .instance file to + Editors/text/x-java/Actions folder. +

+
+ +
diff --git a/editor/arch.xml b/editor/arch.xml --- a/editor/arch.xml +++ b/editor/arch.xml @@ -925,6 +925,20 @@ No. +
  • +

    + Since version 1.39 the editor actions, ie the actions that are installed + to every JEditorPane that acts as a Netbeans editor, + can be registered in the Actions subfolder. +

    + +
    +<folder name="Editors/text/x-java/Actions">
    +    <file name="org-netbeans-modules-java-editor-imports-FastImportAction.instance" />
    +</folder>
    +            
    +
  • +
  • Side bar components can be registered in the SideBar subfolder. Their appearance can be specified using two optional attributes - location (accepting values "North", "South", "East" and diff --git a/editor/nbproject/project.properties b/editor/nbproject/project.properties --- a/editor/nbproject/project.properties +++ b/editor/nbproject/project.properties @@ -39,7 +39,7 @@ javac.compilerargs=-Xlint:unchecked javac.source=1.5 -spec.version.base=1.38.0 +spec.version.base=1.39.0 is.autoload=true javadoc.arch=${basedir}/arch.xml diff --git a/editor/src/META-INF/services/org.netbeans.spi.editor.mimelookup.Class2LayerFolder b/editor/src/META-INF/services/org.netbeans.spi.editor.mimelookup.Class2LayerFolder --- a/editor/src/META-INF/services/org.netbeans.spi.editor.mimelookup.Class2LayerFolder +++ b/editor/src/META-INF/services/org.netbeans.spi.editor.mimelookup.Class2LayerFolder @@ -1,3 +1,4 @@ org.netbeans.modules.editor.impl.GlyphGu +org.netbeans.modules.editor.impl.EditorActionsProvider org.netbeans.modules.editor.impl.GlyphGutterActionsProvider org.netbeans.modules.editor.impl.PopupMenuActionsProvider org.netbeans.modules.editor.impl.SideBarFactoriesProvider diff --git a/editor/src/org/netbeans/modules/editor/NbEditorKit.java b/editor/src/org/netbeans/modules/editor/NbEditorKit.java --- a/editor/src/org/netbeans/modules/editor/NbEditorKit.java +++ b/editor/src/org/netbeans/modules/editor/NbEditorKit.java @@ -55,6 +55,8 @@ import java.util.MissingResourceExceptio import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.concurrent.Callable; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; @@ -86,6 +88,7 @@ import org.netbeans.modules.editor.codeg import org.netbeans.modules.editor.codegen.NbGenerateCodeAction; import org.netbeans.modules.editor.impl.ActionsList; import org.netbeans.modules.editor.impl.CustomizableSideBar; +import org.netbeans.modules.editor.impl.EditorActionsProvider; import org.netbeans.modules.editor.impl.SearchBar; import org.netbeans.modules.editor.impl.PopupMenuActionsProvider; import org.netbeans.modules.editor.impl.ToolbarActionsProvider; @@ -115,6 +118,8 @@ import org.openide.util.NbBundle; public class NbEditorKit extends ExtKit implements Callable { + private static final Logger LOG = Logger.getLogger(NbEditorKit.class.getName()); + /** Action property that stores the name of the corresponding nb-system-action */ public static final String SYSTEM_ACTION_CLASS_NAME_PROPERTY = "systemActionClassName"; // NOI18N @@ -202,6 +207,28 @@ public class NbEditorKit extends ExtKit return TextAction.augmentList(super.createActions(), nbEditorActions); } + protected @Override Action[] getCustomActions() { + List actions = EditorActionsProvider.getEditorActions(getContentType()); + + if (LOG.isLoggable(Level.FINE)) { + LOG.fine("Custom layer actions for '" + getContentType() + "' {"); //NOI18N + for(Action a : actions) { + LOG.fine(" " + a); //NOI18N + } + LOG.fine("} End of custom layer actions for '" + getContentType() + "'"); //NOI18N + } + + if (!actions.isEmpty()) { + Action [] superActions = super.getCustomActions(); + if (superActions == null || superActions.length == 0) { + return actions.toArray(new Action[actions.size()]); + } else { + return TextAction.augmentList(superActions, actions.toArray(new Action[actions.size()])); + } + } else { + return super.getCustomActions(); + } + } protected void addSystemActionMapping(String editorActionName, Class systemActionClass) { Action a = getActionByName(editorActionName); diff --git a/editor/src/org/netbeans/modules/editor/impl/EditorActionsProvider.java b/editor/src/org/netbeans/modules/editor/impl/EditorActionsProvider.java new file mode 100644 --- /dev/null +++ b/editor/src/org/netbeans/modules/editor/impl/EditorActionsProvider.java @@ -0,0 +1,97 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 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]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * 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. + */ + +package org.netbeans.modules.editor.impl; + +import java.util.Collections; +import java.util.List; +import javax.swing.Action; +import org.netbeans.api.editor.mimelookup.MimeLookup; +import org.netbeans.api.editor.mimelookup.MimePath; +import org.netbeans.spi.editor.mimelookup.Class2LayerFolder; +import org.netbeans.spi.editor.mimelookup.InstanceProvider; +import org.openide.filesystems.FileObject; + +/** + * + * @author Vita Stejskal + * @since 1.39 + */ +public final class EditorActionsProvider extends ActionsList implements Class2LayerFolder, InstanceProvider { + + private static final String EDITOR_ACTIONS_FOLDER_NAME = "Actions"; //NOI18N + + public static List getEditorActions(String mimeType) { + MimePath mimePath = MimePath.parse(mimeType); + EditorActionsProvider provider = MimeLookup.getLookup(mimePath).lookup(EditorActionsProvider.class); + return provider == null ? Collections.emptyList() : provider.getActionsOnly(); + } + + public static List getItems(String mimeType) { + MimePath mimePath = MimePath.parse(mimeType); + EditorActionsProvider provider = MimeLookup.getLookup(mimePath).lookup(EditorActionsProvider.class); + return provider == null ? Collections.emptyList() : provider.getAllInstances(); + } + + public EditorActionsProvider() { + super(null); + } + + private EditorActionsProvider(List keys) { + super(keys); + } + + public Class getClazz(){ + return EditorActionsProvider.class; + } + + public String getLayerFolderName(){ + return EDITOR_ACTIONS_FOLDER_NAME; + } + + public InstanceProvider getInstanceProvider() { + return new EditorActionsProvider(); + } + + public EditorActionsProvider createInstance(List fileObjectList) { + return new EditorActionsProvider(fileObjectList); + } +}