Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#42 icon to open GFM View from Markdown View
- Loading branch information
Showing
4 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |