diff --git a/editor.actions/build.xml b/editor.actions/build.xml
new file mode 100644
--- /dev/null
+++ b/editor.actions/build.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
diff --git a/editor.actions/manifest.mf b/editor.actions/manifest.mf
new file mode 100644
--- /dev/null
+++ b/editor.actions/manifest.mf
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+OpenIDE-Module: org.netbeans.modules.editor.actions/1
+OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/actions/Bundle.properties
+AutoUpdate-Show-In-Client: false
+OpenIDE-Module-Provides: org.netbeans.modules.editor.actions
diff --git a/editor.actions/nbproject/project.properties b/editor.actions/nbproject/project.properties
new file mode 100644
--- /dev/null
+++ b/editor.actions/nbproject/project.properties
@@ -0,0 +1,46 @@
+# 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.
+
+javac.compilerargs=-Xlint:unchecked
+javac.source=1.5
+javadoc.title=Editor Actions
+spec.version.base=1.0.0
+
+#javadoc.arch=${basedir}/arch.xml
+#javadoc.apichanges=${basedir}/apichanges.xml
diff --git a/editor.actions/nbproject/project.xml b/editor.actions/nbproject/project.xml
new file mode 100644
--- /dev/null
+++ b/editor.actions/nbproject/project.xml
@@ -0,0 +1,98 @@
+
+
+
+ org.netbeans.modules.apisupport.project
+
+
+ org.netbeans.modules.editor.actions
+
+
+ org.netbeans.modules.editor.lib
+
+
+
+ 1
+ 1.40
+
+
+
+ org.netbeans.modules.editor.lib2
+
+
+
+ 1
+
+
+
+
+ org.netbeans.modules.editor.mimelookup
+
+
+
+ 1
+ 1.12
+
+
+
+ org.netbeans.modules.editor.settings
+
+
+
+ 1
+ 1.25
+
+
+
+ org.openide.util
+
+
+
+ 7.24
+
+
+
+
+
+
+
+
diff --git a/editor.actions/src/org/netbeans/modules/editor/actions/Bundle.properties b/editor.actions/src/org/netbeans/modules/editor/actions/Bundle.properties
new file mode 100644
--- /dev/null
+++ b/editor.actions/src/org/netbeans/modules/editor/actions/Bundle.properties
@@ -0,0 +1,51 @@
+# 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.
+
+OpenIDE-Module-Name=Editor Actions
+OpenIDE-Module-Display-Category=Editing
+OpenIDE-Module-Short-Description=Contains editor actions implementations
+OpenIDE-Module-Long-Description=Editor Actions module contains default editor actions implementations.
+
+# Actions
+toggle-toolbar=Toggle Toolbar
+toggle-toolbar_menu_text=S&how Editor Toolbar
+toggle-line-numbers=Toggle Line Numbers
+toggle-line-numbers_menu_text=&Show Line Numbers
+goto-declaration=Go to Declaration
+goto-declaration_menu_text=Go to &Declaration
diff --git a/editor.actions/src/org/netbeans/modules/editor/actions/GotoAction.java b/editor.actions/src/org/netbeans/modules/editor/actions/GotoAction.java
new file mode 100644
--- /dev/null
+++ b/editor.actions/src/org/netbeans/modules/editor/actions/GotoAction.java
@@ -0,0 +1,98 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 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 2008 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.editor.actions;
+
+import org.netbeans.modules.editor.lib2.actions.AbstractEditorAction;
+import java.awt.event.ActionEvent;
+import java.util.logging.Logger;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Caret;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorActionRegistration;
+import org.netbeans.api.editor.EditorActionRegistrations;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.editor.Utilities;
+import org.netbeans.editor.ext.ExtSyntaxSupport;
+import org.netbeans.modules.editor.lib2.actions.EditorActionNames;
+
+/**
+ * Toggle toolbar/lines visibility.
+ *
+ * @author Miloslav Metelka
+ * @since 1.13
+ */
+
+@EditorActionRegistrations({
+ @EditorActionRegistration(
+ name = EditorActionNames.gotoDeclarationAction,
+ menuPath = "GoTo",
+ menuPosition = 900,
+ menuText = "#" + EditorActionNames.gotoDeclarationAction + "_menu_text"
+ )
+})
+public final class GotoAction extends AbstractEditorAction {
+
+ // -J-Dorg.netbeans.modules.editor.actions.GotoAction.level=FINEST
+ private static final Logger LOG = Logger.getLogger(GotoAction.class.getName());
+
+ public void actionPerformed(ActionEvent evt, JTextComponent target) {
+ String actionName = actionName();
+ if (EditorActionNames.gotoDeclarationAction.equals(actionName)) {
+ magicPositionReset(target);
+ BaseDocument doc = Utilities.getDocument(target);
+ if (doc != null) {
+ try {
+ Caret caret = target.getCaret();
+ int dotPos = caret.getDot();
+ int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos);
+ ExtSyntaxSupport extSup = (ExtSyntaxSupport)doc.getSyntaxSupport();
+ if (idBlk != null) {
+ int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]);
+ if (decPos >= 0) {
+ caret.setDot(decPos);
+ }
+ }
+ } catch (BadLocationException e) {
+ }
+ }
+ }
+ }
+
+}
diff --git a/editor.actions/src/org/netbeans/modules/editor/actions/ToggleAction.java b/editor.actions/src/org/netbeans/modules/editor/actions/ToggleAction.java
new file mode 100644
--- /dev/null
+++ b/editor.actions/src/org/netbeans/modules/editor/actions/ToggleAction.java
@@ -0,0 +1,158 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 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 2008 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.editor.actions;
+
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.PreferenceChangeListener;
+import org.netbeans.modules.editor.lib2.actions.AbstractEditorAction;
+import java.awt.event.ActionEvent;
+import java.util.Map;
+import java.util.logging.Logger;
+import java.util.prefs.Preferences;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorActionRegistration;
+import org.netbeans.api.editor.EditorActionRegistrations;
+import org.netbeans.api.editor.mimelookup.MimeLookup;
+import org.netbeans.api.editor.mimelookup.MimePath;
+import org.netbeans.api.editor.settings.SimpleValueNames;
+import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
+import org.netbeans.modules.editor.lib2.actions.EditorActionNames;
+import org.openide.util.Lookup;
+import org.openide.util.LookupEvent;
+import org.openide.util.LookupListener;
+
+/**
+ * Toggle toolbar/lines visibility.
+ *
+ * @author Miloslav Metelka
+ * @since 1.13
+ */
+public final class ToggleAction extends AbstractEditorAction {
+
+@EditorActionRegistrations({
+ @EditorActionRegistration(
+ name = EditorActionNames.toggleToolbarAction,
+ menuPath = "View",
+ menuPosition = 800,
+ menuText = "#" + EditorActionNames.toggleToolbarAction + "_menu_text",
+ presenterType = "CheckBox"
+ ),
+ @EditorActionRegistration(
+ name = EditorActionNames.toggleLineNumbersAction,
+ menuPath = "View",
+ menuPosition = 850,
+ menuText = "#" + EditorActionNames.toggleLineNumbersAction + "_menu_text",
+ presenterType = "CheckBox"
+ )
+})
+ public static ToggleAction create(Map attrs) {
+ return new ToggleAction(attrs);
+ }
+
+ // -J-Dorg.netbeans.modules.editor.actions.ToggleAction.level=FINEST
+ private static final Logger LOG = Logger.getLogger(ToggleAction.class.getName());
+
+ private String settingName;
+
+ private Boolean defaultValue;
+
+ private LookupListener lookupListener;
+
+ private PreferenceChangeListener preferenceChangeListener;
+
+ public ToggleAction(Map attrs) {
+ super(attrs);
+ }
+
+ @Override
+ protected void actionNameUpdate(String actionName) {
+ super.actionNameUpdate(actionName);
+
+ if (EditorActionNames.toggleToolbarAction.equals(actionName)) {
+ settingName = SimpleValueNames.TOOLBAR_VISIBLE_PROP;
+ defaultValue = EditorPreferencesDefaults.defaultToolbarVisible;
+ } else if (EditorActionNames.toggleLineNumbersAction.equals(actionName)) {
+ settingName = SimpleValueNames.LINE_NUMBER_VISIBLE;
+ defaultValue = EditorPreferencesDefaults.defaultLineNumberVisible;
+ } else {
+ throw new IllegalStateException("Unsupported actionName='" + actionName + "'"); // NOI18N
+ }
+
+ updateSelected();
+ }
+
+ public void actionPerformed(ActionEvent evt, JTextComponent target) {
+ boolean newSelected = !isSelected();
+ prefs().putBoolean(settingName, newSelected);
+ updateSelected();
+ }
+
+ private boolean isSelected() {
+ return prefs().getBoolean(settingName, defaultValue);
+ }
+
+ private void updateSelected() {
+ System.err.println("action: " + actionName() + ", SELECTED_KEY: " + isSelected());
+ putValue(AbstractEditorAction.SELECTED_KEY, isSelected());
+ }
+
+ private Preferences prefs() {
+ Lookup globalMimeLookup = MimeLookup.getLookup(MimePath.EMPTY);
+ Preferences prefs = globalMimeLookup.lookup(Preferences.class);
+ if (lookupListener == null) {
+ globalMimeLookup.lookupResult(Preferences.class).addLookupListener(lookupListener = new LookupListener() {
+ public void resultChanged(LookupEvent evt) {
+ updateSelected();
+ }
+ });
+ }
+ if (preferenceChangeListener == null) {
+ prefs.addPreferenceChangeListener(preferenceChangeListener = new PreferenceChangeListener() {
+ public void preferenceChange(PreferenceChangeEvent evt) {
+ if (settingName.equals(evt.getKey())) {
+ updateSelected();
+ }
+ }
+ });
+ }
+ return prefs;
+ }
+
+}
diff --git a/editor.deprecated.pre61settings/nbproject/project.xml b/editor.deprecated.pre61settings/nbproject/project.xml
--- a/editor.deprecated.pre61settings/nbproject/project.xml
+++ b/editor.deprecated.pre61settings/nbproject/project.xml
@@ -65,6 +65,15 @@
+ org.netbeans.modules.editor.lib2
+
+
+
+ 1
+
+
+
+ org.netbeans.modules.editor.mimelookup
diff --git a/editor.deprecated.pre61settings/src/org/netbeans/editor/SettingsDefaults.java b/editor.deprecated.pre61settings/src/org/netbeans/editor/SettingsDefaults.java
--- a/editor.deprecated.pre61settings/src/org/netbeans/editor/SettingsDefaults.java
+++ b/editor.deprecated.pre61settings/src/org/netbeans/editor/SettingsDefaults.java
@@ -48,7 +48,7 @@
import javax.swing.UIManager;
import java.util.Map;
import java.util.HashMap;
-import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
+import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
/**
* Default values for the settings. They are used
@@ -156,8 +156,8 @@
public static final Color defaultTextLimitLineColor = new Color(255, 235, 235);
public static final Integer defaultTextLimitWidth = EditorPreferencesDefaults.defaultTextLimitWidth;
- public static final Acceptor defaultIdentifierAcceptor = EditorPreferencesDefaults.defaultIdentifierAcceptor;
- public static final Acceptor defaultWhitespaceAcceptor = EditorPreferencesDefaults.defaultWhitespaceAcceptor;
+// public static final Acceptor defaultIdentifierAcceptor = EditorPreferencesDefaults.defaultIdentifierAcceptor;
+// public static final Acceptor defaultWhitespaceAcceptor = EditorPreferencesDefaults.defaultWhitespaceAcceptor;
public static final Float defaultLineHeightCorrection = EditorPreferencesDefaults.defaultLineHeightCorrection;
diff --git a/editor.deprecated.pre61settings/src/org/netbeans/editor/SettingsNames.java b/editor.deprecated.pre61settings/src/org/netbeans/editor/SettingsNames.java
--- a/editor.deprecated.pre61settings/src/org/netbeans/editor/SettingsNames.java
+++ b/editor.deprecated.pre61settings/src/org/netbeans/editor/SettingsNames.java
@@ -41,7 +41,7 @@
package org.netbeans.editor;
-import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
+import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
/**
* Names of the base settings defined in the editor. The other packages
diff --git a/editor.deprecated.pre61settings/src/org/netbeans/editor/ext/ExtSettingsNames.java b/editor.deprecated.pre61settings/src/org/netbeans/editor/ext/ExtSettingsNames.java
--- a/editor.deprecated.pre61settings/src/org/netbeans/editor/ext/ExtSettingsNames.java
+++ b/editor.deprecated.pre61settings/src/org/netbeans/editor/ext/ExtSettingsNames.java
@@ -42,7 +42,7 @@
package org.netbeans.editor.ext;
import org.netbeans.editor.SettingsNames;
-import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
+import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
/**
* Names of the extended editor settings.
diff --git a/editor.lib/nbproject/project.xml b/editor.lib/nbproject/project.xml
--- a/editor.lib/nbproject/project.xml
+++ b/editor.lib/nbproject/project.xml
@@ -87,7 +87,7 @@
1
- 1.25
+ 1.30
diff --git a/editor.lib/src/org/netbeans/editor/Analyzer.java b/editor.lib/src/org/netbeans/editor/Analyzer.java
--- a/editor.lib/src/org/netbeans/editor/Analyzer.java
+++ b/editor.lib/src/org/netbeans/editor/Analyzer.java
@@ -51,7 +51,7 @@
import javax.swing.text.Document;
import javax.swing.text.Segment;
import org.netbeans.api.lexer.TokenHierarchy;
-import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
+import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
import org.netbeans.spi.lexer.MutableTextInput;
/**
diff --git a/editor.lib/src/org/netbeans/editor/BaseAction.java b/editor.lib/src/org/netbeans/editor/BaseAction.java
--- a/editor.lib/src/org/netbeans/editor/BaseAction.java
+++ b/editor.lib/src/org/netbeans/editor/BaseAction.java
@@ -56,14 +56,17 @@
import javax.swing.text.Caret;
/**
-* This is the parent of majority of the actions. It implements
-* the necessary resetting depending of what is required
-* by constructor of target action.
-* The other thing implemented here is macro recording.
-*
-* @author Miloslav Metelka
-* @version 1.00
-*/
+ * This is the parent of majority of the actions. It implements
+ * the necessary resetting depending of what is required
+ * by constructor of target action.
+ * The other thing implemented here is macro recording.
+ *
+ * Property "noIconInMenu" can be set to inform menu items not to use action's icon.
+ *
+ *
+ * @author Miloslav Metelka
+ * @version 1.00
+ */
public abstract class BaseAction extends TextAction {
@@ -120,7 +123,7 @@
* the action's real task is invoked.
*/
protected int updateMask;
-
+
private static boolean recording;
private static StringBuffer macroBuffer = new StringBuffer();
private static StringBuffer textBuffer = new StringBuffer();
diff --git a/editor.lib/src/org/netbeans/editor/BaseCaret.java b/editor.lib/src/org/netbeans/editor/BaseCaret.java
--- a/editor.lib/src/org/netbeans/editor/BaseCaret.java
+++ b/editor.lib/src/org/netbeans/editor/BaseCaret.java
@@ -105,7 +105,7 @@
import org.netbeans.api.editor.settings.FontColorSettings;
import org.netbeans.api.editor.settings.SimpleValueNames;
import org.netbeans.lib.editor.util.swing.DocumentListenerPriority;
-import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
+import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
import org.netbeans.modules.editor.lib.SettingsConversions;
import org.openide.util.WeakListeners;
@@ -122,10 +122,10 @@
AtomicLockListener, FoldHierarchyListener {
/** Caret type representing block covering current character */
- public static final String BLOCK_CARET = "block-caret"; // NOI18N
+ public static final String BLOCK_CARET = EditorPreferencesDefaults.BLOCK_CARET; // NOI18N
/** Default caret type */
- public static final String LINE_CARET = "line-caret"; // NOI18N
+ public static final String LINE_CARET = EditorPreferencesDefaults.LINE_CARET; // NOI18N
/** One dot thin line compatible with Swing default caret */
public static final String THIN_LINE_CARET = "thin-line-caret"; // NOI18N
diff --git a/editor.lib/src/org/netbeans/editor/BaseDocument.java b/editor.lib/src/org/netbeans/editor/BaseDocument.java
--- a/editor.lib/src/org/netbeans/editor/BaseDocument.java
+++ b/editor.lib/src/org/netbeans/editor/BaseDocument.java
@@ -92,8 +92,8 @@
import org.netbeans.lib.editor.util.ListenerList;
import org.netbeans.lib.editor.util.swing.DocumentListenerPriority;
import org.netbeans.modules.editor.lib.EditorPackageAccessor;
-import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
-import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
+import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
+import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
import org.netbeans.modules.editor.lib.FormatterOverride;
import org.netbeans.modules.editor.lib.TrailingWhitespaceRemove;
import org.netbeans.modules.editor.lib.SettingsConversions;
diff --git a/editor.lib/src/org/netbeans/editor/BaseKit.java b/editor.lib/src/org/netbeans/editor/BaseKit.java
--- a/editor.lib/src/org/netbeans/editor/BaseKit.java
+++ b/editor.lib/src/org/netbeans/editor/BaseKit.java
@@ -65,6 +65,7 @@
import javax.swing.text.Caret;
import javax.swing.text.JTextComponent;
import java.io.CharArrayWriter;
+import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.Set;
import java.util.Vector;
@@ -74,6 +75,8 @@
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;
import javax.swing.KeyStroke;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
import javax.swing.text.AbstractDocument;
import javax.swing.text.EditorKit;
import javax.swing.text.Position;
@@ -82,9 +85,10 @@
import org.netbeans.api.editor.mimelookup.MimeLookup;
import org.netbeans.api.editor.mimelookup.MimePath;
import org.netbeans.api.editor.settings.KeyBindingSettings;
+import org.netbeans.lib.editor.util.ListenerList;
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
-import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
-import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
+import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
+import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
import org.netbeans.modules.editor.lib.KitsTracker;
import org.netbeans.modules.editor.lib.NavigationHistory;
import org.netbeans.modules.editor.lib.SettingsConversions;
@@ -113,6 +117,7 @@
*/
static ThreadLocal IN_PASTE = new ThreadLocal();
+ // -J-Dorg.netbeans.editor.BaseKit.level=FINEST
private static final Logger LOG = Logger.getLogger(BaseKit.class.getName());
/** split the current line at cursor position */
@@ -352,6 +357,8 @@
public static final int MAGIC_POSITION_MAX = Integer.MAX_VALUE - 1;
+ private final SearchableKit searchableKit;
+
// static SettingsChangeListener settingsListener = new SettingsChangeListener() {
// public void settingsChange(SettingsChangeEvent evt) {
// String settingName = (evt != null) ? evt.getSettingName() : null;
@@ -534,6 +541,10 @@
kits.put(this.getClass(), this); // register itself
}
}
+ // Directly implementing searchable editor kit would require module dependency changes
+ // of any modules using BaseKit reference so make a wrapper instead
+ org.netbeans.modules.editor.lib2.actions.EditorActionUtilities.registerSearchableKit(this,
+ searchableKit = new SearchableKit(this));
}
/** Clone this editor kit */
@@ -691,21 +702,34 @@
/** Creates map with [name, action] pairs from the given
* array of actions.
*/
- public static Map actionsToMap(Action[] actions) {
- Map map = new HashMap();
+ public static void addActionsToMap(Map map, Action[] actions, String logActionsType) {
+ boolean fineLoggable = LOG.isLoggable(Level.FINE);
+ if (fineLoggable) {
+ LOG.fine(logActionsType + " start --------------------\n");
+ }
for (int i = 0; i < actions.length; i++) {
Action a = actions[i];
if (a == null) {
- throw new IllegalStateException("actions[] contains null at index " + i +
- ((i > 0) ? ". Preceding action is " + actions[i - 1] : ""));
+ LOG.info("actions[] contains null at index " + i +
+ ((i > 0) ? ". Preceding action is " + actions[i - 1] : "."));
+ continue;
}
String name = (String) a.getValue(Action.NAME);
if (name == null) {
- throw new IllegalStateException("Null Action.NAME property of action " + a);
+ LOG.info("Null Action.NAME property of action " + a);
+ continue;
}
+
+ if (fineLoggable) {
+ String overriding = map.containsKey(name) ? " OVERRIDING\n" : "\n"; // NOI18N
+ LOG.fine(" " + name + ": " + a + overriding); // NOI18N
+ }
+
map.put(name, a); // NOI18N
}
- return map;
+ if (fineLoggable) {
+ LOG.fine(logActionsType + " end ----------------------\n");
+ }
}
/** Converts map with [name, action] back
@@ -848,7 +872,7 @@
removeSelectionActionDef,
undoActionDef,
redoActionDef,
- new ActionFactory.ToggleLineNumbersAction(),
+ //new ActionFactory.ToggleLineNumbersAction(),
new NextWordAction(nextWordAction),
new NextWordAction(selectionNextWordAction),
new PreviousWordAction(previousWordAction),
@@ -895,31 +919,43 @@
* to get basic list and then customActions are added.
*/
public @Override final Action[] getActions() {
- return (Action []) getActionsAndMap()[0];
+ return (Action []) addActionsToMap()[0];
}
/* package */ Map getActionMap() {
- return (Map) getActionsAndMap()[1];
+ return (Map) addActionsToMap()[1];
}
- private Object[] getActionsAndMap() {
+ private Object[] addActionsToMap() {
synchronized (KEYMAPS_AND_ACTIONS_LOCK) {
MimePath mimePath = MimePath.parse(getContentType());
Action[] actions = kitActions.get(mimePath);
Map actionMap = kitActionMaps.get(mimePath);
if (actions == null || actionMap == null) {
- // create map of actions
- actions = createActions();
- actionMap = actionsToMap(actions);
+ // Initialize actions - use the following actions:
+ // 1. Declared "global" actions (declared in the xml layer under "Editors/Actions")
+ // 2. Declared "mime-type actions (declared in the xml layer under "Editors/content-type/Actions")
+ // 3. Result of createActions()
+ // 4. Custom actions (EditorPreferencesKeys.CUSTOM_ACTION_LIST)
+ // Higher levels override actions with same Action.NAME
+ actions = getDeclaredActions(); // non-null
+ actionMap = new HashMap(actions.length << 1);
+ addActionsToMap(actionMap, actions, "Declared actions"); // NOI18N
+
+ Action[] createActionsMethodResult = createActions();
+ if (createActionsMethodResult != null) {
+ addActionsToMap(actionMap, createActionsMethodResult, "Actions from createActions()"); // NOI18N
+ }
// add custom actions
Action[] customActions = getCustomActions();
if (customActions != null) {
- actionMap.putAll(actionsToMap(customActions));
- actions = actionMap.values().toArray(new Action[actionMap.values().size()]);
+ addActionsToMap(actionMap, customActions, "Custom actions"); // NOI18N
}
+ actions = actionMap.values().toArray(new Action[actionMap.values().size()]);
+
kitActions.put(mimePath, actions);
kitActionMaps.put(mimePath, actionMap);
@@ -932,6 +968,16 @@
return new Object [] { actions, actionMap };
}
}
+
+ /**
+ * Get actions declared in the xml layer. They may be overriden by result
+ * of createActions() and finally by result of getCustomActions().
+ *
+ * @return non-null list of declared actions.
+ */
+ protected Action[] getDeclaredActions() {
+ return new Action[0];
+ }
/** Update the actions right after their creation was finished.
* The getActions() and getActionByName()
@@ -2725,7 +2771,41 @@
for(JTextComponent c : arr) {
c.setKeymap(keymap);
}
+
+ searchableKit.fireActionsChange();
}
} // End of KeymapTracker class
+
+ private static final class SearchableKit implements org.netbeans.modules.editor.lib2.actions.SearchableEditorKit {
+
+ private final BaseKit baseKit;
+
+ private final ListenerList actionsListenerList = new ListenerList();
+
+ SearchableKit(BaseKit baseKit) {
+ this.baseKit = baseKit;
+ }
+
+ public Action getAction(String actionName) {
+ return baseKit.getActionByName(actionName);
+ }
+
+ public void addActionsChangeListener(ChangeListener listener) {
+ actionsListenerList.add(listener);
+ }
+
+ public void removeActionsChangeListener(ChangeListener listener) {
+ actionsListenerList.remove(listener);
+ }
+
+ void fireActionsChange() {
+ ChangeEvent evt = new ChangeEvent(this);
+ for (ChangeListener listener : actionsListenerList.getListeners()) {
+ listener.stateChanged(evt);
+ }
+ }
+
+ }
+
}
diff --git a/editor.lib/src/org/netbeans/editor/BaseTextUI.java b/editor.lib/src/org/netbeans/editor/BaseTextUI.java
--- a/editor.lib/src/org/netbeans/editor/BaseTextUI.java
+++ b/editor.lib/src/org/netbeans/editor/BaseTextUI.java
@@ -66,8 +66,8 @@
import org.netbeans.api.editor.settings.SimpleValueNames;
import org.netbeans.modules.editor.lib2.EditorApiPackageAccessor;
import org.netbeans.editor.view.spi.LockView;
-import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
-import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
+import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
+import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
import org.netbeans.modules.editor.lib.SettingsConversions;
import org.openide.util.WeakListeners;
diff --git a/editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java b/editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java
--- a/editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java
+++ b/editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java
@@ -84,7 +84,7 @@
import org.netbeans.api.editor.settings.FontColorSettings;
import org.netbeans.api.editor.settings.SimpleValueNames;
import org.netbeans.editor.CodeFoldingSideBar.PaintInfo;
-import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
+import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
import org.netbeans.modules.editor.lib.SettingsConversions;
import org.openide.util.Lookup;
import org.openide.util.LookupEvent;
diff --git a/editor.lib/src/org/netbeans/editor/EditorUI.java b/editor.lib/src/org/netbeans/editor/EditorUI.java
--- a/editor.lib/src/org/netbeans/editor/EditorUI.java
+++ b/editor.lib/src/org/netbeans/editor/EditorUI.java
@@ -86,8 +86,8 @@
import org.netbeans.editor.ext.ExtKit;
import org.netbeans.editor.ext.ToolTipSupport;
import org.netbeans.modules.editor.lib.ColoringMap;
-import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
-import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
+import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
+import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
import org.netbeans.modules.editor.lib.KitsTracker;
import org.netbeans.modules.editor.lib.SettingsConversions;
import org.openide.util.WeakListeners;
diff --git a/editor.lib/src/org/netbeans/editor/Formatter.java b/editor.lib/src/org/netbeans/editor/Formatter.java
--- a/editor.lib/src/org/netbeans/editor/Formatter.java
+++ b/editor.lib/src/org/netbeans/editor/Formatter.java
@@ -61,7 +61,7 @@
import org.netbeans.api.editor.settings.SimpleValueNames;
import org.netbeans.lib.editor.util.CharSequenceUtilities;
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
-import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
+import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
import org.netbeans.modules.editor.lib.KitsTracker;
import org.netbeans.modules.editor.lib.SettingsConversions;
import org.openide.util.Lookup;
diff --git a/editor.lib/src/org/netbeans/editor/StatusBar.java b/editor.lib/src/org/netbeans/editor/StatusBar.java
--- a/editor.lib/src/org/netbeans/editor/StatusBar.java
+++ b/editor.lib/src/org/netbeans/editor/StatusBar.java
@@ -86,7 +86,7 @@
import org.netbeans.api.editor.settings.FontColorNames;
import org.netbeans.api.editor.settings.FontColorSettings;
import org.netbeans.api.editor.settings.SimpleValueNames;
-import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
+import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
import org.openide.util.NbBundle;
import org.openide.util.WeakListeners;
diff --git a/editor.lib/src/org/netbeans/editor/Utilities.java b/editor.lib/src/org/netbeans/editor/Utilities.java
--- a/editor.lib/src/org/netbeans/editor/Utilities.java
+++ b/editor.lib/src/org/netbeans/editor/Utilities.java
@@ -61,7 +61,7 @@
import javax.swing.text.View;
import org.netbeans.lib.editor.util.CharSequenceUtilities;
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
-import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
+import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
import org.openide.util.NbBundle;
/**
diff --git a/editor.lib/src/org/netbeans/editor/WordMatch.java b/editor.lib/src/org/netbeans/editor/WordMatch.java
--- a/editor.lib/src/org/netbeans/editor/WordMatch.java
+++ b/editor.lib/src/org/netbeans/editor/WordMatch.java
@@ -52,8 +52,8 @@
import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;
import org.netbeans.api.editor.mimelookup.MimeLookup;
-import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
-import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
+import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
+import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
import org.openide.util.WeakListeners;
/** Word matching support enables to fill in the rest of the word
diff --git a/editor.lib/src/org/netbeans/editor/ext/ExtFormatter.java b/editor.lib/src/org/netbeans/editor/ext/ExtFormatter.java
--- a/editor.lib/src/org/netbeans/editor/ext/ExtFormatter.java
+++ b/editor.lib/src/org/netbeans/editor/ext/ExtFormatter.java
@@ -65,7 +65,7 @@
import org.netbeans.editor.AcceptorFactory;
import org.netbeans.editor.BaseKit;
import org.netbeans.editor.Syntax;
-import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
+import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
import org.netbeans.modules.editor.lib.SettingsConversions;
import org.openide.util.Lookup;
import org.openide.util.WeakListeners;
diff --git a/editor.lib/src/org/netbeans/modules/editor/lib/ColoringMap.java b/editor.lib/src/org/netbeans/modules/editor/lib/ColoringMap.java
--- a/editor.lib/src/org/netbeans/modules/editor/lib/ColoringMap.java
+++ b/editor.lib/src/org/netbeans/modules/editor/lib/ColoringMap.java
@@ -40,6 +40,7 @@
*/
package org.netbeans.modules.editor.lib;
+import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.reflect.Field;
diff --git a/editor.lib/src/org/netbeans/modules/editor/lib/SettingsConversions.java b/editor.lib/src/org/netbeans/modules/editor/lib/SettingsConversions.java
--- a/editor.lib/src/org/netbeans/modules/editor/lib/SettingsConversions.java
+++ b/editor.lib/src/org/netbeans/modules/editor/lib/SettingsConversions.java
@@ -52,6 +52,7 @@
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import org.netbeans.api.editor.mimelookup.MimePath;
+import org.netbeans.editor.Acceptor;
import org.openide.util.Lookup;
/**
@@ -259,7 +260,7 @@
}
}
}
-
+
private SettingsConversions() {
}
diff --git a/editor.lib2/manifest.mf b/editor.lib2/manifest.mf
--- a/editor.lib2/manifest.mf
+++ b/editor.lib2/manifest.mf
@@ -3,3 +3,4 @@
OpenIDE-Module-Implementation-Version: 2
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib2/Bundle.properties
OpenIDE-Module-Layer: org/netbeans/modules/editor/lib2/resources/layer.xml
+OpenIDE-Module-Needs: org.netbeans.modules.editor.actions
\ No newline at end of file
diff --git a/editor.lib2/src/org/netbeans/api/editor/EditorActionRegistration.java b/editor.lib2/src/org/netbeans/api/editor/EditorActionRegistration.java
--- a/editor.lib2/src/org/netbeans/api/editor/EditorActionRegistration.java
+++ b/editor.lib2/src/org/netbeans/api/editor/EditorActionRegistration.java
@@ -134,4 +134,45 @@
*/
String popupText() default "";
+ /**
+ * Path of this action in main menu e.g. "Edit".
+ */
+ String menuPath() default "";
+
+ /**
+ * Integer position of the main menu item among the other menu items.
+ *
+ * The default Integer.MAX_VALUE value means no menu representation.
+ */
+ int menuPosition() default Integer.MAX_VALUE;
+
+ /**
+ * Path of this action in popup menu e.g. "" for appearance right in the context menu
+ * or a corresponding path for nested submenu appearance.
+ */
+ String popupPath() default "";
+
+ /**
+ * Integer position of the popup menu item among the other popup menu (or submenu) items.
+ *
+ * The default Integer.MAX_VALUE value means no popup menu representation.
+ */
+ int popupPosition() default Integer.MAX_VALUE;
+
+ /**
+ * Integer position of this action in editor toolbar.
+ *
+ * The default Integer.MAX_VALUE value means no toolbar representation.
+ */
+ int toolBarPosition() default Integer.MAX_VALUE;
+
+ /**
+ * Get type of the presenter used in menu (and toolbar).
+ *
+ * Currently supported types are default "" and "CheckBox".
+ *
+ * The value will be present in the action in "PresenterType" property.
+ */
+ String presenterType() default "";
+
}
diff --git a/editor.lib2/src/org/netbeans/api/editor/EditorUtilities.java b/editor.lib2/src/org/netbeans/api/editor/EditorUtilities.java
new file mode 100644
--- /dev/null
+++ b/editor.lib2/src/org/netbeans/api/editor/EditorUtilities.java
@@ -0,0 +1,73 @@
+/*
+ * 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.api.editor;
+
+import javax.swing.Action;
+import javax.swing.text.EditorKit;
+import org.netbeans.modules.editor.lib2.actions.EditorActionUtilities;
+
+
+/**
+ * Various utility methods related to editor.
+ *
+ * @author Miloslav Metelka
+ * @since 1.13
+ */
+
+public final class EditorUtilities {
+
+ private EditorUtilities() {
+ // No instances
+ }
+
+ /**
+ * Find an action with the given name in the editor kit.
+ *
+ * @param editorKit non-null editor kit in which search is performed.
+ * @param actionName non-null action name to search for.
+ * @return action instance with the given name or null if action not found.
+ */
+ public static Action getAction(EditorKit editorKit, String actionName) {
+ return EditorActionUtilities.getAction(editorKit, actionName);
+ }
+
+}
diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/EditorActionRegistrationProcessor.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/EditorActionRegistrationProcessor.java
--- a/editor.lib2/src/org/netbeans/modules/editor/lib2/EditorActionRegistrationProcessor.java
+++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/EditorActionRegistrationProcessor.java
@@ -39,13 +39,10 @@
package org.netbeans.modules.editor.lib2;
-import java.io.IOException;
-import java.util.MissingResourceException;
-import java.util.PropertyResourceBundle;
-import java.util.ResourceBundle;
+import java.util.List;
+import org.netbeans.modules.editor.lib2.actions.EditorActionUtilities;
+import org.netbeans.modules.editor.lib2.actions.PresenterEditorAction;
import java.util.Set;
-import javax.annotation.processing.Filer;
-import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
@@ -55,10 +52,10 @@
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter;
import javax.swing.Action;
-import javax.tools.StandardLocation;
import org.netbeans.api.editor.EditorActionRegistration;
import org.netbeans.api.editor.EditorActionRegistrations;
import org.openide.filesystems.annotations.LayerBuilder;
@@ -67,7 +64,8 @@
import org.openide.util.lookup.ServiceProvider;
/**
- * Annotation processor for
+ * Annotation processor for {@link EditorActionRegistration}
+ * and {@link EditorActionRegistrations}.
*/
@ServiceProvider(service=Processor.class)
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@@ -101,7 +99,9 @@
String methodName;
TypeMirror swingActionType = processingEnv.getTypeUtils().getDeclaredType(
processingEnv.getElementUtils().getTypeElement("javax.swing.Action"));
-
+ TypeMirror utilMapType = processingEnv.getTypeUtils().getDeclaredType(
+ processingEnv.getElementUtils().getTypeElement("java.util.Map"));
+ boolean directActionCreation = false; // Whether construct AlwaysEnabledAction or annotated action directly
switch (e.getKind()) {
case CLASS:
className = processingEnv.getElementUtils().getBinaryName((TypeElement)e).toString();
@@ -111,24 +111,35 @@
if (!e.getModifiers().contains(Modifier.PUBLIC)) {
throw new LayerGenerationException(className + " is not public", e);
}
- boolean hasDefaultCtor = false;
+ ExecutableElement defaultCtor = null;
+ ExecutableElement mapCtor = null;
for (ExecutableElement constructor : ElementFilter.constructorsIn(e.getEnclosedElements())) {
- if (constructor.getParameters().isEmpty()) {
- if (!constructor.getModifiers().contains(Modifier.PUBLIC)) {
- throw new LayerGenerationException("Default constructor of " + className + " is not public", e);
- }
- hasDefaultCtor = true;
- break;
+ List extends VariableElement> params = constructor.getParameters();
+ if (params.isEmpty()) {
+ defaultCtor = constructor;
+
+ } else if (params.size() == 1 &&
+ processingEnv.getTypeUtils().isAssignable(params.get(0).asType(), utilMapType))
+ {
+ mapCtor = constructor;
}
}
- if (!hasDefaultCtor) {
- throw new LayerGenerationException(className + " must have a no-argument constructor", e);
+ String msgBase = "No-argument (or single-argument \"Map attrs\") constructor";
+ if (defaultCtor == null && mapCtor == null) {
+ throw new LayerGenerationException(msgBase + " not present in " + className, e);
+ }
+ boolean defaultCtorPublic = (defaultCtor != null && defaultCtor.getModifiers().contains(Modifier.PUBLIC));
+ boolean mapCtorPublic = (mapCtor != null && mapCtor.getModifiers().contains(Modifier.PUBLIC));
+ if (!defaultCtorPublic && !mapCtorPublic) {
+ throw new LayerGenerationException(msgBase + " not public in " + className, e);
}
if (!processingEnv.getTypeUtils().isAssignable(e.asType(), swingActionType)) {
throw new LayerGenerationException(className + " is not assignable to javax.swing.Action", e);
}
-
+ if (mapCtorPublic) {
+ directActionCreation = true;
+ }
methodName = null;
break;
@@ -136,18 +147,28 @@
className = processingEnv.getElementUtils().getBinaryName((TypeElement) e.getEnclosingElement()).toString();
methodName = e.getSimpleName().toString();
if (!e.getModifiers().contains(Modifier.STATIC)) {
- throw new LayerGenerationException(className + "." + methodName + " must be static", e);
+ throw new LayerGenerationException(className + "." + methodName + " must be static", e); // NOI18N
}
// It appears that actually even non-public method registration works - so commented following
// if (!e.getModifiers().contains(Modifier.PUBLIC)) {
// throw new LayerGenerationException(className + "." + methodName + " must be public", e);
// }
- if (!((ExecutableElement) e).getParameters().isEmpty()) {
- throw new LayerGenerationException(className + "." + methodName + " must not take arguments", e);
+ List extends VariableElement> params = ((ExecutableElement)e).getParameters();
+ boolean emptyParams = params.isEmpty();
+ boolean mapParam = (params.size() == 1 && processingEnv.getTypeUtils().isAssignable(
+ params.get(0).asType(), utilMapType));
+ if (!emptyParams && !mapParam)
+ {
+ throw new LayerGenerationException(className + "." + methodName +
+ " must not take arguments (or have a single-argument \"Map attrs\")", e); // NOI18N
}
- if (swingActionType != null && !processingEnv.getTypeUtils().isAssignable(((ExecutableElement)e).getReturnType(), swingActionType)) {
+ TypeMirror returnType = ((ExecutableElement)e).getReturnType();
+ if (swingActionType != null && !processingEnv.getTypeUtils().isAssignable(returnType, swingActionType)) {
throw new LayerGenerationException(className + "." + methodName + " is not assignable to javax.swing.Action", e);
}
+ if (mapParam) {
+ directActionCreation = true;
+ }
break;
default:
@@ -162,9 +183,8 @@
filePath.append("/").append(annotation.mimeType());
}
filePath.append("/Actions/").append(actionName).append(".instance");
- LayerBuilder.File file = layer(e).file(filePath.toString());
-
- file.stringvalue("displayName", actionName);
+ LayerBuilder layer = layer(e);
+ LayerBuilder.File file = layer.file(filePath.toString());
// Resolve icon resource
String iconResource = annotation.iconResource();
@@ -199,13 +219,109 @@
file.bundlevalue("popupText", popupText);
}
- file.methodvalue("instanceCreate", "org.openide.awt.Actions", "alwaysEnabled");
- if (methodName != null) {
- file.methodvalue("delegate", className, methodName);
- } else {
- file.newvalue("delegate", className);
+ // Check presenters
+ String presenterActionName = null;
+ String presenterType = annotation.presenterType();
+ if (presenterType.length() > 0) { // Non-default presenter type
+ directActionCreation = true;
+ }
+
+ // Check menu path
+ String menuPath = annotation.menuPath();
+ int menuPosition = annotation.menuPosition();
+ if (menuPosition != Integer.MAX_VALUE) {
+ StringBuilder presenterFilePath = new StringBuilder(50);
+ presenterFilePath.append("Menu/");
+ if (menuPath.length() > 0) {
+ presenterFilePath.append(menuPath).append('/');
+ }
+ presenterFilePath.append(actionName).append(".shadow");
+ LayerBuilder.File presenterShadowFile = layer.file(presenterFilePath.toString());
+ if (presenterActionName == null) {
+ presenterActionName = generatePresenterAction(layer, actionName, presenterType);
+ }
+ presenterShadowFile.stringvalue("originalFile", presenterActionName);
+ presenterShadowFile.intvalue("position", menuPosition);
+ presenterShadowFile.write();
+ }
+
+ // Check popup path
+ String popupPath = annotation.popupPath();
+ int popupPosition = annotation.popupPosition();
+ if (popupPosition != Integer.MAX_VALUE) {
+ StringBuilder presenterFilePath = new StringBuilder(50);
+ presenterFilePath.append("Editors");
+ if (annotation.mimeType().length() > 0) {
+ filePath.append("/").append(annotation.mimeType());
+ }
+ if (popupPath.length() > 0) {
+ presenterFilePath.append(popupPath).append('/');
+ }
+ presenterFilePath.append(actionName).append(".shadow");
+ LayerBuilder.File presenterShadowFile = layer.file(presenterFilePath.toString());
+ if (presenterActionName == null) {
+ presenterActionName = generatePresenterAction(layer, actionName, presenterType);
+ }
+ presenterShadowFile.stringvalue("originalFile", presenterActionName);
+ presenterShadowFile.intvalue("position", popupPosition);
+ presenterShadowFile.write();
+ }
+
+ int toolBarPosition = annotation.toolBarPosition();
+ if (toolBarPosition != Integer.MAX_VALUE) {
+ StringBuilder presenterFilePath = new StringBuilder(50);
+ presenterFilePath.append("/Editors/Toolbar/");
+ if (popupPath.length() > 0) {
+ presenterFilePath.append(popupPath).append('/');
+ }
+ presenterFilePath.append(actionName).append(".shadow");
+ LayerBuilder.File presenterShadowFile = layer.file(presenterFilePath.toString());
+ if (presenterActionName == null) {
+ presenterActionName = generatePresenterAction(layer, actionName, presenterType);
+ }
+ presenterShadowFile.stringvalue("originalFile", presenterActionName);
+ presenterShadowFile.intvalue("position", toolBarPosition);
+ presenterShadowFile.write();
+ }
+
+ // Deafult helpID is action's name
+ file.stringvalue("helpID", actionName);
+
+ // Resolve accelerator through method
+ file.methodvalue(Action.ACCELERATOR_KEY, EditorActionUtilities.class.getName(), "getAccelerator");
+
+ // Always generate Action.NAME since although AlwaysEnabledAction tweaks its retrieval to "displayName"
+ // some tools may query FO's properties and expect it there.
+ file.stringvalue(Action.NAME, actionName);
+
+ if (directActionCreation) {
+ if (methodName != null) {
+ file.methodvalue("instanceCreate", className, methodName);
+ } else {
+ file.newvalue("instanceCreate", className);
+ }
+
+ } else { // Create always enabled action
+ file.methodvalue("instanceCreate", "org.openide.awt.Actions", "alwaysEnabled");
+ file.stringvalue("displayName", actionName);
+
+ if (methodName != null) {
+ file.methodvalue("delegate", className, methodName);
+ } else {
+ file.newvalue("delegate", className);
+ }
}
file.write();
}
+ private String generatePresenterAction(LayerBuilder layer, String actionName, String presenterType) {
+ String presenterActionName = "Editors/ActionPresenters/" + actionName + ".instance";
+ LayerBuilder.File presenterActionFile = layer.file(presenterActionName);
+ presenterActionFile.methodvalue("instanceCreate", PresenterEditorAction.class.getName(), "create");
+ presenterActionFile.stringvalue(Action.NAME, actionName);
+ presenterActionFile.stringvalue("PresenterType", presenterType);
+ presenterActionFile.write();
+ return presenterActionName;
+ }
+
}
diff --git a/editor.lib/src/org/netbeans/modules/editor/lib/EditorPreferencesDefaults.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/EditorPreferencesDefaults.java
rename from editor.lib/src/org/netbeans/modules/editor/lib/EditorPreferencesDefaults.java
rename to editor.lib2/src/org/netbeans/modules/editor/lib2/EditorPreferencesDefaults.java
--- a/editor.lib/src/org/netbeans/modules/editor/lib/EditorPreferencesDefaults.java
+++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/EditorPreferencesDefaults.java
@@ -39,13 +39,10 @@
* made subject to such option by the copyright holder.
*/
-package org.netbeans.modules.editor.lib;
+package org.netbeans.modules.editor.lib2;
import java.awt.Insets;
import java.awt.Dimension;
-import org.netbeans.editor.Acceptor;
-import org.netbeans.editor.AcceptorFactory;
-import org.netbeans.editor.BaseCaret;
/**
* This class contains settings default values copied over from SettingsDefaults and ExtSettingsDefaults.
@@ -57,6 +54,9 @@
private EditorPreferencesDefaults() {
// no-op
}
+
+ public static final String LINE_CARET = "line-caret";
+ public static final String BLOCK_CARET = "block-caret";
// not in SettingsDefaults not ExtSettingsDefaults
public static final boolean defaultToolbarVisible = true;
@@ -98,8 +98,8 @@
public static final boolean defaultExpandTabs = true;
- public static final String defaultCaretTypeInsertMode = BaseCaret.LINE_CARET;
- public static final String defaultCaretTypeOverwriteMode = BaseCaret.BLOCK_CARET;
+ public static final String defaultCaretTypeInsertMode = LINE_CARET;
+ public static final String defaultCaretTypeOverwriteMode = BLOCK_CARET;
public static final boolean defaultCaretItalicInsertMode = false;
public static final boolean defaultCaretItalicOverwriteMode = false;
/** @since 1.23 */
diff --git a/editor.lib/src/org/netbeans/modules/editor/lib/EditorPreferencesKeys.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/EditorPreferencesKeys.java
rename from editor.lib/src/org/netbeans/modules/editor/lib/EditorPreferencesKeys.java
rename to editor.lib2/src/org/netbeans/modules/editor/lib2/EditorPreferencesKeys.java
--- a/editor.lib/src/org/netbeans/modules/editor/lib/EditorPreferencesKeys.java
+++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/EditorPreferencesKeys.java
@@ -39,7 +39,7 @@
* made subject to such option by the copyright holder.
*/
-package org.netbeans.modules.editor.lib;
+package org.netbeans.modules.editor.lib2;
import org.netbeans.api.editor.settings.SimpleValueNames;
diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/AbstractEditorAction.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/AbstractEditorAction.java
new file mode 100644
--- /dev/null
+++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/AbstractEditorAction.java
@@ -0,0 +1,178 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 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 2008 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.editor.lib2.actions;
+
+import java.awt.event.ActionEvent;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import javax.swing.Action;
+import javax.swing.text.Caret;
+import javax.swing.text.JTextComponent;
+import javax.swing.text.TextAction;
+import org.openide.util.NbBundle;
+import org.openide.util.RequestProcessor;
+
+/**
+ * Base class for editor actions.
+ *
+ * @author Miloslav Metelka
+ * @since 1.13
+ */
+public abstract class AbstractEditorAction extends TextAction {
+
+ /**
+ * Boolean action property displayed by the checkbox menu item.
+ */
+ public static final String SELECTED_KEY = "SwingSelectedKey"; // [TODO] Replace with Action.SELECTED_KEY on 1.6
+
+ /** Logger for reporting invoked actions */
+ private static Logger UILOG = Logger.getLogger("org.netbeans.ui.actions.editor"); // NOI18N
+
+ private final Map attrs;
+
+ public AbstractEditorAction(Map attrs) {
+ super(null);
+ this.attrs = attrs;
+
+ String actionName = (String)attrs.get(Action.NAME);
+ if (actionName == null) {
+ throw new IllegalArgumentException("Null Action.NAME attribute for action " + this.getClass()); // NOI18N
+ }
+ putValue(Action.NAME, actionName);
+ }
+
+ public AbstractEditorAction() {
+ super(null);
+ this.attrs = null;
+ }
+
+ public abstract void actionPerformed(ActionEvent evt, JTextComponent component);
+
+ /**
+ * Called by {@link #putValue(String,String)} when {@link Action#NAME} property
+ * is set to a non-null String value. This allows a "polymorphic" action (with
+ * Action.NAME-specific behavior) to update certain properties (e.g. an icon)
+ * according to the name that was set.
+ *
+ * @param actionName non-null action's name (value of Action.NAME property).
+ * @since 1.34
+ */
+ protected void actionNameUpdate(String actionName) {
+ }
+
+ public final void actionPerformed(final ActionEvent evt) {
+ final JTextComponent target = getTextComponent(evt);
+ MacroRecording.get().recordAction(this, evt); // Possibly record action in a currently recorded macro
+
+ if (UILOG.isLoggable(Level.FINE)) {
+ // TODO [Mila] - Set action's property to disable UI logging
+ String actionNameLowerCase = actionName();
+ if (actionNameLowerCase != null &&
+ !"default-typed".equals(actionNameLowerCase) && //NOI18N
+ -1 == actionNameLowerCase.indexOf("caret") && //NOI18N
+ -1 == actionNameLowerCase.indexOf("delete") && //NOI18N
+ -1 == actionNameLowerCase.indexOf("selection") && //NOI18N
+ -1 == actionNameLowerCase.indexOf("build-tool-tip") &&//NOI18N
+ -1 == actionNameLowerCase.indexOf("build-popup-menu") &&//NOI18N
+ -1 == actionNameLowerCase.indexOf("page-up") &&//NOI18N
+ -1 == actionNameLowerCase.indexOf("page-down") &&//NOI18N
+ -1 == actionNameLowerCase.indexOf("-kit-install") //NOI18N
+ ) {
+ LogRecord r = new LogRecord(Level.FINE, "UI_ACTION_EDITOR"); // NOI18N
+ r.setResourceBundle(NbBundle.getBundle(AbstractEditorAction.class));
+ if (evt != null) {
+ r.setParameters(new Object[] { evt, evt.toString(), this, toString(), getValue(NAME) });
+ } else {
+ r.setParameters(new Object[] { "no-ActionEvent", "no-ActionEvent", this, toString(), getValue(NAME) }); //NOI18N
+ }
+ r.setLoggerName(UILOG.getName());
+ UILOG.log(r);
+ }
+ }
+
+ if (asynchronous()) {
+ RequestProcessor.getDefault().post(new Runnable () {
+ public void run() {
+ actionPerformed(evt, target);
+ }
+ });
+ } else {
+ actionPerformed(evt, target);
+ }
+ }
+
+ @Override
+ public Object getValue(String key) {
+ Object value = super.getValue(key);
+ if (value == null && attrs != null) {
+ if (!"instanceCreate".equals(key)) { // Return null for this key
+ value = attrs.get(key);
+ }
+ }
+ return value;
+ }
+
+ @Override
+ public void putValue(String key, Object value) {
+ super.putValue(key, value);
+ if (Action.NAME.equals(key) && value instanceof String) {
+ actionNameUpdate((String)value);
+ }
+ }
+
+
+ protected boolean asynchronous() {
+ return false;
+ }
+
+ protected final String actionName() {
+ return (String) getValue(Action.NAME);
+ }
+
+ protected final void magicPositionReset(JTextComponent target) {
+ Caret caret = target.getCaret();
+ if (caret != null) {
+ caret.setMagicCaretPosition(null);
+ }
+ }
+
+}
diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/Bundle.properties b/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/Bundle.properties
new file mode 100644
--- /dev/null
+++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/Bundle.properties
@@ -0,0 +1,51 @@
+# 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.
+
+#
+# UI Logging
+#
+# UI logging of button press
+# {0} instance of the button
+# {1} class of the button
+# {2} instance of the action
+# {3} class of the action
+# {4} display name of the action
+UI_ACTION_EDITOR=Invoking {4} implemented as {3} thru {1}
+UI_ACTION_EDITOR_ICON_BASE=org/netbeans/modules/editor/lib2/resources/defaultglyph.gif
+
diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionNames.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionNames.java
new file mode 100644
--- /dev/null
+++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionNames.java
@@ -0,0 +1,59 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 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 2008 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.editor.lib2.actions;
+
+/**
+ * Names of basic editor actions.
+ *
+ * @author Miloslav Metelka
+ * @since 1.13
+ */
+public final class EditorActionNames {
+
+ /** Toggle the visibility of the editor toolbar */
+ public static final String toggleToolbarAction = "toggle-toolbar"; // NOI18N
+
+ /** Toggle visibility of line numbers*/
+ public static final String toggleLineNumbersAction = "toggle-line-numbers"; // NOI18N
+
+ /** Goto declaration depending on the context under the caret */
+ public static final String gotoDeclarationAction = "goto-declaration"; // NOI18N
+
+}
diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionUtilities.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionUtilities.java
new file mode 100644
--- /dev/null
+++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionUtilities.java
@@ -0,0 +1,302 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 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 2008 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.editor.lib2.actions;
+
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.Action;
+import javax.swing.KeyStroke;
+import javax.swing.event.ChangeListener;
+import javax.swing.text.EditorKit;
+import org.netbeans.api.editor.mimelookup.MimeLookup;
+import org.netbeans.api.editor.mimelookup.MimePath;
+import org.netbeans.api.editor.settings.KeyBindingSettings;
+import org.netbeans.api.editor.settings.MultiKeyBinding;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Lookup;
+import org.openide.util.LookupEvent;
+import org.openide.util.LookupListener;
+import org.openide.util.lookup.Lookups;
+
+
+/**
+ * Various utility methods for declarative editor action registrations.
+ */
+public final class EditorActionUtilities {
+
+ // -J-Dorg.netbeans.modules.editor.lib2.actions.EditorActionUtilities.level=FINEST
+ private static final Logger LOG = Logger.getLogger(EditorActionUtilities.class.getName());
+
+ private static Map> mimeType2actionName2KeyStroke;
+
+ private static Map mimeType2ListenerPresent = new HashMap();
+
+ private static Reference globalKitRef;
+
+ private static LookupListener globalKitListener;
+
+ private static final Map kit2searchable = new WeakHashMap();
+
+ private EditorActionUtilities() {
+ // No instances
+ }
+
+ public static EditorKit getGlobalKit() {
+ synchronized (kit2searchable) {
+ EditorKit globalKit = (globalKitRef != null) ? globalKitRef.get() : null;
+ if (globalKit == null) {
+ Lookup.Result result = MimeLookup.getLookup("").lookupResult(EditorKit.class);
+ Iterator extends EditorKit> instancesIterator = result.allInstances().iterator();
+ globalKit = instancesIterator.hasNext() ? instancesIterator.next() : null;
+ if (globalKit != null) {
+ globalKitRef = new WeakReference(globalKit);
+ }
+ if (globalKitListener == null) {
+ globalKitListener = new LookupListener() {
+ public void resultChanged(LookupEvent evt) {
+ synchronized (kit2searchable) {
+ globalKitRef = null;
+ }
+ }
+ };
+ result.addLookupListener(globalKitListener);
+ }
+ }
+ return globalKit;
+ }
+ }
+
+ public static EditorKit getKit(String mimeType) {
+ Lookup.Result result = MimeLookup.getLookup(mimeType).lookupResult(EditorKit.class);
+ Iterator extends EditorKit> instancesIterator = result.allInstances().iterator();
+ EditorKit kit = instancesIterator.hasNext() ? instancesIterator.next() : null;
+ return kit;
+ }
+
+ public static void registerSearchableKit(EditorKit kit, SearchableEditorKit searchableKit) {
+ synchronized (kit2searchable) {
+ kit2searchable.put(kit, searchableKit);
+ }
+ }
+
+ /**
+ * Get an editor action in a constant time (wrap a kit with a SearchableEditorKit if necessary).
+ *
+ * @param kit non-null kit.
+ * @param actionName non-null action name.
+ * @return action's instance or null.
+ */
+ public static Action getAction(EditorKit kit, String actionName) {
+ return getSearchableKit(kit).getAction(actionName);
+ }
+
+ /**
+ * Get searchable editor kit for the given kit.
+ * @param kit non-null kit.
+ * @return non-null searchable kit.
+ */
+ public static SearchableEditorKit getSearchableKit(EditorKit kit) {
+ SearchableEditorKit searchableKit;
+ if (kit instanceof SearchableEditorKit) {
+ searchableKit = ((SearchableEditorKit)kit);
+ } else {
+ synchronized (kit2searchable) {
+ searchableKit = kit2searchable.get(kit);
+ if (searchableKit == null) {
+ searchableKit = new DefaultSearchableKit(kit);
+ registerSearchableKit(kit, searchableKit);
+ }
+ }
+ }
+ return searchableKit;
+ }
+
+ public static Lookup.Result createActionsLookupResult(String mimeType) {
+ if (!MimePath.validate(mimeType)) {
+ throw new IllegalArgumentException("Ïnvalid mimeType=\"" + mimeType + "\"");
+ }
+ Lookup lookup = Lookups.forPath(getPath(mimeType, "Actions"));
+ return lookup.lookupResult(Action.class);
+ }
+
+ private static String getPath(String mimeType, String subFolder) {
+ StringBuilder path = new StringBuilder(50);
+ path.append("Editors/");
+ if (mimeType.length() > 0) {
+ path.append('/').append(mimeType);
+ }
+ if (subFolder.length() > 0) {
+ path.append('/').append(subFolder);
+ }
+ return path.toString();
+ }
+
+ /**
+ * Get single-key accelerator for a given declared action.
+ * Only a single-key accelerators are supported.
+ */
+ public static KeyStroke getAccelerator(FileObject fo) {
+ if (fo == null) {
+ throw new IllegalArgumentException("Must be called with non-null fileObject"); // NOI18N
+ }
+ boolean fineLoggable = LOG.isLoggable(Level.FINE);
+ String path = fo.getParent().getPath();
+ String actionName = (String) fo.getAttribute(Action.NAME);
+ KeyStroke ks = null;
+ if (path.startsWith("Editors/")) {
+ path = path.substring(7); // Leave ending '/' to support "Editors/Actions"
+ if (path.endsWith("/Actions")) {
+ path = path.substring(0, path.length() - 8);
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+ String mimeType = path;
+ if (!MimePath.validate(mimeType)) {
+ LOG.info("Invalid mime-type='" + mimeType + "' of action's fileObject=" + fo); // NOI18N
+ }
+ ks = getAccelerator(mimeType, actionName);
+ } else if (fineLoggable) {
+ LOG.fine("No \"/Actions\" at end of mime-type='" + path +
+ "' of action's fileObject=" + fo); // NOI18N
+ }
+ } else if (fineLoggable) {
+ LOG.fine("No \"Editors/\" at begining of mime-type='" + path + // NOI18N
+ "' of action's fileObject=" + fo); // NOI18N
+ }
+
+ if (LOG.isLoggable(Level.FINER)) {
+ LOG.finer("Accelerator for action \"" + actionName + "\" is " + ks);
+ }
+ return ks;
+ }
+
+ /**
+ * Get single-key accelerator for a given declared action.
+ *
+ * Unfortunately currently there's no easy way to display multi-keybinding in menu-item
+ * (there's just JMenuItem.setAccelerator() and its impl is L&F-based)
+ * so just display single-keystroke accelerators.
+ */
+ public static KeyStroke getAccelerator(String mimeType, String actionName) {
+ KeyStroke ks = null;
+ if (actionName != null) {
+ synchronized (EditorActionUtilities.class) {
+ if (mimeType2actionName2KeyStroke == null) {
+ mimeType2actionName2KeyStroke = new HashMap>();
+ }
+ Map actionName2KeyStrokeList = mimeType2actionName2KeyStroke.get(mimeType);
+ if (actionName2KeyStrokeList == null) {
+ actionName2KeyStrokeList = new HashMap();
+ Lookup.Result result = MimeLookup.getLookup(mimeType).lookupResult(
+ KeyBindingSettings.class);
+ Collection extends KeyBindingSettings> instances = result.allInstances();
+ if (!instances.isEmpty()) {
+ KeyBindingSettings kbs = instances.iterator().next();
+ for (MultiKeyBinding kb : kbs.getKeyBindings()) {
+ if (!actionName2KeyStrokeList.containsKey(kb.getActionName())
+ && kb.getKeyStrokeCount() == 1)
+ {
+ actionName2KeyStrokeList.put(kb.getActionName(), kb.getKeyStroke(0));
+ }
+ }
+ }
+ mimeType2actionName2KeyStroke.put(mimeType, actionName2KeyStrokeList);
+ // Ensure listening on changes in keybinding settings
+ if (!Boolean.TRUE.equals(mimeType2ListenerPresent.get(mimeType))) {
+ mimeType2ListenerPresent.put(mimeType, true);
+ result.addLookupListener(KeyBindingSettingsListener.INSTANCE);
+ }
+ }
+ ks = actionName2KeyStrokeList.get(actionName);
+ }
+ }
+ return ks;
+ }
+
+ private static final class KeyBindingSettingsListener implements LookupListener {
+
+ static final KeyBindingSettingsListener INSTANCE = new KeyBindingSettingsListener();
+
+ private KeyBindingSettingsListener() {
+ }
+
+ public void resultChanged(LookupEvent ev) {
+ synchronized (EditorActionUtilities.class) {
+ mimeType2actionName2KeyStroke = null;
+ LOG.fine("mimeType2actionName2KeyStroke cleared."); // NOI18N
+ }
+ }
+
+ }
+
+ private static final class DefaultSearchableKit implements SearchableEditorKit {
+
+ private final Map> name2actionRef = new WeakHashMap>();
+
+ DefaultSearchableKit(EditorKit kit) {
+ for (Action action : kit.getActions()) {
+ if (action != null) {
+ name2actionRef.put((String)action.getValue(Action.NAME), new WeakReference(action));
+ }
+ }
+ }
+
+ public Action getAction(String actionName) {
+ Reference actionRef = name2actionRef.get(actionName);
+ return (actionRef != null) ? actionRef.get() : null;
+ }
+
+ public void addActionsChangeListener(ChangeListener listener) {
+ }
+
+ public void removeActionsChangeListener(ChangeListener listener) {
+ }
+
+
+ }
+
+}
diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionsProvider.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionsProvider.java
new file mode 100644
--- /dev/null
+++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionsProvider.java
@@ -0,0 +1,59 @@
+/*
+ * 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.lib2.actions;
+
+import java.util.List;
+import javax.swing.Action;
+
+/**
+ * Abstract class implemented by editor module providing editor actions.
+ *
+ * @author Vita Stejskal
+ * @since 1.39
+ */
+public interface EditorActionsProvider {
+
+ List getActionsOnly();
+
+ List