Implement code folding [message #506417] |
Thu, 07 January 2010 13:28 |
Kevin KIN-FOO Messages: 58 Registered: January 2010 |
Member |
|
|
Hi,
I have been searching the forum for a while but I wasn't able to find a satifying answer. How to enable code folding in a DLTK based editor. I've got both DLTK parser and editor, I just would like to fold function in the editor. Does anyone know where I should look?
Regards
[Updated on: Thu, 07 January 2010 13:32] Report message to a moderator
|
|
|
|
Re: Implement code folding [message #506608 is a reply to message #506519] |
Fri, 08 January 2010 10:23 |
Kevin KIN-FOO Messages: 58 Registered: January 2010 |
Member |
|
|
Thanks for your quick answer.
I've implemented the minimal folding, just to have a quick look. Functions don't fold yet. I think that's pretty normal as functions aren't partitionned yet.
Anyway, comments are partitionned and they don't fold either. Am I forgetting something? The comments and strings are in color, that mean that ther are parsed and the editor is aware of their existence.
Here my partitions:
public interface ILuaPartitions {
public static final String LUA_PARTITIONING = LuaConstants.LUA_PARTITIONING;
public static final String LUA_COMMENT = "__lua_comment"; //$NON-NLS-1$
public static final String LUA_MULTI_LINE_COMMENT = "__lua_multi_line_comment"; //$NON-NLS-1$
public static final String LUA_STRING = "__lua_string"; //$NON-NLS-1$
public static final String LUA_SINGLE_QUOTE_STRING = "__lua_single_quote_string"; //$NON-NLS-1$
public final static String[] LUA_PARTITION_TYPES = new String[] {
IDocument.DEFAULT_CONTENT_TYPE, ILuaPartitions.LUA_COMMENT,
ILuaPartitions.LUA_STRING, ILuaPartitions.LUA_SINGLE_QUOTE_STRING,
ILuaPartitions.LUA_MULTI_LINE_COMMENT };
}
And the associated rules:public class LuaPartitionScanner extends RuleBasedPartitionScanner {
public LuaPartitionScanner() {
super();
List<PatternRule> rules = new ArrayList<PatternRule>();
/*
* Deal with single and double quote multi lines strings
*/
IToken string = new Token(ILuaPartitions.LUA_STRING);
IToken singleQuoteString = new Token(
ILuaPartitions.LUA_SINGLE_QUOTE_STRING);
rules
.add(new MultiLineRule(
"\'", "\'", singleQuoteString, '\\', false)); //$NON-NLS-1$ //$NON-NLS-2$
rules.add(new MultiLineRule("\"", "\"", string, '\\', false)); //$NON-NLS-1$ //$NON-NLS-2$
/*
* Deal with comments
*/
// Multi-line
IToken multiLineComment = new Token(
ILuaPartitions.LUA_MULTI_LINE_COMMENT);
rules.add(new MultiLineRule("--[[", "]]", multiLineComment));//$NON-NLS-1$
// Single line
IToken comment = new Token(ILuaPartitions.LUA_COMMENT);
rules.add(new EndOfLineRule("--", comment)); //$NON-NLS-1$
// Apply rules
IPredicateRule[] result = new IPredicateRule[rules.size()];
rules.toArray(result);
setPredicateRules(result);
}
}
|
|
|
|
|
Re: Implement code folding [message #507430 is a reply to message #507391] |
Wed, 13 January 2010 13:37 |
Alex Panchenko Messages: 342 Registered: July 2009 |
Senior Member |
|
|
Hi Kevin,
I am not sure what makes you think it's enabled by default. If you want it to, then you should set it
<extension point="org.eclipse.core.runtime.preferences">
<initializer class="MyPreferenceInitializer"/>
</extension>
public class MyPreferenceInitializer extends AbstractPreferenceInitializer {
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = MyUI.getDefault().getPreferenceStore();
....
store.setDefault(PreferenceConstants.EDITOR_FOLDING_ENABLED, true);
....
}
}
It's used in ScriptEditor as following:
private boolean isFoldingEnabled() {
return getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
}
Regards,
Alex
[Updated on: Thu, 14 January 2010 07:13] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04879 seconds