From efcfd3bcea1015f17dd8dc4c37fcab4a9b9e3aef Mon Sep 17 00:00:00 2001 From: mindolph Date: Sat, 21 Dec 2024 17:35:01 +0800 Subject: [PATCH] fix: ignore file link to mmd topic when insert image from custom snippet; --- .../extension/attributes/AttributeUtils.java | 37 +++++++++++++++++++ .../images/ImagePopUpMenuExtension.java | 31 +--------------- .../com/mindolph/mindmap/MindMapEditor.java | 4 +- code/pom.xml | 14 +++---- 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/code/mindmap-panel/src/main/java/com/mindolph/mindmap/extension/attributes/AttributeUtils.java b/code/mindmap-panel/src/main/java/com/mindolph/mindmap/extension/attributes/AttributeUtils.java index ebc39adb..f38fa049 100644 --- a/code/mindmap-panel/src/main/java/com/mindolph/mindmap/extension/attributes/AttributeUtils.java +++ b/code/mindmap-panel/src/main/java/com/mindolph/mindmap/extension/attributes/AttributeUtils.java @@ -1,11 +1,19 @@ package com.mindolph.mindmap.extension.attributes; +import com.igormaznitsa.mindmap.model.MMapURI; +import com.mindolph.mfx.dialog.DialogFactory; +import com.mindolph.mfx.util.FxImageUtils; +import com.mindolph.mindmap.I18n; import com.mindolph.mindmap.dialog.ImagePreviewDialog; +import com.mindolph.mindmap.extension.api.ExtensionContext; import com.mindolph.mindmap.model.TopicNode; import javafx.scene.image.Image; +import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.FileInputStream; import java.util.List; import java.util.Objects; import java.util.Set; @@ -79,4 +87,33 @@ public static boolean setIconAttribute(String iconName, Set topics) { } return changed; } + + /** + * @param context + * @param selected file to load to topics. + * @param withFileLink ank user for attach file link to the image attribute if true. + */ + public static void loadImageFileToSelectedTopics(ExtensionContext context, File selected, boolean withFileLink) { + Image image; + try { + image = new Image(new FileInputStream(selected)); + ImagePreviewDialog scaleImageDialog = new ImagePreviewDialog("Resize&Preview", image); + Image scaledImage = scaleImageDialog.showAndWait(); + if (scaledImage != null) { + String rescaledImageAsBase64 = FxImageUtils.imageToBase64(scaledImage); + String fileName = FilenameUtils.getBaseName(selected.getName()); + String filePath; + if (withFileLink && DialogFactory.yesNoConfirmDialog(I18n.getIns().getString("Images.Extension.Question.AddFilePath.Title"), I18n.getIns().getString("Images.Extension.Question.AddFilePath"))) { + filePath = MMapURI.makeFromFilePath(context.getWorkspaceDir(), selected.getAbsolutePath(), null).toString(); + } + else { + filePath = null; + } + setImageAttribute(context.getSelectedTopics(), rescaledImageAsBase64, filePath, fileName); + context.doNotifyModelChanged(true); + } + } catch (Exception ex) { + DialogFactory.errDialog(I18n.getIns().getString("Images.Extension.Error")); + } + } } diff --git a/code/mindmap-panel/src/main/java/com/mindolph/mindmap/extension/attributes/images/ImagePopUpMenuExtension.java b/code/mindmap-panel/src/main/java/com/mindolph/mindmap/extension/attributes/images/ImagePopUpMenuExtension.java index a3331119..efcfbece 100644 --- a/code/mindmap-panel/src/main/java/com/mindolph/mindmap/extension/attributes/images/ImagePopUpMenuExtension.java +++ b/code/mindmap-panel/src/main/java/com/mindolph/mindmap/extension/attributes/images/ImagePopUpMenuExtension.java @@ -1,6 +1,5 @@ package com.mindolph.mindmap.extension.attributes.images; -import com.igormaznitsa.mindmap.model.MMapURI; import com.mindolph.base.FontIconManager; import com.mindolph.base.constant.IconKey; import com.mindolph.base.dialog.DialogFileFilters; @@ -8,7 +7,6 @@ import com.mindolph.mfx.dialog.DialogFactory; import com.mindolph.mfx.dialog.FileDialogBuilder; import com.mindolph.mfx.util.AwtImageUtils; -import com.mindolph.mfx.util.FxImageUtils; import com.mindolph.mindmap.I18n; import com.mindolph.mindmap.dialog.AddImageChooseDialog; import com.mindolph.mindmap.dialog.ImagePreviewDialog; @@ -21,13 +19,11 @@ import javafx.scene.control.MenuItem; import javafx.scene.image.Image; import javafx.scene.input.Clipboard; -import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.SystemUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.io.FileInputStream; import java.util.ArrayList; public class ImagePopUpMenuExtension extends BasePopupMenuItemExtension { @@ -96,7 +92,7 @@ public MenuItem makeMenuItem(ExtensionContext context, TopicNode activeTopic) { .extensionFilters(DialogFileFilters.IMAGE_EXTENSION_FILTER).buildAndShow(); // TODO remember the selected for next time popup; if (selected != null) { - loadImageFileToSelectedTopics(context, selected); + AttributeUtils.loadImageFileToSelectedTopics(context, selected, true); } } }); @@ -104,31 +100,6 @@ public MenuItem makeMenuItem(ExtensionContext context, TopicNode activeTopic) { return result; } - public static void loadImageFileToSelectedTopics(ExtensionContext context, File selected) { - Image image; - try { - image = new Image(new FileInputStream(selected)); - ImagePreviewDialog scaleImageDialog = new ImagePreviewDialog("Resize&Preview", image); - Image scaledImage = scaleImageDialog.showAndWait(); - if (scaledImage != null) { - String rescaledImageAsBase64 = FxImageUtils.imageToBase64(scaledImage); - String fileName = FilenameUtils.getBaseName(selected.getName()); - String filePath; - if (DialogFactory.yesNoConfirmDialog(I18n.getIns().getString("Images.Extension.Question.AddFilePath.Title"), I18n.getIns().getString("Images.Extension.Question.AddFilePath"))) { - filePath = MMapURI.makeFromFilePath(context.getWorkspaceDir(), selected.getAbsolutePath(), null).toString(); - } - else { - filePath = null; - } - AttributeUtils.setImageAttribute(context.getSelectedTopics(), rescaledImageAsBase64, filePath, fileName); - context.doNotifyModelChanged(true); - } - } catch (Exception ex) { - DialogFactory.errDialog(I18n.getIns().getString("Images.Extension.Error")); - log.error("Unexpected error during loading image file : " + selected, ex); - } - } - @Override public ContextMenuSection getSection() { return ContextMenuSection.EXTRAS; diff --git a/code/mindolph-mindmap/src/main/java/com/mindolph/mindmap/MindMapEditor.java b/code/mindolph-mindmap/src/main/java/com/mindolph/mindmap/MindMapEditor.java index c0475138..60daf784 100644 --- a/code/mindolph-mindmap/src/main/java/com/mindolph/mindmap/MindMapEditor.java +++ b/code/mindolph-mindmap/src/main/java/com/mindolph/mindmap/MindMapEditor.java @@ -21,7 +21,7 @@ import com.mindolph.mfx.dialog.DialogFactory; import com.mindolph.mindmap.event.MindmapEvents; import com.mindolph.mindmap.extension.api.ExtensionContext; -import com.mindolph.mindmap.extension.attributes.images.ImagePopUpMenuExtension; +import com.mindolph.mindmap.extension.attributes.AttributeUtils; import com.mindolph.mindmap.icon.IconID; import com.mindolph.mindmap.model.BaseElement; import com.mindolph.mindmap.model.ModelManager; @@ -375,7 +375,7 @@ public void onSnippet(Snippet snippet) { // since the ImageSnippet only works for JFX, it cant be imported to core module, so the custom // image snippet needs to be handled separately. if (StringUtils.isNotBlank(snippet.getFilePath())) { - ImagePopUpMenuExtension.loadImageFileToSelectedTopics((ExtensionContext) mindMapView, new File(snippet.getFilePath())); + AttributeUtils.loadImageFileToSelectedTopics((ExtensionContext) mindMapView, new File(snippet.getFilePath()), false); } else { mindMapView.appendTextAsTopicTree(snippet.getCode(), ""); diff --git a/code/pom.xml b/code/pom.xml index efb83348..a264740c 100644 --- a/code/pom.xml +++ b/code/pom.xml @@ -27,29 +27,29 @@ 21 23.0.1 3.17.0 - 2.17.0 - 1.12.0 + 2.18.0 + 1.13.0 4.4 1.17.1 1.9.0 1.12.0 2.0.1 - 1.2024.7 + 1.2024.8 2.4.8 2.0.16 2.24.1 - 5.11.0 + 5.11.4 2.0 2.11.0 11.2.1 - 0.11.3 + 0.11.4 2.0-M5 - 1.18.1 + 1.18.3 20240303 0.64.8 0.35.0 - 2.16.9 + 2.16.10