Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 166027 | Differences between
and this patch

Collapse All | Expand All

(-)a/editor.actions/build.xml (+47 lines)
Line 0    Link Here 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
7
8
The contents of this file are subject to the terms of either the GNU
9
General Public License Version 2 only ("GPL") or the Common
10
Development and Distribution License("CDDL") (collectively, the
11
"License"). You may not use this file except in compliance with the
12
License. You can obtain a copy of the License at
13
http://www.netbeans.org/cddl-gplv2.html
14
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15
specific language governing permissions and limitations under the
16
License.  When distributing the software, include this License Header
17
Notice in each file and include the License file at
18
nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
19
particular file as subject to the "Classpath" exception as provided
20
by Sun in the GPL Version 2 section of the License file that
21
accompanied this code. If applicable, add the following below the
22
License Header, with the fields enclosed by brackets [] replaced by
23
your own identifying information:
24
"Portions Copyrighted [year] [name of copyright owner]"
25
26
Contributor(s):
27
28
The Original Software is NetBeans. The Initial Developer of the Original
29
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
Microsystems, Inc. All Rights Reserved.
31
32
If you wish your version of this file to be governed by only the CDDL
33
or only the GPL Version 2, indicate your decision by adding
34
"[Contributor] elects to include this software in this distribution
35
under the [CDDL or GPL Version 2] license." If you do not indicate a
36
single choice of license, a recipient has the option to distribute
37
your version of this file under either the CDDL, the GPL Version 2 or
38
to extend the choice of license to its licensees as provided above.
39
However, if you add GPL Version 2 code and therefore, elected the GPL
40
Version 2 license, then the option applies only if the new code is
41
made subject to such option by the copyright holder.
42
-->
43
44
<project name="editor.actions" default="netbeans" basedir=".">
45
    <import file="../nbbuild/templates/projectized.xml"/>
46
47
</project>
(-)a/editor.actions/manifest.mf (+5 lines)
Line 0    Link Here 
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.editor.actions/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/actions/Bundle.properties
4
AutoUpdate-Show-In-Client: false
5
OpenIDE-Module-Provides: org.netbeans.modules.editor.actions
(-)a/editor.actions/nbproject/project.properties (+46 lines)
Line 0    Link Here 
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
4
#
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
7
# Development and Distribution License("CDDL") (collectively, the
8
# "License"). You may not use this file except in compliance with the
9
# License. You can obtain a copy of the License at
10
# http://www.netbeans.org/cddl-gplv2.html
11
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12
# specific language governing permissions and limitations under the
13
# License.  When distributing the software, include this License Header
14
# Notice in each file and include the License file at
15
# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
16
# particular file as subject to the "Classpath" exception as provided
17
# by Sun in the GPL Version 2 section of the License file that
18
# accompanied this code. If applicable, add the following below the
19
# License Header, with the fields enclosed by brackets [] replaced by
20
# your own identifying information:
21
# "Portions Copyrighted [year] [name of copyright owner]"
22
#
23
# Contributor(s):
24
#
25
# The Original Software is NetBeans. The Initial Developer of the Original
26
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
# Microsystems, Inc. All Rights Reserved.
28
#
29
# If you wish your version of this file to be governed by only the CDDL
30
# or only the GPL Version 2, indicate your decision by adding
31
# "[Contributor] elects to include this software in this distribution
32
# under the [CDDL or GPL Version 2] license." If you do not indicate a
33
# single choice of license, a recipient has the option to distribute
34
# your version of this file under either the CDDL, the GPL Version 2 or
35
# to extend the choice of license to its licensees as provided above.
36
# However, if you add GPL Version 2 code and therefore, elected the GPL
37
# Version 2 license, then the option applies only if the new code is
38
# made subject to such option by the copyright holder.
39
40
javac.compilerargs=-Xlint:unchecked
41
javac.source=1.5
42
javadoc.title=Editor Actions
43
spec.version.base=1.0.0
44
45
#javadoc.arch=${basedir}/arch.xml
46
#javadoc.apichanges=${basedir}/apichanges.xml
(-)a/editor.actions/nbproject/project.xml (+98 lines)
Line 0    Link Here 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
7
8
The contents of this file are subject to the terms of either the GNU
9
General Public License Version 2 only ("GPL") or the Common
10
Development and Distribution License("CDDL") (collectively, the
11
"License"). You may not use this file except in compliance with the
12
License. You can obtain a copy of the License at
13
http://www.netbeans.org/cddl-gplv2.html
14
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15
specific language governing permissions and limitations under the
16
License.  When distributing the software, include this License Header
17
Notice in each file and include the License file at
18
nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
19
particular file as subject to the "Classpath" exception as provided
20
by Sun in the GPL Version 2 section of the License file that
21
accompanied this code. If applicable, add the following below the
22
License Header, with the fields enclosed by brackets [] replaced by
23
your own identifying information:
24
"Portions Copyrighted [year] [name of copyright owner]"
25
26
Contributor(s):
27
28
The Original Software is NetBeans. The Initial Developer of the Original
29
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
Microsystems, Inc. All Rights Reserved.
31
32
If you wish your version of this file to be governed by only the CDDL
33
or only the GPL Version 2, indicate your decision by adding
34
"[Contributor] elects to include this software in this distribution
35
under the [CDDL or GPL Version 2] license." If you do not indicate a
36
single choice of license, a recipient has the option to distribute
37
your version of this file under either the CDDL, the GPL Version 2 or
38
to extend the choice of license to its licensees as provided above.
39
However, if you add GPL Version 2 code and therefore, elected the GPL
40
Version 2 license, then the option applies only if the new code is
41
made subject to such option by the copyright holder.
42
-->
43
<project xmlns="http://www.netbeans.org/ns/project/1">
44
    <type>org.netbeans.modules.apisupport.project</type>
45
    <configuration>
46
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
47
            <code-name-base>org.netbeans.modules.editor.actions</code-name-base>
48
            <module-dependencies>
49
                <dependency>
50
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
51
                    <build-prerequisite/>
52
                    <compile-dependency/>
53
                    <run-dependency>
54
                        <release-version>1</release-version>
55
                        <specification-version>1.40</specification-version>
56
                    </run-dependency>
57
                </dependency>
58
                <dependency>
59
                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
60
                    <build-prerequisite/>
61
                    <compile-dependency/>
62
                    <run-dependency>
63
                        <release-version>1</release-version>
64
                        <implementation-version/>
65
                    </run-dependency>
66
                </dependency>
67
                <dependency>
68
                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
69
                    <build-prerequisite/>
70
                    <compile-dependency/>
71
                    <run-dependency>
72
                        <release-version>1</release-version>
73
                        <specification-version>1.12</specification-version>
74
                    </run-dependency>
75
                </dependency>
76
                <dependency>
77
                    <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
78
                    <build-prerequisite/>
79
                    <compile-dependency/>
80
                    <run-dependency>
81
                        <release-version>1</release-version>
82
                        <specification-version>1.25</specification-version>
83
                    </run-dependency>
84
                </dependency>
85
                <dependency>
86
                    <code-name-base>org.openide.util</code-name-base>
87
                    <build-prerequisite/>
88
                    <compile-dependency/>
89
                    <run-dependency>
90
                        <specification-version>7.24</specification-version>
91
                    </run-dependency>
92
                </dependency>
93
            </module-dependencies>
94
            <test-dependencies/>
95
            <public-packages/>
96
        </data>
97
    </configuration>
