Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "DLTK Adding Todo Task Tag Support"
(→Steps) |
(→Steps) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Summary == | == Summary == | ||
− | |||
− | |||
This mini tutorial outlines the steps required to add todo task tag support to your plugin. | This mini tutorial outlines the steps required to add todo task tag support to your plugin. | ||
Line 15: | Line 13: | ||
* If you have not done so already, set up a preference initializer for your core plugin. | * If you have not done so already, set up a preference initializer for your core plugin. | ||
− | * Once complete, initialize your plugin store's default values with a call to: | + | * Once complete, initialize your plugin store's default values with a call to: |
+ | |||
+ | <source lang="java"> | ||
+ | package org.eclipse.dltk.python.internal.core; | ||
+ | |||
+ | import org.eclipse.core.runtime.Preferences; | ||
+ | import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; | ||
+ | import org.eclipse.dltk.compiler.task.TaskTagUtils; | ||
+ | import org.eclipse.dltk.python.core.PythonPlugin; | ||
+ | |||
+ | |||
+ | public class PythonCorePreferenceInitializer extends AbstractPreferenceInitializer { | ||
+ | |||
+ | public void initializeDefaultPreferences() { | ||
+ | Preferences store = PythonPlugin.getDefault().getPluginPreferences(); | ||
+ | TaskTagUtils.initializeDefaultValues(store); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
* Add org.eclipse.dltk.validators.core as a dependency for your core plugin. | * Add org.eclipse.dltk.validators.core as a dependency for your core plugin. | ||
− | * Create an implementation of org.eclipse.dltk.validators.core.AbstractTodoParserBuildParticipantType and add the extension definition, | + | * Create an implementation of org.eclipse.dltk.validators.core.AbstractTodoParserBuildParticipantType |
+ | |||
+ | <source lang="java"> | ||
+ | package org.eclipse.dltk.python.internal.core.parser; | ||
+ | |||
+ | import org.eclipse.dltk.compiler.task.ITodoTaskPreferences; | ||
+ | import org.eclipse.dltk.compiler.task.TodoTaskPreferencesOnPrefernceLookupDelegate; | ||
+ | import org.eclipse.dltk.core.IScriptProject; | ||
+ | import org.eclipse.dltk.core.builder.AbstractTodoTaskBuildParticipantType; | ||
+ | import org.eclipse.dltk.python.core.PythonPlugin; | ||
+ | |||
+ | public class PythonTodoParserType extends AbstractTodoTaskBuildParticipantType { | ||
+ | |||
+ | protected ITodoTaskPreferences getPreferences(IScriptProject project) { | ||
+ | return new TodoTaskPreferencesOnPreferenceLookupDelegate(PythonPlugin.PLUGIN_ID, project); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | * and add the extension definition, this also includes adding a parser build participant if you have not already done so. | ||
<source lang="xml"> | <source lang="xml"> | ||
<extension | <extension | ||
− | point="org.eclipse.dltk. | + | point="org.eclipse.dltk.core.buildParticipant"> |
− | < | + | <buildParticipant |
+ | class="org.eclipse.dltk.core.builder.ParserBuildParticipantFactory" | ||
+ | id="org.eclipse.dltk.python.buildParticipant.parser" | ||
+ | name="%parserBuildParticipant.name" | ||
+ | nature="org.eclipse.dltk.python.core.nature"> | ||
+ | </buildParticipant> | ||
+ | <buildParticipant | ||
class="org.eclipse.dltk.python.internal.core.parser.PythonTodoParserType" | class="org.eclipse.dltk.python.internal.core.parser.PythonTodoParserType" | ||
id="org.eclipse.dltk.python.todo" | id="org.eclipse.dltk.python.todo" | ||
+ | name="%taskTagsBuildParticipant.name" | ||
nature="org.eclipse.dltk.python.core.nature"> | nature="org.eclipse.dltk.python.core.nature"> | ||
− | </ | + | <requires |
+ | id="org.eclipse.dltk.python.buildParticipant.parser"> | ||
+ | </requires> | ||
+ | </buildParticipant> | ||
</extension> | </extension> | ||
</source> | </source> | ||
Line 33: | Line 79: | ||
<source lang="java"> | <source lang="java"> | ||
− | fCommentScanner = | + | fCommentScanner = createCommentScanner(PythonColorConstants.PYTHON_SINGLE_LINE_COMMENT, PythonColorConstants.PYTHON_TODO_TAG); |
− | + | ||
− | + | ||
− | + | ||
</source> | </source> | ||
Line 49: | Line 92: | ||
</source> | </source> | ||
− | * Create an implementation of org.eclipse.dltk.ui.preferences. | + | * Create an implementation of org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage |
+ | |||
+ | <source lang="java"> | ||
+ | package org.eclipse.dltk.python.internal.ui.preferences; | ||
+ | |||
+ | import org.eclipse.core.resources.IProject; | ||
+ | import org.eclipse.core.runtime.Preferences; | ||
+ | import org.eclipse.dltk.python.core.PythonPlugin; | ||
+ | import org.eclipse.dltk.python.core.PythonNature; | ||
+ | import org.eclipse.dltk.ui.PreferencesAdapter; | ||
+ | import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage; | ||
+ | import org.eclipse.dltk.ui.preferences.AbstractOptionsBlock; | ||
+ | import org.eclipse.dltk.ui.preferences.AbstractTodoTaskOptionsBlock; | ||
+ | import org.eclipse.dltk.ui.preferences.PreferenceKey; | ||
+ | import org.eclipse.dltk.ui.util.IStatusChangeListener; | ||
+ | import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; | ||
+ | |||
+ | public class PythonTodoTaskPreferencePage extends AbstractConfigurationBlockPropertyAndPreferencePage { | ||
+ | |||
+ | static final PreferenceKey CASE_SENSITIVE = AbstractTodoTaskOptionsBlock.createCaseSensitiveKey(PythonPlugin.PLUGIN_ID); | ||
+ | |||
+ | static final PreferenceKey ENABLED = AbstractTodoTaskOptionsBlock.createEnabledKey(PythonPlugin.PLUGIN_ID); | ||
+ | |||
+ | static final PreferenceKey TAGS = AbstractTodoTaskOptionsBlock.createTagKey(PythonPlugin.PLUGIN_ID); | ||
+ | |||
+ | protected String getHelpId() { | ||
+ | return null; | ||
+ | } | ||
+ | |||
+ | protected void setDescription() { | ||
+ | setDescription(PythonPreferencesMessages.TodoTaskDescription); | ||
+ | } | ||
+ | |||
+ | protected Preferences getPluginPreferences() { | ||
+ | return PythonPlugin.getDefault().getPluginPreferences(); | ||
+ | } | ||
+ | |||
+ | protected AbstractOptionsBlock createOptionsBlock(IStatusChangeListener newStatusChangedListener, IProject project, | ||
+ | IWorkbenchPreferenceContainer container) { | ||
+ | return new AbstractTodoTaskOptionsBlock(newStatusChangedListener,project, getPreferenceKeys(), container) { | ||
+ | protected PreferenceKey getTags() { | ||
+ | return TAGS; | ||
+ | } | ||
+ | |||
+ | protected PreferenceKey getEnabledKey() { | ||
+ | return ENABLED; | ||
+ | } | ||
+ | |||
+ | protected PreferenceKey getCaseSensitiveKey() { | ||
+ | return CASE_SENSITIVE; | ||
+ | } | ||
+ | }; | ||
+ | } | ||
+ | |||
+ | protected String getNatureId() { | ||
+ | return PythonNature.NATURE_ID; | ||
+ | } | ||
+ | |||
+ | protected String getProjectHelpId() { | ||
+ | return null; | ||
+ | } | ||
+ | |||
+ | protected void setPreferenceStore() { | ||
+ | setPreferenceStore(new PreferencesAdapter(PythonPlugin.getDefault().getPluginPreferences())); | ||
+ | } | ||
+ | |||
+ | protected String getPreferencePageId() { | ||
+ | return "org.eclipse.dltk.python.preferences.todo"; | ||
+ | } | ||
+ | |||
+ | protected String getPropertyPageId() { | ||
+ | return "org.eclipse.dltk.python.propertyPage.todo"; | ||
+ | } | ||
+ | |||
+ | protected PreferenceKey[] getPreferenceKeys() { | ||
+ | return new PreferenceKey[] { TAGS, ENABLED, CASE_SENSITIVE }; | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | * add the preference page definition | ||
<source lang="xml"> | <source lang="xml"> | ||
Line 57: | Line 180: | ||
id="org.eclipse.dltk.python.ui.editor.TodoTasks" | id="org.eclipse.dltk.python.ui.editor.TodoTasks" | ||
name="%PythonTaskTags.name"/> | name="%PythonTaskTags.name"/> | ||
+ | </source> | ||
+ | |||
+ | * and the property page definition | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <page | ||
+ | category="org.eclipse.dltk.python.propertyPage" | ||
+ | class="org.eclipse.dltk.python.internal.ui.preferences.PythonTodoTaskPreferencePage" | ||
+ | id="org.eclipse.dltk.python.propertyPage.todo" | ||
+ | name="%PythonTodoPropertyPage.name"> | ||
+ | <enabledWhen> | ||
+ | <adapt type="org.eclipse.core.resources.IProject"> | ||
+ | <test property="org.eclipse.core.resources.projectNature" value="org.eclipse.dltk.python.core.nature"/> | ||
+ | </adapt> | ||
+ | </enabledWhen> | ||
+ | </page> | ||
</source> | </source> | ||
Line 62: | Line 201: | ||
<source lang="java"> | <source lang="java"> | ||
− | { PreferencesMessages.DLTKEditorPreferencePage_CommentTaskTags, | + | { |
+ | PreferencesMessages.DLTKEditorPreferencePage_CommentTaskTags, | ||
PythonPreferenceConstants.COMMENT_TASK_TAGS, | PythonPreferenceConstants.COMMENT_TASK_TAGS, | ||
sCommentsCategory | sCommentsCategory | ||
Line 69: | Line 209: | ||
* and you're done! if all went right, you should have task tag support. | * and you're done! if all went right, you should have task tag support. | ||
+ | |||
+ | [[Category:DLTK]] |
Latest revision as of 16:38, 2 November 2008
Summary
This mini tutorial outlines the steps required to add todo task tag support to your plugin.
Prerequisites
This tutorial assumes the following have been implemented:
- document partitioning
- syntax highlighting
Steps
- If you have not done so already, set up a preference initializer for your core plugin.
- Once complete, initialize your plugin store's default values with a call to:
package org.eclipse.dltk.python.internal.core; import org.eclipse.core.runtime.Preferences; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.dltk.compiler.task.TaskTagUtils; import org.eclipse.dltk.python.core.PythonPlugin; public class PythonCorePreferenceInitializer extends AbstractPreferenceInitializer { public void initializeDefaultPreferences() { Preferences store = PythonPlugin.getDefault().getPluginPreferences(); TaskTagUtils.initializeDefaultValues(store); } }
- Add org.eclipse.dltk.validators.core as a dependency for your core plugin.
- Create an implementation of org.eclipse.dltk.validators.core.AbstractTodoParserBuildParticipantType
package org.eclipse.dltk.python.internal.core.parser; import org.eclipse.dltk.compiler.task.ITodoTaskPreferences; import org.eclipse.dltk.compiler.task.TodoTaskPreferencesOnPrefernceLookupDelegate; import org.eclipse.dltk.core.IScriptProject; import org.eclipse.dltk.core.builder.AbstractTodoTaskBuildParticipantType; import org.eclipse.dltk.python.core.PythonPlugin; public class PythonTodoParserType extends AbstractTodoTaskBuildParticipantType { protected ITodoTaskPreferences getPreferences(IScriptProject project) { return new TodoTaskPreferencesOnPreferenceLookupDelegate(PythonPlugin.PLUGIN_ID, project); } }
- and add the extension definition, this also includes adding a parser build participant if you have not already done so.
<extension point="org.eclipse.dltk.core.buildParticipant"> <buildParticipant class="org.eclipse.dltk.core.builder.ParserBuildParticipantFactory" id="org.eclipse.dltk.python.buildParticipant.parser" name="%parserBuildParticipant.name" nature="org.eclipse.dltk.python.core.nature"> </buildParticipant> <buildParticipant class="org.eclipse.dltk.python.internal.core.parser.PythonTodoParserType" id="org.eclipse.dltk.python.todo" name="%taskTagsBuildParticipant.name" nature="org.eclipse.dltk.python.core.nature"> <requires id="org.eclipse.dltk.python.buildParticipant.parser"> </requires> </buildParticipant> </extension>
- replace the comment scanner in your org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration implementation with a org.eclipse.dltk.ui.text.ScriptCommentScanner, ie:
fCommentScanner = createCommentScanner(PythonColorConstants.PYTHON_SINGLE_LINE_COMMENT, PythonColorConstants.PYTHON_TODO_TAG);
- add ui preference constants and their initialization values, ie:
public final static String COMMENT_TASK_TAGS = PythonColorConstants.PYTHON_TODO_TAG; public final static String COMMENT_TASK_TAGS_BOLD = COMMENT_TASK_TAGS + EDITOR_BOLD_SUFFIX; PreferenceConverter.setDefault(store, COMMENT_TASK_TAGS, new RGB(127, 159, 191)); store.setDefault(COMMENT_TASK_TAGS_BOLD, true);
- Create an implementation of org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage
package org.eclipse.dltk.python.internal.ui.preferences; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Preferences; import org.eclipse.dltk.python.core.PythonPlugin; import org.eclipse.dltk.python.core.PythonNature; import org.eclipse.dltk.ui.PreferencesAdapter; import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage; import org.eclipse.dltk.ui.preferences.AbstractOptionsBlock; import org.eclipse.dltk.ui.preferences.AbstractTodoTaskOptionsBlock; import org.eclipse.dltk.ui.preferences.PreferenceKey; import org.eclipse.dltk.ui.util.IStatusChangeListener; import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; public class PythonTodoTaskPreferencePage extends AbstractConfigurationBlockPropertyAndPreferencePage { static final PreferenceKey CASE_SENSITIVE = AbstractTodoTaskOptionsBlock.createCaseSensitiveKey(PythonPlugin.PLUGIN_ID); static final PreferenceKey ENABLED = AbstractTodoTaskOptionsBlock.createEnabledKey(PythonPlugin.PLUGIN_ID); static final PreferenceKey TAGS = AbstractTodoTaskOptionsBlock.createTagKey(PythonPlugin.PLUGIN_ID); protected String getHelpId() { return null; } protected void setDescription() { setDescription(PythonPreferencesMessages.TodoTaskDescription); } protected Preferences getPluginPreferences() { return PythonPlugin.getDefault().getPluginPreferences(); } protected AbstractOptionsBlock createOptionsBlock(IStatusChangeListener newStatusChangedListener, IProject project, IWorkbenchPreferenceContainer container) { return new AbstractTodoTaskOptionsBlock(newStatusChangedListener,project, getPreferenceKeys(), container) { protected PreferenceKey getTags() { return TAGS; } protected PreferenceKey getEnabledKey() { return ENABLED; } protected PreferenceKey getCaseSensitiveKey() { return CASE_SENSITIVE; } }; } protected String getNatureId() { return PythonNature.NATURE_ID; } protected String getProjectHelpId() { return null; } protected void setPreferenceStore() { setPreferenceStore(new PreferencesAdapter(PythonPlugin.getDefault().getPluginPreferences())); } protected String getPreferencePageId() { return "org.eclipse.dltk.python.preferences.todo"; } protected String getPropertyPageId() { return "org.eclipse.dltk.python.propertyPage.todo"; } protected PreferenceKey[] getPreferenceKeys() { return new PreferenceKey[] { TAGS, ENABLED, CASE_SENSITIVE }; } }
- add the preference page definition
<page category="org.eclipse.dltk.python.preferences" class="org.eclipse.dltk.python.internal.ui.preferences.PythonTodoTaskPreferencePage" id="org.eclipse.dltk.python.ui.editor.TodoTasks" name="%PythonTaskTags.name"/>
- and the property page definition
<page category="org.eclipse.dltk.python.propertyPage" class="org.eclipse.dltk.python.internal.ui.preferences.PythonTodoTaskPreferencePage" id="org.eclipse.dltk.python.propertyPage.todo" name="%PythonTodoPropertyPage.name"> <enabledWhen> <adapt type="org.eclipse.core.resources.IProject"> <test property="org.eclipse.core.resources.projectNature" value="org.eclipse.dltk.python.core.nature"/> </adapt> </enabledWhen> </page>
- add an entry for the color syntax to your org.eclipse.dltk.ui.preferences.AbstractScriptEditorColoringConfigurationBlock implementation, ie:
{ PreferencesMessages.DLTKEditorPreferencePage_CommentTaskTags, PythonPreferenceConstants.COMMENT_TASK_TAGS, sCommentsCategory }
- and you're done! if all went right, you should have task tag support.