]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/winterwell.markdown/src/winterwell/markdown/commands/OpenGfmView.java
migrated to svn revision 33108
[simantics/platform.git] / bundles / winterwell.markdown / src / winterwell / markdown / commands / OpenGfmView.java
diff --git a/bundles/winterwell.markdown/src/winterwell/markdown/commands/OpenGfmView.java b/bundles/winterwell.markdown/src/winterwell/markdown/commands/OpenGfmView.java
new file mode 100644 (file)
index 0000000..80dc8eb
--- /dev/null
@@ -0,0 +1,41 @@
+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.PlatformUI;
+
+import winterwell.markdown.LogUtil;
+
+public class OpenGfmView extends AbstractHandler {
+
+       @Override
+       public Object execute(final ExecutionEvent event) throws ExecutionException {
+               try {
+               IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+               String gfmViewId = "code.satyagraha.gfm.viewer.views.GfmView";
+               IViewPart gfmView = activePage.showView(gfmViewId);
+               activePage.activate(gfmView);
+               } catch (PartInitException e) {
+                       showError(e);
+           } catch (Exception e) {
+               showError(e);
+           }           
+               return null;
+       }
+
+       private void showError(Exception e) {
+               String title = "Exception while opening GitHub Flavored Markdown View";
+               String message = title+" (code.satyagraha.gfm.viewer.views.GfmView)"
+                               +"\nCheck Error Log View and continue at https://github.com/winterstein/Eclipse-Markdown-Editor-Plugin/issues/42"
+                               +"\n\nYou can also right-click file in Project Explorer"
+                               +"\n and select \"Show in GFM view\".";
+               LogUtil.error(message, e);
+               MessageDialog.openError(Display.getDefault().getActiveShell(), title , message);
+       }
+}