98
</project>
(-)a/editor.actions/src/org/netbeans/modules/editor/actions/Bundle.properties (+51 lines)
Line 0    Link Here 
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
4
#
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
7
# Development and Distribution License("CDDL") (collectively, the
8
# "License"). You may not use this file except in compliance with the
9
# License. You can obtain a copy of the License at
10
# http://www.netbeans.org/cddl-gplv2.html
11
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12
# specific language governing permissions and limitations under the
13
# License.  When distributing the software, include this License Header
14
# Notice in each file and include the License file at
15
# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
16
# particular file as subject to the "Classpath" exception as provided
17
# by Sun in the GPL Version 2 section of the License file that
18
# accompanied this code. If applicable, add the following below the
19
# License Header, with the fields enclosed by brackets [] replaced by
20
# your own identifying information:
21
# "Portions Copyrighted [year] [name of copyright owner]"
22
#
23
# Contributor(s):
24
#
25
# The Original Software is NetBeans. The Initial Developer of the Original
26
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
# Microsystems, Inc. All Rights Reserved.
28
#
29
# If you wish your version of this file to be governed by only the CDDL
30
# or only the GPL Version 2, indicate your decision by adding
31
# "[Contributor] elects to include this software in this distribution
32
# under the [CDDL or GPL Version 2] license." If you do not indicate a
33
# single choice of license, a recipient has the option to distribute
34
# your version of this file under either the CDDL, the GPL Version 2 or
35
# to extend the choice of license to its licensees as provided above.
36
# However, if you add GPL Version 2 code and therefore, elected the GPL
37
# Version 2 license, then the option applies only if the new code is
38
# made subject to such option by the copyright holder.
39
40
OpenIDE-Module-Name=Editor Actions
41
OpenIDE-Module-Display-Category=Editing
42
OpenIDE-Module-Short-Description=Contains editor actions implementations
43
OpenIDE-Module-Long-Description=Editor Actions module contains default editor actions implementations.
44
45
# Actions
46
toggle-toolbar=Toggle Toolbar
47
toggle-toolbar_menu_text=S&how Editor Toolbar
48
toggle-line-numbers=Toggle Line Numbers
49
toggle-line-numbers_menu_text=&Show Line Numbers
50
goto-declaration=Go to Declaration
51
goto-declaration_menu_text=Go to &Declaration
(-)a/editor.actions/src/org/netbeans/modules/editor/actions/GotoAction.java (+98 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.actions;
41
42
import org.netbeans.modules.editor.lib2.actions.AbstractEditorAction;
43
import java.awt.event.ActionEvent;
44
import java.util.logging.Logger;
45
import javax.swing.text.BadLocationException;
46
import javax.swing.text.Caret;
47
import javax.swing.text.JTextComponent;
48
import org.netbeans.api.editor.EditorActionRegistration;
49
import org.netbeans.api.editor.EditorActionRegistrations;
50
import org.netbeans.editor.BaseDocument;
51
import org.netbeans.editor.Utilities;
52
import org.netbeans.editor.ext.ExtSyntaxSupport;
53
import org.netbeans.modules.editor.lib2.actions.EditorActionNames;
54
55
/**
56
 * Toggle toolbar/lines visibility.
57
 *
58
 * @author Miloslav Metelka
59
 * @since 1.13
60
 */
61
62
@EditorActionRegistrations({
63
    @EditorActionRegistration(
64
        name = EditorActionNames.gotoDeclarationAction,
65
        menuPath = "GoTo",
66
        menuPosition = 900,
67
        menuText = "#" + EditorActionNames.gotoDeclarationAction + "_menu_text"
68
    )
69
})
70
public final class GotoAction extends AbstractEditorAction {
71
72
    // -J-Dorg.netbeans.modules.editor.actions.GotoAction.level=FINEST
73
    private static final Logger LOG = Logger.getLogger(GotoAction.class.getName());
74
75
    public void actionPerformed(ActionEvent evt, JTextComponent target) {
76
        String actionName = actionName();
77
        if (EditorActionNames.gotoDeclarationAction.equals(actionName)) {
78
            magicPositionReset(target);
79
            BaseDocument doc = Utilities.getDocument(target);
80
            if (doc != null) {
81
                try {
82
                    Caret caret = target.getCaret();
83
                    int dotPos = caret.getDot();
84
                    int[] idBlk = Utilities.getIdentifierBlock(doc, dotPos);
85
                    ExtSyntaxSupport extSup = (ExtSyntaxSupport)doc.getSyntaxSupport();
86
                    if (idBlk != null) {
87
                        int decPos = extSup.findDeclarationPosition(doc.getText(idBlk), idBlk[1]);
88
                        if (decPos >= 0) {
89
                            caret.setDot(decPos);
90
                        }
91
                    }
92
                } catch (BadLocationException e) {
93
                }
94
            }
95
        }
96
    }
97
98
}
(-)a/editor.actions/src/org/netbeans/modules/editor/actions/ToggleAction.java (+158 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.actions;
41
42
import java.util.prefs.PreferenceChangeEvent;
43
import java.util.prefs.PreferenceChangeListener;
44
import org.netbeans.modules.editor.lib2.actions.AbstractEditorAction;
45
import java.awt.event.ActionEvent;
46
import java.util.Map;
47
import java.util.logging.Logger;
48
import java.util.prefs.Preferences;
49
import javax.swing.text.JTextComponent;
50
import org.netbeans.api.editor.EditorActionRegistration;
51
import org.netbeans.api.editor.EditorActionRegistrations;
52
import org.netbeans.api.editor.mimelookup.MimeLookup;
53
import org.netbeans.api.editor.mimelookup.MimePath;
54
import org.netbeans.api.editor.settings.SimpleValueNames;
55
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
56
import org.netbeans.modules.editor.lib2.actions.EditorActionNames;
57
import org.openide.util.Lookup;
58
import org.openide.util.LookupEvent;
59
import org.openide.util.LookupListener;
60
61
/**
62
 * Toggle toolbar/lines visibility.
63
 *
64
 * @author Miloslav Metelka
65
 * @since 1.13
66
 */
67
public final class ToggleAction extends AbstractEditorAction {
68
69
@EditorActionRegistrations({
70
    @EditorActionRegistration(
71
        name = EditorActionNames.toggleToolbarAction,
72
        menuPath = "View",
73
        menuPosition = 800,
74
        menuText = "#" + EditorActionNames.toggleToolbarAction + "_menu_text",
75
        presenterType = "CheckBox"
76
    ),
77
    @EditorActionRegistration(
78
        name = EditorActionNames.toggleLineNumbersAction,
79
        menuPath = "View",
80
        menuPosition = 850,
81
        menuText = "#" + EditorActionNames.toggleLineNumbersAction + "_menu_text",
82
        presenterType = "CheckBox"
83
    )
84
})
85
    public static ToggleAction create(Map<String,?> attrs) {
86
        return new ToggleAction(attrs);
87
    }
88
89
    // -J-Dorg.netbeans.modules.editor.actions.ToggleAction.level=FINEST
90
    private static final Logger LOG = Logger.getLogger(ToggleAction.class.getName());
91
92
    private String settingName;
93
94
    private Boolean defaultValue;
95
96
    private LookupListener lookupListener;
97
98
    private PreferenceChangeListener preferenceChangeListener;
99
100
    public ToggleAction(Map<String,?> attrs) {
101
        super(attrs);
102
    }
103
104
    @Override
105
    protected void actionNameUpdate(String actionName) {
106
        super.actionNameUpdate(actionName);
107
108
        if (EditorActionNames.toggleToolbarAction.equals(actionName)) {
109
            settingName = SimpleValueNames.TOOLBAR_VISIBLE_PROP;
110
            defaultValue = EditorPreferencesDefaults.defaultToolbarVisible;
111
        } else if (EditorActionNames.toggleLineNumbersAction.equals(actionName)) {
112
            settingName = SimpleValueNames.LINE_NUMBER_VISIBLE;
113
            defaultValue = EditorPreferencesDefaults.defaultLineNumberVisible;
114
        } else {
115
            throw new IllegalStateException("Unsupported actionName='" + actionName + "'"); // NOI18N
116
        }
117
118
        updateSelected();
119
    }
120
121
    public void actionPerformed(ActionEvent evt, JTextComponent target) {
122
        boolean newSelected = !isSelected();
123
        prefs().putBoolean(settingName, newSelected);
124
        updateSelected();
125
    }
126
127
    private boolean isSelected() {
128
        return prefs().getBoolean(settingName, defaultValue);
129
    }
130
131
    private void updateSelected() {
132
        System.err.println("action: " + actionName() + ", SELECTED_KEY: " + isSelected());
133
        putValue(AbstractEditorAction.SELECTED_KEY, isSelected());
134
    }
135
136
    private Preferences prefs() {
137
        Lookup globalMimeLookup = MimeLookup.getLookup(MimePath.EMPTY);
138
        Preferences prefs = globalMimeLookup.lookup(Preferences.class);
139
        if (lookupListener == null) {
140
            globalMimeLookup.lookupResult(Preferences.class).addLookupListener(lookupListener = new LookupListener() {
141
                public void resultChanged(LookupEvent evt) {
142
                    updateSelected();
143
                }
144
            });
145
        }
146
        if (preferenceChangeListener == null) {
147
            prefs.addPreferenceChangeListener(preferenceChangeListener = new PreferenceChangeListener() {
148
                public void preferenceChange(PreferenceChangeEvent evt) {
149
                    if (settingName.equals(evt.getKey())) {
150
                        updateSelected();
151
                    }
152
                }
153
            });
154
        }
155
        return prefs;
156
    }
157
158
}
(-)a/editor.deprecated.pre61settings/nbproject/project.xml (+9 lines)
 Lines 65-70    Link Here 
65
                    </run-dependency>
65
                    </run-dependency>
66
                </dependency>
66
                </dependency>
67
                <dependency>
67
                <dependency>
68
                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
69
                    <build-prerequisite/>
70
                    <compile-dependency/>
71
                    <run-dependency>
72
                        <release-version>1</release-version>
73
                        <implementation-version/>
74
                    </run-dependency>
75
                </dependency>
76
                <dependency>
68
                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
77
                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
69
                    <build-prerequisite/>
78
                    <build-prerequisite/>
70
                    <compile-dependency/>
79
                    <compile-dependency/>
(-)a/editor.deprecated.pre61settings/src/org/netbeans/editor/SettingsDefaults.java (-3 / +3 lines)
 Lines 48-54    Link Here 
48
import javax.swing.UIManager;
48
import javax.swing.UIManager;
49
import java.util.Map;
49
import java.util.Map;
50
import java.util.HashMap;
50
import java.util.HashMap;
51
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
51
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
52
52
53
/**
53
/**
54
* Default values for the settings. They are used
54
* Default values for the settings. They are used
 Lines 156-163    Link Here 
156
    public static final Color defaultTextLimitLineColor = new Color(255, 235, 235);
156
    public static final Color defaultTextLimitLineColor = new Color(255, 235, 235);
157
    public static final Integer defaultTextLimitWidth = EditorPreferencesDefaults.defaultTextLimitWidth;
157
    public static final Integer defaultTextLimitWidth = EditorPreferencesDefaults.defaultTextLimitWidth;
158
158
159
    public static final Acceptor defaultIdentifierAcceptor = EditorPreferencesDefaults.defaultIdentifierAcceptor;
159
//    public static final Acceptor defaultIdentifierAcceptor = EditorPreferencesDefaults.defaultIdentifierAcceptor;
160
    public static final Acceptor defaultWhitespaceAcceptor = EditorPreferencesDefaults.defaultWhitespaceAcceptor;
160
//    public static final Acceptor defaultWhitespaceAcceptor = EditorPreferencesDefaults.defaultWhitespaceAcceptor;
161
161
162
    public static final Float defaultLineHeightCorrection = EditorPreferencesDefaults.defaultLineHeightCorrection;
162
    public static final Float defaultLineHeightCorrection = EditorPreferencesDefaults.defaultLineHeightCorrection;
163
163
(-)a/editor.deprecated.pre61settings/src/org/netbeans/editor/SettingsNames.java (-1 / +1 lines)
 Lines 41-47    Link Here 
41
41
42
package org.netbeans.editor;
42
package org.netbeans.editor;
43
43
44
import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
44
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
45
45
46
/**
46
/**
47
* Names of the base settings defined in the editor. The other packages
47
* Names of the base settings defined in the editor. The other packages
(-)a/editor.deprecated.pre61settings/src/org/netbeans/editor/ext/ExtSettingsNames.java (-1 / +1 lines)
 Lines 42-48    Link Here 
42
package org.netbeans.editor.ext;
42
package org.netbeans.editor.ext;
43
43
44
import org.netbeans.editor.SettingsNames;
44
import org.netbeans.editor.SettingsNames;
45
import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
45
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
46
46
47
/**
47
/**
48
* Names of the extended editor settings.
48
* Names of the extended editor settings.
(-)a/editor.lib/nbproject/project.xml (-1 / +1 lines)
 Lines 87-93    Link Here 
87
                    <compile-dependency/>
87
                    <compile-dependency/>
88
                    <run-dependency>
88
                    <run-dependency>
89
                        <release-version>1</release-version>
89
                        <release-version>1</release-version>
90
                        <specification-version>1.25</specification-version>
90
                        <specification-version>1.30</specification-version>
91
                    </run-dependency>
91
                    </run-dependency>
92
                </dependency>
92
                </dependency>
93
                <dependency>
93
                <dependency>
(-)a/editor.lib/src/org/netbeans/editor/Analyzer.java (-1 / +1 lines)
 Lines 51-57    Link Here 
51
import javax.swing.text.Document;
51
import javax.swing.text.Document;
52
import javax.swing.text.Segment;
52
import javax.swing.text.Segment;
53
import org.netbeans.api.lexer.TokenHierarchy;
53
import org.netbeans.api.lexer.TokenHierarchy;
54
import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
54
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
55
import org.netbeans.spi.lexer.MutableTextInput;
55
import org.netbeans.spi.lexer.MutableTextInput;
56
56
57
/**
57
/**
(-)a/editor.lib/src/org/netbeans/editor/BaseAction.java (-9 / +12 lines)
 Lines 56-69    Link Here 
56
import javax.swing.text.Caret;
56
import javax.swing.text.Caret;
57
57
58
/**
58
/**
59
* This is the parent of majority of the actions. It implements
59
 * This is the parent of majority of the actions. It implements
60
* the necessary resetting depending of what is required
60
 * the necessary resetting depending of what is required
61
* by constructor of target action.
61
 * by constructor of target action.
62
* The other thing implemented here is macro recording.
62
 * The other thing implemented here is macro recording.
63
*
63
 * <br/>
64
* @author Miloslav Metelka
64
 * Property "noIconInMenu" can be set to inform menu items not to use action's icon.
65
* @version 1.00
65
 * <br/>
66
*/
66
 *
67
 * @author Miloslav Metelka
68
 * @version 1.00
69
 */
67
70
68
public abstract class BaseAction extends TextAction {
71
public abstract class BaseAction extends TextAction {
69
72
 Lines 120-126    Link Here 
120
    * the action's real task is invoked.
123
    * the action's real task is invoked.
121
    */
124
    */
122
    protected int updateMask;
125
    protected int updateMask;
123
    
126
124
    private static boolean recording;
127
    private static boolean recording;
125
    private static StringBuffer macroBuffer = new StringBuffer();
128
    private static StringBuffer macroBuffer = new StringBuffer();
126
    private static StringBuffer textBuffer = new StringBuffer();
129
    private static StringBuffer textBuffer = new StringBuffer();
(-)a/editor.lib/src/org/netbeans/editor/BaseCaret.java (-3 / +3 lines)
 Lines 105-111    Link Here 
105
import org.netbeans.api.editor.settings.FontColorSettings;
105
import org.netbeans.api.editor.settings.FontColorSettings;
106
import org.netbeans.api.editor.settings.SimpleValueNames;
106
import org.netbeans.api.editor.settings.SimpleValueNames;
107
import org.netbeans.lib.editor.util.swing.DocumentListenerPriority;
107
import org.netbeans.lib.editor.util.swing.DocumentListenerPriority;
108
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
108
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
109
import org.netbeans.modules.editor.lib.SettingsConversions;
109
import org.netbeans.modules.editor.lib.SettingsConversions;
110
import org.openide.util.WeakListeners;
110
import org.openide.util.WeakListeners;
111
111
 Lines 122-131    Link Here 
122
AtomicLockListener, FoldHierarchyListener {
122
AtomicLockListener, FoldHierarchyListener {
123
123
124
    /** Caret type representing block covering current character */
124
    /** Caret type representing block covering current character */
125
    public static final String BLOCK_CARET = "block-caret"; // NOI18N
125
    public static final String BLOCK_CARET = EditorPreferencesDefaults.BLOCK_CARET; // NOI18N
126
126
127
    /** Default caret type */
127
    /** Default caret type */
128
    public static final String LINE_CARET = "line-caret"; // NOI18N
128
    public static final String LINE_CARET = EditorPreferencesDefaults.LINE_CARET; // NOI18N
129
129
130
    /** One dot thin line compatible with Swing default caret */
130
    /** One dot thin line compatible with Swing default caret */
131
    public static final String THIN_LINE_CARET = "thin-line-caret"; // NOI18N
131
    public static final String THIN_LINE_CARET = "thin-line-caret"; // NOI18N
(-)a/editor.lib/src/org/netbeans/editor/BaseDocument.java (-2 / +2 lines)
 Lines 92-99    Link Here 
92
import org.netbeans.lib.editor.util.ListenerList;
92
import org.netbeans.lib.editor.util.ListenerList;
93
import org.netbeans.lib.editor.util.swing.DocumentListenerPriority;
93
import org.netbeans.lib.editor.util.swing.DocumentListenerPriority;
94
import org.netbeans.modules.editor.lib.EditorPackageAccessor;
94
import org.netbeans.modules.editor.lib.EditorPackageAccessor;
95
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
95
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
96
import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
96
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
97
import org.netbeans.modules.editor.lib.FormatterOverride;
97
import org.netbeans.modules.editor.lib.FormatterOverride;
98
import org.netbeans.modules.editor.lib.TrailingWhitespaceRemove;
98
import org.netbeans.modules.editor.lib.TrailingWhitespaceRemove;
99
import org.netbeans.modules.editor.lib.SettingsConversions;
99
import org.netbeans.modules.editor.lib.SettingsConversions;
(-)a/editor.lib/src/org/netbeans/editor/BaseKit.java (-17 / +97 lines)
 Lines 65-70    Link Here 
65
import javax.swing.text.Caret;
65
import javax.swing.text.Caret;
66
import javax.swing.text.JTextComponent;
66
import javax.swing.text.JTextComponent;
67
import java.io.CharArrayWriter;
67
import java.io.CharArrayWriter;
68
import java.lang.ref.WeakReference;
68
import java.lang.reflect.Method;
69
import java.lang.reflect.Method;
69
import java.util.Set;
70
import java.util.Set;
70
import java.util.Vector;
71
import java.util.Vector;
 Lines 74-79    Link Here 
74
import java.util.prefs.PreferenceChangeListener;
75
import java.util.prefs.PreferenceChangeListener;
75
import java.util.prefs.Preferences;
76
import java.util.prefs.Preferences;
76
import javax.swing.KeyStroke;
77
import javax.swing.KeyStroke;
78
import javax.swing.event.ChangeEvent;
79
import javax.swing.event.ChangeListener;
77
import javax.swing.text.AbstractDocument;
80
import javax.swing.text.AbstractDocument;
78
import javax.swing.text.EditorKit;
81
import javax.swing.text.EditorKit;
79
import javax.swing.text.Position;
82
import javax.swing.text.Position;
 Lines 82-90    Link Here 
82
import org.netbeans.api.editor.mimelookup.MimeLookup;
85
import org.netbeans.api.editor.mimelookup.MimeLookup;
83
import org.netbeans.api.editor.mimelookup.MimePath;
86
import org.netbeans.api.editor.mimelookup.MimePath;
84
import org.netbeans.api.editor.settings.KeyBindingSettings;
87
import org.netbeans.api.editor.settings.KeyBindingSettings;
88
import org.netbeans.lib.editor.util.ListenerList;
85
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
89
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
86
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
90
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
87
import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
91
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
88
import org.netbeans.modules.editor.lib.KitsTracker;
92
import org.netbeans.modules.editor.lib.KitsTracker;
89
import org.netbeans.modules.editor.lib.NavigationHistory;
93
import org.netbeans.modules.editor.lib.NavigationHistory;
90
import org.netbeans.modules.editor.lib.SettingsConversions;
94
import org.netbeans.modules.editor.lib.SettingsConversions;
 Lines 113-118    Link Here 
113
     */
117
     */
114
    static ThreadLocal<Boolean> IN_PASTE = new ThreadLocal<Boolean>();
118
    static ThreadLocal<Boolean> IN_PASTE = new ThreadLocal<Boolean>();
115
119
120
    // -J-Dorg.netbeans.editor.BaseKit.level=FINEST
116
    private static final Logger LOG = Logger.getLogger(BaseKit.class.getName());
121
    private static final Logger LOG = Logger.getLogger(BaseKit.class.getName());
117
    
122
    
118
    /** split the current line at cursor position */
123
    /** split the current line at cursor position */
 Lines 352-357    Link Here 
352
    
357
    
353
    public static final int MAGIC_POSITION_MAX = Integer.MAX_VALUE - 1;
358
    public static final int MAGIC_POSITION_MAX = Integer.MAX_VALUE - 1;
354
359
360
    private final SearchableKit searchableKit;
361
355
//    static SettingsChangeListener settingsListener = new SettingsChangeListener() {
362
//    static SettingsChangeListener settingsListener = new SettingsChangeListener() {
356
//        public void settingsChange(SettingsChangeEvent evt) {
363
//        public void settingsChange(SettingsChangeEvent evt) {
357
//            String settingName = (evt != null) ? evt.getSettingName() : null;
364
//            String settingName = (evt != null) ? evt.getSettingName() : null;
 Lines 534-539    Link Here 
534
                kits.put(this.getClass(), this); // register itself
541
                kits.put(this.getClass(), this); // register itself
535
            }
542
            }
536
        }
543
        }
544
        // Directly implementing searchable editor kit would require module dependency changes
545
        // of any modules using BaseKit reference so make a wrapper instead
546
        org.netbeans.modules.editor.lib2.actions.EditorActionUtilities.registerSearchableKit(this,
547
                searchableKit = new SearchableKit(this));
537
    }
548
    }
538
549
539
    /** Clone this editor kit */
550
    /** Clone this editor kit */
 Lines 691-711    Link Here 
691
    /** Creates map with [name, action] pairs from the given
702
    /** Creates map with [name, action] pairs from the given
692
    * array of actions.
703
    * array of actions.
693
    */
704
    */
