Search in sources :

Example 1 with Options

use of org.intellij.images.options.Options 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 Options

use of org.intellij.images.options.Options in project intellij-community by JetBrains.

the class ImagesConfigurable method reset.

public void reset() {
    if (myComponent != null) {
        Options options = OptionsManager.getInstance().getOptions();
        myComponent.getOptions().inject(options);
        myComponent.updateUI();
    }
}
Also used : Options(org.intellij.images.options.Options)

Example 3 with Options

use of org.intellij.images.options.Options in project intellij-community by JetBrains.

the class ImagesConfigurable method createComponent.

public JComponent createComponent() {
    if (myComponent == null) {
        myComponent = new ImagesOptionsComponent();
        Options options = OptionsManager.getInstance().getOptions();
        options.addPropertyChangeListener(this);
        myComponent.getOptions().inject(options);
        myComponent.updateUI();
        myComponent.getOptions().addPropertyChangeListener(this);
        setModified(false);
    }
    return myComponent.getContentPane();
}
Also used : Options(org.intellij.images.options.Options)

Example 4 with Options

use of org.intellij.images.options.Options in project android by JetBrains.

the class LayeredImageEditor method setImage.

private void setImage(Image image) throws IOException {
    ImageDocument document = myImageEditor.getDocument();
    BufferedImage previousImage = document.getValue();
    document.setValue(Utilities.getDisplayableImage(image));
    String format = image.getFormat() + "/" + image.getColorMode();
    String description = image.getColorProfileDescription();
    if (!description.isEmpty()) {
        format += ", " + description;
    }
    document.setFormat(format);
    // from ImageEditorUI
    ImageZoomModel zoomModel = myImageEditor.getZoomModel();
    if (previousImage == null || !zoomModel.isZoomLevelChanged()) {
        Options options = OptionsManager.getInstance().getOptions();
        ZoomOptions zoomOptions = options.getEditorOptions().getZoomOptions();
        zoomModel.setZoomFactor(1.0d);
        if (zoomOptions.isSmartZooming()) {
            Dimension preferred = zoomOptions.getPrefferedSize();
            if (preferred.width > image.getWidth() && preferred.height > image.getHeight()) {
                double factor = (preferred.getWidth() / (double) image.getWidth() + preferred.getHeight() / (double) image.getHeight()) / 2.0d;
                zoomModel.setZoomFactor(Math.ceil(factor));
            }
        }
    }
}
Also used : ImageZoomModel(org.intellij.images.editor.ImageZoomModel) ZoomOptions(org.intellij.images.options.ZoomOptions) Options(org.intellij.images.options.Options) ZoomOptions(org.intellij.images.options.ZoomOptions) ImageDocument(org.intellij.images.editor.ImageDocument) BufferedImage(java.awt.image.BufferedImage)

Example 5 with Options

use of org.intellij.images.options.Options in project intellij-community by JetBrains.

the class ImagesConfigurable method apply.

public void apply() {
    if (myComponent != null) {
        Options options = OptionsManager.getInstance().getOptions();
        options.inject(myComponent.getOptions());
    }
}
Also used : Options(org.intellij.images.options.Options)

Aggregations

Options (org.intellij.images.options.Options)8 ExecutionException (com.intellij.execution.ExecutionException)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 ImageDocument (org.intellij.images.editor.ImageDocument)1 ImageZoomModel (org.intellij.images.editor.ImageZoomModel)1 ImageFileTypeManager (org.intellij.images.fileTypes.ImageFileTypeManager)1 EditorOptions (org.intellij.images.options.EditorOptions)1 ExternalEditorOptions (org.intellij.images.options.ExternalEditorOptions)1 ZoomOptions (org.intellij.images.options.ZoomOptions)1