Skip to content
Merged
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
34 changes: 34 additions & 0 deletions plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@
style="push">
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="winterwell.markdown.MarkdownEditor">
<command
commandId="winterwell.markdown.commands.OpenMdView"
icon="icons/notepad.gif"
style="push">
<visibleWhen
checkEnabled="true">
</visibleWhen>
</command>
</toolbar>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
Expand All @@ -50,6 +65,10 @@
id="winterwell.markdown.commands.OpenGfmView"
name="Open GitHub Flavored Markdown View">
</command>
<command
id="winterwell.markdown.commands.OpenMdView"
name="Open Markdown View">
</command>
<command
defaultHandler="winterwell.markdown.commands.Preferences"
id="winterwell.markdown.commands.Preferences"
Expand Down Expand Up @@ -121,5 +140,20 @@
</action>
</actionSet>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="winterwell.markdown.commands.OpenMdView"
commandId="winterwell.markdown.commands.OpenMdView">
<activeWhen>
<with
variable="activeEditorId">
<equals
value="winterwell.markdown.editors.MarkdownEditor">
</equals>
</with>
</activeWhen>
</handler>
</extension>

</plugin>
39 changes: 39 additions & 0 deletions plugin/src/winterwell/markdown/commands/OpenMdView.java
Original file line number Diff line number Diff line change
@@ -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);
}
}