This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new 2fa450b7c5 Create Markdown file #7075 (#7076)
2fa450b7c5 is described below
commit 2fa450b7c57ecae56393afeac271fa152fb1d91a
Author: Nicolas Adment <[email protected]>
AuthorDate: Mon May 4 09:49:49 2026 +0200
Create Markdown file #7075 (#7076)
---
.../transforms/types/MarkDownExplorerFileType.java | 60 ++++++++++++++++++++--
.../textfile/src/main/resources/markdown.svg | 1 -
.../types/messages/messages_en_US.properties | 22 ++++++++
.../textfile/src/main/resources/textfile.svg | 6 +--
.../textfile/src/main/resources/textfileinput.svg | 6 +--
.../textfile/src/main/resources/textfileoutput.svg | 6 +--
.../delegates/HopGuiFileRefreshDelegate.java | 3 +-
.../text/BaseTextExplorerFileTypeHandler.java | 6 ++-
8 files changed, 88 insertions(+), 22 deletions(-)
diff --git
a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/MarkDownExplorerFileType.java
b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/MarkDownExplorerFileType.java
index 4f26c0bd75..27f797e4da 100644
---
a/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/MarkDownExplorerFileType.java
+++
b/plugins/transforms/textfile/src/main/java/org/apache/hop/pipeline/transforms/types/MarkDownExplorerFileType.java
@@ -17,13 +17,20 @@
package org.apache.hop.pipeline.transforms.types;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.hop.core.exception.HopException;
+import org.apache.hop.core.gui.plugin.action.GuiAction;
+import org.apache.hop.core.gui.plugin.action.GuiActionType;
import org.apache.hop.core.variables.IVariables;
+import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.hopgui.HopGui;
+import org.apache.hop.ui.hopgui.context.GuiContextHandler;
+import org.apache.hop.ui.hopgui.context.IGuiContextHandler;
import org.apache.hop.ui.hopgui.file.HopFileTypePlugin;
import org.apache.hop.ui.hopgui.file.IHopFileType;
import org.apache.hop.ui.hopgui.file.IHopFileTypeHandler;
-import org.apache.hop.ui.hopgui.file.empty.EmptyHopFileTypeHandler;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerFile;
import org.apache.hop.ui.hopgui.perspective.explorer.ExplorerPerspective;
import
org.apache.hop.ui.hopgui.perspective.explorer.file.capabilities.FileTypeCapabilities;
@@ -36,6 +43,9 @@ import
org.apache.hop.ui.hopgui.perspective.explorer.file.types.text.BaseTextExp
image = "markdown.svg")
public class MarkDownExplorerFileType
extends BaseTextExplorerFileType<TextExplorerFileTypeHandler> {
+ public static final Class<?> PKG = MarkDownExplorerFileType.class;
+
+ public static final String ACTION_ID_NEW_MARKDOWN = "NewMarkdown";
public MarkDownExplorerFileType() {
super(
@@ -44,6 +54,7 @@ public class MarkDownExplorerFileType
new String[] {"*.md"},
new String[] {"MarkDown files"},
FileTypeCapabilities.getCapabilities(
+ IHopFileType.CAPABILITY_NEW,
IHopFileType.CAPABILITY_SAVE,
IHopFileType.CAPABILITY_SAVE_AS,
IHopFileType.CAPABILITY_CLOSE,
@@ -59,8 +70,49 @@ public class MarkDownExplorerFileType
}
@Override
- public IHopFileTypeHandler newFile(HopGui hopGui, IVariables
parentVariableSpace)
- throws HopException {
- return new EmptyHopFileTypeHandler();
+ public IHopFileTypeHandler newFile(HopGui hopGui, IVariables variables)
throws HopException {
+ ExplorerFile explorerFile = new ExplorerFile("New markdown", null, this);
+ ExplorerPerspective explorerPerspective =
ExplorerPerspective.getInstance();
+ TextExplorerFileTypeHandler fileHandler =
+ new TextExplorerFileTypeHandler(hopGui, explorerPerspective,
explorerFile);
+
+ explorerPerspective.addFile(fileHandler);
+ explorerPerspective.activate();
+
+ return fileHandler;
+ }
+
+ @Override
+ public List<IGuiContextHandler> getContextHandlers() {
+ HopGui hopGui = HopGui.getInstance();
+
+ List<IGuiContextHandler> handlers = new ArrayList<>();
+
+ GuiAction newAction =
+ new GuiAction(
+ ACTION_ID_NEW_MARKDOWN,
+ GuiActionType.Create,
+ BaseMessages.getString(PKG,
"MarkDownFileType.GuiAction.NewMarkDown.Name"),
+ BaseMessages.getString(PKG,
"MarkDownFileType.GuiAction.NewMarkDown.Tooltip"),
+ "markdown.svg",
+ (shiftClicked, controlClicked, parameters) -> {
+ try {
+ newFile(hopGui, hopGui.getVariables());
+ } catch (Exception e) {
+ new ErrorDialog(
+ hopGui.getShell(),
+ BaseMessages.getString(
+ PKG,
"MarkDownFileType.ErrorDialog.NewMarkDownCreation.Header"),
+ BaseMessages.getString(
+ PKG,
"MarkDownFileType.ErrorDialog.NewMarkDownCreation.Message"),
+ e);
+ }
+ });
+ newAction.setCategory("File");
+ newAction.setCategoryOrder("1");
+
+ handlers.add(new GuiContextHandler(ACTION_ID_NEW_MARKDOWN,
List.of(newAction)));
+
+ return handlers;
}
}
diff --git a/plugins/transforms/textfile/src/main/resources/markdown.svg
b/plugins/transforms/textfile/src/main/resources/markdown.svg
index cd290db1d7..8cd30f8570 100644
--- a/plugins/transforms/textfile/src/main/resources/markdown.svg
+++ b/plugins/transforms/textfile/src/main/resources/markdown.svg
@@ -1,4 +1,3 @@
-<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="800px" height="800px">
<path fill="#9575CD"
d="M14.5,572.4V209.5h79.527l119.29,136.088L332.607,209.5h79.526v362.9h-79.526V337.877l-119.29,136.089L94.028,337.877V572.4
H14.5
M571.189,209.5h119.29v181.451h99.407L630.832,595.084L471.779,390.951h99.41V209.5z"/>
diff --git
a/plugins/transforms/textfile/src/main/resources/org/apache/hop/pipeline/transforms/types/messages/messages_en_US.properties
b/plugins/transforms/textfile/src/main/resources/org/apache/hop/pipeline/transforms/types/messages/messages_en_US.properties
new file mode 100644
index 0000000000..95bd580999
--- /dev/null
+++
b/plugins/transforms/textfile/src/main/resources/org/apache/hop/pipeline/transforms/types/messages/messages_en_US.properties
@@ -0,0 +1,22 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+MarkDownFileType.GuiAction.NewMarkDown.Name=Markdown
+MarkDownFileType.GuiAction.NewMarkDown.Tooltip=Create a new Markdown file
+MarkDownFileType.ErrorDialog.NewMarkDownCreation.Header=Error creating
Markdown file
+MarkDownFileType.ErrorDialog.NewMarkDownCreation.Message=An error occurred
while creating the Markdown file:
diff --git a/plugins/transforms/textfile/src/main/resources/textfile.svg
b/plugins/transforms/textfile/src/main/resources/textfile.svg
index 92853272ec..dd4098fb28 100644
--- a/plugins/transforms/textfile/src/main/resources/textfile.svg
+++ b/plugins/transforms/textfile/src/main/resources/textfile.svg
@@ -1,8 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version:
6.00 Build 43363) -->
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
-<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
- width="42px" height="42px" viewBox="0 0 42 42" enable-background="new
0 0 42 42" xml:space="preserve">
+<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="42px"
height="42px" viewBox="0 0 42 42">
<path fill="#C9E8FB" d="M7.652,2.564v36.868h26.632V8.997h-6.426V2.564"/>
<path fill="#0E3A5A"
d="M34.271,6.429h-3.847V2.583L27.843,0H5.085v42h31.767V9.008L34.271,6.429z
M12.894,2.565h14.964v6.431h6.426
v30.436H7.652V2.565h3.43"/>
diff --git a/plugins/transforms/textfile/src/main/resources/textfileinput.svg
b/plugins/transforms/textfile/src/main/resources/textfileinput.svg
index 99363bad42..4a8aa12350 100644
--- a/plugins/transforms/textfile/src/main/resources/textfileinput.svg
+++ b/plugins/transforms/textfile/src/main/resources/textfileinput.svg
@@ -1,8 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version:
6.00 Build 0) -->
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
-<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
- width="42px" height="42px" viewBox="0 0 42 42" enable-background="new 0 0
42 42">
+<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="42px"
height="42px" viewBox="0 0 42 42" enable-background="new 0 0 42 42">
<g>
<polygon fill="#0E3A5A" points="36.516,32.635 36.516,35.718
31.292,30.493 29.948,31.837 35.173,37.062 32.029,37.063
32.029,38.963 38.416,38.962 38.416,32.635 "/>
diff --git a/plugins/transforms/textfile/src/main/resources/textfileoutput.svg
b/plugins/transforms/textfile/src/main/resources/textfileoutput.svg
index 4bea4958a1..bfaad44e3b 100644
--- a/plugins/transforms/textfile/src/main/resources/textfileoutput.svg
+++ b/plugins/transforms/textfile/src/main/resources/textfileoutput.svg
@@ -1,8 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version:
6.00 Build 0) -->
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
-<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
- width="42px" height="42px" viewBox="0 0 42 42" enable-background="new 0 0
42 42">
+<svg xmlns="http://www.w3.org/2000/svg" width="42px" height="42px" viewBox="0
0 42 42">
<rect x="14.365" y="17.552" fill="#0E3A5A" width="11.902" height="0.801"/>
<polygon fill="#0E3A5A" points="9.148,5.794 9.148,8.877 3.923,3.652
2.579,4.996 7.805,10.221 4.659,10.221 4.659,12.122
11.049,12.121 11.049,5.794 "/>
diff --git
a/ui/src/main/java/org/apache/hop/ui/hopgui/delegates/HopGuiFileRefreshDelegate.java
b/ui/src/main/java/org/apache/hop/ui/hopgui/delegates/HopGuiFileRefreshDelegate.java
index 0f1d838cf6..ee916d5ea5 100644
---
a/ui/src/main/java/org/apache/hop/ui/hopgui/delegates/HopGuiFileRefreshDelegate.java
+++
b/ui/src/main/java/org/apache/hop/ui/hopgui/delegates/HopGuiFileRefreshDelegate.java
@@ -80,9 +80,10 @@ public class HopGuiFileRefreshDelegate {
// saved in the file system
//
public void register(String fileName, IHopFileTypeHandler fileTypeHandler) {
- if (!hopGui.getProps().isReloadingFilesOnChange()) {
+ if (fileName == null || !hopGui.getProps().isReloadingFilesOnChange()) {
return;
}
+
try {
FileObject file = HopVfs.getFileObject(fileName);
fileMonitor.addFile(file);
diff --git
a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/text/BaseTextExplorerFileTypeHandler.java
b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/text/BaseTextExplorerFileTypeHandler.java
index 863b19c205..36859628fb 100644
---
a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/text/BaseTextExplorerFileTypeHandler.java
+++
b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/explorer/file/types/text/BaseTextExplorerFileTypeHandler.java
@@ -57,7 +57,11 @@ public class BaseTextExplorerFileTypeHandler extends
BaseExplorerFileTypeHandler
public void renderFile(Composite composite) {
editorWidget = ContentEditorFacade.createContentEditor(composite,
getLanguageId());
- reload();
+ // If it's a new file, there's no need to reload it
+ if (this.getFilename() != null) {
+ reload();
+ }
+
reloadListener = true;
editorWidget.addModifyListener(
e -> {