Skip to content

Commit

Permalink
#42 icon to open GFM View from Markdown View
Browse files Browse the repository at this point in the history
  • Loading branch information
paulvi committed Jan 12, 2015
1 parent 5d1afa5 commit b08ff5f
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 2 deletions.
5 changes: 4 additions & 1 deletion plugin/META-INF/MANIFEST.MF
Expand Up @@ -10,7 +10,10 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.ui.editors,
org.eclipse.jface.text,
org.eclipse.core.resources,
org.eclipse.ui.views
org.eclipse.ui.views,
org.eclipse.jface,
org.eclipse.swt,
org.eclipse.ui.workbench
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.core.internal.resources,
Expand Down
12 changes: 11 additions & 1 deletion plugin/plugin.xml
Expand Up @@ -19,6 +19,11 @@
<menuContribution
allPopups="false"
locationURI="toolbar:winterwell.markdown.views.MarkdownPreview">
<command
commandId="winterwell.markdown.commands.OpenGfmView"
icon="icons/github-cat_yellow.png"
style="push">
</command>
<command
commandId="winterwell.markdown.commands.Preferences"
icon="icons/settings16_yellow.png"
Expand All @@ -28,6 +33,11 @@
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="winterwell.markdown.commands.OpenGfmView"
id="winterwell.markdown.commands.OpenGfmView"
name="Open GitHub Flavored Markdown View">
</command>
<command
defaultHandler="winterwell.markdown.commands.Preferences"
id="winterwell.markdown.commands.Preferences"
Expand All @@ -45,7 +55,7 @@
class="winterwell.markdown.views.MarkdownPreview"
icon="icons/notepad.gif"
id="winterwell.markdown.views.MarkdownPreview"
name="Markdown HTML Preview"/>
name="Markdown View"/>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
Expand Down
41 changes: 41 additions & 0 deletions plugin/src/winterwell/markdown/LogUtil.java
@@ -0,0 +1,41 @@
package winterwell.markdown;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

/**
* Nodeclipse Log Util
* @author Lamb Gao, Paul Verest
*/
public class LogUtil {

public static void info(String message) {
log(IStatus.INFO, IStatus.OK, message, null);
}

public static void error(Throwable exception) {
error("Unexpected Exception", exception);
}

public static void error(String message) {
error(message, null);
}

public static void error(String message, Throwable exception) {
log(IStatus.ERROR, IStatus.ERROR, message, exception);
}

public static void log(int severity, int code, String message, Throwable exception) {
log(createStatus(severity, code, message, exception));
}

public static IStatus createStatus(int severity, int code, String message, Throwable exception) {
return new Status(severity, Activator.PLUGIN_ID, code, message, exception);
}

public static void log(IStatus status) {
ILog log = Activator.getDefault().getLog();
log.log(status);
}
}
41 changes: 41 additions & 0 deletions plugin/src/winterwell/markdown/commands/OpenGfmView.java
@@ -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);
}
}

0 comments on commit b08ff5f

Please sign in to comment.