use of com.android.tools.idea.npw.template.ConfigureTemplateParametersStep in project android by JetBrains.
the class NewAndroidComponentAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (view == null) {
return;
}
Module module = LangDataKeys.MODULE.getData(dataContext);
if (module == null) {
return;
}
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null || facet.getAndroidModel() == null) {
return;
}
VirtualFile targetFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
File file = TemplateManager.getInstance().getTemplateFile(myTemplateCategory, myTemplateName);
assert targetFile != null;
VirtualFile targetDirectory = targetFile;
if (!targetDirectory.isDirectory()) {
targetDirectory = targetFile.getParent();
assert targetDirectory != null;
}
assert file != null;
// e.g. "Empty Activity", "Tabbed Activity"
String activityDescription = e.getPresentation().getText();
List<AndroidSourceSet> sourceSets = AndroidSourceSet.getSourceSets(facet, targetDirectory);
assert sourceSets.size() > 0;
String initialPackageSuggestion = AndroidPackageUtils.getPackageForPath(facet, sourceSets, targetDirectory);
Project project = module.getProject();
RenderTemplateModel templateModel = new RenderTemplateModel(project, new TemplateHandle(file), initialPackageSuggestion, sourceSets.get(0), "New " + activityDescription);
boolean isActivity = isActivityTemplate();
String dialogTitle = AndroidBundle.message(isActivity ? "android.wizard.new.activity.title" : "android.wizard.new.component.title");
String stepTitle = AndroidBundle.message(isActivity ? "android.wizard.config.activity.title" : "android.wizard.config.component.title");
ModelWizard.Builder wizardBuilder = new ModelWizard.Builder();
wizardBuilder.addStep(new ConfigureTemplateParametersStep(templateModel, stepTitle, sourceSets, facet));
ModelWizardDialog dialog = new StudioWizardDialogBuilder(wizardBuilder.build(), dialogTitle).setProject(project).build();
dialog.show();
/*
// TODO: Implement the getCreatedElements call for the wizard
final PsiElement[] createdElements = dialog.getCreatedElements();
for (PsiElement createdElement : createdElements) {
view.selectElement(createdElement);
}
*/
}
Aggregations