marfous@16264
|
1 |
/*
|
marfous@16264
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
marfous@16264
|
3 |
*
|
marfous@16264
|
4 |
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
|
marfous@16264
|
5 |
*
|
marfous@16264
|
6 |
* The contents of this file are subject to the terms of either the GNU
|
marfous@16264
|
7 |
* General Public License Version 2 only ("GPL") or the Common
|
marfous@16264
|
8 |
* Development and Distribution License("CDDL") (collectively, the
|
marfous@16264
|
9 |
* "License"). You may not use this file except in compliance with the
|
marfous@16264
|
10 |
* License. You can obtain a copy of the License at
|
marfous@16264
|
11 |
* http://www.netbeans.org/cddl-gplv2.html
|
marfous@16264
|
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
marfous@16264
|
13 |
* specific language governing permissions and limitations under the
|
marfous@16264
|
14 |
* License. When distributing the software, include this License Header
|
marfous@16264
|
15 |
* Notice in each file and include the License file at
|
marfous@16264
|
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
|
marfous@16264
|
17 |
* particular file as subject to the "Classpath" exception as provided
|
marfous@16264
|
18 |
* by Sun in the GPL Version 2 section of the License file that
|
marfous@16264
|
19 |
* accompanied this code. If applicable, add the following below the
|
marfous@16264
|
20 |
* License Header, with the fields enclosed by brackets [] replaced by
|
marfous@16264
|
21 |
* your own identifying information:
|
marfous@16264
|
22 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
marfous@16264
|
23 |
*
|
marfous@16264
|
24 |
* Contributor(s):
|
marfous@16264
|
25 |
*
|
marfous@16264
|
26 |
* The Original Software is NetBeans. The Initial Developer of the Original
|
marfous@16264
|
27 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
|
marfous@16264
|
28 |
* Microsystems, Inc. All Rights Reserved.
|
marfous@16264
|
29 |
*
|
marfous@16264
|
30 |
* If you wish your version of this file to be governed by only the CDDL
|
marfous@16264
|
31 |
* or only the GPL Version 2, indicate your decision by adding
|
marfous@16264
|
32 |
* "[Contributor] elects to include this software in this distribution
|
marfous@16264
|
33 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
marfous@16264
|
34 |
* single choice of license, a recipient has the option to distribute
|
marfous@16264
|
35 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
marfous@16264
|
36 |
* to extend the choice of license to its licensees as provided above.
|
marfous@16264
|
37 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
marfous@16264
|
38 |
* Version 2 license, then the option applies only if the new code is
|
marfous@16264
|
39 |
* made subject to such option by the copyright holder.
|
marfous@16264
|
40 |
*/
|
marfous@16264
|
41 |
|
marfous@16264
|
42 |
package org.netbeans.modules.php.smarty.editor;
|
marfous@16264
|
43 |
|
marfous@16264
|
44 |
|
marfous@16264
|
45 |
import org.netbeans.editor.ext.ExtKit;
|
marfous@16264
|
46 |
import org.netbeans.modules.editor.NbEditorKit;
|
marfous@16264
|
47 |
import javax.swing.Action;
|
marfous@17309
|
48 |
import javax.swing.SwingUtilities;
|
marfous@16264
|
49 |
import javax.swing.text.*;
|
marfous@16264
|
50 |
import org.netbeans.modules.editor.NbEditorUtilities;
|
marfous@16264
|
51 |
import org.openide.filesystems.FileObject;
|
marfous@16264
|
52 |
import org.openide.loaders.DataObject;
|
marfous@16264
|
53 |
import org.netbeans.api.lexer.InputAttributes;
|
marfous@16264
|
54 |
import org.netbeans.modules.csl.api.InstantRenameAction;
|
marfous@16264
|
55 |
import org.netbeans.modules.csl.api.SelectCodeElementAction;
|
marfous@16264
|
56 |
import org.netbeans.modules.csl.api.ToggleBlockCommentAction;
|
marfous@17309
|
57 |
import org.netbeans.modules.editor.NbEditorDocument;
|
marfous@16264
|
58 |
import org.netbeans.modules.php.smarty.editor.lexer.TplTopTokenId;
|
marfous@16264
|
59 |
import org.netbeans.modules.php.smarty.editor.utlis.TplUtils;
|
marfous@16264
|
60 |
import org.netbeans.spi.lexer.MutableTextInput;
|
marfous@16264
|
61 |
|
marfous@16264
|
62 |
/**
|
marfous@16264
|
63 |
* Editor kit implementation for TPL content type
|
marfous@16264
|
64 |
*
|
marfous@16264
|
65 |
* @author Martin Fousek
|
marfous@16264
|
66 |
*/
|
marfous@16264
|
67 |
public class TplKit extends NbEditorKit implements org.openide.util.HelpCtx.Provider{ // NbEditorKit implements org.openide.util.HelpCtx.Provider{
|
marfous@16264
|
68 |
|
marfous@16264
|
69 |
public static final String TPL_MIME_TYPE = "text/x-tpl"; // NOI18N
|
marfous@16264
|
70 |
|
marfous@16264
|
71 |
/** serialVersionUID */
|
marfous@16264
|
72 |
private static final long serialVersionUID = 8922234837050367142L;
|
marfous@16264
|
73 |
|
marfous@16264
|
74 |
public TplKit() {
|
marfous@16264
|
75 |
this(TPL_MIME_TYPE);
|
marfous@16264
|
76 |
}
|
marfous@16264
|
77 |
|
marfous@16264
|
78 |
public TplKit(String mimeType) {
|
marfous@16264
|
79 |
super();
|
marfous@16264
|
80 |
// createDefaultDocument();
|
marfous@16264
|
81 |
}
|
marfous@16264
|
82 |
|
marfous@16264
|
83 |
@Override
|
marfous@16264
|
84 |
public String getContentType() {
|
marfous@16264
|
85 |
return TPL_MIME_TYPE;
|
marfous@16264
|
86 |
}
|
marfous@16264
|
87 |
|
marfous@16264
|
88 |
@Override
|
marfous@16264
|
89 |
public Object clone() {
|
marfous@16264
|
90 |
return new TplKit();
|
marfous@16264
|
91 |
}
|
marfous@16264
|
92 |
|
marfous@16264
|
93 |
@Override
|
marfous@16264
|
94 |
public Document createDefaultDocument() {
|
marfous@16264
|
95 |
final Document doc = super.createDefaultDocument();
|
marfous@16264
|
96 |
// see TplEditorSupport.createStyledDocument;
|
marfous@16264
|
97 |
doc.putProperty("postInitRunnable", new Runnable() { //NOI18N
|
marfous@16264
|
98 |
public void run() {
|
marfous@16264
|
99 |
initLexerColoringListener(doc);
|
marfous@16264
|
100 |
}
|
marfous@16264
|
101 |
});
|
marfous@16264
|
102 |
return doc;
|
marfous@16264
|
103 |
}
|
marfous@16264
|
104 |
|
marfous@16264
|
105 |
@Override
|
marfous@16264
|
106 |
protected Action[] createActions() {
|
marfous@16264
|
107 |
Action[] javaActions = new Action[] {
|
marfous@16264
|
108 |
new SelectCodeElementAction(SelectCodeElementAction.selectNextElementAction, true),
|
marfous@16264
|
109 |
new SelectCodeElementAction(SelectCodeElementAction.selectPreviousElementAction, false),
|
marfous@16264
|
110 |
new InstantRenameAction(),
|
marfous@16264
|
111 |
new ToggleBlockCommentAction(),
|
marfous@16264
|
112 |
new ExtKit.CommentAction(""), //NOI18N
|
marfous@16264
|
113 |
new ExtKit.UncommentAction("") //NOI18N
|
marfous@16264
|
114 |
};
|
marfous@16264
|
115 |
|
marfous@16264
|
116 |
return TextAction.augmentList(super.createActions(), javaActions);
|
marfous@16264
|
117 |
}
|
marfous@16264
|
118 |
|
marfous@17309
|
119 |
public void initLexerColoringListener(final Document doc) {
|
marfous@16264
|
120 |
DataObject dobj = NbEditorUtilities.getDataObject(doc);
|
marfous@16264
|
121 |
FileObject fobj = (dobj != null) ? dobj.getPrimaryFile() : null;
|
marfous@16264
|
122 |
|
marfous@16264
|
123 |
TplMetaData tplMetaData = TplUtils.getProjectPropertiesForFileObject(fobj);
|
marfous@16264
|
124 |
|
marfous@16264
|
125 |
//add an instance of InputAttributes to the document property,
|
marfous@16264
|
126 |
//lexer will use it to read coloring information
|
marfous@16264
|
127 |
InputAttributes inputAttributes = new InputAttributes();
|
marfous@16264
|
128 |
inputAttributes.setValue(TplTopTokenId.language(), TplMetaData.class, tplMetaData, false);
|
marfous@16264
|
129 |
doc.putProperty(InputAttributes.class, inputAttributes);
|
marfous@16264
|
130 |
|
marfous@17309
|
131 |
SwingUtilities.invokeLater(new Runnable() {
|
marfous@17309
|
132 |
|
marfous@17309
|
133 |
@Override
|
marfous@17309
|
134 |
public void run() {
|
marfous@17309
|
135 |
NbEditorDocument nbdoc = (NbEditorDocument) doc;
|
marfous@17309
|
136 |
nbdoc.runAtomic(new Runnable() {
|
marfous@17309
|
137 |
|
marfous@17309
|
138 |
@Override
|
marfous@17309
|
139 |
public void run() {
|
marfous@17309
|
140 |
MutableTextInput mti = (MutableTextInput) doc.getProperty(MutableTextInput.class);
|
marfous@17309
|
141 |
if (mti != null) {
|
marfous@17309
|
142 |
mti.tokenHierarchyControl().rebuild();
|
marfous@17309
|
143 |
}
|
marfous@17309
|
144 |
}
|
marfous@17309
|
145 |
});
|
marfous@17309
|
146 |
}
|
marfous@17309
|
147 |
});
|
marfous@16264
|
148 |
}
|
marfous@16264
|
149 |
|
marfous@16264
|
150 |
@Override
|
marfous@16264
|
151 |
public org.openide.util.HelpCtx getHelpCtx() {
|
marfous@16264
|
152 |
return new org.openide.util.HelpCtx(TplKit.class);
|
marfous@16264
|
153 |
}
|
marfous@16264
|
154 |
|
marfous@16264
|
155 |
}
|
marfous@16264
|
156 |
|