Search in sources :

Example 11 with VirtualFile

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));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 12 with VirtualFile

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList)

Example 13 with VirtualFile

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AndroidSelectorDialog(importre.intellij.android.selector.form.AndroidSelectorDialog)

Example 14 with VirtualFile

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 15 with VirtualFile

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;
}
Also used : FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)5443 File (java.io.File)757 Nullable (org.jetbrains.annotations.Nullable)719 Project (com.intellij.openapi.project.Project)718 NotNull (org.jetbrains.annotations.NotNull)703 PsiFile (com.intellij.psi.PsiFile)564 Module (com.intellij.openapi.module.Module)495 IOException (java.io.IOException)327 ArrayList (java.util.ArrayList)258 Document (com.intellij.openapi.editor.Document)241 PsiElement (com.intellij.psi.PsiElement)205 Test (org.junit.Test)193 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)124 PsiDirectory (com.intellij.psi.PsiDirectory)124 XmlFile (com.intellij.psi.xml.XmlFile)124 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)116 Editor (com.intellij.openapi.editor.Editor)114 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)100 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)91 List (java.util.List)90