694
    public static Map<String, Action> actionsToMap(Action[] actions) {
705
    public static void addActionsToMap(Map<String, Action> map, Action[] actions, String logActionsType) {
695
        Map<String, Action> map = new HashMap<String, Action>();
706
        boolean fineLoggable = LOG.isLoggable(Level.FINE);
707
        if (fineLoggable) {
708
            LOG.fine(logActionsType + " start --------------------\n");
709
        }
696
        for (int i = 0; i < actions.length; i++) {
710
        for (int i = 0; i < actions.length; i++) {
697
            Action a = actions[i];
711
            Action a = actions[i];
698
            if (a == null) {
712
            if (a == null) {
699
                throw new IllegalStateException("actions[] contains null at index " + i +
713
                LOG.info("actions[] contains null at index " + i +
700
                        ((i > 0) ? ". Preceding action is " + actions[i - 1] : ""));
714
                        ((i > 0) ? ". Preceding action is " + actions[i - 1] : "."));
715
                continue;
701
            }
716
            }
702
            String name = (String) a.getValue(Action.NAME);
717
            String name = (String) a.getValue(Action.NAME);
703
            if (name == null) {
718
            if (name == null) {
704
                throw new IllegalStateException("Null Action.NAME property of action " + a);
719
                LOG.info("Null Action.NAME property of action " + a);
720
                continue;
705
            }
721
            }
722
723
            if (fineLoggable) {
724
                String overriding = map.containsKey(name) ? " OVERRIDING\n" : "\n"; // NOI18N
725
                LOG.fine("    " + name + ": " + a + overriding); // NOI18N
726
            }
727
706
            map.put(name, a); // NOI18N
728
            map.put(name, a); // NOI18N
707
        }
729
        }
708
        return map;
730
        if (fineLoggable) {
731
            LOG.fine(logActionsType + " end ----------------------\n");
732
        }
709
    }
733
    }
710
734
711
    /** Converts map with [name, action] back
735
    /** Converts map with [name, action] back
 Lines 848-854    Link Here 
848
                   removeSelectionActionDef,
872
                   removeSelectionActionDef,
849
                   undoActionDef,
873
                   undoActionDef,
850
                   redoActionDef,
874
                   redoActionDef,
851
                   new ActionFactory.ToggleLineNumbersAction(),
875
                   //new ActionFactory.ToggleLineNumbersAction(),
852
                   new NextWordAction(nextWordAction),
876
                   new NextWordAction(nextWordAction),
853
                   new NextWordAction(selectionNextWordAction),
877
                   new NextWordAction(selectionNextWordAction),
854
                   new PreviousWordAction(previousWordAction),
878
                   new PreviousWordAction(previousWordAction),
 Lines 895-925    Link Here 
895
    * to get basic list and then customActions are added.
919
    * to get basic list and then customActions are added.
896
    */
920
    */
897
    public @Override final Action[] getActions() {
921
    public @Override final Action[] getActions() {
898
        return (Action []) getActionsAndMap()[0];
922
        return (Action []) addActionsToMap()[0];
899
    }
923
    }
900
924
901
    /* package */ Map<String, Action> getActionMap() {
925
    /* package */ Map<String, Action> getActionMap() {
902
        return (Map<String, Action>) getActionsAndMap()[1];
926
        return (Map<String, Action>) addActionsToMap()[1];
903
    }
927
    }
