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;
}
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;
}
Aggregations