Search in sources :

Example 1 with ResourcesDomFileDescription

use of org.jetbrains.android.dom.resources.ResourcesDomFileDescription in project android by JetBrains.

the class AndroidXmlFormattingModelBuilder method getContextSpecificSettings.

@Nullable
private static ContextSpecificSettingsProviders.Provider getContextSpecificSettings(PsiElement context) {
    final PsiFile file = context.getContainingFile();
    if (!(file instanceof XmlFile) || AndroidFacet.getInstance(file) == null) {
        return null;
    }
    final DomFileDescription<?> description = DomManager.getDomManager(context.getProject()).getDomFileDescription((XmlFile) file);
    if (description instanceof LayoutDomFileDescription) {
        return ContextSpecificSettingsProviders.LAYOUT;
    } else if (description instanceof ManifestDomFileDescription) {
        return ContextSpecificSettingsProviders.MANIFEST;
    } else if (description instanceof ResourcesDomFileDescription || description instanceof DrawableStateListDomFileDescription || description instanceof ColorDomFileDescription) {
        return ContextSpecificSettingsProviders.VALUE_RESOURCE_FILE;
    } else if (description instanceof AndroidResourceDomFileDescription) {
        return ContextSpecificSettingsProviders.OTHER;
    }
    return null;
}
Also used : ManifestDomFileDescription(org.jetbrains.android.dom.manifest.ManifestDomFileDescription) LayoutDomFileDescription(org.jetbrains.android.dom.layout.LayoutDomFileDescription) XmlFile(com.intellij.psi.xml.XmlFile) AndroidResourceDomFileDescription(org.jetbrains.android.dom.AndroidResourceDomFileDescription) PsiFile(com.intellij.psi.PsiFile) ColorDomFileDescription(org.jetbrains.android.dom.color.ColorDomFileDescription) ResourcesDomFileDescription(org.jetbrains.android.dom.resources.ResourcesDomFileDescription) DrawableStateListDomFileDescription(org.jetbrains.android.dom.drawable.fileDescriptions.DrawableStateListDomFileDescription) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ResourcesDomFileDescription

use of org.jetbrains.android.dom.resources.ResourcesDomFileDescription in project android by JetBrains.

the class CreateValueResourceQuickFix method doInvoke.

protected boolean doInvoke() {
    Project project = myFile.getProject();
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        final String fileName = AndroidResourceUtil.getDefaultResourceFileName(myResourceType);
        assert fileName != null;
        VirtualFile resourceDir = myFacet.getPrimaryResourceDir();
        assert resourceDir != null;
        if (!AndroidResourceUtil.createValueResource(project, resourceDir, myResourceName, myResourceType, fileName, Collections.singletonList(SdkConstants.FD_RES_VALUES), "a")) {
            return false;
        }
    } else {
        final String value = myResourceType == ResourceType.STYLEABLE || myResourceType == ResourceType.ATTR ? "\n" : null;
        VirtualFile defaultFileToCreate = null;
        if (myFile instanceof XmlFile && myFile.isWritable() && myFile.getManager().isInProject(myFile)) {
            final DomFileDescription<?> description = DomManager.getDomManager(project).getDomFileDescription((XmlFile) myFile);
            if (description instanceof ResourcesDomFileDescription) {
                final VirtualFile defaultFile = myFile.getVirtualFile();
                if (defaultFile != null) {
                    defaultFileToCreate = defaultFile;
                }
            }
        }
        final CreateXmlResourceDialog dialog = new CreateXmlResourceDialog(myFacet.getModule(), myResourceType, myResourceName, value, myChooseName, defaultFileToCreate, myFile.getVirtualFile());
        dialog.setTitle("New " + StringUtil.capitalize(myResourceType.getDisplayName()) + " Value Resource");
        if (!dialog.showAndGet()) {
            return false;
        }
        final VirtualFile resourceDir = dialog.getResourceDirectory();
        if (resourceDir == null) {
            AndroidUtils.reportError(project, AndroidBundle.message("check.resource.dir.error", myFacet.getModule()));
            return false;
        }
        final String fileName = dialog.getFileName();
        final List<String> dirNames = dialog.getDirNames();
        final String resValue = dialog.getValue();
        final String resName = dialog.getResourceName();
        if (!AndroidResourceUtil.createValueResource(project, resourceDir, resName, myResourceType, fileName, dirNames, resValue)) {
            return false;
        }
    }
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    UndoUtil.markPsiFileForUndo(myFile);
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) CreateXmlResourceDialog(org.jetbrains.android.actions.CreateXmlResourceDialog) ResourcesDomFileDescription(org.jetbrains.android.dom.resources.ResourcesDomFileDescription)

Aggregations

XmlFile (com.intellij.psi.xml.XmlFile)2 ResourcesDomFileDescription (org.jetbrains.android.dom.resources.ResourcesDomFileDescription)2 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 CreateXmlResourceDialog (org.jetbrains.android.actions.CreateXmlResourceDialog)1 AndroidResourceDomFileDescription (org.jetbrains.android.dom.AndroidResourceDomFileDescription)1 ColorDomFileDescription (org.jetbrains.android.dom.color.ColorDomFileDescription)1 DrawableStateListDomFileDescription (org.jetbrains.android.dom.drawable.fileDescriptions.DrawableStateListDomFileDescription)1 LayoutDomFileDescription (org.jetbrains.android.dom.layout.LayoutDomFileDescription)1 ManifestDomFileDescription (org.jetbrains.android.dom.manifest.ManifestDomFileDescription)1 Nullable (org.jetbrains.annotations.Nullable)1