use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class CreateResourceDirectoryDialogBase method setupDeviceConfigurationPanel.
protected DeviceConfiguratorPanel setupDeviceConfigurationPanel(final JComboBox resourceTypeComboBox, final JTextField directoryNameTextField, final JBLabel errorLabel) {
return new DeviceConfiguratorPanel() {
@Override
public void applyEditors() {
try {
doApplyEditors();
final FolderConfiguration config = this.getConfiguration();
final ResourceFolderType selectedResourceType = (ResourceFolderType) resourceTypeComboBox.getSelectedItem();
directoryNameTextField.setText(selectedResourceType != null ? config.getFolderName(selectedResourceType) : "");
errorLabel.setText("");
} catch (InvalidOptionValueException e) {
errorLabel.setText(new HtmlBuilder().openHtmlBody().coloredText(JBColor.RED, e.getMessage()).closeHtmlBody().getHtml());
directoryNameTextField.setText("");
}
setOKActionEnabled(directoryNameTextField.getText().length() > 0);
}
};
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class CreateResourceFileAction method invokeDialog.
@NotNull
@Override
public PsiElement[] invokeDialog(@NotNull final Project project, @NotNull final DataContext dataContext) {
Module module = LangDataKeys.MODULE.getData(dataContext);
if (module == null) {
return PsiElement.EMPTY_ARRAY;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
LOG.assertTrue(facet != null);
VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
ResourceFolderType folderType = getUniqueFolderType(files);
FolderConfiguration config = null;
if (files != null && files.length > 0) {
config = files.length == 1 ? FolderConfiguration.getConfigForFolder(files[0].getName()) : null;
}
myNavigate = true;
NewResourceCreationHandler newResourceHandler = NewResourceCreationHandler.getInstance(project);
final CreateResourceFileDialogBase dialog = newResourceHandler.createNewResourceFileDialog(facet, mySubactions.values(), folderType, null, null, config, true, false, CreateResourceDialogUtils.findResourceDirectory(dataContext), dataContext, createValidatorFactory(project));
if (!dialog.showAndGet()) {
return PsiElement.EMPTY_ARRAY;
}
return dialog.getCreatedElements();
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class InlinedResource method getResolvedString.
@Nullable
public String getResolvedString() {
if (myResourceRepository != null) {
if (myResourceRepository.hasResourceItem(myType, myKey)) {
FolderConfiguration referenceConfig = new FolderConfiguration();
// Nonexistent language qualifier: trick it to fall back to the default locale
referenceConfig.setLocaleQualifier(new LocaleQualifier("xx"));
ResourceValue value = myResourceRepository.getConfiguredValue(myType, myKey, referenceConfig);
if (value != null) {
String text = value.getValue();
if (text != null) {
if (myElement instanceof PsiMethodCallExpression) {
text = insertArguments((PsiMethodCallExpression) myElement, text);
}
if (myType == ResourceType.PLURALS && text.startsWith(STRING_PREFIX)) {
value = myResourceRepository.getConfiguredValue(ResourceType.STRING, text.substring(STRING_PREFIX.length()), referenceConfig);
if (value != null && value.getValue() != null) {
text = value.getValue();
return '"' + StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH - 2, 0) + '"';
}
}
if (myType == ResourceType.STRING || myElement instanceof XmlAttributeValue) {
return '"' + StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH - 2, 0) + '"';
} else if (text.length() <= 1) {
// This is similar to how IntelliJ 14 handles call parameters
return myKey + ": " + text;
} else {
return StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH, 0);
}
}
}
}
}
return null;
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class AndroidResGroupNode method findFileToOpen.
/** Returns the best configuration of a particular resource given a set of multiple configurations of the same resource. */
@Nullable
private static PsiFile findFileToOpen(@NotNull List<PsiFile> files) {
PsiFile bestFile = null;
FolderConfiguration bestConfig = null;
for (PsiFile file : files) {
PsiDirectory qualifiedDirectory = file.getParent();
assert qualifiedDirectory != null : "Resource file's parent directory cannot be null";
FolderConfiguration config = FolderConfiguration.getConfigForFolder(qualifiedDirectory.getName());
if (// first time through the loop
bestConfig == null || // FolderConfiguration is null for default configurations
config == null || config.compareTo(bestConfig) < 0) {
// lower FolderConfiguration value than current best
bestConfig = config;
bestFile = file;
}
}
return bestFile;
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class AndroidResComparator method compare.
@Override
public int compare(Object o1, Object o2) {
if (!(o1 instanceof NodeDescriptor) || !(o2 instanceof NodeDescriptor)) {
return 0;
}
// we only support comparing res file nodes and res group nodes
if (!(o1 instanceof AndroidResFileNode) && !(o1 instanceof AndroidResGroupNode)) {
return 0;
}
if (!(o2 instanceof AndroidResFileNode) && !(o2 instanceof AndroidResGroupNode)) {
return 0;
}
// if one of them is a group node, then we just have to compare them alphabetically
if (o1 instanceof AndroidResGroupNode || o2 instanceof AndroidResGroupNode) {
String n1 = getName(o1);
String n2 = getName(o2);
return StringUtil.compare(n1, n2, false);
}
AndroidResFileNode r1 = (AndroidResFileNode) o1;
AndroidResFileNode r2 = (AndroidResFileNode) o2;
// first check file names
PsiFile file1 = r1.getValue();
PsiFile file2 = r2.getValue();
if (file1 != null && file2 != null) {
int c = StringUtil.compare(file1.getName(), file2.getName(), false);
if (c != 0) {
return c;
}
}
// check folder configurations
FolderConfiguration config1 = r1.getFolderConfiguration();
FolderConfiguration config2 = r2.getFolderConfiguration();
if (config1 != null && config2 != null) {
int c = config1.compareTo(config2);
if (c != 0) {
return c;
}
}
// then check qualifiers
return StringUtil.compare(r1.getQualifier(), r2.getQualifier(), false);
}
Aggregations