From 84cb9f7bff1f15305b06526e0e162d0973b69a69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20G=C3=B3mez?= Date: Wed, 9 Mar 2016 17:05:18 +0100 Subject: [PATCH] Add toolbar button to open the Markdown View directly from the Markdown Editor --- plugin/plugin.xml | 34 ++++++++++++++++ .../markdown/commands/OpenMdView.java | 39 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 plugin/src/winterwell/markdown/commands/OpenMdView.java diff --git a/plugin/plugin.xml b/plugin/plugin.xml index dddb1b3..8d043e7 100755 --- a/plugin/plugin.xml +++ b/plugin/plugin.xml @@ -42,6 +42,21 @@ style="push"> + + + + + + + + @@ -50,6 +65,10 @@ id="winterwell.markdown.commands.OpenGfmView" name="Open GitHub Flavored Markdown View"> + + + + + + + + + + + + diff --git a/plugin/src/winterwell/markdown/commands/OpenMdView.java b/plugin/src/winterwell/markdown/commands/OpenMdView.java new file mode 100644 index 0000000..f36d7bd --- /dev/null +++ b/plugin/src/winterwell/markdown/commands/OpenMdView.java @@ -0,0 +1,39 @@ +package winterwell.markdown.commands; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.handlers.HandlerUtil; + +import winterwell.markdown.LogUtil; + +public class OpenMdView extends AbstractHandler { + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + try { + IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); + String mdViewId = "winterwell.markdown.views.MarkdownPreview"; + IViewPart mdView = activePage.showView(mdViewId); + activePage.activate(mdView); + } catch (PartInitException e) { + showError(e); + } catch (Exception e) { + showError(e); + } + return null; + } + + private void showError(Exception e) { + String title = "Exception while opening Markdown View"; + String message = title+" (winterwell.markdown.views.MarkdownPreview)" + +"\nCheck Error Log View"; + LogUtil.error(message, e); + MessageDialog.openError(Display.getDefault().getActiveShell(), title , message); + } +}