use of com.intellij.openapi.vfs.VirtualFile in project android-selector-chapek by inmite.
the class SelectorChapekAction method update.
@Override
public void update(AnActionEvent e) {
VirtualFile selectedFile = DataKeys.VIRTUAL_FILE.getData(e.getDataContext());
e.getPresentation().setEnabled(isCorrectFolderSelected(selectedFile));
}
use of com.intellij.openapi.vfs.VirtualFile in project android-selector-chapek by inmite.
the class SelectorDetector method detectStates.
private static List<Result> detectStates(VirtualFile file, VirtualFile folder) {
List<Result> results = new ArrayList<Result>();
results.add(new Result(detectSuffixes(file), removeFileEndings(file.getName())));
for (VirtualFile other : folder.getChildren()) {
if (matches(file, other)) {
results.add(new Result(detectSuffixes(other), removeFileEndings(other.getName())));
}
}
return results;
}
use of com.intellij.openapi.vfs.VirtualFile in project android-selector-intellij-plugin by importre.
the class AndroidSelector method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final VirtualFile dir = e.getData(LangDataKeys.VIRTUAL_FILE);
if (dir == null) {
return;
}
Project project = e.getProject();
AndroidSelectorDialog dialog = new AndroidSelectorDialog(project, dir);
dialog.show();
}
use of com.intellij.openapi.vfs.VirtualFile in project android-selector-intellij-plugin by importre.
the class AndroidSelectorDialog method createDrawableV21.
private void createDrawableV21(String filename, String color, String pressed) throws Exception {
VirtualFile child = dir.findChild(drawableV21Dir);
if (child == null) {
child = dir.createChildDirectory(null, drawableV21Dir);
}
VirtualFile newXmlFile = child.findChild(filename);
if (newXmlFile != null && newXmlFile.exists()) {
newXmlFile.delete(null);
}
newXmlFile = child.createChildData(null, filename);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element root = doc.createElement("ripple");
root.setAttributeNS(nsUri, "xmlns:android", androidUri);
root.setAttribute("android:color", pressed);
doc.appendChild(root);
Element item = doc.createElement("item");
item.setAttribute("android:drawable", color);
root.appendChild(item);
OutputStream os = newXmlFile.getOutputStream(null);
PrintWriter out = new PrintWriter(os);
StringWriter writer = new StringWriter();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(INDENT_SPACE, "4");
transformer.transform(new DOMSource(doc), new StreamResult(writer));
out.println(writer.getBuffer().toString());
out.close();
}
use of com.intellij.openapi.vfs.VirtualFile in project scss-lint-plugin by idok.
the class ActualFile method getOrCreateActualFile.
@Nullable
public static ActualFile getOrCreateActualFile(@NotNull Key<ThreadLocalActualFile> key, @NotNull VirtualFile virtualFile, @Nullable String content) {
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
if (!fileDocumentManager.isFileModified(virtualFile)) {
File file = new File(virtualFile.getPath());
if (file.isFile()) {
return new ActualFile(file);
}
}
ThreadLocalActualFile threadLocal = key.get(virtualFile);
if (threadLocal == null) {
threadLocal = virtualFile.putUserDataIfAbsent(key, new ThreadLocalActualFile(virtualFile));
}
File file = threadLocal.getOrCreateFile();
if (file == null) {
return null;
}
if (content == null) {
Document document = fileDocumentManager.getDocument(virtualFile);
if (document != null) {
content = document.getText();
}
}
if (content == null) {
return null;
}
try {
FileUtil.writeToFile(file, content);
return new ActualFile(new File(virtualFile.getPath()), file);
} catch (IOException e) {
LOG.warn("Can not write to " + file.getAbsolutePath(), e);
}
return null;
}
Aggregations