| author | Marc Aubry | 2012-11-13 05:54:49 (EST) |
|---|---|---|
| committer | Simon Bernard | 2012-11-13 05:54:49 (EST) |
| commit | 306cbe1fa3e029672b7d01361875b51eae5f1b59 (patch) (side-by-side diff) | |
| tree | 65e55933f67cc9004fe80235102866e4583ccfdf | |
| parent | 3f623b652fdd1fa174972671b4ab444a5871cdc4 (diff) | |
| download | org.eclipse.koneki.ldt-306cbe1fa3e029672b7d01361875b51eae5f1b59.zip org.eclipse.koneki.ldt-306cbe1fa3e029672b7d01361875b51eae5f1b59.tar.gz org.eclipse.koneki.ldt-306cbe1fa3e029672b7d01361875b51eae5f1b59.tar.bz2 | |
13 files changed, 419 insertions, 91 deletions
diff --git a/plugins/org.eclipse.koneki.ldt.remote.debug.ui/plugin.xml b/plugins/org.eclipse.koneki.ldt.remote.debug.ui/plugin.xml index fb8d3a4..8f3fc60 100644 --- a/plugins/org.eclipse.koneki.ldt.remote.debug.ui/plugin.xml +++ b/plugins/org.eclipse.koneki.ldt.remote.debug.ui/plugin.xml @@ -28,19 +28,19 @@ </extension> <extension point="org.eclipse.debug.ui.launchShortcuts"> <shortcut - label="Lua Remote Application" + label="%launchshortcut.label" icon="icons/obj16/lua_remote.png" helpContextId="org.eclipse.jdt.debug.ui" modes="run, debug" class="org.eclipse.koneki.ldt.remote.debug.ui.internal.launch.LuaRemoteLaunchShortcut" - description="Launch a Lua application on remote host" + description="%launchshortcut.description" id="org.eclipse.koneki.ldt.debug.ui.localLuaShortcut"> <description - description="Run a Lua application on a remote host" + description="%runasshortcut.description" mode="run"> </description> <description - description="Debug a Lua application on a remote host" + description="%debugasshortcut.description" mode="debug"> </description> <contextualLaunch> diff --git a/plugins/org.eclipse.koneki.ldt.ui/OSGI-INF/l10n/bundle.properties b/plugins/org.eclipse.koneki.ldt.ui/OSGI-INF/l10n/bundle.properties index 861ec26..951b8c9 100644 --- a/plugins/org.eclipse.koneki.ldt.ui/OSGI-INF/l10n/bundle.properties +++ b/plugins/org.eclipse.koneki.ldt.ui/OSGI-INF/l10n/bundle.properties @@ -31,4 +31,7 @@ context.description = Editing Lua Source Context context.name = Editing Lua Source proposals.luaDocumentor.name = LuaDocumentor Proposals proposals.luaDocumentor.category.name = LuaDocumentor Proposals -wizard.file.new.name = Lua File
\ No newline at end of file +wizard.file.new.name = Lua File +theme.docforeground = Documentation Foreground +theme.docbackground = Documentation Background +theme.ldtcategoryname = Lua Development Tool
\ No newline at end of file diff --git a/plugins/org.eclipse.koneki.ldt.ui/build.properties b/plugins/org.eclipse.koneki.ldt.ui/build.properties index b93ca27..d42089d 100644 --- a/plugins/org.eclipse.koneki.ldt.ui/build.properties +++ b/plugins/org.eclipse.koneki.ldt.ui/build.properties @@ -19,7 +19,8 @@ bin.includes = META-INF/,\ about.html,\ build.properties,\ sample/,\ - templates/ + templates/,\ + resources/ src.includes = icons/ javacProjectSettings = true javacDefaultEncoding.. = UTF-8 diff --git a/plugins/org.eclipse.koneki.ldt.ui/plugin.xml b/plugins/org.eclipse.koneki.ldt.ui/plugin.xml index 5c766ce..52414f9 100644 --- a/plugins/org.eclipse.koneki.ldt.ui/plugin.xml +++ b/plugins/org.eclipse.koneki.ldt.ui/plugin.xml @@ -435,4 +435,25 @@ class="org.eclipse.koneki.ldt.ui.internal.editor.text.folding.LuaCodeFoldingBlockProvider"> </blockProvider> </extension> +<extension + point="org.eclipse.ui.themes"> + <colorDefinition + categoryId="org.eclipse.koneki.ldt.ui.theme" + id="org.eclipse.koneki.ldt.ui.docforeground" + isEditable="true" + label="%theme.docforeground" + value="COLOR_INFO_FOREGROUND"> + </colorDefinition> + <colorDefinition + categoryId="org.eclipse.koneki.ldt.ui.theme" + id="org.eclipse.koneki.ldt.ui.docbackground" + isEditable="true" + label="%theme.docbackground" + value="COLOR_INFO_BACKGROUND"> + </colorDefinition> + <themeElementCategory + id="org.eclipse.koneki.ldt.ui.theme" + label="%theme.ldtcategoryname"> + </themeElementCategory> +</extension> </plugin> diff --git a/plugins/org.eclipse.koneki.ldt.ui/resources/css/lua_documentation.css b/plugins/org.eclipse.koneki.ldt.ui/resources/css/lua_documentation.css new file mode 100644 index 0000000..e567ffa --- a/dev/null +++ b/plugins/org.eclipse.koneki.ldt.ui/resources/css/lua_documentation.css @@ -0,0 +1,34 @@ +/* Font definitions */ +html { font-family: sans-serif; font-size: 10pt; font-style: normal; font-weight: normal; } +body, h4, h5, h6, p, table, td, caption, th, ul, ol, dl, li, dd, dt { font-size: 1em; } +pre { font-family: monospace; } +h1 { font-size: 1.8em; } +h2 { font-size: 1.2em; } +h3 { font-size: 1.1em; } + +/* Margins */ +h1 { margin-top: 0.3em; margin-bottom: 0.04em } +h2 { margin-top: 2em; margin-bottom: 0.25em } +h3 { margin-top: 1.7em; margin-bottom: 0.25em } +h4 { margin-top: 2em; margin-bottom: 0.3em } +h5 { margin-top: 0px; margin-bottom: 0px } +p:first-child{ margin-top: 0px; } +p {margin-bottom: 0px;} +pre { margin-left: 0.6em } +ul { margin-top: 0px; margin-bottom: 1em; } +li { margin-top: 0px; margin-bottom: 0px; } +ol { margin-top: 0px; margin-bottom: 1em; } +dl { margin-top: 0px; margin-bottom: 1em; } +dt { margin-top: 0px; margin-bottom: 0px; font-weight: bold; } +dd { margin-top: 10px; margin-bottom: 0px; } +td.summary p {margin-top: 0px;} + +/* Styles and colors */ +a:link { color: #0000FF; } +a:hover { color: #000080; } +a:visited { text-decoration: underline; } +h4 { font-style: italic; } +strong { font-weight: bold; } +em { font-style: italic; } +var { font-style: italic; } +th { font-weight: bold; } diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/LuaDocumentationHelper.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/LuaDocumentationHelper.java new file mode 100644 index 0000000..32048b7 --- a/dev/null +++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/LuaDocumentationHelper.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.internal; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.text.MessageFormat; + +import org.apache.commons.io.FileUtils; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.dltk.ui.PreferenceConstants; +import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.themes.ITheme; +import org.eclipse.ui.themes.IThemeManager; +import org.osgi.framework.Bundle; + +public final class LuaDocumentationHelper { + + public static final String BACKGROUND_COLOR_ID = "org.eclipse.koneki.ldt.ui.docbackground"; //$NON-NLS-1$ + public static final String FOREGROUND_COLOR_ID = "org.eclipse.koneki.ldt.ui.docforeground"; //$NON-NLS-1$ + + private static final String CSS_FILE_PATH = "/resources/css/lua_documentation.css"; //$NON-NLS-1$ + + private static String styleSheet; + + private LuaDocumentationHelper() { + } + + private static ColorRegistry getColorRegistry() { + IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager(); + ITheme currentTheme = themeManager.getCurrentTheme(); + return currentTheme.getColorRegistry(); + } + + public static Color getForegroundColor() { + return getColorRegistry().get(FOREGROUND_COLOR_ID); + } + + public static Color getBackgroundColor() { + return getColorRegistry().get(BACKGROUND_COLOR_ID); + } + + public static String getStyleSheet() { + if (styleSheet == null) { + styleSheet = initStyleSheet(); + } + + // Retrieve font from preference + FontData fontData = JFaceResources.getFontRegistry().getFontData(PreferenceConstants.APPEARANCE_DOCUMENTATION_FONT)[0]; + String styleSheetWithPreference = org.eclipse.dltk.ui.text.completion.HTMLPrinter.convertTopLevelFont(styleSheet, fontData); + + // Retrieve colors from theme: + RGB bgColor = getBackgroundColor().getRGB(); + RGB fgColor = getForegroundColor().getRGB(); + + styleSheetWithPreference = "body {color:" + toHtmlColor(fgColor) + "; background-color:" + toHtmlColor(bgColor) + ";}" + styleSheet; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + return styleSheetWithPreference; + } + + protected static String initStyleSheet() { + Bundle bundle = Activator.getDefault().getBundle(); + URL styleSheetURL = bundle.getEntry(CSS_FILE_PATH); + if (styleSheetURL == null) { + String errorMessage = MessageFormat.format("No css found on the path: {1}", CSS_FILE_PATH); //$NON-NLS-1$ + Activator.logError(errorMessage, new NullPointerException()); + } + try { + styleSheetURL = FileLocator.toFileURL(styleSheetURL); + File cssFile = FileUtils.toFile(styleSheetURL); + return FileUtils.readFileToString(cssFile); + + } catch (IOException ex) { + Activator.logError("Unable to open CSS file for luadoc view", ex); //$NON-NLS-1$ + } + return null; + } + + protected static String toHtmlColor(RGB color) { + StringBuffer buffer = new StringBuffer(); + + buffer.append('#'); + appendHex(color.red, buffer); + appendHex(color.green, buffer); + appendHex(color.blue, buffer); + + return buffer.toString(); + } + + protected static void appendHex(int color, StringBuffer buffer) { + String string = Integer.toHexString(color).toUpperCase(); + if (string.length() == 1) { + buffer.append("0"); //$NON-NLS-1$ + } + buffer.append(string); + } + + public static String generatePage(String htmlContent) { + return generatePage(getStyleSheet(), htmlContent); + } + + public static String generatePage(String cssStyle, String htmlContent) { + StringBuffer buffer = new StringBuffer(); + buffer.append("<html><head><style CHARSET=\"ISO-8859-1\" TYPE=\"text/css\">"); //$NON-NLS-1$ + buffer.append(cssStyle); + buffer.append("</style></head><body>"); //$NON-NLS-1$ + buffer.append(htmlContent); + buffer.append("</body></html>"); //$NON-NLS-1$ + return buffer.toString(); + } + +} diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/DelegateLuaCompletionProposalMethods.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/DelegateLuaCompletionProposalMethods.java new file mode 100644 index 0000000..eb6a46a --- a/dev/null +++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/DelegateLuaCompletionProposalMethods.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.internal.editor.completion; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.dltk.ui.text.completion.AbstractScriptCompletionProposal; +import org.eclipse.koneki.ldt.ui.internal.LuaDocumentationHelper; + +public final class DelegateLuaCompletionProposalMethods { + + private DelegateLuaCompletionProposalMethods() { + } + + public static Object getAdditionalProposalInfo(AbstractScriptCompletionProposal proposal, IProgressMonitor monitor) { + if (proposal.getProposalInfo() != null) { + String info = proposal.getProposalInfo().getInfo(monitor); + if (info != null && info.length() > 0) { + info = LuaDocumentationHelper.generatePage(info); + } + return info; + } + return null; + } + +} diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaCompletionProposal.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaCompletionProposal.java index 341a16c..9880e2b 100644 --- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaCompletionProposal.java +++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaCompletionProposal.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.koneki.ldt.ui.internal.editor.completion; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.dltk.ui.PreferenceConstants; import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposal; import org.eclipse.jface.preference.IPreferenceStore; @@ -34,4 +35,9 @@ public class LuaCompletionProposal extends ScriptCompletionProposal { IPreferenceStore preference = Activator.getDefault().getPreferenceStore(); return preference.getBoolean(PreferenceConstants.CODEASSIST_INSERT_COMPLETION); } + + @Override + public Object getAdditionalProposalInfo(IProgressMonitor monitor) { + return DelegateLuaCompletionProposalMethods.getAdditionalProposalInfo(this, monitor); + } } diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaCompletionProposalCollector.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaCompletionProposalCollector.java index 61308b9..e44b594 100644 --- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaCompletionProposalCollector.java +++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaCompletionProposalCollector.java @@ -10,11 +10,11 @@ *******************************************************************************/ package org.eclipse.koneki.ldt.ui.internal.editor.completion; -import org.eclipse.dltk.core.IScriptProject; +import org.eclipse.dltk.core.CompletionProposal; import org.eclipse.dltk.core.ISourceModule; +import org.eclipse.dltk.ui.text.completion.IScriptCompletionProposal; import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposal; import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalCollector; -import org.eclipse.dltk.ui.text.completion.ScriptOverrideCompletionProposal; import org.eclipse.koneki.ldt.core.LuaNature; import org.eclipse.swt.graphics.Image; @@ -27,12 +27,6 @@ public class LuaCompletionProposalCollector extends ScriptCompletionProposalColl } @Override - protected ScriptCompletionProposal createOverrideCompletionProposal(IScriptProject scriptProject, ISourceModule compilationUnit, String name, - String[] paramTypes, int start, int length, String displayName, String completionProposal) { - return new ScriptOverrideCompletionProposal(scriptProject, compilationUnit, name, paramTypes, start, length, displayName, completionProposal); - } - - @Override protected ScriptCompletionProposal createScriptCompletionProposal(String completion, int replaceStart, int length, Image image, String displayString, int i) { return new LuaCompletionProposal(completion, replaceStart, length, image, displayString, i); @@ -45,6 +39,11 @@ public class LuaCompletionProposalCollector extends ScriptCompletionProposalColl } @Override + protected IScriptCompletionProposal createMethodReferenceProposal(CompletionProposal methodProposal) { + return new LuaScriptMethodCompletionProposal(methodProposal, getInvocationContext()); + } + + @Override protected char[] getVarTrigger() { return VAR_TRIGGER; } diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaScriptMethodCompletionProposal.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaScriptMethodCompletionProposal.java new file mode 100644 index 0000000..0bfdbe8 --- a/dev/null +++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaScriptMethodCompletionProposal.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.internal.editor.completion; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.dltk.core.CompletionProposal; +import org.eclipse.dltk.ui.text.completion.ScriptContentAssistInvocationContext; +import org.eclipse.dltk.ui.text.completion.ScriptMethodCompletionProposal; + +public class LuaScriptMethodCompletionProposal extends ScriptMethodCompletionProposal { + + public LuaScriptMethodCompletionProposal(CompletionProposal proposal, ScriptContentAssistInvocationContext context) { + super(proposal, context); + } + + @Override + public Object getAdditionalProposalInfo(IProgressMonitor monitor) { + return DelegateLuaCompletionProposalMethods.getAdditionalProposalInfo(this, monitor); + } +} diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaDocumentationHover.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaDocumentationHover.java new file mode 100644 index 0000000..aded535 --- a/dev/null +++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaDocumentationHover.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.internal.editor.text; + +import java.io.IOException; + +import org.eclipse.dltk.core.IModelElement; +import org.eclipse.dltk.internal.ui.text.HTMLPrinter; +import org.eclipse.dltk.internal.ui.text.hover.DocumentationHover; +import org.eclipse.dltk.internal.ui.text.hover.ScriptHoverMessages; +import org.eclipse.dltk.ui.ScriptElementImageProvider; +import org.eclipse.dltk.ui.ScriptElementLabels; +import org.eclipse.dltk.ui.documentation.IDocumentationResponse; +import org.eclipse.dltk.ui.documentation.IScriptDocumentationTitleAdapter; +import org.eclipse.dltk.ui.documentation.ScriptDocumentationAccess; +import org.eclipse.dltk.ui.documentation.TextDocumentationResponse; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.koneki.ldt.ui.internal.LuaDocumentationHelper; +import org.eclipse.ui.IEditorPart; + +@SuppressWarnings("restriction") +public class LuaDocumentationHover extends DocumentationHover { + + private static final long LABEL_FLAGS = ScriptElementLabels.ALL_FULLY_QUALIFIED | ScriptElementLabels.M_APP_RETURNTYPE + | ScriptElementLabels.F_APP_TYPE_SIGNATURE | ScriptElementLabels.M_PARAMETER_TYPES | ScriptElementLabels.M_PARAMETER_NAMES + | ScriptElementLabels.M_EXCEPTIONS | ScriptElementLabels.F_PRE_TYPE_SIGNATURE | ScriptElementLabels.M_PRE_TYPE_PARAMETERS + | ScriptElementLabels.T_TYPE_PARAMETERS | ScriptElementLabels.USE_RESOLVED; + private static final long LOCAL_VARIABLE_FLAGS = LABEL_FLAGS & ~ScriptElementLabels.F_FULLY_QUALIFIED | ScriptElementLabels.F_POST_QUALIFIED; + + private static final IScriptDocumentationTitleAdapter TITLE_ADAPTER = new IScriptDocumentationTitleAdapter() { + + private ScriptElementImageProvider fImageProvider = new ScriptElementImageProvider(); + + public String getTitle(Object element) { + if (element instanceof IModelElement) { + IModelElement member = (IModelElement) element; + long flags = member.getElementType() == IModelElement.LOCAL_VARIABLE ? LOCAL_VARIABLE_FLAGS : LABEL_FLAGS; + String label = ScriptElementLabels.getDefault().getElementLabel(member, flags); + return label; + } else { + return null; + } + } + + public ImageDescriptor getImage(Object element) { + if (element instanceof IModelElement) { + final IModelElement modelElement = (IModelElement) element; + if (fImageProvider == null) { + fImageProvider = new ScriptElementImageProvider(); + } + return fImageProvider.getScriptImageDescriptor(modelElement, ScriptElementImageProvider.OVERLAY_ICONS + | ScriptElementImageProvider.SMALL_ICONS); + } + return null; + } + }; + + public LuaDocumentationHover(IEditorPart editor, IPreferenceStore store) { + super(); + setEditor(editor); + setPreferenceStore(store); + } + + @Override + protected String getHoverInfo(String nature, Object[] result) { + String htmlContent = null; + + int nResults = result.length; + if (nResults == 0) + return null; + + boolean hasContents = false; + if (nResults > 0) { + + Object element = result[0]; + IDocumentationResponse response = ScriptDocumentationAccess.getDocumentation(nature, element, TITLE_ADAPTER); + // Provide hint why there's no doc + if (response == null) { + response = new TextDocumentationResponse(element, TITLE_ADAPTER.getTitle(element), TITLE_ADAPTER.getImage(element), + ScriptHoverMessages.ScriptdocHover_noAttachedInformation); + } + try { + + htmlContent = HTMLPrinter.read(response.getReader()); + hasContents = true; + } catch (IOException e) { + return null; + } + + } + if (!hasContents) + return null; + + if (!htmlContent.isEmpty()) { + return LuaDocumentationHelper.generatePage(htmlContent); + } + return null; + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaSourceViewerConfiguration.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaSourceViewerConfiguration.java index d0eb2e2..34c46f6 100644 --- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaSourceViewerConfiguration.java +++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaSourceViewerConfiguration.java @@ -12,6 +12,9 @@ package org.eclipse.koneki.ldt.ui.internal.editor.text; import org.eclipse.dltk.compiler.task.ITodoTaskPreferences; +import org.eclipse.dltk.internal.ui.editor.ScriptEditor; +import org.eclipse.dltk.internal.ui.text.hover.EditorTextHoverDescriptor; +import org.eclipse.dltk.ui.DLTKUIPlugin; import org.eclipse.dltk.ui.text.AbstractScriptScanner; import org.eclipse.dltk.ui.text.IColorManager; import org.eclipse.dltk.ui.text.ScriptCommentScanner; @@ -25,6 +28,7 @@ import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy; import org.eclipse.jface.text.IAutoEditStrategy; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextDoubleClickStrategy; +import org.eclipse.jface.text.ITextHover; import org.eclipse.jface.text.contentassist.ContentAssistant; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.presentation.IPresentationReconciler; @@ -37,6 +41,7 @@ import org.eclipse.koneki.ldt.ui.internal.editor.completion.LuaCompletionProcess import org.eclipse.koneki.ldt.ui.internal.editor.completion.LuaContentAssistPreference; import org.eclipse.ui.texteditor.ITextEditor; +@SuppressWarnings("restriction") public class LuaSourceViewerConfiguration extends ScriptSourceViewerConfiguration { // CHECKSTYLE:OFF @@ -224,4 +229,26 @@ public class LuaSourceViewerConfiguration extends ScriptSourceViewerConfiguratio } }; } + + @Override + public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) { + final String natureId = getNatureId(); + if (natureId == null) { + return null; + } + EditorTextHoverDescriptor[] hoverDescs = DLTKUIPlugin.getDefault().getEditorTextHoverDescriptors(fPreferenceStore, natureId); + for (EditorTextHoverDescriptor hoverDesc : hoverDescs) { + if (hoverDesc.isEnabled() && hoverDesc.getStateMask() == stateMask) + return new LuaDocumentationHover(getEditor(), fPreferenceStore); + } + return null; + } + + private String getNatureId() { + final ITextEditor editor = getEditor(); + if (editor == null || !(editor instanceof ScriptEditor)) { + return null; + } + return ((ScriptEditor) editor).getLanguageToolkit().getNatureId(); + } } diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/views/LuaDocView.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/views/LuaDocView.java index a5b1663..7bc3436 100644 --- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/views/LuaDocView.java +++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/views/LuaDocView.java @@ -10,34 +10,21 @@ *******************************************************************************/ package org.eclipse.koneki.ldt.ui.internal.views; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.Reader; -import java.net.URL; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.Platform; import org.eclipse.dltk.core.IMember; import org.eclipse.dltk.core.IModelElement; import org.eclipse.dltk.core.ISourceModule; import org.eclipse.dltk.core.ModelException; import org.eclipse.dltk.internal.ui.text.HTMLPrinter; -import org.eclipse.dltk.ui.DLTKUIPlugin; -import org.eclipse.dltk.ui.PreferenceConstants; import org.eclipse.dltk.ui.ScriptElementLabels; import org.eclipse.dltk.ui.documentation.ScriptDocumentationAccess; import org.eclipse.dltk.ui.infoviews.AbstractDocumentationView; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.JFaceResources; import org.eclipse.koneki.ldt.core.internal.LuaLanguageToolkit; import org.eclipse.koneki.ldt.ui.internal.Activator; +import org.eclipse.koneki.ldt.ui.internal.LuaDocumentationHelper; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Composite; -import org.osgi.framework.Bundle; /** * The view which show the documentation of a selected ModelElement @@ -50,62 +37,30 @@ public class LuaDocView extends AbstractDocumentationView { private static final long LABEL_FLAGS = ScriptElementLabels.ALL_FULLY_QUALIFIED | ScriptElementLabels.M_APP_RETURNTYPE | ScriptElementLabels.F_APP_TYPE_SIGNATURE | ScriptElementLabels.M_PARAMETER_TYPES | ScriptElementLabels.M_PARAMETER_NAMES | ScriptElementLabels.M_EXCEPTIONS | ScriptElementLabels.T_TYPE_PARAMETERS; // FIXME DUPLICATE CODE from parent class due to private - // method declaration ... - - private static String fgStyleSheet; // FIXME DUPLICATE CODE from parent class due to private method declaration ... - - private RGB fBackgroundColorRGB; // FIXME DUPLICATE CODE from parent class due to private method declaration ... public LuaDocView() { } - // FIXME DUPLICATE CODE from parent class due to private method declaration ... - private static void initStyleSheet() { - Bundle bundle = Platform.getBundle(DLTKUIPlugin.getPluginId()); - URL styleSheetURL = bundle.getEntry("/DocumentationViewStyleSheet.css"); //$NON-NLS-1$ - if (styleSheetURL == null) - return; - try { - styleSheetURL = FileLocator.toFileURL(styleSheetURL); - InputStream openStream = styleSheetURL.openStream(); - InputStreamReader inputStreamReader = new InputStreamReader(openStream); - BufferedReader reader = new BufferedReader(inputStreamReader); - StringBuffer buffer = new StringBuffer(200); - String line = reader.readLine(); - while (line != null) { - buffer.append(line); - buffer.append('\n'); - line = reader.readLine(); - } - reader.close(); - FontData fontData = JFaceResources.getFontRegistry().getFontData(PreferenceConstants.APPEARANCE_DOCUMENTATION_FONT)[0]; - fgStyleSheet = org.eclipse.dltk.ui.text.completion.HTMLPrinter.convertTopLevelFont(buffer.toString(), fontData); - } catch (IOException ex) { - DLTKUIPlugin.log(ex); - } - } - - // //FIXME workarround due to private method declaration ... @Override - protected void internalCreatePartControl(Composite parent) { - super.internalCreatePartControl(parent); - initStyleSheet(); + protected IPreferenceStore getPreferenceStore() { + return Activator.getDefault().getPreferenceStore(); } @Override - protected void setBackground(Color color) { - fBackgroundColorRGB = color.getRGB(); - super.setBackground(color); + protected String getNature() { + return LuaLanguageToolkit.getDefault().getNatureId(); } @Override - protected IPreferenceStore getPreferenceStore() { - return Activator.getDefault().getPreferenceStore(); + protected void setBackground(Color color) { + // Hack to change control color (because we can not override inititalizeColors() + super.setBackground(LuaDocumentationHelper.getBackgroundColor()); } @Override - protected String getNature() { - return LuaLanguageToolkit.getDefault().getNatureId(); + protected void setForeground(Color color) { + // Hack to change control color (because we can not override inititalizeColors() + super.setForeground(LuaDocumentationHelper.getForegroundColor()); } /** @@ -133,13 +88,12 @@ public class LuaDocView extends AbstractDocumentationView { * @return the lua doc in HTML format for a given model Element or null if no documentation is attached */ private String getScriptdocHtml(IModelElement modelelement) { - StringBuffer buffer = new StringBuffer(); - // HTMLPrinter.addSmallHeader(buffer, getInfoText(member)); + Reader reader = ScriptDocumentationAccess.getHTMLContentReader(getNature(), modelelement, true, true); if (reader != null) { - HTMLPrinter.addParagraph(buffer, reader); + return LuaDocumentationHelper.generatePage(HTMLPrinter.read(reader)); } - return addPrologeEpilog(buffer); + return null; } /** @@ -149,10 +103,7 @@ public class LuaDocView extends AbstractDocumentationView { if (modelElement instanceof ISourceModule) { return getDefaultDocumentation((ISourceModule) modelElement); } else if (modelElement instanceof IMember) { - final StringBuffer buffer = new StringBuffer(); - HTMLPrinter.addParagraph(buffer, getInfoText(modelElement)); - HTMLPrinter.addParagraph(buffer, "<br><em>Note: This element has no attached documentation.</em>"); //$NON-NLS-1$ - return addPrologeEpilog(buffer); + return LuaDocumentationHelper.generatePage("<br><em>Note: This element has no attached documentation.</em>"); //$NON-NLS-1$ } else { return null; } @@ -164,6 +115,8 @@ public class LuaDocView extends AbstractDocumentationView { private String getDefaultDocumentation(ISourceModule sourcemodule) { final StringBuffer buffer = new StringBuffer(); try { + String styleSheet = LuaDocumentationHelper.getStyleSheet(); + IModelElement[] children = sourcemodule.getChildren(); HTMLPrinter.startBulletList(buffer); for (int i = 0; i < children.length; i++) { @@ -175,10 +128,10 @@ public class LuaDocView extends AbstractDocumentationView { } HTMLPrinter.endBulletList(buffer); HTMLPrinter.addParagraph(buffer, "<em>Note: This element has no attached documentation.</em>"); //$NON-NLS-1$ + return LuaDocumentationHelper.generatePage(styleSheet, buffer.toString()); } catch (ModelException ex) { return null; } - return addPrologeEpilog(buffer); } /** @@ -192,16 +145,4 @@ public class LuaDocView extends AbstractDocumentationView { } } - /** - * add header and footer to the html page - */ - private String addPrologeEpilog(StringBuffer buffer) { - if (buffer.length() > 0) { - HTMLPrinter.insertPageProlog(buffer, 0, fBackgroundColorRGB, fgStyleSheet); - // HTMLPrinter.insertPageProlog(buffer, 0); - HTMLPrinter.addPageEpilog(buffer); - return buffer.toString(); - } - return null; - } } |

