blob: b36d890155fd0795ffa55ec2f99f4e72e0bfccdf [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009, 2017 xored software, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* xored software, Inc. - initial API and Implementation (Alex Panchenko)
*******************************************************************************/
package org.eclipse.dltk.tcl.internal.ui.text;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.dltk.tcl.internal.ui.TclUI;
import org.eclipse.dltk.ui.text.templates.CodeTemplateAccess;
import org.eclipse.dltk.ui.text.templates.CodeTemplateCategory;
import org.eclipse.dltk.ui.text.templates.ICodeTemplateCategory;
import org.eclipse.jface.text.templates.ContextTypeRegistry;
import org.eclipse.jface.text.templates.TemplateContextType;
import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
public class TclCodeTemplateAccess extends CodeTemplateAccess {
/**
* The key to store customized code templates.
*/
private static final String CODE_TEMPLATES_KEY = "org.eclipse.dltk.tcl.text.custom_code_templates"; //$NON-NLS-1$
public TclCodeTemplateAccess() {
super(TclUI.PLUGIN_ID, CODE_TEMPLATES_KEY,
TclUI.getDefault().getPreferenceStore());
}
@Override
protected ContextTypeRegistry createContextTypeRegistry() {
final ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry();
registry.addContextType("org.eclipse.dltk.tcl.text.template.type.tcl");
return registry;
}
private ICodeTemplateCategory[] categories = null;
@Override
public ICodeTemplateCategory[] getCategories() {
if (categories == null) {
Iterator<TemplateContextType> i = getContextTypeRegistry()
.contextTypes();
List<TemplateContextType> contextTypes = new ArrayList<>();
while (i.hasNext()) {
contextTypes.add(i.next());
}
categories = new ICodeTemplateCategory[] { new CodeTemplateCategory(
"Files", true, contextTypes.toArray(
new TemplateContextType[contextTypes.size()])) };
}
return categories;
}
@Override
public ICodeTemplateCategory getCategoryOfContextType(
String contextTypeId) {
return getCategories()[0];
}
}