Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ release.properties
pom.xml.releaseBackup
*.iml
.idea
.junie
bin
*.class
*.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public JsonExplorerFileType() {
IHopFileType.CAPABILITY_CLOSE,
IHopFileType.CAPABILITY_FILE_HISTORY,
IHopFileType.CAPABILITY_COPY,
IHopFileType.CAPABILITY_CUT,
IHopFileType.CAPABILITY_PASTE,
IHopFileType.CAPABILITY_SELECT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public BatExplorerFileType() {
IHopFileType.CAPABILITY_CLOSE,
IHopFileType.CAPABILITY_FILE_HISTORY,
IHopFileType.CAPABILITY_COPY,
IHopFileType.CAPABILITY_CUT,
IHopFileType.CAPABILITY_PASTE,
IHopFileType.CAPABILITY_SELECT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public CsvExplorerFileType() {
IHopFileType.CAPABILITY_CLOSE,
IHopFileType.CAPABILITY_FILE_HISTORY,
IHopFileType.CAPABILITY_COPY,
IHopFileType.CAPABILITY_CUT,
IHopFileType.CAPABILITY_PASTE,
IHopFileType.CAPABILITY_SELECT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public MarkDownExplorerFileType() {
IHopFileType.CAPABILITY_CLOSE,
IHopFileType.CAPABILITY_FILE_HISTORY,
IHopFileType.CAPABILITY_COPY,
IHopFileType.CAPABILITY_CUT,
IHopFileType.CAPABILITY_PASTE,
IHopFileType.CAPABILITY_SELECT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.apache.hop.core.Props;
import org.apache.hop.core.gui.plugin.GuiPlugin;
import org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement;
import org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElementFilter;
import org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElementType;
import org.apache.hop.ui.core.FormDataBuilder;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.core.gui.GuiToolbarWidgets;
import org.apache.hop.ui.core.gui.IToolbarContainer;
import org.apache.hop.ui.core.widget.editor.IContentEditorWidget;
import org.apache.hop.ui.hopgui.ContentEditorFacade;
import org.apache.hop.ui.hopgui.HopGui;
import org.apache.hop.ui.hopgui.ToolbarFacade;
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.types.text.BaseTextExplorerFileTypeHandler;
Expand All @@ -45,19 +44,16 @@
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/** How do we handle a markdown file in the file explorer perspective? */
@GuiPlugin
@GuiPlugin(name = "Markdown file type handler")
public class MarkDownExplorerFileTypeHandler extends BaseTextExplorerFileTypeHandler {

private static final Class<?> PKG = MarkDownExplorerFileType.class;

public static final String TOOLBAR_PARENT_ID = "MarkDownExplorerFileTypeHandler-Toolbar";
protected static final String LANGUAGE = "markdown";

public static final String TOOLBAR_ITEM_PREVIEW =
"MarkDownExplorerFileTypeHandler-ToolBar-Preview";

Expand All @@ -72,41 +68,17 @@ public MarkDownExplorerFileTypeHandler(

@Override
protected String getLanguageId() {
return "markdown";
return LANGUAGE;
}

@Override
public void renderFile(Composite composite) {
// Create the toolbar container using the facade
IToolbarContainer toolBarContainer =
ToolbarFacade.createToolbarContainer(composite, SWT.WRAP | SWT.LEFT | SWT.HORIZONTAL);
Control toolBarControl = toolBarContainer.getControl();

// Create the toolbar widgets using GuiToolbarWidgets
GuiToolbarWidgets toolBarWidgets = new GuiToolbarWidgets();
toolBarWidgets.registerGuiPluginObject(this);
toolBarWidgets.createToolbarWidgets(toolBarContainer, TOOLBAR_PARENT_ID);

// Layout data for the toolbar control
FormData fdToolBar = new FormData();
fdToolBar.left = new FormAttachment(0, 0);
fdToolBar.right = new FormAttachment(100, 0);
fdToolBar.top = new FormAttachment(0, 0);
toolBarControl.setLayoutData(fdToolBar);
toolBarControl.pack();
PropsUi.setLook(toolBarControl, Props.WIDGET_STYLE_TOOLBAR);

// Create the standard editor widget
editorWidget = ContentEditorFacade.createContentEditor(composite, getLanguageId());

// Position the editor widget below the toolbar
Control editorControl = editorWidget.getControl();
FormData fdEditor = new FormData();
fdEditor.left = new FormAttachment(0, 0);
fdEditor.right = new FormAttachment(100, 0);
fdEditor.top = new FormAttachment(toolBarControl, 0);
fdEditor.bottom = new FormAttachment(100, 0);
editorControl.setLayoutData(fdEditor);
editorWidget.getControl().setLayoutData(FormDataBuilder.builder().fullSize().build());

// If it's a new file, there's no need to reload it
if (this.getFilename() != null) {
Expand All @@ -123,14 +95,26 @@ public void renderFile(Composite composite) {
});
}

@GuiToolbarElementFilter(parentId = IContentEditorWidget.GUI_PLUGIN_TOOLBAR_PARENT_ID)
public static boolean showForMarkdownFileType(String itemId, Object guiPluginInstance) {
if (TOOLBAR_ITEM_PREVIEW.equals(itemId)
&& guiPluginInstance instanceof IContentEditorWidget editor) {
return LANGUAGE.equals(editor.getLanguage());
}
return true;
}

@GuiToolbarElement(
root = TOOLBAR_PARENT_ID,
root = IContentEditorWidget.GUI_PLUGIN_TOOLBAR_PARENT_ID,
id = TOOLBAR_ITEM_PREVIEW,
toolTip = "i18n::MarkDownFileTypeHandler.Preview.Tooltip",
type = GuiToolbarElementType.BUTTON,
image = "ui/images/preview.svg")
image = "ui/images/preview.svg",
separator = true)
// public static void previewMarkdown(IContentEditorWidget editorWidget) {
public void previewMarkdown() {
try {
// IContentEditorWidget editorWidget = (IContentEditorWidget) event.widget;
String markdown = editorWidget.getText();

// Parse markdown to HTML body content
Expand Down Expand Up @@ -304,7 +288,10 @@ public void previewMarkdown() {
EnvironmentUtils.getInstance().openUrl(tempFile.toURI().toString());
} catch (Exception e) {
new ErrorDialog(
hopGui.getShell(), "Error", "Error generating or displaying Markdown preview", e);
HopGui.getInstance().getActiveShell(),
"Error",
"Error generating or displaying Markdown preview",
e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public PythonExplorerFileType() {
IHopFileType.CAPABILITY_CLOSE,
IHopFileType.CAPABILITY_FILE_HISTORY,
IHopFileType.CAPABILITY_COPY,
IHopFileType.CAPABILITY_CUT,
IHopFileType.CAPABILITY_PASTE,
IHopFileType.CAPABILITY_SELECT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public ShellExplorerFileType() {
IHopFileType.CAPABILITY_CLOSE,
IHopFileType.CAPABILITY_FILE_HISTORY,
IHopFileType.CAPABILITY_COPY,
IHopFileType.CAPABILITY_CUT,
IHopFileType.CAPABILITY_PASTE,
IHopFileType.CAPABILITY_SELECT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public TextExplorerFileType() {
IHopFileType.CAPABILITY_CLOSE,
IHopFileType.CAPABILITY_FILE_HISTORY,
IHopFileType.CAPABILITY_COPY,
IHopFileType.CAPABILITY_CUT,
IHopFileType.CAPABILITY_PASTE,
IHopFileType.CAPABILITY_SELECT));
}

Expand Down
Loading
Loading