use of com.android.tools.idea.npw.NewAndroidActivityWizard in project android by JetBrains.
the class TemplateManager method fillCategory.
private void fillCategory(NonEmptyActionGroup categoryGroup, final String category, ActionManager am) {
Map<String, File> categoryRow = myCategoryTable.row(category);
if (CATEGORY_ACTIVITY.equals(category)) {
AnAction galleryAction = new AnAction() {
@Override
public void update(AnActionEvent e) {
updateAction(e, "Gallery...", true);
}
@Override
public void actionPerformed(AnActionEvent e) {
// TODO: before submitting this code, change this to only use the new wizard
if (Boolean.getBoolean("use.npw.modelwizard") && (e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
DataContext dataContext = e.getDataContext();
Module module = LangDataKeys.MODULE.getData(dataContext);
assert module != null;
VirtualFile targetFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
assert targetFile != null;
VirtualFile targetDirectory = targetFile;
if (!targetDirectory.isDirectory()) {
targetDirectory = targetFile.getParent();
assert targetDirectory != null;
}
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null && facet.getAndroidModel() != null;
List<TemplateHandle> templateList = getTemplateList(FormFactor.MOBILE);
List<AndroidSourceSet> sourceSets = AndroidSourceSet.getSourceSets(facet, targetDirectory);
assert (sourceSets.size() > 0);
String initialPackageSuggestion = AndroidPackageUtils.getPackageForPath(facet, sourceSets, targetDirectory);
Project project = facet.getModule().getProject();
// TODO: Missing logic to select the default template
RenderTemplateModel renderModel = new RenderTemplateModel(project, templateList.get(0), initialPackageSuggestion, sourceSets.get(0), AndroidBundle.message("android.wizard.activity.add"));
NewModuleModel moduleModel = new NewModuleModel(project);
ChooseActivityTypeStep chooseActivityTypeStep = new ChooseActivityTypeStep(moduleModel, renderModel, facet, templateList, targetDirectory);
ModelWizard wizard = new ModelWizard.Builder().addStep(chooseActivityTypeStep).build();
new StudioWizardDialogBuilder(wizard, "New Android Activity").build().show();
} else {
DataContext dataContext = e.getDataContext();
final Module module = LangDataKeys.MODULE.getData(dataContext);
VirtualFile targetFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
NewAndroidActivityWizard wizard = new NewAndroidActivityWizard(module, targetFile, null);
wizard.init();
wizard.show();
}
}
};
categoryGroup.add(galleryAction);
categoryGroup.addSeparator();
setPresentation(category, galleryAction);
}
for (String templateName : categoryRow.keySet()) {
if (EXCLUDED_TEMPLATES.contains(templateName)) {
continue;
}
TemplateMetadata metadata = getTemplateMetadata(myCategoryTable.get(category, templateName));
NewAndroidComponentAction templateAction = new NewAndroidComponentAction(category, templateName, metadata);
String actionId = ACTION_ID_PREFIX + category + templateName;
am.unregisterAction(actionId);
am.registerAction(actionId, templateAction);
categoryGroup.add(templateAction);
}
}
Aggregations