diff --git a/image-api/src/main/java/consulo/images/BinaryImageFileType.java b/image-api/src/main/java/consulo/images/BinaryImageFileType.java
index c1c04d3..c33fe7d 100644
--- a/image-api/src/main/java/consulo/images/BinaryImageFileType.java
+++ b/image-api/src/main/java/consulo/images/BinaryImageFileType.java
@@ -38,7 +38,7 @@ public String getDefaultExtension() {
@Nonnull
@Override
public Image getIcon() {
- return ImagesIconGroup.imagesfiletype();
+ return ImagesIconGroup.filetypeImage();
}
@Override
diff --git a/image-api/src/main/java/org/intellij/images/editor/ImageZoomModel.java b/image-api/src/main/java/org/intellij/images/editor/ImageZoomModel.java
index 8dbdc01..b587cd4 100644
--- a/image-api/src/main/java/org/intellij/images/editor/ImageZoomModel.java
+++ b/image-api/src/main/java/org/intellij/images/editor/ImageZoomModel.java
@@ -31,18 +31,20 @@ public interface ImageZoomModel {
void setZoomFactor(double zoomFactor);
- void fitZoomToWindow();
-
- void zoomOut();
+ void zoomFitToWindow();
void zoomIn();
+ void zoomOut();
+
void setZoomLevelChanged(boolean value);
- boolean canZoomOut();
+ boolean canZoomFitToWindow();
boolean canZoomIn();
+ boolean canZoomOut();
+
boolean isZoomLevelChanged();
ImageZoomModel STUB = new ImageZoomModel() {
@@ -56,7 +58,7 @@ public void setZoomFactor(double zoomFactor) {
}
@Override
- public void zoomOut() {
+ public void zoomFitToWindow() {
}
@Override
@@ -64,15 +66,15 @@ public void zoomIn() {
}
@Override
- public void setZoomLevelChanged(boolean value) {
+ public void zoomOut() {
}
@Override
- public void fitZoomToWindow() {
+ public void setZoomLevelChanged(boolean value) {
}
@Override
- public boolean canZoomOut() {
+ public boolean canZoomFitToWindow() {
return false;
}
@@ -81,6 +83,11 @@ public boolean canZoomIn() {
return false;
}
+ @Override
+ public boolean canZoomOut() {
+ return false;
+ }
+
@Override
public boolean isZoomLevelChanged() {
return false;
diff --git a/image-api/src/main/java/org/intellij/images/editor/actionSystem/ImageEditorActionUtil.java b/image-api/src/main/java/org/intellij/images/editor/actionSystem/ImageEditorActionUtil.java
index d3b38f7..3478051 100644
--- a/image-api/src/main/java/org/intellij/images/editor/actionSystem/ImageEditorActionUtil.java
+++ b/image-api/src/main/java/org/intellij/images/editor/actionSystem/ImageEditorActionUtil.java
@@ -16,21 +16,56 @@
package org.intellij.images.editor.actionSystem;
import consulo.ui.ex.action.AnActionEvent;
+import org.intellij.images.editor.ImageZoomModel;
import org.intellij.images.ui.ImageComponentDecorator;
-import jakarta.annotation.Nullable;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
/**
* Editor actions utility.
*
* @author Alexey Efimov
+ * @author UNV
*/
public final class ImageEditorActionUtil {
- private ImageEditorActionUtil() {
+ public static void acceptImageDecorator(AnActionEvent e, Consumer consumer) {
+ ImageComponentDecorator decorator = getValidDecorator(e);
+ if (decorator != null) {
+ consumer.accept(decorator);
+ }
+ }
+
+ public static void acceptZoomModel(AnActionEvent e, Consumer consumer) {
+ ImageComponentDecorator decorator = getValidDecorator(e);
+ if (decorator != null) {
+ consumer.accept(decorator.getZoomModel());
+ }
}
- @Nullable
- public static ImageComponentDecorator getImageComponentDecorator(AnActionEvent e) {
- return e.getData(ImageComponentDecorator.DATA_KEY);
+ public static boolean testImageDecorator(AnActionEvent e, Predicate predicate) {
+ return testImageDecorator(e, predicate, false);
+ }
+
+ public static boolean testImageDecorator(AnActionEvent e, Predicate predicate, boolean defaultValue) {
+ ImageComponentDecorator decorator = getValidDecorator(e);
+ return decorator != null ? predicate.test(decorator) : defaultValue;
+ }
+
+ public static boolean testZoomModel(AnActionEvent e, Predicate predicate) {
+ return testZoomModel(e, predicate, false);
+ }
+
+ public static boolean testZoomModel(AnActionEvent e, Predicate predicate, boolean defaultValue) {
+ ImageComponentDecorator decorator = getValidDecorator(e);
+ return decorator != null ? predicate.test(decorator.getZoomModel()) : defaultValue;
+ }
+
+ private static ImageComponentDecorator getValidDecorator(AnActionEvent e) {
+ ImageComponentDecorator decorator = e.getData(ImageComponentDecorator.DATA_KEY);
+ return decorator != null && decorator.isEnabledForActionPlace(e.getPlace()) ? decorator : null;
+ }
+
+ private ImageEditorActionUtil() {
}
}
diff --git a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/ImagesFileType.svg b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/ImagesFileType.svg
deleted file mode 100644
index e353010..0000000
--- a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/ImagesFileType.svg
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
diff --git a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/ThumbnailToolWindow.svg b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/ThumbnailToolWindow.svg
deleted file mode 100644
index 2d8ff7d..0000000
--- a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/ThumbnailToolWindow.svg
+++ /dev/null
@@ -1,3 +0,0 @@
-
diff --git a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/ToggleTransparencyChessboard.svg b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/ToggleTransparencyChessboard.svg
deleted file mode 100644
index eb4fce7..0000000
--- a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/ToggleTransparencyChessboard.svg
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
diff --git a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/actualZoom.svg b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/actualZoom.svg
new file mode 100644
index 0000000..f1db596
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/actualZoom.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/chessboard.svg b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/chessboard.svg
new file mode 100644
index 0000000..07f6e9c
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/chessboard.svg
@@ -0,0 +1,8 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/fitContent.svg b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/fitContent.svg
new file mode 100644
index 0000000..876bcc8
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/fitContent.svg
@@ -0,0 +1,5 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/grid.svg b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/grid.svg
new file mode 100644
index 0000000..fc053b4
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/grid.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/zoomIn.svg b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/zoomIn.svg
new file mode 100644
index 0000000..806d335
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/zoomIn.svg
@@ -0,0 +1,5 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/zoomOut.svg b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/zoomOut.svg
new file mode 100644
index 0000000..ac3a4b9
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/action/zoomOut.svg
@@ -0,0 +1,5 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/fileType/image.svg b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/fileType/image.svg
new file mode 100644
index 0000000..b2ba9a6
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/fileType/image.svg
@@ -0,0 +1,6 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/toolWindow/thumbnail.svg b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/toolWindow/thumbnail.svg
new file mode 100644
index 0000000..a09638e
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/dark/consulo.images.ImagesIconGroup/toolWindow/thumbnail.svg
@@ -0,0 +1,3 @@
+
diff --git a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/ImagesFileType.svg b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/ImagesFileType.svg
deleted file mode 100644
index 215ce3a..0000000
--- a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/ImagesFileType.svg
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
diff --git a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/ThumbnailToolWindow.svg b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/ThumbnailToolWindow.svg
deleted file mode 100644
index 584ae3e..0000000
--- a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/ThumbnailToolWindow.svg
+++ /dev/null
@@ -1,3 +0,0 @@
-
diff --git a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/ToggleTransparencyChessboard.svg b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/ToggleTransparencyChessboard.svg
deleted file mode 100644
index 896f2af..0000000
--- a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/ToggleTransparencyChessboard.svg
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
diff --git a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/actualZoom.svg b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/actualZoom.svg
new file mode 100644
index 0000000..95d8107
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/actualZoom.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/chessboard.svg b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/chessboard.svg
new file mode 100644
index 0000000..231510b
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/chessboard.svg
@@ -0,0 +1,8 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/fitContent.svg b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/fitContent.svg
new file mode 100644
index 0000000..6fe208f
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/fitContent.svg
@@ -0,0 +1,5 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/grid.svg b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/grid.svg
new file mode 100644
index 0000000..6602ab0
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/grid.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/zoomIn.svg b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/zoomIn.svg
new file mode 100644
index 0000000..a317ade
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/zoomIn.svg
@@ -0,0 +1,5 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/zoomOut.svg b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/zoomOut.svg
new file mode 100644
index 0000000..d5be775
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/action/zoomOut.svg
@@ -0,0 +1,5 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/fileType/image.svg b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/fileType/image.svg
new file mode 100644
index 0000000..37d416f
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/fileType/image.svg
@@ -0,0 +1,6 @@
+
+
diff --git a/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/toolWindow/thumbnail.svg b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/toolWindow/thumbnail.svg
new file mode 100644
index 0000000..777c0ea
--- /dev/null
+++ b/image-api/src/main/resources/ICON-LIB/light/consulo.images.ImagesIconGroup/toolWindow/thumbnail.svg
@@ -0,0 +1,3 @@
+
diff --git a/image-api/src/main/resources/LOCALIZE-LIB/en_US/consulo.images.ImagesLocalize.yaml b/image-api/src/main/resources/LOCALIZE-LIB/en_US/consulo.images.ImagesLocalize.yaml
index cd70ea3..447a6fe 100644
--- a/image-api/src/main/resources/LOCALIZE-LIB/en_US/consulo.images.ImagesLocalize.yaml
+++ b/image-api/src/main/resources/LOCALIZE-LIB/en_US/consulo.images.ImagesLocalize.yaml
@@ -12,6 +12,8 @@ action.Images.Editor.Toggle.Transparency.Chessboard.show.text:
text: Show Chessboard
action.Images.Editor.Zoom.Actual.text:
text: Zoom to Actual Size
+action.Images.Editor.Zoom.Fit.To.Window.text:
+ text: Fit to Window
action.Images.Editor.Zoom.In.text:
text: Zoom In
action.Images.Editor.Zoom.Out.text:
diff --git a/image-desktop-awt-impl/src/main/java/consulo/images/desktop/awt/impl/editor/ImageEditorUI.java b/image-desktop-awt-impl/src/main/java/consulo/images/desktop/awt/impl/editor/ImageEditorUI.java
index 2fef4fa..bdff759 100644
--- a/image-desktop-awt-impl/src/main/java/consulo/images/desktop/awt/impl/editor/ImageEditorUI.java
+++ b/image-desktop-awt-impl/src/main/java/consulo/images/desktop/awt/impl/editor/ImageEditorUI.java
@@ -485,35 +485,35 @@ private double getMinimumZoomFactor() {
}
@Override
- public void fitZoomToWindow() {
- Options options = OptionsManager.getInstance().getOptions();
- ZoomOptions zoomOptions = options.getEditorOptions().getZoomOptions();
-
- Double smartZoomFactor = getSmartZoomFactor(zoomOptions);
- if (smartZoomFactor != null) {
- zoomModel.setZoomFactor(smartZoomFactor);
- }
- else {
- zoomModel.setZoomFactor(1.0d);
- }
- myZoomLevelChanged = false;
+ public void zoomFitToWindow() {
+ setZoomFactor(getZoomFitToWindow());
+ myZoomLevelChanged = true;
}
@Override
- public void zoomOut() {
- setZoomFactor(getNextZoomOut());
+ public void zoomIn() {
+ setZoomFactor(getNextZoomIn());
myZoomLevelChanged = true;
}
@Override
- public void zoomIn() {
- setZoomFactor(getNextZoomIn());
+ public void zoomOut() {
+ setZoomFactor(getNextZoomOut());
myZoomLevelChanged = true;
}
- private double getNextZoomOut() {
- double factor = getZoomFactor() / ZOOM_RATIO;
- return Math.max(factor, getMinimumZoomFactor());
+ private double getZoomFitToWindow() {
+ Rectangle bounds = getValidImageBounds();
+ if (bounds == null) {
+ return 1.0;
+ }
+
+ Dimension canvasSize = getValidCanvasSize();
+ if (canvasSize == null) {
+ return 1.0;
+ }
+
+ return Math.min((double)canvasSize.width / bounds.width, (double)canvasSize.height / bounds.height);
}
private double getNextZoomIn() {
@@ -521,10 +521,22 @@ private double getNextZoomIn() {
return Math.min(factor, getMaximumZoomFactor());
}
+ private double getNextZoomOut() {
+ double factor = getZoomFactor() / ZOOM_RATIO;
+ return Math.max(factor, getMinimumZoomFactor());
+ }
+
@Override
- public boolean canZoomOut() {
- // Ignore small differences caused by floating-point arithmetic.
- return getZoomFactor() - 1.0e-14 > getMinimumZoomFactor();
+ public boolean canZoomFitToWindow() {
+ Rectangle bounds = getValidImageBounds();
+ if (bounds == null) {
+ return false;
+ }
+
+ Dimension canvasSize = getValidCanvasSize();
+ return canvasSize != null
+ && canvasSize.width != Math.round(bounds.width * zoomFactor)
+ && canvasSize.height != Math.round(bounds.height * zoomFactor);
}
@Override
@@ -532,6 +544,12 @@ public boolean canZoomIn() {
return getZoomFactor() < getMaximumZoomFactor();
}
+ @Override
+ public boolean canZoomOut() {
+ // Ignore small differences caused by floating-point arithmetic.
+ return getZoomFactor() - 1.0e-14 > getMinimumZoomFactor();
+ }
+
@Override
public void setZoomLevelChanged(boolean value) {
myZoomLevelChanged = value;
@@ -545,28 +563,21 @@ public boolean isZoomLevelChanged() {
@Nullable
private Double getSmartZoomFactor(@Nonnull ZoomOptions zoomOptions) {
- Rectangle bounds = imageComponent.getDocument().getBounds();
+ Rectangle bounds = getValidImageBounds();
if (bounds == null) {
return null;
}
- if (bounds.getWidth() == 0 || bounds.getHeight() == 0) {
- return null;
- }
- int width = bounds.width;
- int height = bounds.height;
+ int width = bounds.width, height = bounds.height;
Size preferredMinimumSize = zoomOptions.getPrefferedSize();
- if (width < preferredMinimumSize.getWidth() &&
- height < preferredMinimumSize.getHeight()) {
+ if (width < preferredMinimumSize.getWidth() && height < preferredMinimumSize.getHeight()) {
double factor = (preferredMinimumSize.getWidth() / (double)width +
preferredMinimumSize.getHeight() / (double)height) / 2.0d;
return Math.ceil(factor);
}
- Dimension canvasSize = myScrollPane.getViewport().getExtentSize();
- canvasSize.height -= ImageComponent.IMAGE_INSETS * 2;
- canvasSize.width -= ImageComponent.IMAGE_INSETS * 2;
- if (canvasSize.width <= 0 || canvasSize.height <= 0) {
+ Dimension canvasSize = getValidCanvasSize();
+ if (canvasSize == null) {
return null;
}
@@ -580,6 +591,21 @@ private Double getSmartZoomFactor(@Nonnull ZoomOptions zoomOptions) {
return 1.0d;
}
+ private Rectangle getValidImageBounds() {
+ Rectangle bounds = imageComponent.getDocument().getBounds();
+ return bounds == null || bounds.width == 0 || bounds.height == 0 ? null : bounds;
+ }
+
+ private Dimension getValidCanvasSize() {
+ Dimension canvasSize = myScrollPane.getViewport().getExtentSize();
+ canvasSize.height -= ImageComponent.IMAGE_INSETS * 2;
+ canvasSize.width -= ImageComponent.IMAGE_INSETS * 2;
+ if (canvasSize.width <= 0 || canvasSize.height <= 0) {
+ return null;
+ }
+ return canvasSize;
+ }
+
private void updateImageComponentSize() {
Rectangle bounds = imageComponent.getDocument().getBounds();
if (bounds != null) {
diff --git a/image-desktop-awt-impl/src/main/java/consulo/images/desktop/awt/impl/thumbnail/ThumbnailViewImpl.java b/image-desktop-awt-impl/src/main/java/consulo/images/desktop/awt/impl/thumbnail/ThumbnailViewImpl.java
index 3f5a922..d8af56a 100644
--- a/image-desktop-awt-impl/src/main/java/consulo/images/desktop/awt/impl/thumbnail/ThumbnailViewImpl.java
+++ b/image-desktop-awt-impl/src/main/java/consulo/images/desktop/awt/impl/thumbnail/ThumbnailViewImpl.java
@@ -57,7 +57,7 @@ public ThumbnailViewImpl(Project project) {
ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
myThubmnailViewUi = new ThumbnailViewUI(this);
toolWindow = windowManager.registerToolWindow(TOOLWINDOW_ID, myThubmnailViewUi, ToolWindowAnchor.BOTTOM);
- toolWindow.setIcon(ImagesIconGroup.thumbnailtoolwindow());
+ toolWindow.setIcon(ImagesIconGroup.toolwindowThumbnail());
setVisible(false);
}
diff --git a/image-svg-api/src/main/java/consulo/images/svg/SVGFileType.java b/image-svg-api/src/main/java/consulo/images/svg/SVGFileType.java
index 93c97ad..8f0f0d4 100644
--- a/image-svg-api/src/main/java/consulo/images/svg/SVGFileType.java
+++ b/image-svg-api/src/main/java/consulo/images/svg/SVGFileType.java
@@ -61,7 +61,7 @@ public String getDefaultExtension() {
@Nonnull
@Override
public Image getIcon() {
- return ImagesIconGroup.imagesfiletype();
+ return ImagesIconGroup.filetypeImage();
}
@Override
diff --git a/image-svg-impl/src/main/java/consulo/images/svg/impl/codeInsight/SVGColorProvider.java b/image-svg-impl/src/main/java/consulo/images/svg/impl/codeInsight/SVGColorProvider.java
index 7edbc6d..11948a5 100644
--- a/image-svg-impl/src/main/java/consulo/images/svg/impl/codeInsight/SVGColorProvider.java
+++ b/image-svg-impl/src/main/java/consulo/images/svg/impl/codeInsight/SVGColorProvider.java
@@ -75,6 +75,7 @@ public enum NamedColor {
DARKSEAGREEN(0x8FBC8F),
DARKSLATEBLUE(0x483D8B),
DARKSLATEGRAY(0x2F4F4F),
+ DARKSLATEGREY(0x2F4F4F),
DARKTURQUOISE(0x00CED1),
DARKVIOLET(0x9400D3),
DEEPPINK(0xFF1493),
diff --git a/plugin/src/main/java/consulo/images/impl/action/ImagesEditorToolbarGroup.java b/plugin/src/main/java/consulo/images/impl/action/ImagesEditorToolbarGroup.java
index 1b31539..62a126e 100644
--- a/plugin/src/main/java/consulo/images/impl/action/ImagesEditorToolbarGroup.java
+++ b/plugin/src/main/java/consulo/images/impl/action/ImagesEditorToolbarGroup.java
@@ -17,6 +17,7 @@
@ActionRef(type = ZoomInAction.class),
@ActionRef(type = ZoomOutAction.class),
@ActionRef(type = ZoomActualAction.class),
+ @ActionRef(type = ZoomFitToWindowAction.class),
@ActionRef(type = AnSeparator.class),
@ActionRef(type = OpenSettingsAction.class)
})
diff --git a/plugin/src/main/java/consulo/images/impl/action/ToggleGridAction.java b/plugin/src/main/java/consulo/images/impl/action/ToggleGridAction.java
index 7b8fe77..80a8088 100644
--- a/plugin/src/main/java/consulo/images/impl/action/ToggleGridAction.java
+++ b/plugin/src/main/java/consulo/images/impl/action/ToggleGridAction.java
@@ -16,9 +16,9 @@
package consulo.images.impl.action;
import consulo.annotation.component.ActionImpl;
+import consulo.images.icon.ImagesIconGroup;
import consulo.images.localize.ImagesLocalize;
import consulo.localize.LocalizeValue;
-import consulo.platform.base.icon.PlatformIconGroup;
import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.ex.action.AnActionEvent;
import consulo.ui.ex.action.Presentation;
@@ -38,30 +38,25 @@
// TODO
public final class ToggleGridAction extends ToggleAction {
public ToggleGridAction() {
- super(ImagesLocalize.actionImagesEditorToggleGridShowText(), LocalizeValue.empty(), PlatformIconGroup.graphGrid());
+ super(ImagesLocalize.actionImagesEditorToggleGridShowText(), LocalizeValue.empty(), ImagesIconGroup.actionGrid());
}
@Override
public boolean isSelected(@Nonnull AnActionEvent e) {
- ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
- return decorator != null && decorator.isGridVisible();
+ return ImageEditorActionUtil.testImageDecorator(e, ImageComponentDecorator::isGridVisible);
}
@Override
public void setSelected(@Nonnull AnActionEvent e, boolean state) {
- ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
- if (decorator != null) {
- decorator.setGridVisible(state);
- }
+ ImageEditorActionUtil.acceptImageDecorator(e, decorator -> decorator.setGridVisible(state));
}
@Override
@RequiredUIAccess
public void update(@Nonnull AnActionEvent e) {
super.update(e);
- ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
Presentation presentation = e.getPresentation();
- presentation.setEnabled(decorator != null);
+ presentation.setEnabled(ImageEditorActionUtil.testImageDecorator(e, decorator -> true));
presentation.setTextValue(
isSelected(e) ? ImagesLocalize.actionImagesEditorToggleGridHideText() : ImagesLocalize.actionImagesEditorToggleGridShowText()
);
diff --git a/plugin/src/main/java/consulo/images/impl/action/ToggleTransparencyChessboardAction.java b/plugin/src/main/java/consulo/images/impl/action/ToggleTransparencyChessboardAction.java
index e70915d..08155e9 100644
--- a/plugin/src/main/java/consulo/images/impl/action/ToggleTransparencyChessboardAction.java
+++ b/plugin/src/main/java/consulo/images/impl/action/ToggleTransparencyChessboardAction.java
@@ -38,40 +38,30 @@ public ToggleTransparencyChessboardAction() {
super(
ImagesLocalize.actionImagesEditorToggleTransparencyChessboardShowText(),
ImagesLocalize.actionImagesEditorToggleTransparencyChessboardDescription(),
- ImagesIconGroup.toggletransparencychessboard()
+ ImagesIconGroup.actionChessboard()
);
}
@Override
public boolean isSelected(@Nonnull AnActionEvent e) {
- ImageComponentDecorator decorator = getDecoratorIfEnabled(e);
- return decorator != null && decorator.isTransparencyChessboardVisible();
+ return ImageEditorActionUtil.testImageDecorator(e, ImageComponentDecorator::isTransparencyChessboardVisible);
}
@Override
public void setSelected(@Nonnull AnActionEvent e, boolean state) {
- ImageComponentDecorator decorator = getDecoratorIfEnabled(e);
- if (decorator != null) {
- decorator.setTransparencyChessboardVisible(state);
- }
+ ImageEditorActionUtil.acceptImageDecorator(e, decorator -> decorator.setTransparencyChessboardVisible(state));
}
@Override
@RequiredUIAccess
public void update(@Nonnull AnActionEvent e) {
super.update(e);
- ImageComponentDecorator decorator = getDecoratorIfEnabled(e);
Presentation presentation = e.getPresentation();
- presentation.setEnabled(decorator != null);
+ presentation.setEnabled(ImageEditorActionUtil.testImageDecorator(e, decorator -> true));
presentation.setTextValue(
isSelected(e)
? ImagesLocalize.actionImagesEditorToggleTransparencyChessboardHideText()
: ImagesLocalize.actionImagesEditorToggleTransparencyChessboardShowText()
);
}
-
- private ImageComponentDecorator getDecoratorIfEnabled(AnActionEvent e) {
- ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
- return decorator != null && decorator.isEnabledForActionPlace(e.getPlace()) ? decorator : null;
- }
}
diff --git a/plugin/src/main/java/consulo/images/impl/action/ZoomActualAction.java b/plugin/src/main/java/consulo/images/impl/action/ZoomActualAction.java
index e57d359..cd191d9 100644
--- a/plugin/src/main/java/consulo/images/impl/action/ZoomActualAction.java
+++ b/plugin/src/main/java/consulo/images/impl/action/ZoomActualAction.java
@@ -16,21 +16,16 @@
package consulo.images.impl.action;
import consulo.annotation.component.ActionImpl;
+import consulo.images.icon.ImagesIconGroup;
import consulo.images.localize.ImagesLocalize;
import consulo.localize.LocalizeValue;
-import consulo.platform.base.icon.PlatformIconGroup;
import consulo.ui.annotation.RequiredUIAccess;
-import consulo.ui.ex.action.AnAction;
import consulo.ui.ex.action.AnActionEvent;
import consulo.ui.ex.action.DumbAwareAction;
-import consulo.ui.image.Image;
-import jakarta.annotation.Nullable;
+import jakarta.annotation.Nonnull;
import org.intellij.images.editor.ImageEditor;
import org.intellij.images.editor.ImageZoomModel;
import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
-import org.intellij.images.ui.ImageComponentDecorator;
-
-import jakarta.annotation.Nonnull;
/**
* Resize image to actual size.
@@ -47,23 +42,19 @@ public ZoomActualAction() {
super(
ImagesLocalize.actionImagesEditorZoomActualText(),
LocalizeValue.empty(),
- PlatformIconGroup.graphActualzoom()
+ ImagesIconGroup.actionActualzoom()
);
}
@Override
@RequiredUIAccess
public void actionPerformed(@Nonnull AnActionEvent e) {
- ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
- if (decorator != null) {
- decorator.getZoomModel().setZoomFactor(1.0d);
- }
+ ImageEditorActionUtil.acceptZoomModel(e, zoomModel -> zoomModel.setZoomFactor(1.0d));
}
@Override
@RequiredUIAccess
public void update(@Nonnull AnActionEvent e) {
- ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
- e.getPresentation().setEnabled(decorator != null && decorator.getZoomModel().getZoomFactor() != 1.0d);
+ e.getPresentation().setEnabled(ImageEditorActionUtil.testZoomModel(e, zoomModel -> zoomModel.getZoomFactor() != 1.0d));
}
}
diff --git a/plugin/src/main/java/consulo/images/impl/action/ZoomFitToWindowAction.java b/plugin/src/main/java/consulo/images/impl/action/ZoomFitToWindowAction.java
new file mode 100644
index 0000000..6ae17ab
--- /dev/null
+++ b/plugin/src/main/java/consulo/images/impl/action/ZoomFitToWindowAction.java
@@ -0,0 +1,39 @@
+package consulo.images.impl.action;
+
+import consulo.annotation.component.ActionImpl;
+import consulo.images.icon.ImagesIconGroup;
+import consulo.images.localize.ImagesLocalize;
+import consulo.localize.LocalizeValue;
+import consulo.ui.annotation.RequiredUIAccess;
+import consulo.ui.ex.action.AnActionEvent;
+import consulo.ui.ex.action.DumbAwareAction;
+import jakarta.annotation.Nonnull;
+import org.intellij.images.editor.ImageZoomModel;
+import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
+
+/**
+ * @author UNV
+ * @since 2025-03-31
+ */
+@ActionImpl(id = "Images.Editor.Zoom.Fit.To.Window")
+public class ZoomFitToWindowAction extends DumbAwareAction {
+ public ZoomFitToWindowAction() {
+ super(
+ ImagesLocalize.actionImagesEditorZoomFitToWindowText(),
+ LocalizeValue.empty(),
+ ImagesIconGroup.actionFitcontent()
+ );
+ }
+
+ @Override
+ @RequiredUIAccess
+ public void actionPerformed(@Nonnull AnActionEvent e) {
+ ImageEditorActionUtil.acceptZoomModel(e, ImageZoomModel::zoomFitToWindow);
+ }
+
+ @Override
+ @RequiredUIAccess
+ public void update(@Nonnull AnActionEvent e) {
+ e.getPresentation().setEnabled(ImageEditorActionUtil.testZoomModel(e, ImageZoomModel::canZoomFitToWindow));
+ }
+}
diff --git a/plugin/src/main/java/consulo/images/impl/action/ZoomInAction.java b/plugin/src/main/java/consulo/images/impl/action/ZoomInAction.java
index de98666..754ac63 100644
--- a/plugin/src/main/java/consulo/images/impl/action/ZoomInAction.java
+++ b/plugin/src/main/java/consulo/images/impl/action/ZoomInAction.java
@@ -17,9 +17,9 @@
import consulo.annotation.component.ActionImpl;
import consulo.annotation.component.ActionRef;
+import consulo.images.icon.ImagesIconGroup;
import consulo.images.localize.ImagesLocalize;
import consulo.localize.LocalizeValue;
-import consulo.platform.base.icon.PlatformIconGroup;
import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.ex.action.AnActionEvent;
import consulo.ui.ex.action.DumbAwareAction;
@@ -28,7 +28,6 @@
import org.intellij.images.editor.ImageEditor;
import org.intellij.images.editor.ImageZoomModel;
import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
-import org.intellij.images.ui.ImageComponentDecorator;
/**
* Zoom in.
@@ -39,23 +38,18 @@
@ActionImpl(id = "Images.Editor.Zoom.In", shortcutFrom = @ActionRef(id = IdeActions.ACTION_EXPAND_ALL))
public final class ZoomInAction extends DumbAwareAction {
public ZoomInAction() {
- super(ImagesLocalize.actionImagesEditorZoomInText(), LocalizeValue.empty(), PlatformIconGroup.graphZoomin());
+ super(ImagesLocalize.actionImagesEditorZoomInText(), LocalizeValue.empty(), ImagesIconGroup.actionZoomin());
}
@Override
@RequiredUIAccess
public void actionPerformed(@Nonnull AnActionEvent e) {
- ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
- if (decorator != null) {
- ImageZoomModel zoomModel = decorator.getZoomModel();
- zoomModel.zoomIn();
- }
+ ImageEditorActionUtil.acceptZoomModel(e, ImageZoomModel::zoomIn);
}
@Override
@RequiredUIAccess
public void update(@Nonnull AnActionEvent e) {
- ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
- e.getPresentation().setEnabled(decorator != null && decorator.getZoomModel().canZoomIn());
+ e.getPresentation().setEnabled(ImageEditorActionUtil.testZoomModel(e, ImageZoomModel::canZoomIn));
}
}
diff --git a/plugin/src/main/java/consulo/images/impl/action/ZoomOutAction.java b/plugin/src/main/java/consulo/images/impl/action/ZoomOutAction.java
index a2e90ec..c84c6db 100644
--- a/plugin/src/main/java/consulo/images/impl/action/ZoomOutAction.java
+++ b/plugin/src/main/java/consulo/images/impl/action/ZoomOutAction.java
@@ -17,9 +17,9 @@
import consulo.annotation.component.ActionImpl;
import consulo.annotation.component.ActionRef;
+import consulo.images.icon.ImagesIconGroup;
import consulo.images.localize.ImagesLocalize;
import consulo.localize.LocalizeValue;
-import consulo.platform.base.icon.PlatformIconGroup;
import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.ex.action.AnActionEvent;
import consulo.ui.ex.action.DumbAwareAction;
@@ -28,7 +28,6 @@
import org.intellij.images.editor.ImageEditor;
import org.intellij.images.editor.ImageZoomModel;
import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
-import org.intellij.images.ui.ImageComponentDecorator;
/**
* Zoom out.
@@ -39,23 +38,18 @@
@ActionImpl(id = "Images.Editor.Zoom.Out", shortcutFrom = @ActionRef(id = IdeActions.ACTION_COLLAPSE_ALL))
public final class ZoomOutAction extends DumbAwareAction {
public ZoomOutAction() {
- super(ImagesLocalize.actionImagesEditorZoomOutText(), LocalizeValue.empty(), PlatformIconGroup.graphZoomout());
+ super(ImagesLocalize.actionImagesEditorZoomOutText(), LocalizeValue.empty(), ImagesIconGroup.actionZoomout());
}
@Override
@RequiredUIAccess
public void actionPerformed(@Nonnull AnActionEvent e) {
- ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
- if (decorator != null) {
- ImageZoomModel zoomModel = decorator.getZoomModel();
- zoomModel.zoomOut();
- }
+ ImageEditorActionUtil.acceptZoomModel(e, ImageZoomModel::zoomOut);
}
@Override
@RequiredUIAccess
public void update(@Nonnull AnActionEvent e) {
- ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
- e.getPresentation().setEnabled(decorator != null && decorator.getZoomModel().canZoomOut());
+ e.getPresentation().setEnabled(ImageEditorActionUtil.testZoomModel(e, ImageZoomModel::canZoomOut));
}
}