Skip to content

Commit

Permalink
Merge pull request #53 from Nodeclipse/master
Browse files Browse the repository at this point in the history
open GFM View from Markdown View
  • Loading branch information
Paul Verest committed Jan 26, 2015
2 parents 1d9eac2 + b08ff5f commit 5317569
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 18 deletions.
5 changes: 4 additions & 1 deletion plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
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
Binary file added plugin/icons/github-cat_yellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion plugin/plugin.xml
Original file line number Diff line number Diff line change
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
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);
}
}
41 changes: 41 additions & 0 deletions plugin/src/winterwell/markdown/commands/OpenGfmView.java
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);
}
}
32 changes: 16 additions & 16 deletions plugin/src/winterwell/markdown/editors/MarkdownEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,15 @@ private void updateSectionFoldingAnnotations2(IDocument doc, List<Header> header


}



/*
<?xml version="1.0" encoding="UTF-8" ?>
- <templates>
<template name="updateSWT" description="Performs an update to an SWT control in the SWT thread" context="java" enabled="true">${control}.getDisplay().syncExec(new Runnable() { public void run() { ${control}.${cursor} } });</template>
<template name="findView" description="Find a workbench view by ID" context="java" enabled="true" deleted="false">${viewType} ${view} = null; IWorkbenchWindow ${window} = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (${window} != null) { IWorkbenchPage ${activePage} = ${window}.getActivePage(); if (${activePage} != null) ${view} = (${viewType}) ${activePage}.findView("${viewID}"); } if (${view} != null) { ${cursor}//${todo}: Add operations for opened view }</template>



/*
<?xml version="1.0" encoding="UTF-8" ?>
- <templates>
<template name="updateSWT" description="Performs an update to an SWT control in the SWT thread" context="java" enabled="true">${control}.getDisplay().syncExec(new Runnable() { public void run() { ${control}.${cursor} } });</template>
<template name="findView" description="Find a workbench view by ID" context="java" enabled="true" deleted="false">${viewType} ${view} = null; IWorkbenchWindow ${window} = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (${window} != null) { IWorkbenchPage ${activePage} = ${window}.getActivePage(); if (${activePage} != null) ${view} = (${viewType}) ${activePage}.findView("${viewID}"); } if (${view} != null) { ${cursor}//${todo}: Add operations for opened view }</template>
<template name="getActiveEditor" description="Retrieves the currently active editor in the active page" context="java" enabled="true" deleted="false">IEditorPart ${editor} = null; IWorkbenchWindow ${window} = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (${window} != null) { IWorkbenchPage ${activePage} = ${window}.getActivePage(); if (${activePage} != null) ${editor} = ${activePage}.getActiveEditor(); } if (${editor} != null) { ${cursor}//${todo}: Add operations for active editor }</template>
IEditorPart editor = null;
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
Expand All @@ -445,11 +445,11 @@ private void updateSectionFoldingAnnotations2(IDocument doc, List<Header> header
if (editor != null) {
// todo: Add operations for active editor
}
<template name="openDialog" description="Creates and opens a JFace dialog" context="java" enabled="true" deleted="false">${dialogType} ${dialog} = new ${dialogType}(${cursor}); ${dialog}.create(); //${todo}: Complete dialog creation if (${dialog}.open() == Dialog.OK) { //${todo}: Perform actions on success };</template>
<template name="scanExtensionRegistry" description="Scans the extension registry for extensions of a given extension point" context="java" enabled="true" deleted="false">IExtensionRegistry ${registry} = Platform.getExtensionRegistry(); IExtensionPoint ${point} = ${registry}.getExtensionPoint(${pluginId}, ${expointId}); IExtension[] ${extensions} = ${point}.getExtensions(); for (int ${index} = 0; ${index} < ${extensions}.length; ${index}++) { IConfigurationElement[] ${elements} = ${extensions}[${index}].getConfigurationElements(); for (int ${index2} = 0; ${index2} < ${elements}.length; ${index2}++) { IConfigurationElement ${element} = ${elements}[${index2}]; String ${attValue} = ${element}.getAttribute(${attName}); ${cursor}//${todo}: Implement processing for configuration element } }</template>
<template name="showView" description="finds a workbench view by ID and shows it" context="java" enabled="true" deleted="false">${viewType} ${view} = null; IWorkbenchWindow ${window} = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (${window} != null) { IWorkbenchPage ${activePage} = ${window}.getActivePage(); if (${activePage} != null) try { ${view} = (${viewType}) ${activePage}.showView("${viewID}"); } catch (${Exception} e) { // ${todo}: handle exception } } if (${view} != null) { ${cursor} }</template>
<template name="signalError" description="Shows an error message in the editors status line" context="java" enabled="true" deleted="false">IEditorActionBarContributor ${contributor} = ${editor}.getEditorSite().getActionBarContributor(); if (${contributor} instanceof EditorActionBarContributor) { IActionBars ${actionBars} = ((EditorActionBarContributor) ${contributor}).getActionBars(); if (${actionBars} != null) { IStatusLineManager ${manager} = ${actionBars}.getStatusLineManager(); if (${manager} != null) ${manager}.setErrorMessage(msg); } }</template>
</templates>
<template name="openDialog" description="Creates and opens a JFace dialog" context="java" enabled="true" deleted="false">${dialogType} ${dialog} = new ${dialogType}(${cursor}); ${dialog}.create(); //${todo}: Complete dialog creation if (${dialog}.open() == Dialog.OK) { //${todo}: Perform actions on success };</template>
<template name="scanExtensionRegistry" description="Scans the extension registry for extensions of a given extension point" context="java" enabled="true" deleted="false">IExtensionRegistry ${registry} = Platform.getExtensionRegistry(); IExtensionPoint ${point} = ${registry}.getExtensionPoint(${pluginId}, ${expointId}); IExtension[] ${extensions} = ${point}.getExtensions(); for (int ${index} = 0; ${index} < ${extensions}.length; ${index}++) { IConfigurationElement[] ${elements} = ${extensions}[${index}].getConfigurationElements(); for (int ${index2} = 0; ${index2} < ${elements}.length; ${index2}++) { IConfigurationElement ${element} = ${elements}[${index2}]; String ${attValue} = ${element}.getAttribute(${attName}); ${cursor}//${todo}: Implement processing for configuration element } }</template>
<template name="showView" description="finds a workbench view by ID and shows it" context="java" enabled="true" deleted="false">${viewType} ${view} = null; IWorkbenchWindow ${window} = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (${window} != null) { IWorkbenchPage ${activePage} = ${window}.getActivePage(); if (${activePage} != null) try { ${view} = (${viewType}) ${activePage}.showView("${viewID}"); } catch (${Exception} e) { // ${todo}: handle exception } } if (${view} != null) { ${cursor} }</template>
<template name="signalError" description="Shows an error message in the editors status line" context="java" enabled="true" deleted="false">IEditorActionBarContributor ${contributor} = ${editor}.getEditorSite().getActionBarContributor(); if (${contributor} instanceof EditorActionBarContributor) { IActionBars ${actionBars} = ((EditorActionBarContributor) ${contributor}).getActionBars(); if (${actionBars} != null) { IStatusLineManager ${manager} = ${actionBars}.getStatusLineManager(); if (${manager} != null) ${manager}.setErrorMessage(msg); } }</template>
</templates>
*/

0 comments on commit 5317569

Please sign in to comment.