Search in sources :

Example 56 with FolderConfiguration

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);
        }
    };
}
Also used : ResourceFolderType(com.android.resources.ResourceFolderType) HtmlBuilder(com.android.utils.HtmlBuilder) InvalidOptionValueException(org.jetbrains.android.uipreview.InvalidOptionValueException) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) DeviceConfiguratorPanel(org.jetbrains.android.uipreview.DeviceConfiguratorPanel)

Example 57 with FolderConfiguration

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceFolderType(com.android.resources.ResourceFolderType) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with FolderConfiguration

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;
}
Also used : ResourceValue(com.android.ide.common.rendering.api.ResourceValue) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 59 with FolderConfiguration

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;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Nullable(org.jetbrains.annotations.Nullable)

Example 60 with FolderConfiguration

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);
}
Also used : NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) PsiFile(com.intellij.psi.PsiFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Aggregations

FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)69 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 NotNull (org.jetbrains.annotations.NotNull)14 VersionQualifier (com.android.ide.common.resources.configuration.VersionQualifier)12 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)12 Nullable (org.jetbrains.annotations.Nullable)12 ResourceItem (com.android.ide.common.res2.ResourceItem)10 LocaleQualifier (com.android.ide.common.resources.configuration.LocaleQualifier)10 DensityQualifier (com.android.ide.common.resources.configuration.DensityQualifier)9 ResourceFolderType (com.android.resources.ResourceFolderType)9 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)7 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 Project (com.intellij.openapi.project.Project)7 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)6 ResourceResolver (com.android.ide.common.resources.ResourceResolver)6 LayoutDirectionQualifier (com.android.ide.common.resources.configuration.LayoutDirectionQualifier)6 ScreenOrientationQualifier (com.android.ide.common.resources.configuration.ScreenOrientationQualifier)6 ScreenSizeQualifier (com.android.ide.common.resources.configuration.ScreenSizeQualifier)6 SessionParams (com.android.ide.common.rendering.api.SessionParams)5 CountryCodeQualifier (com.android.ide.common.resources.configuration.CountryCodeQualifier)5