904
928
905
    private Object[] getActionsAndMap() {
929
    private Object[] addActionsToMap() {
906
        synchronized (KEYMAPS_AND_ACTIONS_LOCK) {
930
        synchronized (KEYMAPS_AND_ACTIONS_LOCK) {
907
            MimePath mimePath = MimePath.parse(getContentType());
931
            MimePath mimePath = MimePath.parse(getContentType());
908
            Action[] actions = kitActions.get(mimePath);
932
            Action[] actions = kitActions.get(mimePath);
909
            Map<String, Action> actionMap = kitActionMaps.get(mimePath);
933
            Map<String, Action> actionMap = kitActionMaps.get(mimePath);
910
            
934
            
911
            if (actions == null || actionMap == null) {
935
            if (actions == null || actionMap == null) {
912
                // create map of actions
936
                // Initialize actions - use the following actions:
913
                actions = createActions();
937
                // 1. Declared "global" actions (declared in the xml layer under "Editors/Actions")
914
                actionMap = actionsToMap(actions);
938
                // 2. Declared "mime-type actions (declared in the xml layer under "Editors/content-type/Actions")
939
                // 3. Result of createActions()
940
                // 4. Custom actions (EditorPreferencesKeys.CUSTOM_ACTION_LIST)
941
                // Higher levels override actions with same Action.NAME
942
                actions = getDeclaredActions(); // non-null
943
                actionMap = new HashMap<String, Action>(actions.length << 1);
944
                addActionsToMap(actionMap, actions, "Declared actions"); // NOI18N
945
946
                Action[] createActionsMethodResult = createActions();
947
                if (createActionsMethodResult != null) {
948
                    addActionsToMap(actionMap, createActionsMethodResult, "Actions from createActions()"); // NOI18N
949
                }
915
                
950
                
916
                // add custom actions
951
                // add custom actions
917
                Action[] customActions = getCustomActions();
952
                Action[] customActions = getCustomActions();
918
                if (customActions != null) {
953
                if (customActions != null) {
919
                    actionMap.putAll(actionsToMap(customActions));
954
                    addActionsToMap(actionMap, customActions, "Custom actions"); // NOI18N
920
                    actions = actionMap.values().toArray(new Action[actionMap.values().size()]);
921
                }
955
                }
922
956
957
                actions = actionMap.values().toArray(new Action[actionMap.values().size()]);
958
923
                kitActions.put(mimePath, actions);
959
                kitActions.put(mimePath, actions);
924
                kitActionMaps.put(mimePath, actionMap);
960
                kitActionMaps.put(mimePath, actionMap);
925
961
 Lines 932-937    Link Here 
932
            return new Object [] { actions, actionMap };
968
            return new Object [] { actions, actionMap };
933
        }
969
        }
934
    }
970
    }
971
972
    /**
973
     * Get actions declared in the xml layer. They may be overriden by result
974
     * of <code>createActions()</code> and finally by result of <code>getCustomActions()</code>.
975
     *
976
     * @return non-null list of declared actions.
977
     */
978
    protected Action[] getDeclaredActions() {
979
        return new Action[0];
980
    }
935
    
981
    
936
    /** Update the actions right after their creation was finished.
982
    /** Update the actions right after their creation was finished.
937
     * The <code>getActions()</code> and <code>getActionByName()</code>
983
     * The <code>getActions()</code> and <code>getActionByName()</code>
 Lines 2725-2731    Link Here 
2725
            for(JTextComponent c : arr) {
2771
            for(JTextComponent c : arr) {
2726
                c.setKeymap(keymap);
2772
                c.setKeymap(keymap);
2727
            }
2773
            }
2774
2775
            searchableKit.fireActionsChange();
2728
        }
2776
        }
2729
        
2777
        
2730
    } // End of KeymapTracker class
2778
    } // End of KeymapTracker class
2779
2780
    private static final class SearchableKit implements org.netbeans.modules.editor.lib2.actions.SearchableEditorKit {
2781
2782
        private final BaseKit baseKit;
2783
2784
        private final ListenerList<ChangeListener> actionsListenerList = new ListenerList<ChangeListener>();
2785
2786
        SearchableKit(BaseKit baseKit) {
2787
            this.baseKit = baseKit;
2788
        }
2789
2790
        public Action getAction(String actionName) {
2791
            return baseKit.getActionByName(actionName);
2792
        }
2793
2794
        public void addActionsChangeListener(ChangeListener listener) {
2795
            actionsListenerList.add(listener);
2796
        }
2797
2798
        public void removeActionsChangeListener(ChangeListener listener) {
2799
            actionsListenerList.remove(listener);
2800
        }
2801
2802
        void fireActionsChange() {
2803
            ChangeEvent evt = new ChangeEvent(this);
2804
            for (ChangeListener listener : actionsListenerList.getListeners()) {
2805
                listener.stateChanged(evt);
2806
            }
2807
        }
2808
2809
    }
2810
2731
}
2811
}
(-)a/editor.lib/src/org/netbeans/editor/BaseTextUI.java (-2 / +2 lines)
 Lines 66-73    Link Here 
66
import org.netbeans.api.editor.settings.SimpleValueNames;
66
import org.netbeans.api.editor.settings.SimpleValueNames;
67
import org.netbeans.modules.editor.lib2.EditorApiPackageAccessor;
67
import org.netbeans.modules.editor.lib2.EditorApiPackageAccessor;
68
import org.netbeans.editor.view.spi.LockView;
68
import org.netbeans.editor.view.spi.LockView;
69
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
69
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
70
import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
70
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
71
import org.netbeans.modules.editor.lib.SettingsConversions;
71
import org.netbeans.modules.editor.lib.SettingsConversions;
72
import org.openide.util.WeakListeners;
72
import org.openide.util.WeakListeners;
73
73
(-)a/editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java (-1 / +1 lines)
 Lines 84-90    Link Here 
84
import org.netbeans.api.editor.settings.FontColorSettings;
84
import org.netbeans.api.editor.settings.FontColorSettings;
85
import org.netbeans.api.editor.settings.SimpleValueNames;
85
import org.netbeans.api.editor.settings.SimpleValueNames;
86
import org.netbeans.editor.CodeFoldingSideBar.PaintInfo;
86
import org.netbeans.editor.CodeFoldingSideBar.PaintInfo;
87
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
87
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
88
import org.netbeans.modules.editor.lib.SettingsConversions;
88
import org.netbeans.modules.editor.lib.SettingsConversions;
89
import org.openide.util.Lookup;
89
import org.openide.util.Lookup;
90
import org.openide.util.LookupEvent;
90
import org.openide.util.LookupEvent;
(-)a/editor.lib/src/org/netbeans/editor/EditorUI.java (-2 / +2 lines)
 Lines 86-93    Link Here 
86
import org.netbeans.editor.ext.ExtKit;
86
import org.netbeans.editor.ext.ExtKit;
87
import org.netbeans.editor.ext.ToolTipSupport;
87
import org.netbeans.editor.ext.ToolTipSupport;
88
import org.netbeans.modules.editor.lib.ColoringMap;
88
import org.netbeans.modules.editor.lib.ColoringMap;
89
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
89
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
90
import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
90
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
91
import org.netbeans.modules.editor.lib.KitsTracker;
91
import org.netbeans.modules.editor.lib.KitsTracker;
92
import org.netbeans.modules.editor.lib.SettingsConversions;
92
import org.netbeans.modules.editor.lib.SettingsConversions;
93
import org.openide.util.WeakListeners;
93
import org.openide.util.WeakListeners;
(-)a/editor.lib/src/org/netbeans/editor/Formatter.java (-1 / +1 lines)
 Lines 61-67    Link Here 
61
import org.netbeans.api.editor.settings.SimpleValueNames;
61
import org.netbeans.api.editor.settings.SimpleValueNames;
62
import org.netbeans.lib.editor.util.CharSequenceUtilities;
62
import org.netbeans.lib.editor.util.CharSequenceUtilities;
63
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
63
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
64
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
64
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
65
import org.netbeans.modules.editor.lib.KitsTracker;
65
import org.netbeans.modules.editor.lib.KitsTracker;
66
import org.netbeans.modules.editor.lib.SettingsConversions;
66
import org.netbeans.modules.editor.lib.SettingsConversions;
67
import org.openide.util.Lookup;
67
import org.openide.util.Lookup;
(-)a/editor.lib/src/org/netbeans/editor/StatusBar.java (-1 / +1 lines)
 Lines 86-92    Link Here 
86
import org.netbeans.api.editor.settings.FontColorNames;
86
import org.netbeans.api.editor.settings.FontColorNames;
87
import org.netbeans.api.editor.settings.FontColorSettings;
87
import org.netbeans.api.editor.settings.FontColorSettings;
88
import org.netbeans.api.editor.settings.SimpleValueNames;
88
import org.netbeans.api.editor.settings.SimpleValueNames;
89
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
89
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
90
import org.openide.util.NbBundle;
90
import org.openide.util.NbBundle;
91
import org.openide.util.WeakListeners;
91
import org.openide.util.WeakListeners;
92
92
(-)a/editor.lib/src/org/netbeans/editor/Utilities.java (-1 / +1 lines)
 Lines 61-67    Link Here 
61
import javax.swing.text.View;
61
import javax.swing.text.View;
62
import org.netbeans.lib.editor.util.CharSequenceUtilities;
62
import org.netbeans.lib.editor.util.CharSequenceUtilities;
63
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
63
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
64
import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
64
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
65
import org.openide.util.NbBundle;
65
import org.openide.util.NbBundle;
66
66
67
/**
67
/**
(-)a/editor.lib/src/org/netbeans/editor/WordMatch.java (-2 / +2 lines)
 Lines 52-59    Link Here 
52
import javax.swing.text.BadLocationException;
52
import javax.swing.text.BadLocationException;
53
import javax.swing.text.JTextComponent;
53
import javax.swing.text.JTextComponent;
54
import org.netbeans.api.editor.mimelookup.MimeLookup;
54
import org.netbeans.api.editor.mimelookup.MimeLookup;
55
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
55
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
56
import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
56
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
57
import org.openide.util.WeakListeners;
57
import org.openide.util.WeakListeners;
58
58
59
/** Word matching support enables to fill in the rest of the word
59
/** Word matching support enables to fill in the rest of the word
(-)a/editor.lib/src/org/netbeans/editor/ext/ExtFormatter.java (-1 / +1 lines)
 Lines 65-71    Link Here 
65
import org.netbeans.editor.AcceptorFactory;
65
import org.netbeans.editor.AcceptorFactory;
66
import org.netbeans.editor.BaseKit;
66
import org.netbeans.editor.BaseKit;
67
import org.netbeans.editor.Syntax;
67
import org.netbeans.editor.Syntax;
68
import org.netbeans.modules.editor.lib.EditorPreferencesKeys;
68
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
69
import org.netbeans.modules.editor.lib.SettingsConversions;
69
import org.netbeans.modules.editor.lib.SettingsConversions;
70
import org.openide.util.Lookup;
70
import org.openide.util.Lookup;
71
import org.openide.util.WeakListeners;
71
import org.openide.util.WeakListeners;
(-)a/editor.lib/src/org/netbeans/modules/editor/lib/ColoringMap.java (+1 lines)
 Lines 40-45    Link Here 
40
 */
40
 */
41
package org.netbeans.modules.editor.lib;
41
package org.netbeans.modules.editor.lib;
42
42
43
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
43
import java.beans.PropertyChangeListener;
44
import java.beans.PropertyChangeListener;
44
import java.beans.PropertyChangeSupport;
45
import java.beans.PropertyChangeSupport;
45
import java.lang.reflect.Field;
46
import java.lang.reflect.Field;
(-)a/editor.lib/src/org/netbeans/modules/editor/lib/SettingsConversions.java (-1 / +2 lines)
 Lines 52-57    Link Here 
52
import java.util.logging.Logger;
52
import java.util.logging.Logger;
53
import java.util.prefs.Preferences;
53
import java.util.prefs.Preferences;
54
import org.netbeans.api.editor.mimelookup.MimePath;
54
import org.netbeans.api.editor.mimelookup.MimePath;
55
import org.netbeans.editor.Acceptor;
55
import org.openide.util.Lookup;
56
import org.openide.util.Lookup;
56
57
57
/**
58
/**
 Lines 259-265    Link Here 
259
            }
260
            }
260
        }
261
        }
261
    }
262
    }
262
    
263
263
    private SettingsConversions() {
264
    private SettingsConversions() {
264
        
265
        
265
    }
266
    }
(-)a/editor.lib2/manifest.mf (+1 lines)
 Lines 3-5    Link Here 
3
OpenIDE-Module-Implementation-Version: 2
3
OpenIDE-Module-Implementation-Version: 2
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib2/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib2/Bundle.properties
5
OpenIDE-Module-Layer: org/netbeans/modules/editor/lib2/resources/layer.xml
5
OpenIDE-Module-Layer: org/netbeans/modules/editor/lib2/resources/layer.xml
6
OpenIDE-Module-Needs: org.netbeans.modules.editor.actions
(-)a/editor.lib2/src/org/netbeans/api/editor/EditorActionRegistration.java (+41 lines)
 Lines 134-137    Link Here 
134
     */
134
     */
135
    String popupText() default "";
135
    String popupText() default "";
136
136
137
    /**
138
     * Path of this action in main menu e.g. "Edit".
139
     */
140
    String menuPath() default "";
141
142
    /**
143
     * Integer position of the main menu item among the other menu items.
144
     * <br/>
145
     * The default Integer.MAX_VALUE value means no menu representation.
146
     */
147
    int menuPosition() default Integer.MAX_VALUE;
148
149
    /**
150
     * Path of this action in popup menu e.g. "" for appearance right in the context menu
151
     * or a corresponding path for nested submenu appearance.
152
     */
153
    String popupPath() default "";
154
155
    /**
156
     * Integer position of the popup menu item among the other popup menu (or submenu) items.
157
     * <br/>
158
     * The default Integer.MAX_VALUE value means no popup menu representation.
159
     */
160
    int popupPosition() default Integer.MAX_VALUE;
161
162
    /**
163
     * Integer position of this action in editor toolbar.
164
     * <br/>
165
     * The default Integer.MAX_VALUE value means no toolbar representation.
166
     */
167
    int toolBarPosition() default Integer.MAX_VALUE;
168
169
    /**
170
     * Get type of the presenter used in menu (and toolbar).
171
     * <br/>
172
     * Currently supported types are default "" and "CheckBox".
173
     * <br/>
174
     * The value will be present in the action in "PresenterType" property.
175
     */
176
    String presenterType() default "";
177
137
}
178
}
(-)a/editor.lib2/src/org/netbeans/api/editor/EditorUtilities.java (+73 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.api.editor;
43
44
import javax.swing.Action;
45
import javax.swing.text.EditorKit;
46
import org.netbeans.modules.editor.lib2.actions.EditorActionUtilities;
47
48
49
/**
50
 * Various utility methods related to editor.
51
 *
52
 * @author Miloslav Metelka
53
 * @since 1.13
54
 */
55
56
public final class EditorUtilities {
57
58
    private EditorUtilities() {
59
        // No instances
60
    }
61
62
    /**
63
     * Find an action with the given name in the editor kit.
64
     *
65
     * @param editorKit non-null editor kit in which search is performed.
66
     * @param actionName non-null action name to search for.
67
     * @return action instance with the given name or null if action not found.
68
     */
69
    public static Action getAction(EditorKit editorKit, String actionName) {
70
        return EditorActionUtilities.getAction(editorKit, actionName);
71
    }
72
73
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/EditorActionRegistrationProcessor.java (-31 / +147 lines)
 Lines 39-51    Link Here 
39
39
40
package org.netbeans.modules.editor.lib2;
40
package org.netbeans.modules.editor.lib2;
41
41
42
import java.io.IOException;
42
import java.util.List;
43
import java.util.MissingResourceException;
43
import org.netbeans.modules.editor.lib2.actions.EditorActionUtilities;
44
import java.util.PropertyResourceBundle;
44
import org.netbeans.modules.editor.lib2.actions.PresenterEditorAction;
45
import java.util.ResourceBundle;
46
import java.util.Set;
45
import java.util.Set;
47
import javax.annotation.processing.Filer;
48
import javax.annotation.processing.ProcessingEnvironment;
49
import javax.annotation.processing.Processor;
46
import javax.annotation.processing.Processor;
50
import javax.annotation.processing.RoundEnvironment;
47
import javax.annotation.processing.RoundEnvironment;
51
import javax.annotation.processing.SupportedAnnotationTypes;
48
import javax.annotation.processing.SupportedAnnotationTypes;
 Lines 55-64    Link Here 
55
import javax.lang.model.element.ExecutableElement;
52
import javax.lang.model.element.ExecutableElement;
56
import javax.lang.model.element.Modifier;
53
import javax.lang.model.element.Modifier;
57
import javax.lang.model.element.TypeElement;
54
import javax.lang.model.element.TypeElement;
55
import javax.lang.model.element.VariableElement;
58
import javax.lang.model.type.TypeMirror;
56
import javax.lang.model.type.TypeMirror;
59
import javax.lang.model.util.ElementFilter;
57
import javax.lang.model.util.ElementFilter;
60
import javax.swing.Action;
58
import javax.swing.Action;
61
import javax.tools.StandardLocation;
62
import org.netbeans.api.editor.EditorActionRegistration;
59
import org.netbeans.api.editor.EditorActionRegistration;
63
import org.netbeans.api.editor.EditorActionRegistrations;
60
import org.netbeans.api.editor.EditorActionRegistrations;
64
import org.openide.filesystems.annotations.LayerBuilder;
61
import org.openide.filesystems.annotations.LayerBuilder;
 Lines 67-73    Link Here 
67
import org.openide.util.lookup.ServiceProvider;
64
import org.openide.util.lookup.ServiceProvider;
68
65
69
/**
66
/**
70
 * Annotation processor for
67
 * Annotation processor for {@link EditorActionRegistration}
68
 * and {@link EditorActionRegistrations}.
71
 */
69
 */
72
@ServiceProvider(service=Processor.class)
70
@ServiceProvider(service=Processor.class)
73
@SupportedSourceVersion(SourceVersion.RELEASE_6)
71
@SupportedSourceVersion(SourceVersion.RELEASE_6)
 Lines 101-107    Link Here 
101
        String methodName;
99
        String methodName;
102
        TypeMirror swingActionType = processingEnv.getTypeUtils().getDeclaredType(
100
        TypeMirror swingActionType = processingEnv.getTypeUtils().getDeclaredType(
103
                processingEnv.getElementUtils().getTypeElement("javax.swing.Action"));
101
                processingEnv.getElementUtils().getTypeElement("javax.swing.Action"));
104
102
        TypeMirror utilMapType = processingEnv.getTypeUtils().getDeclaredType(
103
                processingEnv.getElementUtils().getTypeElement("java.util.Map"));
104
        boolean directActionCreation = false; // Whether construct AlwaysEnabledAction or annotated action directly
105
        switch (e.getKind()) {
105
        switch (e.getKind()) {
106
            case CLASS:
106
            case CLASS:
107
                className = processingEnv.getElementUtils().getBinaryName((TypeElement)e).toString();
107
                className = processingEnv.getElementUtils().getBinaryName((TypeElement)e).toString();
 Lines 111-134    Link Here 
111
                if (!e.getModifiers().contains(Modifier.PUBLIC)) {
111
                if (!e.getModifiers().contains(Modifier.PUBLIC)) {
112
                    throw new LayerGenerationException(className + " is not public", e);
112
                    throw new LayerGenerationException(className + " is not public", e);
113
                }
113
                }
114
                boolean hasDefaultCtor = false;
114
                ExecutableElement defaultCtor = null;
115
                ExecutableElement mapCtor = null;
115
                for (ExecutableElement constructor : ElementFilter.constructorsIn(e.getEnclosedElements())) {
116
                for (ExecutableElement constructor : ElementFilter.constructorsIn(e.getEnclosedElements())) {
116
                    if (constructor.getParameters().isEmpty()) {
117
                    List<? extends VariableElement> params = constructor.getParameters();
117
                        if (!constructor.getModifiers().contains(Modifier.PUBLIC)) {
118
                    if (params.isEmpty()) {
118
                            throw new LayerGenerationException("Default constructor of " + className + " is not public", e);
119
                        defaultCtor = constructor;
119
                        }
120
120
                        hasDefaultCtor = true;
121
                    } else if (params.size() == 1 &&
121
                        break;
122
                        processingEnv.getTypeUtils().isAssignable(params.get(0).asType(), utilMapType))
123
                    {
124
                        mapCtor = constructor;
122
                    }
125
                    }
123
                }
126
                }
124
                if (!hasDefaultCtor) {
127
                String msgBase = "No-argument (or single-argument \"Map<String,?> attrs\") constructor";
125
                    throw new LayerGenerationException(className + " must have a no-argument constructor", e);
128
                if (defaultCtor == null && mapCtor == null) {
129
                    throw new LayerGenerationException(msgBase + " not present in " + className, e);
130
                }
131
                boolean defaultCtorPublic = (defaultCtor != null && defaultCtor.getModifiers().contains(Modifier.PUBLIC));
132
                boolean mapCtorPublic = (mapCtor != null && mapCtor.getModifiers().contains(Modifier.PUBLIC));
133
                if (!defaultCtorPublic && !mapCtorPublic) {
134
                    throw new LayerGenerationException(msgBase + " not public in " + className, e);
126
                }
135
                }
127
136
128
                if (!processingEnv.getTypeUtils().isAssignable(e.asType(), swingActionType)) {
137
                if (!processingEnv.getTypeUtils().isAssignable(e.asType(), swingActionType)) {
129
                    throw new LayerGenerationException(className + " is not assignable to javax.swing.Action", e);
138
                    throw new LayerGenerationException(className + " is not assignable to javax.swing.Action", e);
130
                }
139
                }
131
140
                if (mapCtorPublic) {
141
                    directActionCreation = true;
142
                }
132
                methodName = null;
143
                methodName = null;
133
                break;
144
                break;
134
145
 Lines 136-153    Link Here 
136
                className = processingEnv.getElementUtils().getBinaryName((TypeElement) e.getEnclosingElement()).toString();
147
                className = processingEnv.getElementUtils().getBinaryName((TypeElement) e.getEnclosingElement()).toString();
137
                methodName = e.getSimpleName().toString();
148
                methodName = e.getSimpleName().toString();
138
                if (!e.getModifiers().contains(Modifier.STATIC)) {
149
                if (!e.getModifiers().contains(Modifier.STATIC)) {
139
                    throw new LayerGenerationException(className + "." + methodName + " must be static", e);
150
                    throw new LayerGenerationException(className + "." + methodName + " must be static", e); // NOI18N
140
                }
151
                }
141
                // It appears that actually even non-public method registration works - so commented following
152
                // It appears that actually even non-public method registration works - so commented following
142
//                    if (!e.getModifiers().contains(Modifier.PUBLIC)) {
153
//                    if (!e.getModifiers().contains(Modifier.PUBLIC)) {
143
//                        throw new LayerGenerationException(className + "." + methodName + " must be public", e);
154
//                        throw new LayerGenerationException(className + "." + methodName + " must be public", e);
144
//                    }
155
//                    }
145
                if (!((ExecutableElement) e).getParameters().isEmpty()) {
156
                List<? extends VariableElement> params = ((ExecutableElement)e).getParameters();
146
                    throw new LayerGenerationException(className + "." + methodName + " must not take arguments", e);
157
                boolean emptyParams = params.isEmpty();
158
                boolean mapParam = (params.size() == 1 && processingEnv.getTypeUtils().isAssignable(
159
                        params.get(0).asType(), utilMapType));
160
                if (!emptyParams && !mapParam)
161
                {
162
                    throw new LayerGenerationException(className + "." + methodName +
163
                            " must not take arguments (or have a single-argument \"Map<String,?> attrs\")", e); // NOI18N
147
                }
164
                }
148
                if (swingActionType != null && !processingEnv.getTypeUtils().isAssignable(((ExecutableElement)e).getReturnType(), swingActionType)) {
165
                TypeMirror returnType = ((ExecutableElement)e).getReturnType();
166
                if (swingActionType != null && !processingEnv.getTypeUtils().isAssignable(returnType, swingActionType)) {
149
                    throw new LayerGenerationException(className + "." + methodName + " is not assignable to javax.swing.Action", e);
167
                    throw new LayerGenerationException(className + "." + methodName + " is not assignable to javax.swing.Action", e);
150
                }
168
                }
169
                if (mapParam) {
170
                    directActionCreation = true;
171
                }
151
                break;
172
                break;
152
173
153
            default:
174
            default:
 Lines 162-170    Link Here 
162
            filePath.append("/").append(annotation.mimeType());
183
            filePath.append("/").append(annotation.mimeType());
163
        }
184
        }
164
        filePath.append("/Actions/").append(actionName).append(".instance");
185
        filePath.append("/Actions/").append(actionName).append(".instance");
165
        LayerBuilder.File file = layer(e).file(filePath.toString());
186
        LayerBuilder layer = layer(e);
166
187
        LayerBuilder.File file = layer.file(filePath.toString());
167
        file.stringvalue("displayName", actionName);
168
188
169
        // Resolve icon resource
189
        // Resolve icon resource
170
        String iconResource = annotation.iconResource();
190
        String iconResource = annotation.iconResource();
 Lines 199-211    Link Here 
199
            file.bundlevalue("popupText", popupText);
219
            file.bundlevalue("popupText", popupText);
200
        }
220
        }
201
221
202
        file.methodvalue("instanceCreate", "org.openide.awt.Actions", "alwaysEnabled");
222
        // Check presenters
203
        if (methodName != null) {
223
        String presenterActionName = null;
204
            file.methodvalue("delegate", className, methodName);
224
        String presenterType = annotation.presenterType();
205
        } else {
225
        if (presenterType.length() > 0) { // Non-default presenter type
206
            file.newvalue("delegate", className);
226
            directActionCreation = true;
227
        }
228
229
        // Check menu path
230
        String menuPath = annotation.menuPath();
231
        int menuPosition = annotation.menuPosition();
232
        if (menuPosition != Integer.MAX_VALUE) {
233
            StringBuilder presenterFilePath = new StringBuilder(50);
234
            presenterFilePath.append("Menu/");
235
            if (menuPath.length() > 0) {
236
                presenterFilePath.append(menuPath).append('/');
237
            }
238
            presenterFilePath.append(actionName).append(".shadow");
239
            LayerBuilder.File presenterShadowFile = layer.file(presenterFilePath.toString());
240
            if (presenterActionName == null) {
241
                presenterActionName = generatePresenterAction(layer, actionName, presenterType);
242
            }
243
            presenterShadowFile.stringvalue("originalFile", presenterActionName);
244
            presenterShadowFile.intvalue("position", menuPosition);
245
            presenterShadowFile.write();
246
        }
247
248
        // Check popup path
249
        String popupPath = annotation.popupPath();
250
        int popupPosition = annotation.popupPosition();
251
        if (popupPosition != Integer.MAX_VALUE) {
252
            StringBuilder presenterFilePath = new StringBuilder(50);
253
            presenterFilePath.append("Editors");
254
            if (annotation.mimeType().length() > 0) {
255
                filePath.append("/").append(annotation.mimeType());
256
            }
257
            if (popupPath.length() > 0) {
258
                presenterFilePath.append(popupPath).append('/');
259
            }
260
            presenterFilePath.append(actionName).append(".shadow");
261
            LayerBuilder.File presenterShadowFile = layer.file(presenterFilePath.toString());
262
            if (presenterActionName == null) {
263
                presenterActionName = generatePresenterAction(layer, actionName, presenterType);
264
            }
265
            presenterShadowFile.stringvalue("originalFile", presenterActionName);
266
            presenterShadowFile.intvalue("position", popupPosition);
267
            presenterShadowFile.write();
268
        }
269
        
270
        int toolBarPosition = annotation.toolBarPosition();
271
        if (toolBarPosition != Integer.MAX_VALUE) {
272
            StringBuilder presenterFilePath = new StringBuilder(50);
273
            presenterFilePath.append("/Editors/Toolbar/");
274
            if (popupPath.length() > 0) {
275
                presenterFilePath.append(popupPath).append('/');
276
            }
277
            presenterFilePath.append(actionName).append(".shadow");
278
            LayerBuilder.File presenterShadowFile = layer.file(presenterFilePath.toString());
279
            if (presenterActionName == null) {
280
                presenterActionName = generatePresenterAction(layer, actionName, presenterType);
281
            }
282
            presenterShadowFile.stringvalue("originalFile", presenterActionName);
283
            presenterShadowFile.intvalue("position", toolBarPosition);
284
            presenterShadowFile.write();
285
        }
286
287
        // Deafult helpID is action's name
288
        file.stringvalue("helpID", actionName);
289
290
        // Resolve accelerator through method
291
        file.methodvalue(Action.ACCELERATOR_KEY, EditorActionUtilities.class.getName(), "getAccelerator");
292
293
        // Always generate Action.NAME since although AlwaysEnabledAction tweaks its retrieval to "displayName"
294
        // some tools may query FO's properties and expect it there.
295
        file.stringvalue(Action.NAME, actionName);
296
297
        if (directActionCreation) {
298
            if (methodName != null) {
299
                file.methodvalue("instanceCreate", className, methodName);
300
            } else {
301
                file.newvalue("instanceCreate", className);
302
            }
303
304
        } else { // Create always enabled action
305
            file.methodvalue("instanceCreate", "org.openide.awt.Actions", "alwaysEnabled");
306
            file.stringvalue("displayName", actionName);
307
308
            if (methodName != null) {
309
                file.methodvalue("delegate", className, methodName);
310
            } else {
311
                file.newvalue("delegate", className);
312
            }
207
        }
313
        }
