Search in sources :

Example 1 with ImageFileTypeManager

use of org.intellij.images.fileTypes.ImageFileTypeManager in project intellij-community by JetBrains.

the class EditExternallyAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    Options options = OptionsManager.getInstance().getOptions();
    String executablePath = options.getExternalEditorOptions().getExecutablePath();
    if (StringUtil.isEmpty(executablePath)) {
        Messages.showErrorDialog(project, ImagesBundle.message("error.empty.external.editor.path"), ImagesBundle.message("error.title.empty.external.editor.path"));
        ImagesConfigurable.show(project);
    } else {
        if (files != null) {
            Map<String, String> env = EnvironmentUtil.getEnvironmentMap();
            for (String varName : env.keySet()) {
                if (SystemInfo.isWindows) {
                    executablePath = StringUtil.replace(executablePath, "%" + varName + "%", env.get(varName), true);
                } else {
                    executablePath = StringUtil.replace(executablePath, "${" + varName + "}", env.get(varName), false);
                }
            }
            executablePath = FileUtil.toSystemDependentName(executablePath);
            File executable = new File(executablePath);
            GeneralCommandLine commandLine = new GeneralCommandLine();
            final String path = executable.exists() ? executable.getAbsolutePath() : executablePath;
            if (SystemInfo.isMac) {
                commandLine.setExePath(ExecUtil.getOpenCommandPath());
                commandLine.addParameter("-a");
                commandLine.addParameter(path);
            } else {
                commandLine.setExePath(path);
            }
            ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
            for (VirtualFile file : files) {
                if (file.isInLocalFileSystem() && typeManager.isImage(file)) {
                    commandLine.addParameter(VfsUtilCore.virtualToIoFile(file).getAbsolutePath());
                }
            }
            commandLine.setWorkDirectory(new File(executablePath).getParentFile());
            try {
                commandLine.createProcess();
            } catch (ExecutionException ex) {
                Messages.showErrorDialog(project, ex.getLocalizedMessage(), ImagesBundle.message("error.title.launching.external.editor"));
                ImagesConfigurable.show(project);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Options(org.intellij.images.options.Options) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ImageFileTypeManager(org.intellij.images.fileTypes.ImageFileTypeManager) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with ImageFileTypeManager

use of org.intellij.images.fileTypes.ImageFileTypeManager in project intellij-community by JetBrains.

the class ThumbnailViewUI method isImagesInDirectory.

private boolean isImagesInDirectory(VirtualFile dir) {
    ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
    VirtualFile[] files = dir.getChildren();
    for (VirtualFile file : files) {
        if (file.isDirectory()) {
            // We can be sure for fast searching
            return true;
        }
        if (typeManager.isImage(file)) {
            return true;
        }
    }
    return false;
}
Also used : ImageFileTypeManager(org.intellij.images.fileTypes.ImageFileTypeManager)

Example 3 with ImageFileTypeManager

use of org.intellij.images.fileTypes.ImageFileTypeManager in project intellij-community by JetBrains.

the class ThumbnailViewUI method findFiles.

private Set<VirtualFile> findFiles(VirtualFile file) {
    Set<VirtualFile> files = new HashSet<>(0);
    Project project = thumbnailView.getProject();
    if (!project.isDisposed()) {
        ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
        boolean projectIgnored = rootManager.getFileIndex().isExcluded(file);
        if (!projectIgnored && !FileTypeManager.getInstance().isFileIgnored(file)) {
            ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
            if (file.isDirectory()) {
                if (thumbnailView.isRecursive()) {
                    files.addAll(findFiles(file.getChildren()));
                } else if (isImagesInDirectory(file)) {
                    files.add(file);
                }
            } else if (typeManager.isImage(file)) {
                files.add(file);
            }
        }
    }
    return files;
}
Also used : Project(com.intellij.openapi.project.Project) ImageFileTypeManager(org.intellij.images.fileTypes.ImageFileTypeManager) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) HashSet(java.util.HashSet)

Example 4 with ImageFileTypeManager

use of org.intellij.images.fileTypes.ImageFileTypeManager in project intellij-community by JetBrains.

the class EnterAction method update.

public void update(AnActionEvent e) {
    super.update(e);
    if (ThumbnailViewActionUtil.setEnabled(e)) {
        Presentation presentation = e.getPresentation();
        ThumbnailView view = ThumbnailViewActionUtil.getVisibleThumbnailView(e);
        VirtualFile[] selection = view.getSelection();
        if (selection.length > 0) {
            if (selection.length == 1 && selection[0].isDirectory()) {
                presentation.setVisible(true);
            } else {
                boolean notImages = false;
                ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
                for (VirtualFile file : selection) {
                    notImages |= !typeManager.isImage(file);
                }
                presentation.setEnabled(!notImages);
                presentation.setVisible(false);
            }
        } else {
            presentation.setVisible(false);
            presentation.setEnabled(false);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ImageFileTypeManager(org.intellij.images.fileTypes.ImageFileTypeManager) ThumbnailView(org.intellij.images.thumbnail.ThumbnailView) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 5 with ImageFileTypeManager

use of org.intellij.images.fileTypes.ImageFileTypeManager in project intellij-community by JetBrains.

the class EditExternallyAction method isImages.

private static boolean isImages(VirtualFile[] files) {
    boolean isImagesFound = false;
    if (files != null) {
        ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
        for (VirtualFile file : files) {
            boolean isImage = typeManager.isImage(file);
            isImagesFound |= isImage;
            if (!file.isInLocalFileSystem() || !isImage) {
                return false;
            }
        }
    }
    return isImagesFound;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ImageFileTypeManager(org.intellij.images.fileTypes.ImageFileTypeManager)

Aggregations

ImageFileTypeManager (org.intellij.images.fileTypes.ImageFileTypeManager)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Project (com.intellij.openapi.project.Project)2 ExecutionException (com.intellij.execution.ExecutionException)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Options (org.intellij.images.options.Options)1 ThumbnailView (org.intellij.images.thumbnail.ThumbnailView)1