blob: 243a1292f827346d7456267bb688cb88cf0f7a86 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2005, 2019 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.base.ext.templates;
import org.eclipse.statet.ecommons.preferences.core.util.PreferenceUtils;
import org.eclipse.statet.base.core.StatetCore;
import org.eclipse.statet.base.core.StatetProject;
import org.eclipse.statet.base.core.preferences.TaskTagsPreferences;
import org.eclipse.statet.ltk.model.core.elements.ISourceUnit;
import org.eclipse.statet.ltk.ui.templates.SourceEditorContextType;
public class StatextCodeTemplateContextType extends SourceEditorContextType {
public static String getTodoTaskTag(final StatetProject project) {
final TaskTagsPreferences taskPrefs = (project != null) ?
new TaskTagsPreferences(project) :
new TaskTagsPreferences(PreferenceUtils.getInstancePrefs());
final String[] markers = taskPrefs.getTags();
if (markers == null || markers.length == 0) {
return null;
}
return markers[0];
}
/**
* Resolver for ToDo-tags.
*/
protected static class StatetTodo extends Todo {
public StatetTodo() {
}
@Override
protected String getTag(final ISourceUnit su) {
final StatetProject project = StatetCore.getStatetProject(su);
return getTodoTaskTag(project);
}
}
public StatextCodeTemplateContextType(final String id, final String name) {
super(id, name);
}
public StatextCodeTemplateContextType(final String id) {
super(id);
}
protected StatextCodeTemplateContextType() {
super();
}
@Override
protected void addCommonVariables() {
super.addCommonVariables();
addResolver(new Todo());
}
}