2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
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]"
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.
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.
42
package org.netbeans.modules.editor;
44
import java.awt.event.InputEvent;
45
import java.util.Iterator;
46
import java.util.List;
48
import java.util.logging.Level;
49
import java.util.logging.Logger;
50
import org.netbeans.api.editor.mimelookup.MimeLookup;
51
import org.netbeans.api.editor.mimelookup.MimePath;
52
import org.netbeans.editor.BaseSettingsInitializer;
53
import org.netbeans.editor.Settings;
54
import org.netbeans.editor.SettingsDefaults;
55
import org.netbeans.editor.ext.ExtSettingsNames;
56
import org.netbeans.editor.ext.ExtSettingsInitializer;
57
import org.netbeans.modules.editor.options.OptionUtilities;
58
import org.netbeans.modules.editor.options.AllOptionsFolder;
59
import org.netbeans.editor.BaseKit;
60
import org.netbeans.editor.SettingsNames;
61
import org.netbeans.modules.editor.impl.KitsTracker;
62
import org.netbeans.modules.editor.options.BaseOptions;
63
import org.openide.util.Utilities;
66
* Customized settings for NetBeans editor
68
* @author Miloslav Metelka
72
public class NbEditorSettingsInitializer extends Settings.AbstractInitializer {
74
// -J-Dorg.netbeans.modules.editor.NbEditorSettingsInitializer.level=FINE
75
private static final Logger LOG = Logger.getLogger(NbEditorSettingsInitializer.class.getName());
77
public static final String NAME = "nb-editor-settings-initializer"; // NOI18N
79
private static boolean mainInitDone;
81
public static void init() {
84
Settings.addInitializer(new BaseSettingsInitializer(), Settings.CORE_LEVEL);
85
Settings.addInitializer(new ExtSettingsInitializer(), Settings.CORE_LEVEL);
86
Settings.addInitializer(new NbEditorSettingsInitializer());
92
public NbEditorSettingsInitializer() {
96
/** Update map filled with the settings.
97
* @param kitClass kit class for which the settings are being updated.
98
* It is always non-null value.
99
* @param settingsMap map holding [setting-name, setting-value] pairs.
100
* The map can be empty if this is the first initializer
101
* that updates it or if no previous initializers updated it.
103
public void updateSettingsMap(Class kitClass, Map settingsMap) {
105
if (kitClass == BaseKit.class) {
106
settingsMap.put(BaseOptions.TOOLBAR_VISIBLE_PROP, Boolean.TRUE);
107
settingsMap.put(BaseOptions.LINE_NUMBER_VISIBLE_PROP, SettingsDefaults.defaultLineNumberVisible);
109
//Fix for IZ bug #53744:
110
//On MAC OS X, Ctrl+left click has the same meaning as the right-click.
111
//The hyperlinking should be enabled for the Command key on MAC OS X, for Ctrl on others:
114
activationMask = Utilities.isMac()? InputEvent.META_MASK: InputEvent.CTRL_DOWN_MASK;
115
settingsMap.put(SettingsNames.HYPERLINK_ACTIVATION_MODIFIERS, Integer.valueOf(activationMask));
118
if (kitClass == NbEditorKit.class) {
119
// init popup menu items from layer folder
120
if (AllOptionsFolder.getDefault().baseInitialized()){
121
// put to the settings map only if base options has been initialized. See #19470
122
settingsMap.put(ExtSettingsNames.POPUP_MENU_ACTION_NAME_LIST,
123
OptionUtilities.getPopupStrings(OptionUtilities.getGlobalPopupMenuItems())
128
List mimeTypes = KitsTracker.getInstance().getMimeTypesForKitClass(kitClass);
129
for(Iterator i = mimeTypes.iterator(); i.hasNext(); ) {
130
String mimeType = (String) i.next();
132
if (LOG.isLoggable(Level.FINE)) {
133
LOG.fine("Initializing settings for '" + mimeType + "', " + kitClass); //NOI18N
136
// Lookup BaseOptions for the given mime type so that it can hook up its
137
// own settings initializer.
138
MimePath mimePath = MimePath.parse(mimeType);
139
BaseOptions bo = (BaseOptions) MimeLookup.getLookup(mimePath).lookup(BaseOptions.class);
141
if (LOG.isLoggable(Level.FINE)) {
142
LOG.fine("Top level mime type '" + mimeType + "' with no BaseOptions."); //NOI18N