208
        file.write();
314
        file.write();
209
    }
315
    }
210
316
317
    private String generatePresenterAction(LayerBuilder layer, String actionName, String presenterType) {
318
        String presenterActionName = "Editors/ActionPresenters/" + actionName + ".instance";
319
        LayerBuilder.File presenterActionFile = layer.file(presenterActionName);
320
        presenterActionFile.methodvalue("instanceCreate", PresenterEditorAction.class.getName(), "create");
321
        presenterActionFile.stringvalue(Action.NAME, actionName);
322
        presenterActionFile.stringvalue("PresenterType", presenterType);
323
        presenterActionFile.write();
324
        return presenterActionName;
325
    }
326
211
}
327
}
(-)a/editor.lib/src/org/netbeans/modules/editor/lib/EditorPreferencesDefaults.java (-6 / +6 lines)
 Lines 39-51    Link Here 
39
 * made subject to such option by the copyright holder.
39
 * made subject to such option by the copyright holder.
40
 */
40
 */
41
41
42
package org.netbeans.modules.editor.lib;
42
package org.netbeans.modules.editor.lib2;
43
43
44
import java.awt.Insets;
44
import java.awt.Insets;
45
import java.awt.Dimension;
45
import java.awt.Dimension;
46
import org.netbeans.editor.Acceptor;
47
import org.netbeans.editor.AcceptorFactory;
48
import org.netbeans.editor.BaseCaret;
49
46
50
/**
47
/**
51
 * This class contains settings default values copied over from SettingsDefaults and ExtSettingsDefaults.
48
 * This class contains settings default values copied over from SettingsDefaults and ExtSettingsDefaults.
 Lines 57-62    Link Here 
57
    private EditorPreferencesDefaults() {
54
    private EditorPreferencesDefaults() {
58
        // no-op
55
        // no-op
59
    }
56
    }
57
58
    public static final String LINE_CARET = "line-caret";
59
    public static final String BLOCK_CARET = "block-caret";
60
    
60
    
61
    // not in SettingsDefaults not ExtSettingsDefaults
61
    // not in SettingsDefaults not ExtSettingsDefaults
62
    public static final boolean defaultToolbarVisible = true;
62
    public static final boolean defaultToolbarVisible = true;
 Lines 98-105    Link Here 
98
98
99
    public static final boolean defaultExpandTabs = true;
99
    public static final boolean defaultExpandTabs = true;
100
100
101
    public static final String defaultCaretTypeInsertMode = BaseCaret.LINE_CARET;
101
    public static final String defaultCaretTypeInsertMode = LINE_CARET;
102
    public static final String defaultCaretTypeOverwriteMode = BaseCaret.BLOCK_CARET;
102
    public static final String defaultCaretTypeOverwriteMode = BLOCK_CARET;
103
    public static final boolean defaultCaretItalicInsertMode = false;
103
    public static final boolean defaultCaretItalicInsertMode = false;
104
    public static final boolean defaultCaretItalicOverwriteMode = false;
104
    public static final boolean defaultCaretItalicOverwriteMode = false;
105
    /** @since 1.23 */
105
    /** @since 1.23 */
(-)a/editor.lib/src/org/netbeans/modules/editor/lib/EditorPreferencesKeys.java (-1 / +1 lines)
 Lines 39-45    Link Here 
39
 * made subject to such option by the copyright holder.
39
 * made subject to such option by the copyright holder.
40
 */
40
 */
