2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2009 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.php.smarty.editor;
45 import org.netbeans.editor.ext.ExtKit;
46 import org.netbeans.modules.editor.NbEditorKit;
47 import javax.swing.Action;
48 import javax.swing.SwingUtilities;
49 import javax.swing.text.*;
50 import org.netbeans.modules.editor.NbEditorUtilities;
51 import org.openide.filesystems.FileObject;
52 import org.openide.loaders.DataObject;
53 import org.netbeans.api.lexer.InputAttributes;
54 import org.netbeans.modules.csl.api.InstantRenameAction;
55 import org.netbeans.modules.csl.api.SelectCodeElementAction;
56 import org.netbeans.modules.csl.api.ToggleBlockCommentAction;
57 import org.netbeans.modules.editor.NbEditorDocument;
58 import org.netbeans.modules.php.smarty.editor.lexer.TplTopTokenId;
59 import org.netbeans.modules.php.smarty.editor.utlis.TplUtils;
60 import org.netbeans.spi.lexer.MutableTextInput;
63 * Editor kit implementation for TPL content type
65 * @author Martin Fousek
67 public class TplKit extends NbEditorKit implements org.openide.util.HelpCtx.Provider{ // NbEditorKit implements org.openide.util.HelpCtx.Provider{
69 public static final String TPL_MIME_TYPE = "text/x-tpl"; // NOI18N
71 /** serialVersionUID */
72 private static final long serialVersionUID = 8922234837050367142L;
78 public TplKit(String mimeType) {
80 // createDefaultDocument();
84 public String getContentType() {
89 public Object clone() {
94 public Document createDefaultDocument() {
95 final Document doc = super.createDefaultDocument();
96 // see TplEditorSupport.createStyledDocument;
97 doc.putProperty("postInitRunnable", new Runnable() { //NOI18N
99 initLexerColoringListener(doc);
106 protected Action[] createActions() {
107 Action[] javaActions = new Action[] {
108 new SelectCodeElementAction(SelectCodeElementAction.selectNextElementAction, true),
109 new SelectCodeElementAction(SelectCodeElementAction.selectPreviousElementAction, false),
110 new InstantRenameAction(),
111 new ToggleBlockCommentAction(),
112 new ExtKit.CommentAction(""), //NOI18N
113 new ExtKit.UncommentAction("") //NOI18N
116 return TextAction.augmentList(super.createActions(), javaActions);
119 public void initLexerColoringListener(final Document doc) {
120 DataObject dobj = NbEditorUtilities.getDataObject(doc);
121 FileObject fobj = (dobj != null) ? dobj.getPrimaryFile() : null;
123 TplMetaData tplMetaData = TplUtils.getProjectPropertiesForFileObject(fobj);
125 //add an instance of InputAttributes to the document property,
126 //lexer will use it to read coloring information
127 InputAttributes inputAttributes = new InputAttributes();
128 inputAttributes.setValue(TplTopTokenId.language(), TplMetaData.class, tplMetaData, false);
129 doc.putProperty(InputAttributes.class, inputAttributes);
131 SwingUtilities.invokeLater(new Runnable() {
135 NbEditorDocument nbdoc = (NbEditorDocument) doc;
136 nbdoc.runAtomic(new Runnable() {
140 MutableTextInput mti = (MutableTextInput) doc.getProperty(MutableTextInput.class);
142 mti.tokenHierarchyControl().rebuild();
151 public org.openide.util.HelpCtx getHelpCtx() {
152 return new org.openide.util.HelpCtx(TplKit.class);