summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Aubry2012-11-13 09:25:21 (EST)
committerSimon Bernard2012-11-13 09:25:21 (EST)
commitac8cb7ebcdacbf8801e77d045356d3fc3c287514 (patch)
treef27f030b50018f60343057e70f569e1dc0f68654
parent6679634f765ee1699ef990d140e2136c9b8b9b3b (diff)
downloadorg.eclipse.koneki.ldt-ac8cb7ebcdacbf8801e77d045356d3fc3c287514.zip
org.eclipse.koneki.ldt-ac8cb7ebcdacbf8801e77d045356d3fc3c287514.tar.gz
org.eclipse.koneki.ldt-ac8cb7ebcdacbf8801e77d045356d3fc3c287514.tar.bz2
Bug 393126 - Fix autocompletion on template preview background
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaDocumentorTemplateCompletionProcessor.java26
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaTemplateCompletionProcessor.java26
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaTemplateInformationControlCreator.java83
3 files changed, 135 insertions, 0 deletions
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaDocumentorTemplateCompletionProcessor.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaDocumentorTemplateCompletionProcessor.java
index 85f8fb0..38fc89b 100644
--- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaDocumentorTemplateCompletionProcessor.java
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaDocumentorTemplateCompletionProcessor.java
@@ -10,19 +10,27 @@
*******************************************************************************/
package org.eclipse.koneki.ldt.ui.internal.editor.templates;
+import org.eclipse.dltk.core.DLTKLanguageManager;
+import org.eclipse.dltk.core.IDLTKLanguageToolkit;
+import org.eclipse.dltk.internal.ui.editor.ScriptEditor;
+import org.eclipse.dltk.ui.DLTKUIPlugin;
import org.eclipse.dltk.ui.templates.ScriptTemplateAccess;
import org.eclipse.dltk.ui.templates.ScriptTemplateCompletionProcessor;
import org.eclipse.dltk.ui.text.completion.ScriptContentAssistInvocationContext;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.templates.Template;
import org.eclipse.jface.text.templates.TemplateContext;
+import org.eclipse.jface.window.Window;
import org.eclipse.koneki.ldt.ui.internal.Activator;
import org.eclipse.koneki.ldt.ui.internal.ImageConstants;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.part.IWorkbenchPartOrientation;
/**
* LuaDocumentor template completion processor
@@ -83,4 +91,22 @@ public class LuaDocumentorTemplateCompletionProcessor extends ScriptTemplateComp
protected Image getImage(Template template) {
return Activator.getDefault().getImageRegistry().get(ImageConstants.TEMPLATE_LUADOC);
}
+
+ /**
+ * Copy of super method, but returning a custom TemplateInformationControlCreator
+ */
+ @Override
+ protected IInformationControlCreator getInformationControlCreator() {
+ int orientation = Window.getDefaultOrientation();
+ IEditorPart editor = getContext().getEditor();
+ if (editor == null)
+ editor = DLTKUIPlugin.getActivePage().getActiveEditor();
+ if (editor instanceof IWorkbenchPartOrientation)
+ orientation = ((IWorkbenchPartOrientation) editor).getOrientation();
+ IDLTKLanguageToolkit toolkit = null;
+ toolkit = DLTKLanguageManager.getLanguageToolkit(getContext().getLanguageNatureID());
+ if ((toolkit == null) && (editor instanceof ScriptEditor))
+ toolkit = ((ScriptEditor) editor).getLanguageToolkit();
+ return new LuaTemplateInformationControlCreator(orientation, toolkit);
+ }
}
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaTemplateCompletionProcessor.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaTemplateCompletionProcessor.java
index 5b6cf47..5262f57 100644
--- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaTemplateCompletionProcessor.java
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaTemplateCompletionProcessor.java
@@ -10,9 +10,17 @@
*******************************************************************************/
package org.eclipse.koneki.ldt.ui.internal.editor.templates;
+import org.eclipse.dltk.core.DLTKLanguageManager;
+import org.eclipse.dltk.core.IDLTKLanguageToolkit;
+import org.eclipse.dltk.internal.ui.editor.ScriptEditor;
+import org.eclipse.dltk.ui.DLTKUIPlugin;
import org.eclipse.dltk.ui.templates.ScriptTemplateAccess;
import org.eclipse.dltk.ui.templates.ScriptTemplateCompletionProcessor;
import org.eclipse.dltk.ui.text.completion.ScriptContentAssistInvocationContext;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.window.Window;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.part.IWorkbenchPartOrientation;
/**
*
@@ -41,4 +49,22 @@ public class LuaTemplateCompletionProcessor extends ScriptTemplateCompletionProc
return LuaTemplateAccess.getInstance();
}
+ /**
+ * Copy of super method, but returning a custom TemplateInformationControlCreator
+ */
+ @Override
+ protected IInformationControlCreator getInformationControlCreator() {
+ int orientation = Window.getDefaultOrientation();
+ IEditorPart editor = getContext().getEditor();
+ if (editor == null)
+ editor = DLTKUIPlugin.getActivePage().getActiveEditor();
+ if (editor instanceof IWorkbenchPartOrientation)
+ orientation = ((IWorkbenchPartOrientation) editor).getOrientation();
+ IDLTKLanguageToolkit toolkit = null;
+ toolkit = DLTKLanguageManager.getLanguageToolkit(getContext().getLanguageNatureID());
+ if ((toolkit == null) && (editor instanceof ScriptEditor))
+ toolkit = ((ScriptEditor) editor).getLanguageToolkit();
+ return new LuaTemplateInformationControlCreator(orientation, toolkit);
+ }
+
}
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaTemplateInformationControlCreator.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaTemplateInformationControlCreator.java
new file mode 100644
index 0000000..12fc6a5
--- /dev/null
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/templates/LuaTemplateInformationControlCreator.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * 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.templates;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.dltk.core.IDLTKLanguageToolkit;
+import org.eclipse.dltk.internal.ui.text.hover.SourceViewerInformationControl;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.IInformationControlCreatorExtension;
+import org.eclipse.koneki.ldt.ui.internal.LuaDocumentationHelper;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Copy of the final class TemplateInformationControlCreator to custom background color.
+ */
+@SuppressWarnings("restriction")
+public class LuaTemplateInformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension {
+
+ private SourceViewerInformationControl fControl;
+
+ /**
+ * The orientation to be used by this hover. Allowed values are: SWT#RIGHT_TO_LEFT or SWT#LEFT_TO_RIGHT
+ *
+ * @since 3.2
+ */
+ private int fOrientation;
+
+ private IDLTKLanguageToolkit fToolkit;
+
+ /**
+ * @param orientation
+ * the orientation, allowed values are: SWT#RIGHT_TO_LEFT or SWT#LEFT_TO_RIGHT
+ */
+ public LuaTemplateInformationControlCreator(int orientation, IDLTKLanguageToolkit toolkit) {
+ Assert.isLegal(orientation == SWT.RIGHT_TO_LEFT || orientation == SWT.LEFT_TO_RIGHT);
+ fOrientation = orientation;
+ fToolkit = toolkit;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
+ */
+ public IInformationControl createInformationControl(Shell parent) {
+ fControl = new SourceViewerInformationControl(parent, SWT.TOOL | fOrientation, SWT.NONE, fToolkit);
+ fControl.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ fControl = null;
+ }
+ });
+
+ // Set control color
+ fControl.setBackgroundColor(LuaDocumentationHelper.getBackgroundColor());
+ fControl.setForegroundColor(LuaDocumentationHelper.getForegroundColor());
+
+ return fControl;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReuse(org.eclipse.jface.text.IInformationControl)
+ */
+ public boolean canReuse(IInformationControl control) {
+ return fControl == control && fControl != null;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReplace(org.eclipse.jface.text.IInformationControlCreator)
+ */
+ public boolean canReplace(IInformationControlCreator creator) {
+ return (creator != null && getClass() == creator.getClass());
+ }
+}