41
41
42
package org.netbeans.modules.editor.lib;
42
package org.netbeans.modules.editor.lib2;
43
43
44
import org.netbeans.api.editor.settings.SimpleValueNames;
44
import org.netbeans.api.editor.settings.SimpleValueNames;
45
45
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/AbstractEditorAction.java (+178 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.lib2.actions;
41
42
import java.awt.event.ActionEvent;
43
import java.util.Map;
44
import java.util.logging.Level;
45
import java.util.logging.LogRecord;
46
import java.util.logging.Logger;
47
import javax.swing.Action;
48
import javax.swing.text.Caret;
49
import javax.swing.text.JTextComponent;
50
import javax.swing.text.TextAction;
51
import org.openide.util.NbBundle;
52
import org.openide.util.RequestProcessor;
53
54
/**
55
 * Base class for editor actions.
56
 *
57
 * @author Miloslav Metelka
58
 * @since 1.13
59
 */
60
public abstract class AbstractEditorAction extends TextAction {
61
62
    /**
63
     * Boolean action property displayed by the checkbox menu item.
64
     */
65
    public static final String SELECTED_KEY = "SwingSelectedKey"; // [TODO] Replace with Action.SELECTED_KEY on 1.6
66
67
    /** Logger for reporting invoked actions */
68
    private static Logger UILOG = Logger.getLogger("org.netbeans.ui.actions.editor"); // NOI18N
69
70
    private final Map<String,?> attrs;
71
72
    public AbstractEditorAction(Map<String,?> attrs) {
73
        super(null);
74
        this.attrs = attrs;
75
76
        String actionName = (String)attrs.get(Action.NAME);
77
        if (actionName == null) {
78
            throw new IllegalArgumentException("Null Action.NAME attribute for action " + this.getClass()); // NOI18N
79
        }
80
        putValue(Action.NAME, actionName);
81
    }
82
83
    public AbstractEditorAction() {
84
        super(null);
85
        this.attrs = null;
86
    }
87
88
    public abstract void actionPerformed(ActionEvent evt, JTextComponent component);
89
90
    /**
91
     * Called by {@link #putValue(String,String)} when {@link Action#NAME} property
92
     * is set to a non-null String value. This allows a "polymorphic" action (with
93
     * Action.NAME-specific behavior) to update certain properties (e.g. an icon)
94
     * according to the name that was set.
95
     *
96
     * @param actionName non-null action's name (value of Action.NAME property).
97
     * @since 1.34
98
     */
99
    protected void actionNameUpdate(String actionName) {
100
    }
101
102
    public final void actionPerformed(final ActionEvent evt) {
103
        final JTextComponent target = getTextComponent(evt);
104
        MacroRecording.get().recordAction(this, evt); // Possibly record action in a currently recorded macro
105
106
        if (UILOG.isLoggable(Level.FINE)) {
107
            // TODO [Mila] - Set action's property to disable UI logging
108
            String actionNameLowerCase = actionName();
109
            if (actionNameLowerCase != null &&
110
                !"default-typed".equals(actionNameLowerCase) && //NOI18N
111
                -1 == actionNameLowerCase.indexOf("caret") && //NOI18N
112
                -1 == actionNameLowerCase.indexOf("delete") && //NOI18N
113
                -1 == actionNameLowerCase.indexOf("selection") && //NOI18N
114
                -1 == actionNameLowerCase.indexOf("build-tool-tip") &&//NOI18N
115
                -1 == actionNameLowerCase.indexOf("build-popup-menu") &&//NOI18N
116
                -1 == actionNameLowerCase.indexOf("page-up") &&//NOI18N
117
                -1 == actionNameLowerCase.indexOf("page-down") &&//NOI18N
118
                -1 == actionNameLowerCase.indexOf("-kit-install") //NOI18N
119
            ) {
120
                LogRecord r = new LogRecord(Level.FINE, "UI_ACTION_EDITOR"); // NOI18N
121
                r.setResourceBundle(NbBundle.getBundle(AbstractEditorAction.class));
122
                if (evt != null) {
123
                    r.setParameters(new Object[] { evt, evt.toString(), this, toString(), getValue(NAME) });
124
                } else {
125
                    r.setParameters(new Object[] { "no-ActionEvent", "no-ActionEvent", this, toString(), getValue(NAME) }); //NOI18N
126
                }
127
                r.setLoggerName(UILOG.getName());
128
                UILOG.log(r);
129
            }
130
        }
131
132
        if (asynchronous()) {
133
            RequestProcessor.getDefault().post(new Runnable () {
134
                public void run() {
135
                    actionPerformed(evt, target);
136
                }
137
            });
138
        } else {
139
            actionPerformed(evt, target);
140
        }
141
    }
142
143
    @Override
144
    public Object getValue(String key) {
145
        Object value = super.getValue(key);
146
        if (value == null && attrs != null) {
147
            if (!"instanceCreate".equals(key)) { // Return null for this key
148
                value = attrs.get(key);
149
            }
150
        }
151
        return value;
152
    }
153
154
    @Override
155
    public void putValue(String key, Object value) {
156
        super.putValue(key, value);
157
        if (Action.NAME.equals(key) && value instanceof String) {
158
            actionNameUpdate((String)value);
159
        }
160
    }
161
162
163
    protected boolean asynchronous() {
164
        return false;
165
    }
166
167
    protected final String actionName() {
168
        return (String) getValue(Action.NAME);
169
    }
170
171
    protected final void magicPositionReset(JTextComponent target) {
172
        Caret caret = target.getCaret();
173
        if (caret != null) {
174
            caret.setMagicCaretPosition(null);
175
        }
176
    }
177
178
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/Bundle.properties (+51 lines)
Line 0    Link Here 
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
4
#
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
7
# Development and Distribution License("CDDL") (collectively, the
8
# "License"). You may not use this file except in compliance with the
9
# License. You can obtain a copy of the License at
10
# http://www.netbeans.org/cddl-gplv2.html
11
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12
# specific language governing permissions and limitations under the
13
# License.  When distributing the software, include this License Header
14
# Notice in each file and include the License file at
15
# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
16
# particular file as subject to the "Classpath" exception as provided
17
# by Sun in the GPL Version 2 section of the License file that
18
# accompanied this code. If applicable, add the following below the
19
# License Header, with the fields enclosed by brackets [] replaced by
20
# your own identifying information:
21
# "Portions Copyrighted [year] [name of copyright owner]"
22
#
23
# Contributor(s):
24
#
25
# The Original Software is NetBeans. The Initial Developer of the Original
26
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
# Microsystems, Inc. All Rights Reserved.
28
#
29
# If you wish your version of this file to be governed by only the CDDL
30
# or only the GPL Version 2, indicate your decision by adding
31
# "[Contributor] elects to include this software in this distribution
32
# under the [CDDL or GPL Version 2] license." If you do not indicate a
33
# single choice of license, a recipient has the option to distribute
34
# your version of this file under either the CDDL, the GPL Version 2 or
35
# to extend the choice of license to its licensees as provided above.
36
# However, if you add GPL Version 2 code and therefore, elected the GPL
37
# Version 2 license, then the option applies only if the new code is
38
# made subject to such option by the copyright holder.
39
40
#
41
# UI Logging
42
#
43
# UI logging of button press
44
# {0} instance of the button
45
# {1} class of the button
46
# {2} instance of the action
47
# {3} class of the action
48
# {4} display name of the action
49
UI_ACTION_EDITOR=Invoking {4} implemented as {3} thru {1}
50
UI_ACTION_EDITOR_ICON_BASE=org/netbeans/modules/editor/lib2/resources/defaultglyph.gif
51
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionNames.java (+59 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.lib2.actions;
41
42
/**
43
 * Names of basic editor actions.
44
 *
45
 * @author Miloslav Metelka
46
 * @since 1.13
47
 */
48
public final class EditorActionNames {
49
50
    /** Toggle the visibility of the editor toolbar */
51
    public static final String toggleToolbarAction = "toggle-toolbar"; // NOI18N
52
53
    /** Toggle visibility of line numbers*/
54
    public static final String toggleLineNumbersAction = "toggle-line-numbers"; // NOI18N
55
56
    /** Goto declaration depending on the context under the caret */
57
    public static final String gotoDeclarationAction = "goto-declaration"; // NOI18N
58
59
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionUtilities.java (+302 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.lib2.actions;
41
42
import java.lang.ref.Reference;
43
import java.lang.ref.WeakReference;
44
import java.util.Collection;
45
import java.util.HashMap;
46
import java.util.Iterator;
47
import java.util.Map;
48
import java.util.WeakHashMap;
49
import java.util.logging.Level;
50
import java.util.logging.Logger;
51
import javax.swing.Action;
52
import javax.swing.KeyStroke;
53
import javax.swing.event.ChangeListener;
54
import javax.swing.text.EditorKit;
55
import org.netbeans.api.editor.mimelookup.MimeLookup;
56
import org.netbeans.api.editor.mimelookup.MimePath;
57
import org.netbeans.api.editor.settings.KeyBindingSettings;
58
import org.netbeans.api.editor.settings.MultiKeyBinding;
59
import org.openide.filesystems.FileObject;
60
import org.openide.util.Lookup;
61
import org.openide.util.LookupEvent;
62
import org.openide.util.LookupListener;
63
import org.openide.util.lookup.Lookups;
64
65
66
/**
67
 * Various utility methods for declarative editor action registrations.
68
 */
69
public final class EditorActionUtilities {
70
71
    // -J-Dorg.netbeans.modules.editor.lib2.actions.EditorActionUtilities.level=FINEST
72
    private static final Logger LOG = Logger.getLogger(EditorActionUtilities.class.getName());
73
74
    private static Map<String,Map<String,KeyStroke>> mimeType2actionName2KeyStroke;
75
76
    private static Map<String,Boolean> mimeType2ListenerPresent = new HashMap<String, Boolean>();
77
78
    private static Reference<EditorKit> globalKitRef;
79
80
    private static LookupListener globalKitListener;
81
82
    private static final Map<EditorKit,SearchableEditorKit> kit2searchable = new WeakHashMap<EditorKit,SearchableEditorKit>();
83
84
    private EditorActionUtilities() {
85
        // No instances
86
    }
87
88
    public static EditorKit getGlobalKit() {
89
        synchronized (kit2searchable) {
90
            EditorKit globalKit = (globalKitRef != null) ? globalKitRef.get() : null;
91
            if (globalKit == null) {
92
                Lookup.Result<EditorKit> result = MimeLookup.getLookup("").lookupResult(EditorKit.class);
93
                Iterator<? extends EditorKit> instancesIterator = result.allInstances().iterator();
94
                globalKit = instancesIterator.hasNext() ? instancesIterator.next() : null;
95
                if (globalKit != null) {
96
                    globalKitRef = new WeakReference<EditorKit>(globalKit);
97
                }
98
                if (globalKitListener == null) {
99
                    globalKitListener = new LookupListener() {
100
                        public void resultChanged(LookupEvent evt) {
101
                            synchronized (kit2searchable) {
102
                                globalKitRef = null;
103
                            }
104
                        }
105
                    };
106
                    result.addLookupListener(globalKitListener);
107
                }
108
            }
109
            return globalKit;
110
        }
111
    }
112
113
    public static EditorKit getKit(String mimeType) {
114
        Lookup.Result<EditorKit> result = MimeLookup.getLookup(mimeType).lookupResult(EditorKit.class);
115
        Iterator<? extends EditorKit> instancesIterator = result.allInstances().iterator();
116
        EditorKit kit = instancesIterator.hasNext() ? instancesIterator.next() : null;
117
        return kit;
118
    }
119
120
    public static void registerSearchableKit(EditorKit kit, SearchableEditorKit searchableKit) {
121
        synchronized (kit2searchable) {
122
            kit2searchable.put(kit, searchableKit);
123
        }
124
    }
125
126
    /**
127
     * Get an editor action in a constant time (wrap a kit with a SearchableEditorKit if necessary).
128
     *
129
     * @param kit non-null kit.
130
     * @param actionName non-null action name.
131
     * @return action's instance or null.
132
     */
133
    public static Action getAction(EditorKit kit, String actionName) {
134
        return getSearchableKit(kit).getAction(actionName);
135
    }
136
137
    /**
138
     * Get searchable editor kit for the given kit.
139
     * @param kit non-null kit.
140
     * @return non-null searchable kit.
141
     */
142
    public static SearchableEditorKit getSearchableKit(EditorKit kit) {
143
        SearchableEditorKit searchableKit;
144
        if (kit instanceof SearchableEditorKit) {
145
            searchableKit = ((SearchableEditorKit)kit);
146
        } else {
147
            synchronized (kit2searchable) {
148
                searchableKit = kit2searchable.get(kit);
149
                if (searchableKit == null) {
150
                    searchableKit = new DefaultSearchableKit(kit);
151
                    registerSearchableKit(kit, searchableKit);
152
                }
153
            }
154
        }
155
        return searchableKit;
156
    }
157
158
    public static Lookup.Result<Action> createActionsLookupResult(String mimeType) {
159
        if (!MimePath.validate(mimeType)) {
160
            throw new IllegalArgumentException("├Ćnvalid mimeType=\"" + mimeType + "\"");
161
        }
162
        Lookup lookup = Lookups.forPath(getPath(mimeType, "Actions"));
163
        return lookup.lookupResult(Action.class);
164
    }
165
166
    private static String getPath(String mimeType, String subFolder) {
167
        StringBuilder path = new StringBuilder(50);
168
        path.append("Editors/");
169
        if (mimeType.length() > 0) {
170
            path.append('/').append(mimeType);
171
        }
172
        if (subFolder.length() > 0) {
173
            path.append('/').append(subFolder);
174
        }
175
        return path.toString();
176
    }
177
178
    /**
179
     * Get single-key accelerator for a given declared action.
180
     * Only a single-key accelerators are supported.
181
     */
182
    public static KeyStroke getAccelerator(FileObject fo) {
183
        if (fo == null) {
184
            throw new IllegalArgumentException("Must be called with non-null fileObject"); // NOI18N
185
        }
186
        boolean fineLoggable = LOG.isLoggable(Level.FINE);
187
        String path = fo.getParent().getPath();
188
        String actionName = (String) fo.getAttribute(Action.NAME);
189
        KeyStroke ks = null;
190
        if (path.startsWith("Editors/")) {
191
            path = path.substring(7); // Leave ending '/' to support "Editors/Actions"
192
            if (path.endsWith("/Actions")) {
193
                path = path.substring(0, path.length() - 8);
194
                if (path.startsWith("/")) {
195
                    path = path.substring(1);
196
                }
197
                String mimeType = path;
198
                if (!MimePath.validate(mimeType)) {
199
                    LOG.info("Invalid mime-type='" + mimeType + "' of action's fileObject=" + fo); // NOI18N
200
                }
201
                ks = getAccelerator(mimeType, actionName);
202
            } else if (fineLoggable) {
203
                LOG.fine("No \"/Actions\" at end of mime-type='" + path +
204
                    "' of action's fileObject=" + fo); // NOI18N
205
            }
206
        } else if (fineLoggable) {
207
            LOG.fine("No \"Editors/\" at begining of mime-type='" + path + // NOI18N
208
                    "' of action's fileObject=" + fo); // NOI18N
209
        }
210
211
        if (LOG.isLoggable(Level.FINER)) {
212
            LOG.finer("Accelerator for action \"" + actionName + "\" is " + ks);
213
        }
214
        return ks;
215
    }
216
217
    /**
218
     * Get single-key accelerator for a given declared action.
219
     * <br/>
220
     * Unfortunately currently there's no easy way to display multi-keybinding in menu-item
221
     * (there's just JMenuItem.setAccelerator() and its impl is L&F-based)
222
     * so just display single-keystroke accelerators.
223
     */
224
    public static KeyStroke getAccelerator(String mimeType, String actionName) {
225
        KeyStroke ks = null;
226
        if (actionName != null) {
227
            synchronized (EditorActionUtilities.class) {
228
                if (mimeType2actionName2KeyStroke == null) {
229
                    mimeType2actionName2KeyStroke = new HashMap<String,Map<String,KeyStroke>>();
230
                }
231
                Map<String,KeyStroke> actionName2KeyStrokeList = mimeType2actionName2KeyStroke.get(mimeType);
232
                if (actionName2KeyStrokeList == null) {
233
                    actionName2KeyStrokeList = new HashMap<String,KeyStroke>();
234
                    Lookup.Result<KeyBindingSettings> result = MimeLookup.getLookup(mimeType).lookupResult(
235
                            KeyBindingSettings.class);
236
                    Collection<? extends KeyBindingSettings> instances = result.allInstances();
237
                    if (!instances.isEmpty()) {
238
                        KeyBindingSettings kbs = instances.iterator().next();
239
                        for (MultiKeyBinding kb : kbs.getKeyBindings()) {
240
                            if (!actionName2KeyStrokeList.containsKey(kb.getActionName())
241
                                && kb.getKeyStrokeCount() == 1)
242
                            {
243
                                actionName2KeyStrokeList.put(kb.getActionName(), kb.getKeyStroke(0));
244
                            }
245
                        }
246
                    }
247
                    mimeType2actionName2KeyStroke.put(mimeType, actionName2KeyStrokeList);
248
                    // Ensure listening on changes in keybinding settings
249
                    if (!Boolean.TRUE.equals(mimeType2ListenerPresent.get(mimeType))) {
250
                        mimeType2ListenerPresent.put(mimeType, true);
251
                        result.addLookupListener(KeyBindingSettingsListener.INSTANCE);
252
                    }
253
                }
254
                ks = actionName2KeyStrokeList.get(actionName);
255
            }
256
        }
257
        return ks;
258
    }
259
260
    private static final class KeyBindingSettingsListener implements LookupListener {
261
        
262
        static final KeyBindingSettingsListener INSTANCE = new KeyBindingSettingsListener();
263
264
        private KeyBindingSettingsListener() {
265
        }
266
267
        public void resultChanged(LookupEvent ev) {
268
            synchronized (EditorActionUtilities.class) {
269
                mimeType2actionName2KeyStroke = null;
270
                LOG.fine("mimeType2actionName2KeyStroke cleared."); // NOI18N
271
            }
272
        }
273
274
    }
275
276
    private static final class DefaultSearchableKit implements SearchableEditorKit {
277
        
278
        private final Map<String,Reference<Action>> name2actionRef = new WeakHashMap<String,Reference<Action>>();
279
280
        DefaultSearchableKit(EditorKit kit) {
281
            for (Action action : kit.getActions()) {
282
                if (action != null) {
283
                    name2actionRef.put((String)action.getValue(Action.NAME), new WeakReference<Action>(action));
284
                }
285
            }
286
        }
287
288
        public Action getAction(String actionName) {
289
            Reference<Action> actionRef = name2actionRef.get(actionName);
290
            return (actionRef != null) ? actionRef.get() : null;
291
        }
292
293
        public void addActionsChangeListener(ChangeListener listener) {
294
        }
295
296
        public void removeActionsChangeListener(ChangeListener listener) {
297
        }
298
299
300
    }
301
302
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/EditorActionsProvider.java (+59 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.editor.lib2.actions;
43
44
import java.util.List;
45
import javax.swing.Action;
46
47
/**
48
 * Abstract class implemented by editor module providing editor actions.
49
 *
50
 * @author Vita Stejskal
51
 * @since 1.39
52
 */
53
public interface EditorActionsProvider {
54
55
    List<Action> getActionsOnly();
56
57
    List<Object> getAllInstances();
58
59
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/MacroRecording.java (+171 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.lib2.actions;
41
42
import java.awt.event.ActionEvent;
43
import javax.swing.Action;
44
import javax.swing.text.DefaultEditorKit;
45
46
/**
47
 * Class handling macro recording of editor actions.
48
 *
49
 * @author Miloslav Metelka
50
 * @since 1.13
51
 */
52
public final class MacroRecording {
53
54
    /** Action's property for disabling recording of the action as part of a macro. */
55
    public static final String NO_MACRO_RECORDING_PROPERTY = "NoMacroRecording";
56
    
57
    private static final MacroRecording INSTANCE = new MacroRecording();
58
59
    public static MacroRecording get() {
60
        return INSTANCE;
61
    }
62
63
    private StringBuilder macroBuffer;
64
65
    private StringBuilder textBuffer;
66
67
    private MacroRecording() {
68
    }
69
70
    /**
71
     * Start recording a macro.
72
     *
73
     * @return true if macro recording started successfully or false otherwise.
74
     */
75
    public synchronized boolean startRecording() {
76
        if (isRecording()) {
77
            return false;
78
        }
79
        macroBuffer = new StringBuilder(100);
80
        textBuffer = new StringBuilder(20);
81
        return true;
82
    }
83
84
    /**
85
     * Stop macro recording.
86
     *
87
     * @return string describing the macro or null if no recording takes place currently.
88
     */
89
    public synchronized String stopRecording() {
90
        if (!isRecording()) {
91
            return null;
92
        }
93
        if (textBuffer.length() > 0) {
94
            if (macroBuffer.length() > 0) {
95
                macroBuffer.append( ' ' );
96
            }
97
            appendEncodedText(macroBuffer, textBuffer);
98
        }
99
        String completeMacroText = macroBuffer.toString();
100
        textBuffer = null;
101
        macroBuffer = null;
102
        return completeMacroText;
103
    }
104
105
    /**
106
     * Record given action into a macro buffer.
107
     *
108
     * @param action non-null action to record
109
     * @param evt non-null evt used when recording typed text of default key-typed action.
110
     */
111
    public synchronized void recordAction(Action action, ActionEvent evt) {
112
        if (isRecording() && !Boolean.TRUE.equals(action.getValue(NO_MACRO_RECORDING_PROPERTY))) {
113
            String actionName = actionName(action);
114
            if (DefaultEditorKit.defaultKeyTypedAction.equals(actionName)) {
115
                textBuffer.append(getFilteredActionCommand(evt.getActionCommand()));
116
            } else {
117
                if (textBuffer.length() > 0) {
118
                    if (macroBuffer.length() > 0) {
119
                        macroBuffer.append( ' ' );
120
                    }
121
                    appendEncodedText(macroBuffer, textBuffer);
122
                    textBuffer.setLength(0);
123
                }
124
                if (macroBuffer.length() > 0) {
125
                    macroBuffer.append(' ');
126
                }
127
                // Append encoded action name
128
                for (int i = 0; i < actionName.length(); i++) {
129
                    char c = actionName.charAt(i);
130
                    if (Character.isWhitespace(c) || c == '\\') {
131
                        macroBuffer.append('\\');
132
                    }
133
                    macroBuffer.append(c);
134
                }
135
            }
136
        }
137
    }
138
139
    private boolean isRecording() {
140
        return (macroBuffer != null);
141
    }
142
143
    private static String actionName(Action action) {
144
        return (String) action.getValue(Action.NAME);
145
    }
146
147
    private static String getFilteredActionCommand(String cmd) {
148
        if (cmd == null || cmd.length() == 0) {
149
            return "";
150
        }
151
        char ch = cmd.charAt(0);
152
        if ((ch >= 0x20) && (ch != 0x7F)) {
153
            return cmd;
154
        } else {
155
            return "";
156
        }
157
    }
158
159
    private static void appendEncodedText(StringBuilder sb, StringBuilder text) {
160
        sb.append('"');
161
        for (int i = 0; i < text.length(); i++) {
162
            char c = text.charAt(i);
163
            if (c == '"' || c == '\\') {
164
                sb.append('\\');
165
            }
166
            sb.append(c);
167
        }
168
        sb.append('"');
169
    }
170
171
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/PresenterEditorAction.java (+359 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.lib2.actions;
41
42
import java.awt.Component;
43
import java.awt.event.ActionEvent;
44
import java.awt.event.ItemEvent;
45
import java.awt.event.ItemListener;
46
import java.beans.PropertyChangeEvent;
47
import java.beans.PropertyChangeListener;
48
import java.lang.ref.Reference;
49
import java.lang.ref.WeakReference;
50
import java.util.Map;
51
import java.util.WeakHashMap;
52
import java.util.logging.Level;
53
import java.util.logging.Logger;
54
import javax.swing.Action;
55
import javax.swing.JButton;
56
import javax.swing.JCheckBoxMenuItem;
57
import javax.swing.JMenuItem;
58
import javax.swing.event.ChangeEvent;
59
import javax.swing.event.ChangeListener;
60
import javax.swing.plaf.TextUI;
61
import javax.swing.text.EditorKit;
62
import javax.swing.text.JTextComponent;
63
import javax.swing.text.TextAction;
64
import org.netbeans.api.editor.EditorRegistry;
65
import org.netbeans.api.editor.EditorUtilities;
66
import org.openide.awt.Actions;
67
import org.openide.util.actions.Presenter;
68
69
/**
70
 * Action that represents a named editor action in main menu, popup menu
71
 * and editor toolbar.
72
 * <br/>
73
 * The actions are registered into "Editors/ActionPresenters" regardless
74
 * of the mime-type for which the actions get created.
75
 */
76
public final class PresenterEditorAction extends TextAction
77
        implements Presenter.Menu, Presenter.Popup, Presenter.Toolbar, PropertyChangeListener, ChangeListener
78
{
79
80
    // -J-Dorg.netbeans.modules.editor.lib2.actions.PresenterEditorAction.level=FINEST
81
    private static final Logger LOG = Logger.getLogger(PresenterEditorAction.class.getName());
82
83
    private static final Map<PresenterEditorAction,String> presenterAction2Name
84
            = new WeakHashMap<PresenterEditorAction,String>();
85
86
    /**
87
     * Currently active editor component's editor kit reference.
88
     */
89
    private static Reference<SearchableEditorKit> activeEditorKitRef;
90
91
    private static ChangeListener kitChangeListener = new ChangeListener() {
92
        public void stateChanged(ChangeEvent evt) {
93
            updateActions(null);
94
        }
95
    };
96
97
    private static SearchableEditorKit activeKit() {
98
        synchronized (PresenterEditorAction.class) {
99
            return (activeEditorKitRef != null) ? activeEditorKitRef.get() : null;
100
        }
101
    }
102
103
    private static void updateActions(SearchableEditorKit kit) {
104
        boolean changed = (activeEditorKitRef == null || kit != activeEditorKitRef.get());
105
        if (changed) {
106
            activeEditorKitRef = new WeakReference<SearchableEditorKit>(kit);
107
            for (Map.Entry<PresenterEditorAction, String> actionAndName : presenterAction2Name.entrySet()) {
108
                PresenterEditorAction presenterAction = actionAndName.getKey();
109
                String actionName = actionAndName.getValue();
110
                // Clear ref to old action
111
                presenterAction.clearDelegateActionRef();
112
                // Update to current delegate action (by using the given kit)
113
                presenterAction.delegateAction(kit, actionName);
114
            }
115
        }
116
    }
117
118
    private static final Action NULL_ACTION = new TextAction("null") {
119
        public void actionPerformed(ActionEvent evt) {
120
        }
121
    };
122
123
    private static final Reference<Action> NULL_ACTION_REF = new WeakReference<Action>(NULL_ACTION);
124
125
    static {
126
        EditorRegistry.addPropertyChangeListener(new PropertyChangeListener() {
127
            public void propertyChange(PropertyChangeEvent evt) {
128
                if (EditorRegistry.FOCUS_GAINED_PROPERTY.equals(evt.getPropertyName())) {
129
                    JTextComponent focusedTextComponent = (JTextComponent) evt.getNewValue();
130
                    TextUI ui = (focusedTextComponent != null) ? focusedTextComponent.getUI() : null;
131
                    EditorKit kit = (ui != null)
132
                            ? ui.getEditorKit(focusedTextComponent)
133
                            : EditorActionUtilities.getGlobalKit();
134
                    if (kit != null) {
135
                        SearchableEditorKit searchableKit = EditorActionUtilities.getSearchableKit(kit);
136
                        updateActions(searchableKit);
137
                    }
138
                }
139
            }
140
        });
141
    }
142
143
    public static Action create(Map<String,?> attrs) {
144
        String actionName = (String)attrs.get(Action.NAME);
145
        if (actionName == null) {
146
            throw new IllegalArgumentException("Null Action.NAME attribute for attrs: " + attrs); // NOI18N
147
        }
148
        return new PresenterEditorAction(actionName, attrs);
149
    }
150
151
    /**
152
     * Corresponding action's reference.
153
     */
154
    private Reference<Action> delegateActionRef;
155
156
    private JMenuItem menuPresenter;
157
158
    private JMenuItem popupPresenter;
159
160
    private Component toolBarPresenter;
161
162
    private Map<String,?> attrs;
163
164
    public PresenterEditorAction(String actionName, Map<String,?> attrs) {
165
        super(actionName);
166
        this.attrs = attrs;
167
        presenterAction2Name.put(this, actionName);
168
    }
169
170
    public void actionPerformed(ActionEvent evt) {
171
        // Find the right action for the corresponding editor kit
172
        JTextComponent component = getTextComponent(evt);
173
        if (component != null) {
174
            TextUI ui = component.getUI();
175
            if (ui != null) {
176
                EditorKit kit = ui.getEditorKit(component);
177
                if (kit != null) {
178
                    String actionName = actionName();
179
                    Action action = EditorUtilities.getAction(kit, actionName);
180
                    if (action != null) {
181
                        action.actionPerformed(evt);
182
                    } else {
183
                        if (LOG.isLoggable(Level.FINE)) {
184
                            LOG.fine("Action '" + actionName + "' not found in editor kit " + kit + '\n'); // NOI18N
185
                        }
186
                    }
187
                }
188
            }
189
        }
190
    }
191
192
    public JMenuItem getMenuPresenter() {
193
        if (menuPresenter == null) {
194
            menuPresenter = createMenuItem(false);
195
        }
196
        if (LOG.isLoggable(Level.FINE)) {
197
            LOG.fine("getMenuPresenter() for action=" + actionName() + " returns " + menuPresenter); // NOI18N
198
        }
199
        return menuPresenter;
200
    }
201
202
    public JMenuItem getPopupPresenter() {
203
        if (popupPresenter == null) {
204
            popupPresenter = createMenuItem(true);
205
        }
206
        if (LOG.isLoggable(Level.FINE)) {
207
            LOG.fine("getPopupPresenter() for action=" + actionName() + " returns " + popupPresenter); // NOI18N
208
        }
209
        return popupPresenter;
210
    }
211
212
    public Component getToolbarPresenter() {
213
        if (toolBarPresenter == null) {
214
            toolBarPresenter = new JButton(this);
215
        }
216
        if (LOG.isLoggable(Level.FINE)) {
217
            LOG.fine("getToolbarPresenter() for action=" + actionName() + " returns " + toolBarPresenter); // NOI18N
218
        }
219
        return toolBarPresenter;
220
    }
221
222
    @Override
223
    public Object getValue(String key) {
224
        Object value = super.getValue(key);
225
        if (value == null) {
226
            if (!"instanceCreate".equals(key)) { // Return null for this key
227
                value = attrs.get(key);
228
                if (value == null) {
229
                    Action delegateAction = delegateAction();
230
                    if (delegateAction != null) {
231
                        value = delegateAction.getValue(key);
232
                    }
233
                }
234
            }
235
        }
236
        return value;
237
    }
238
239
    public void propertyChange(PropertyChangeEvent evt) {
240
        String propertyName = evt.getPropertyName();
241
        if (AbstractEditorAction.SELECTED_KEY.equals(propertyName)) {
242
            if (LOG.isLoggable(Level.FINE)) {
243
                LOG.fine("propertyChange() of SELECTED_KEY for action " + actionName());
244
            }
245
            updateSelected();
246
        }
247
    }
248
249
    private void updateSelected() {
250
        if (isCheckBox()) {
251
            boolean selected = isSelected();
252
            if (menuPresenter instanceof JCheckBoxMenuItem) {
253
                ((JCheckBoxMenuItem)menuPresenter).setSelected(selected);
254
            }
255
            if (popupPresenter instanceof JCheckBoxMenuItem) {
256
                ((JCheckBoxMenuItem)popupPresenter).setSelected(selected);
257
            }
258
        }
259
    }
260
261
    public void stateChanged(ChangeEvent evt) {
262
        clearDelegateActionRef();
263
    }
264
265
    private boolean isSelected() {
266
        Action action = delegateAction();
267
        boolean selected = (action != null) && Boolean.TRUE.equals(action.getValue(
268
                AbstractEditorAction.SELECTED_KEY));
269
        return selected;
270
    }
271
272
    private JMenuItem createMenuItem(boolean isPopup) {
273
        final JMenuItem menuItem;
274
        if (isCheckBox()) {
275
            menuItem = new JCheckBoxMenuItem();
276
            if (LOG.isLoggable(Level.FINE)) {
277
                LOG.fine("Create checkbox menu item for action " + actionName() + ", selected=" + isSelected());
278
            }
279
            menuItem.setSelected(isSelected());
280
            menuItem.addItemListener(new ItemListener() {
281
                public void itemStateChanged(ItemEvent evt) {
282
                    boolean checkboxSelected = ((JCheckBoxMenuItem)evt.getSource()).isSelected();
283
                    boolean actionSelected = isSelected();
284
                    if (checkboxSelected != actionSelected) {
285
                        Action delegateAction = delegateAction();
286
                        if (delegateAction != null) {
287
                            delegateAction.putValue(AbstractEditorAction.SELECTED_KEY, checkboxSelected);
288
                        }
289
                    }
290
                }
291
            });
292
293
        } else { // Regular menu item
294
            menuItem = new JMenuItem();
295
        }
296
        Actions.connect(menuItem, this, isPopup);
297
        return menuItem;
298
    }
299
300
    private boolean isCheckBox() {
301
        String presenterType = (String) getValue("PresenterType");
302
        return "CheckBox".equals(presenterType);
303
    }
304
305
    String actionName() {
306
        return (String) getValue(Action.NAME); // should be non-null (check by constructor)
307
    }
308
309
    Action delegateAction() {
310
        return delegateAction(null, null);
311
    }
312
313
    Action delegateAction(SearchableEditorKit searchableKit, String actionName) {
314
        synchronized (this) {
315
            if (delegateActionRef == null) {
316
                if (actionName == null) {
317
                    actionName = actionName();
318
                }
319
                if (searchableKit == null) {
320
                    EditorKit globalKit = EditorActionUtilities.getGlobalKit();
321
                    searchableKit = (globalKit != null) ? EditorActionUtilities.getSearchableKit(globalKit) : null;
322
                    if (searchableKit == null) {
323
                        return null;
324
                    }
325
                }
326
                Action delegateAction = searchableKit.getAction(actionName);
327
                if (delegateAction != null) {
328
                    delegateActionRef = new WeakReference<Action>(delegateAction);
329
                    delegateAction.addPropertyChangeListener(this);
330
                    setEnabled(delegateAction.isEnabled());
331
                } else {
332
                    delegateActionRef = NULL_ACTION_REF;
333
                    setEnabled(false);
334
                    if (LOG.isLoggable(Level.FINE)) {
335
                        LOG.fine("Action '" + actionName + "' not found in global editor kit " + searchableKit + '\n'); // NOI18N
336
                    }
337
                }
338
                updateSelected();
339
            }
340
            return (delegateActionRef != NULL_ACTION_REF)
341
                    ? delegateActionRef.get()
342
                    : null;
343
        }
344
    }
345
346
    private void clearDelegateActionRef() {
347
        synchronized (this) {
348
            if (delegateActionRef != null && delegateActionRef != NULL_ACTION_REF) {
349
                Action oldDelegateAction = delegateActionRef.get();
350
                if (oldDelegateAction != null) {
351
                    oldDelegateAction.removePropertyChangeListener(this);
352
                }
353
            }
354
            delegateActionRef = null;
355
        }
356
        
357
    }
358
359
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/SearchableEditorKit.java (+73 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.editor.lib2.actions;
43
44
import javax.swing.Action;
45
import javax.swing.event.ChangeListener;
46
47
/**
48
 * This interface should be implemented by editor kits that hold their actions
49
 * in a map. They may also notify
50
 *
51
 * @since 1.13
52
 */
53
public interface SearchableEditorKit {
54
55
    /**
56
     * Find action with the given name.
57
     *
58
     * @param actionName non-null action's name.
59
     * @return action's instance or null if an action with the given name does not exist.
60
     */
61
    Action getAction(String actionName);
62
63
    /**
64
     * Add listener for notifications about any change in a set of actions
65
     * maintained by this editor kit.
66
     *
67
     * @param listener non-null listener to be added.
68
     */
69
    void addActionsChangeListener(ChangeListener listener);
70
71
    void removeActionsChangeListener(ChangeListener listener);
72
73
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/actions/SearchableEditorKitImpl.java (+151 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.editor.lib2.actions;
43
44
import java.util.Collection;
45
import java.util.HashMap;
46
import java.util.Map;
47
import java.util.logging.Level;
48
import java.util.logging.Logger;
49
import javax.swing.Action;
50
import javax.swing.event.ChangeEvent;
51
import javax.swing.event.ChangeListener;
52
import javax.swing.text.DefaultEditorKit;
53
import javax.swing.text.EditorKit;
54
import org.netbeans.lib.editor.util.ListenerList;
55
import org.openide.util.Lookup;
56
import org.openide.util.LookupEvent;
57
import org.openide.util.LookupListener;
58
59
/**
60
 * This interface should be implemented by editor kits that hold their actions
61
 * in a map. They may also notify
62
 *
63
 * @since 1.13
64
 */
65
public final class SearchableEditorKitImpl extends DefaultEditorKit implements SearchableEditorKit {
66
67
    // -J-Dorg.netbeans.modules.editor.lib2.actions.SearchableEditorKitImpl.level=FINEST
68
    private static final Logger LOG = Logger.getLogger(SearchableEditorKitImpl.class.getName());
69
70
    public static EditorKit createGlobalKit() {
71
        return new SearchableEditorKitImpl("");
72
    }
73
74
    private final String mimeType;
75
76
    private final Map<String,Action> name2Action = new HashMap<String,Action>();
77
78
    private Action[] actions;
79
    
80
    private LookupListener actionsListener;
81
82
    private ListenerList<ChangeListener> listenerList = new ListenerList<ChangeListener>();
83
84
    private SearchableEditorKitImpl(String mimeType) {
85
        this.mimeType = mimeType;
86
        if (LOG.isLoggable(Level.FINE)) {
87
            LOG.fine("SearchableEditorKitImpl created for \"" + mimeType + "\"\n"); // NOI18N
88
        }
89
        updateActions();
90
    }
91
92
    public Action getAction(String actionName) {
93
        synchronized (name2Action) {
94
            return name2Action.get(actionName);
95
        }
96
    }
97
98
    private void updateActions() {
99
        synchronized (name2Action) {
100
            // Fill up the actions from layer
101
            Lookup.Result<Action> actionsResult = EditorActionUtilities.createActionsLookupResult(mimeType);
102
            Collection<? extends Action> actionColl = actionsResult.allInstances();
103
            actions = new Action[actionColl.size()];
104
            actionColl.toArray(actions);
105
            name2Action.clear();
106
            for (Action action : actions) {
107
                String actionName;
108
                if (action != null && (actionName = (String) action.getValue(Action.NAME)) != null) {
109
                    name2Action.put(actionName, action);
110
                    if (LOG.isLoggable(Level.FINER)) {
111
                        LOG.finer("Mime-type: \"" + mimeType + "\", registerAction(\"" + actionName + // NOI18N
112
                                "\", " + action + ")\n"); // NOI18N
113
                    }
114
                }
115
            }
116
117
            if (actionsListener == null) {
118
                actionsListener = new LookupListener() {
119
                    public void resultChanged(LookupEvent ev) {
120
                        updateActions();
121
                    }
122
                };
123
                actionsResult.addLookupListener(actionsListener);
124
            }
125
        }
126
127
        // Fire change listeners
128
        fireActionsChange();
129
    }
130
131
    @Override
132
    public String getContentType() {
133
        return mimeType;
134
    }
135
136
    public void addActionsChangeListener(ChangeListener listener) {
137
        listenerList.add(listener);
138
    }
139
140
    public void removeActionsChangeListener(ChangeListener listener) {
141
        listenerList.remove(listener);
142
    }
143
144
    private void fireActionsChange() {
145
        ChangeEvent evt = new ChangeEvent(this);
146
        for (ChangeListener listener : listenerList.getListeners()) {
147
            listener.stateChanged(evt);
148
        }
149
    }
150
151
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/resources/layer.xml (+4 lines)
 Lines 46-51    Link Here 
46
<filesystem>
46
<filesystem>
47
    <folder name="Editors">
47
    <folder name="Editors">
48
        <file name="org-netbeans-modules-editor-lib2-highlighting-Factory.instance" />
48
        <file name="org-netbeans-modules-editor-lib2-highlighting-Factory.instance" />
49
        <file name="EditorKit.instance">
50
            <attr name="instanceCreate" methodvalue="org.netbeans.modules.editor.lib2.actions.SearchableEditorKitImpl.createGlobalKit"/>
51
        </file>
52
49
        <folder name="text">
53
        <folder name="text">
50
            <folder name="x-dialog-binding">
54
            <folder name="x-dialog-binding">
51
                <file name="language.instance">
55
                <file name="language.instance">
(-)a/editor.lib2/test/unit/src/org/netbeans/api/editor/EditorUtilitiesTest.java (+71 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.api.editor;
41
42
import javax.swing.Action;
43
import javax.swing.text.DefaultEditorKit;
44
import javax.swing.text.EditorKit;
45
import org.junit.Test;
46
import static org.junit.Assert.*;
47
48
/**
49
 *
50
 * @author mmetelka
51
 */
52
public class EditorUtilitiesTest {
53
54
    public EditorUtilitiesTest() {
55
    }
56
57
    @Test
58
    public void testGetAction() throws Exception {
59
        EditorKit editorKit = new DefaultEditorKit();
60
        String actionName = DefaultEditorKit.backwardAction;
61
        Action result = EditorUtilities.getAction(editorKit, actionName);
62
        for (Action expected : editorKit.getActions()) {
63
            if (actionName.equals(expected.getValue(Action.NAME))) {
64
                assertEquals(expected, result);
65
                return;
66
            }
67
        }
68
        fail("Action " + actionName + " not found.");
69
    }
70
71
}
(-)a/editor.lib2/test/unit/src/org/netbeans/modules/editor/lib2/actions/MacroRecordingTest.java (+103 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.lib2.actions;
41
42
import java.awt.event.ActionEvent;
43
import javax.swing.Action;
44
import javax.swing.JEditorPane;
45
import javax.swing.text.TextAction;
46
import org.junit.After;
47
import org.junit.Before;
48
import org.junit.Test;
49
import static org.junit.Assert.*;
50
51
/**
52
 *
53
 * @author mmetelka
54
 */
55
public class MacroRecordingTest {
56
57
    static final String TEST_ACTION_NAME = "test-action";
58
59
    public MacroRecordingTest() {
60
    }
61
62
    @Before
63
    public void setUp() {
64
    }
65
66
    @After
67
    public void tearDown() {
68
    }
69
70
    @Test
71
    public void testGet() {
72
        MacroRecording macroRecording = MacroRecording.get();
73
        assertNotNull(macroRecording);
74
    }
75
76
    @Test
77
    public void testRecording() {
78
        MacroRecording macroRecording = MacroRecording.get();
79
        assertNotNull(macroRecording.startRecording());
80
        macroRecording.recordAction(new MacroRecordingTestAction(), new ActionEvent(new JEditorPane(), 0, ""));
81
        String text = macroRecording.stopRecording();
82
        assertEquals(TEST_ACTION_NAME, text);
83
    }
84
85
    @Test
86
    public void testStopRecording() {
87
        MacroRecording macroRecording = MacroRecording.get();
88
        assertNull(macroRecording.stopRecording());
89
    }
90
91
    private static final class MacroRecordingTestAction extends TextAction {
92
93
        MacroRecordingTestAction() {
94
            super(TEST_ACTION_NAME);
95
        }
96
97
        public void actionPerformed(ActionEvent arg0) {
98
            // do nothing
99
        }
100
101
    }
102
103
}
(-)a/editor/src/org/netbeans/modules/editor/ExportHtmlAction.java (-1 / +1 lines)
 Lines 73-79    Link Here 
73
import org.netbeans.api.editor.settings.FontColorNames;
73
import org.netbeans.api.editor.settings.FontColorNames;
74
import org.netbeans.api.editor.settings.FontColorSettings;
74
import org.netbeans.api.editor.settings.FontColorSettings;
75
import org.netbeans.api.editor.settings.SimpleValueNames;
75
import org.netbeans.api.editor.settings.SimpleValueNames;
76
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
76
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
77
import org.openide.awt.Mnemonics;
77
import org.openide.awt.Mnemonics;
78
78
79
public class ExportHtmlAction extends CookieAction {
79
public class ExportHtmlAction extends CookieAction {
(-)a/editor/src/org/netbeans/modules/editor/MainMenuAction.java (-1 / +1 lines)
 Lines 64-70    Link Here 
64
import org.netbeans.editor.Utilities;
64
import org.netbeans.editor.Utilities;
65
import org.netbeans.editor.ext.ExtKit;
65
import org.netbeans.editor.ext.ExtKit;
66
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
66
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
67
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
67
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
68
import org.openide.awt.Mnemonics;
68
import org.openide.awt.Mnemonics;
69
import org.openide.util.HelpCtx;
69
import org.openide.util.HelpCtx;
70
import org.openide.util.ImageUtilities;
70
import org.openide.util.ImageUtilities;
(-)a/editor/src/org/netbeans/modules/editor/NbCodeFoldingAction.java (-1 / +1 lines)
 Lines 58-64    Link Here 
58
import org.netbeans.editor.BaseKit;
58
import org.netbeans.editor.BaseKit;
59
import org.netbeans.editor.Utilities;
59
import org.netbeans.editor.Utilities;
60
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
60
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
61
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
61
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
62
import org.openide.util.HelpCtx;
62
import org.openide.util.HelpCtx;
63
import org.openide.util.NbBundle;
63
import org.openide.util.NbBundle;
64
import org.openide.awt.DynamicMenuContent;
64
import org.openide.awt.DynamicMenuContent;
(-)a/editor/src/org/netbeans/modules/editor/NbEditorKit.java (-26 / +12 lines)
 Lines 98-104    Link Here 
98
import org.netbeans.modules.editor.impl.ToolbarActionsProvider;
98
import org.netbeans.modules.editor.impl.ToolbarActionsProvider;
99
import org.netbeans.modules.editor.impl.actions.NavigationHistoryBackAction;
99
import org.netbeans.modules.editor.impl.actions.NavigationHistoryBackAction;
100
import org.netbeans.modules.editor.impl.actions.NavigationHistoryForwardAction;
100
import org.netbeans.modules.editor.impl.actions.NavigationHistoryForwardAction;
101
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
101
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
102
import org.netbeans.modules.editor.options.AnnotationTypesFolder;
102
import org.netbeans.modules.editor.options.AnnotationTypesFolder;
103
import org.openide.awt.Mnemonics;
103
import org.openide.awt.Mnemonics;
104
import org.openide.filesystems.FileObject;
104
import org.openide.filesystems.FileObject;
 Lines 192-227    Link Here 
192
                                       new NavigationHistoryForwardAction(),
192
                                       new NavigationHistoryForwardAction(),
193
                                       new SearchBar.IncrementalSearchForwardAction(),
193
                                       new SearchBar.IncrementalSearchForwardAction(),
194
                                       new SearchBar.IncrementalSearchBackwardAction(),
194
                                       new SearchBar.IncrementalSearchBackwardAction(),
195
                                       new ToggleToolbarAction(),
195
//                                       new ToggleToolbarAction(),
196
                                       new NbToggleLineNumbersAction(),
196
//                                       new NbToggleLineNumbersAction(),
197
                                       new NbGenerateGoToPopupAction(),
197
                                       new NbGenerateGoToPopupAction(),
198
                                   };
198
                                   };
199
        return TextAction.augmentList(super.createActions(), nbEditorActions);
199
        return TextAction.augmentList(super.createActions(), nbEditorActions);
200
    }
200
    }
201
201
202
    protected @Override Action[] getCustomActions() {
202
    @Override
203
        List<Action> actions = EditorActionsProvider.getEditorActions(getContentType());
203
    protected Action[] getDeclaredActions() {
204
        
204
        List<Action> declaredActionList = EditorActionsProvider.getEditorActions(getContentType());
205
        if (LOG.isLoggable(Level.FINE)) {
205
        Action[] declaredActions = new Action[declaredActionList.size()];
206
            LOG.fine("Custom layer actions for '" + getContentType() + "' {"); //NOI18N
206
        declaredActionList.toArray(declaredActions);
207
            for(Action a : actions) {
207
        return declaredActions;
208
                LOG.fine("    " + a); //NOI18N
209
            }
210
            LOG.fine("} End of custom layer actions for '" + getContentType() + "'"); //NOI18N
211
        }
212
        
213
        if (!actions.isEmpty()) {
214
            Action [] superActions = super.getCustomActions();
215
            if (superActions == null || superActions.length == 0) {
216
                return actions.toArray(new Action[actions.size()]);
217
            } else {
218
                return TextAction.augmentList(superActions, actions.toArray(new Action[actions.size()]));
219
            }
220
        } else {
221
            return super.getCustomActions();
222
        }
223
    }
208
    }
224
        
209
210
225
    protected void addSystemActionMapping(String editorActionName, Class systemActionClass) {
211
    protected void addSystemActionMapping(String editorActionName, Class systemActionClass) {
226
        Action a = getActionByName(editorActionName);
212
        Action a = getActionByName(editorActionName);
227
        if (a != null) {
213
        if (a != null) {
 Lines 571-577    Link Here 
571
    /** Switch visibility of line numbers in editor */
557
    /** Switch visibility of line numbers in editor */
572
    //@EditorActionRegistration(name = BaseKit.toggleLineNumbersAction)
558
    //@EditorActionRegistration(name = BaseKit.toggleLineNumbersAction)
573
    // Registration in createActions() due to getPopupMenuItem() in predecessor
559
    // Registration in createActions() due to getPopupMenuItem() in predecessor
574
    public static class NbToggleLineNumbersAction extends ActionFactory.ToggleLineNumbersAction {
560
    public static final class NbToggleLineNumbersAction extends ActionFactory.ToggleLineNumbersAction {
575
561
576
        public NbToggleLineNumbersAction() {
562
        public NbToggleLineNumbersAction() {
577
        }
563
        }
(-)a/editor/src/org/netbeans/modules/editor/NbEditorToolBar.java (-1 / +1 lines)
 Lines 90-96    Link Here 
90
import org.netbeans.editor.Utilities;
90
import org.netbeans.editor.Utilities;
91
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
91
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
92
import org.netbeans.modules.editor.impl.ToolbarActionsProvider;
92
import org.netbeans.modules.editor.impl.ToolbarActionsProvider;
93
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
93
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
94
import org.openide.filesystems.FileChangeAdapter;
94
import org.openide.filesystems.FileChangeAdapter;
95
import org.openide.filesystems.FileChangeListener;
95
import org.openide.filesystems.FileChangeListener;
96
import org.openide.filesystems.FileEvent;
96
import org.openide.filesystems.FileEvent;
(-)a/editor/src/org/netbeans/modules/editor/NbEditorUI.java (-1 / +1 lines)
 Lines 86-92    Link Here 
86
import org.netbeans.modules.editor.impl.SearchBar;
86
import org.netbeans.modules.editor.impl.SearchBar;
87
import org.netbeans.modules.editor.impl.StatusLineFactories;
87
import org.netbeans.modules.editor.impl.StatusLineFactories;
88
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
88
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
89
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
89
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
90
import org.openide.text.CloneableEditorSupport;
90
import org.openide.text.CloneableEditorSupport;
91
import org.openide.util.ContextAwareAction;
91
import org.openide.util.ContextAwareAction;
92
import org.openide.util.Lookup;
92
import org.openide.util.Lookup;
(-)a/editor/src/org/netbeans/modules/editor/resources/layer.xml (-10 lines)
 Lines 105-116    Link Here 
105
            <file name="org-netbeans-modules-editor-NbCodeFoldingAction.instance">
105
            <file name="org-netbeans-modules-editor-NbCodeFoldingAction.instance">
106
                <attr name="position" intvalue="200"/>
106
                <attr name="position" intvalue="200"/>
107
            </file>
107
            </file>
108
            <file name="org-netbeans-modules-editor-MainMenuAction$ShowToolBarAction.instance">
109
                <attr name="position" intvalue="800"/>
110
            </file>
111
            <file name="org-netbeans-modules-editor-MainMenuAction$ShowLineNumbersAction.instance">
112
                <attr name="position" intvalue="850"/>
113
            </file>
114
            </folder>
108
            </folder>
115
        
109
        
116
        <folder name="GoTo">
110
        <folder name="GoTo">
 Lines 118-127    Link Here 
118
                <attr name="position" intvalue="800"/>
112
                <attr name="position" intvalue="800"/>
119
            </file>
113
            </file>
120
            
114
            
121
            <file name="org-netbeans-modules-editor-MainMenuAction$GoToDeclarationAction.instance">
122
                <attr name="position" intvalue="900"/>
123
            </file>                        
124
            
125
            <file name="org-netbeans-modules-editor-MainMenuAction$GoToSuperAction.instance">
115
            <file name="org-netbeans-modules-editor-MainMenuAction$GoToSuperAction.instance">
126
                <attr name="position" intvalue="1000"/>
116
                <attr name="position" intvalue="1000"/>
127
            </file>
117
            </file>
(-)a/editor/test/qa-functional/src/org/netbeans/test/editor/popup/MainMenuTest.java (-1 / +1 lines)
 Lines 53-59    Link Here 
53
import org.netbeans.jemmy.operators.JEditorPaneOperator;
53
import org.netbeans.jemmy.operators.JEditorPaneOperator;
54
import org.netbeans.jemmy.operators.JTextComponentOperator;
54
import org.netbeans.jemmy.operators.JTextComponentOperator;
55
import org.netbeans.junit.NbModuleSuite;
55
import org.netbeans.junit.NbModuleSuite;
56
import org.netbeans.modules.editor.lib.EditorPreferencesDefaults;
56
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
57
57
58
/**
58
/**
59
 * Test behavior of main menus - Edit, View
59
 * Test behavior of main menus - Edit, View
(-)a/openide.awt/src/org/openide/awt/AlwaysEnabledAction.java (-4 / +8 lines)
 Lines 177-187    Link Here 
177
            return fo == null ? null : fo.get("noIconInMenu"); // NOI18N
177
            return fo == null ? null : fo.get("noIconInMenu"); // NOI18N
178
        }
178
        }
179
        if (Action.ACCELERATOR_KEY.equals(name)) {
179
        if (Action.ACCELERATOR_KEY.equals(name)) {
180
            Keymap map = Lookup.getDefault().lookup(Keymap.class);
180
            Object value = fo.get(Action.ACCELERATOR_KEY);
181
            if (map != null) {
181
            if (value == null) {
182
                KeyStroke[] arr = map.getKeyStrokesForAction(action);
182
                Keymap map = Lookup.getDefault().lookup(Keymap.class);
183
                return arr.length > 0 ? arr[0] : null;
183
                if (map != null) {
184
                    KeyStroke[] arr = map.getKeyStrokesForAction(action);
185
                    value = arr.length > 0 ? arr[0] : null;
186
                }
184
            }
187
            }
188
            return value;
185
        }
189
        }
186
        // Delegate query to other properties to "fo" ignoring special properties
190
        // Delegate query to other properties to "fo" ignoring special properties
187
        if (!"delegate".equals(name) && !"instanceCreate".equals(name)) {
191
        if (!"delegate".equals(name) && !"instanceCreate".equals(name)) {

Return to bug 166027
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo