in aswb/src/com/google/idea/blaze/android/resources/actions/BlazeCreateResourceFileDialog.java [88:211]
public BlazeCreateResourceFileDialog(
AndroidFacet facet,
Collection<CreateTypedResourceFileAction> actions,
ResourceFolderType folderType,
String filename,
String rootElement,
FolderConfiguration folderConfiguration,
boolean chooseFileName,
boolean chooseModule,
PsiDirectory resDirectory,
DataContext dataContext,
ValidatorFactory validatorFactory) {
super(facet.getModule().getProject());
setupUi();
myFacet = facet;
myResDirectory = resDirectory;
myValidatorFactory = validatorFactory;
myResTypeLabel.setLabelFor(myResourceTypeCombo);
myResourceTypeCombo.registerUpDownHint(myFileNameField);
myUpDownHint.setIcon(PlatformIcons.UP_DOWN_ARROWS);
String selectedTemplate = setupSubActions(actions, myResourceTypeCombo, folderType);
myDeviceConfiguratorPanel =
setupDeviceConfigurationPanel(myDirectoryNameTextField, myResourceTypeCombo, myErrorLabel);
if (folderConfiguration != null) {
myDeviceConfiguratorPanel.init(folderConfiguration);
}
myResourceTypeCombo
.getComboBox()
.addActionListener(
e -> {
myDeviceConfiguratorPanel.applyEditors();
updateRootElementTextField();
});
if (folderType != null && selectedTemplate != null) {
final boolean v = folderType == ResourceFolderType.LAYOUT;
myRootElementLabel.setVisible(v);
myRootElementFieldWrapper.setVisible(v);
myResTypeLabel.setVisible(false);
myResourceTypeCombo.setVisible(false);
myUpDownHint.setVisible(false);
myResourceTypeCombo.setSelectedName(selectedTemplate);
} else {
// Select values by default if not otherwise specified
myResourceTypeCombo.setSelectedName(ResourceConstants.FD_RES_VALUES);
}
boolean validateImmediately = false;
if (filename != null && getNameError(filename) != null) {
chooseFileName = true;
validateImmediately = true;
}
if (filename != null) {
if (!chooseFileName) {
myFileNameField.setVisible(false);
myFileNameLabel.setVisible(false);
}
myFileNameField.setText(filename);
}
Project project = myFacet.getModule().getProject();
// Set up UI to choose the base directory if needed (use context to prune selection).
// There may be a resource directory already pre-selected, in which case hide the UI by default.
myResDirLabel.setVisible(false);
myResDirCombo.setVisible(false);
myResDirCombo.addBrowseFolderListener(
project, FileChooserDescriptorFactory.createSingleFolderDescriptor());
if (myResDirectory == null) {
// Try to figure out from context (e.g., right click in project view).
VirtualFile contextFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
if (contextFile != null) {
PsiManager manager = PsiManager.getInstance(project);
VirtualFile virtualDirectory =
BlazeCreateResourceUtils.getResDirFromDataContext(contextFile);
PsiDirectory directory =
virtualDirectory != null ? manager.findDirectory(virtualDirectory) : null;
if (directory != null) {
myResDirectory = directory;
} else {
// As a last resort, if we have poor context,
// e.g., from File > New w/ a .java file open, set up the UI.
BlazeCreateResourceUtils.setupResDirectoryChoices(
project, contextFile, myResDirLabel, myResDirCombo);
}
} else {
// As a last resort, if we have no context, set up the UI.
BlazeCreateResourceUtils.setupResDirectoryChoices(
project, null, myResDirLabel, myResDirCombo);
}
}
myDeviceConfiguratorPanel.updateAll();
myDeviceConfiguratorWrapper.add(myDeviceConfiguratorPanel, BorderLayout.CENTER);
updateOkAction();
updateRootElementTextField();
if (rootElement != null) {
myRootElementLabel.setVisible(false);
myRootElementFieldWrapper.setVisible(false);
myRootElementField.setText(rootElement);
}
init();
setTitle(AndroidBundle.message("new.resource.dialog.title"));
myFileNameField
.getDocument()
.addDocumentListener(
new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent event) {
validateName();
}
});
myResourceTypeCombo.getComboBox().addActionListener(actionEvent -> validateName());
if (validateImmediately) {
validateName();
}
}