mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 14:15:23 +02:00
Adopt ITextHoverExtension2
This commit is contained in:
parent
e8c27d5cae
commit
01a5281372
8 changed files with 135 additions and 48 deletions
|
@ -1,13 +1,14 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2002, 2008 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* IBM Corporation
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* IBM Corporation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.text.c.hover;
|
||||
|
@ -17,6 +18,7 @@ import org.eclipse.jface.text.IInformationControl;
|
|||
import org.eclipse.jface.text.IInformationControlCreator;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITextHoverExtension;
|
||||
import org.eclipse.jface.text.ITextHoverExtension2;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.swt.SWT;
|
||||
|
@ -31,12 +33,11 @@ import org.eclipse.cdt.internal.ui.text.CWordFinder;
|
|||
import org.eclipse.cdt.internal.ui.text.HTMLTextPresenter;
|
||||
|
||||
/**
|
||||
* AbstractCEditorTextHover Abstract class for providing hover information for C
|
||||
* Abstract class for providing hover information for C
|
||||
* elements.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractCEditorTextHover implements ICEditorTextHover,
|
||||
ITextHoverExtension {
|
||||
public abstract class AbstractCEditorTextHover implements ICEditorTextHover, ITextHoverExtension, ITextHoverExtension2 {
|
||||
|
||||
private IEditorPart fEditor;
|
||||
|
||||
|
@ -77,6 +78,13 @@ public abstract class AbstractCEditorTextHover implements ICEditorTextHover,
|
|||
*/
|
||||
public abstract String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion);
|
||||
|
||||
/*
|
||||
* @see ITextHoverExtension2#getHoverInfo2(ITextViewer, IRegion)
|
||||
*/
|
||||
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
|
||||
return getHoverInfo(textViewer, hoverRegion);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ITextHoverExtension#getHoverControlCreator()
|
||||
* @since 3.0
|
||||
|
@ -90,7 +98,20 @@ public abstract class AbstractCEditorTextHover implements ICEditorTextHover,
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.ITextHoverExtension2#getInformationPresenterControlCreator()
|
||||
* @since 5.0
|
||||
*/
|
||||
public IInformationControlCreator getInformationPresenterControlCreator() {
|
||||
return new IInformationControlCreator() {
|
||||
public IInformationControl createInformationControl(Shell shell) {
|
||||
int style= SWT.V_SCROLL | SWT.H_SCROLL;
|
||||
return new DefaultInformationControl(shell, SWT.RESIZE | SWT.TOOL, style, new HTMLTextPresenter(false));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tool tip affordance string.
|
||||
*
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2002, 2008 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.text.c.hover;
|
||||
|
@ -22,6 +23,7 @@ import org.eclipse.jface.text.IInformationControlCreator;
|
|||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITextHover;
|
||||
import org.eclipse.jface.text.ITextHoverExtension;
|
||||
import org.eclipse.jface.text.ITextHoverExtension2;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.information.IInformationProviderExtension2;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
|
@ -29,7 +31,7 @@ import org.eclipse.ui.IEditorPart;
|
|||
/**
|
||||
* BestMatchHover
|
||||
*/
|
||||
public class BestMatchHover extends AbstractCEditorTextHover implements ITextHoverExtension, IInformationProviderExtension2 {
|
||||
public class BestMatchHover extends AbstractCEditorTextHover {
|
||||
|
||||
private List fTextHoverSpecifications;
|
||||
private List fInstantiatedTextHovers;
|
||||
|
@ -107,6 +109,38 @@ public class BestMatchHover extends AbstractCEditorTextHover implements ITextHov
|
|||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.ITextHoverExtension2#getHoverInfo2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
|
||||
*/
|
||||
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
|
||||
|
||||
checkTextHovers();
|
||||
fBestHover= null;
|
||||
|
||||
if (fInstantiatedTextHovers == null)
|
||||
return null;
|
||||
|
||||
for (Iterator iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) {
|
||||
ITextHover hover= (ITextHover)iterator.next();
|
||||
|
||||
if (hover instanceof ITextHoverExtension2) {
|
||||
Object info= ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion);
|
||||
if (info != null) {
|
||||
fBestHover= hover;
|
||||
return info;
|
||||
}
|
||||
} else {
|
||||
String s= hover.getHoverInfo(textViewer, hoverRegion);
|
||||
if (s != null && s.trim().length() > 0) {
|
||||
fBestHover= hover;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
|
||||
* @since 3.0
|
||||
|
@ -123,6 +157,8 @@ public class BestMatchHover extends AbstractCEditorTextHover implements ITextHov
|
|||
* @since 3.0
|
||||
*/
|
||||
public IInformationControlCreator getInformationPresenterControlCreator() {
|
||||
if (fBestHover instanceof ITextHoverExtension2)
|
||||
return ((ITextHoverExtension2)fBestHover).getInformationPresenterControlCreator();
|
||||
if (fBestHover instanceof IInformationProviderExtension2)
|
||||
return ((IInformationProviderExtension2)fBestHover).getInformationPresenterControlCreator();
|
||||
|
||||
|
|
|
@ -1,28 +1,31 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2002, 2008 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.text.c.hover;
|
||||
|
||||
import org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover;
|
||||
import org.eclipse.jface.text.IInformationControlCreator;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITextHoverExtension;
|
||||
import org.eclipse.jface.text.ITextHoverExtension2;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.information.IInformationProviderExtension2;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
|
||||
import org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover;
|
||||
|
||||
/**
|
||||
* CEditorTexHoverProxy
|
||||
*/
|
||||
public class CEditorTextHoverProxy extends AbstractCEditorTextHover implements ITextHoverExtension, IInformationProviderExtension2 {
|
||||
public class CEditorTextHoverProxy extends AbstractCEditorTextHover {
|
||||
|
||||
private CEditorTextHoverDescriptor fHoverDescriptor;
|
||||
private ICEditorTextHover fHover;
|
||||
|
@ -66,6 +69,22 @@ public class CEditorTextHoverProxy extends AbstractCEditorTextHover implements I
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.ITextHoverExtension2#getHoverInfo2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
|
||||
* @since 5.0
|
||||
*/
|
||||
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
|
||||
if (ensureHoverCreated()) {
|
||||
if (fHover instanceof ITextHoverExtension2)
|
||||
return ((ITextHoverExtension2) fHover).getHoverInfo2(textViewer, hoverRegion);
|
||||
else
|
||||
return fHover.getHoverInfo(textViewer, hoverRegion);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean ensureHoverCreated() {
|
||||
if (!isEnabled() || fHoverDescriptor == null)
|
||||
return false;
|
||||
|
@ -98,9 +117,12 @@ public class CEditorTextHoverProxy extends AbstractCEditorTextHover implements I
|
|||
* @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
|
||||
*/
|
||||
public IInformationControlCreator getInformationPresenterControlCreator() {
|
||||
if (ensureHoverCreated() && (fHover instanceof IInformationProviderExtension2))
|
||||
return ((IInformationProviderExtension2)fHover).getInformationPresenterControlCreator();
|
||||
|
||||
if (ensureHoverCreated()) {
|
||||
if (fHover instanceof ITextHoverExtension2)
|
||||
return ((ITextHoverExtension2) fHover).getInformationPresenterControlCreator();
|
||||
if (fHover instanceof IInformationProviderExtension2) // this is wrong, but left here for backwards compatibility
|
||||
return ((IInformationProviderExtension2) fHover).getInformationPresenterControlCreator();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,12 +11,12 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text.c.hover;
|
||||
|
||||
|
||||
import org.eclipse.jface.text.AbstractReusableInformationControlCreator;
|
||||
import org.eclipse.jface.text.DefaultInformationControl;
|
||||
import org.eclipse.jface.text.IInformationControl;
|
||||
import org.eclipse.jface.text.IInformationControlCreator;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITextHoverExtension2;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.information.IInformationProvider;
|
||||
import org.eclipse.jface.text.information.IInformationProviderExtension2;
|
||||
|
@ -40,7 +40,6 @@ import org.eclipse.cdt.internal.ui.text.HTMLTextPresenter;
|
|||
*/
|
||||
public class CInformationProvider implements IInformationProvider, IInformationProviderExtension2 {
|
||||
|
||||
|
||||
/**
|
||||
* Default control creator.
|
||||
*/
|
||||
|
@ -124,8 +123,8 @@ public class CInformationProvider implements IInformationProvider, IInformationP
|
|||
* @see IInformationProviderExtension2#getInformationPresenterControlCreator()
|
||||
*/
|
||||
public IInformationControlCreator getInformationPresenterControlCreator() {
|
||||
if (fImplementation instanceof IInformationProviderExtension2) {
|
||||
IInformationProviderExtension2 ext2= (IInformationProviderExtension2) fImplementation;
|
||||
if (fImplementation instanceof ITextHoverExtension2) {
|
||||
ITextHoverExtension2 ext2= (ITextHoverExtension2) fImplementation;
|
||||
return ext2.getInformationPresenterControlCreator();
|
||||
}
|
||||
if (fPresenterControlCreator == null)
|
||||
|
|
|
@ -52,4 +52,15 @@ public class CMacroExpansionControl extends AbstractSourceViewerInformationContr
|
|||
return "org.eclipse.cdt.ui.text.hover.CMacroExpansion"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.AbstractSourceViewerInformationControl#setInput(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void setInput(Object input) {
|
||||
if (input instanceof CMacroExpansionInput) {
|
||||
setInformation(((CMacroExpansionInput) input).fExplorer.getFullExpansion().getCodeAfterStep());
|
||||
} else {
|
||||
super.setInput(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
package org.eclipse.cdt.internal.ui.text.c.hover;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.SoftReference;
|
||||
|
||||
import org.eclipse.jface.text.IInformationControl;
|
||||
import org.eclipse.jface.text.IInformationControlCreator;
|
||||
|
@ -20,7 +19,6 @@ import org.eclipse.jface.text.IRegion;
|
|||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.jface.text.information.IInformationProviderExtension2;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||
import org.eclipse.swt.SWT;
|
||||
|
@ -32,25 +30,21 @@ import org.eclipse.ui.IEditorPart;
|
|||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public class CMacroExpansionHover extends AbstractCEditorTextHover implements IInformationProviderExtension2 {
|
||||
public class CMacroExpansionHover extends AbstractCEditorTextHover {
|
||||
|
||||
private Reference fCache;
|
||||
private Reference<CMacroExpansionInput> fCache;
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.c.hover.AbstractCEditorTextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
|
||||
*/
|
||||
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
|
||||
Object hoverInfo= getHoverInfo2(textViewer, hoverRegion);
|
||||
return hoverInfo != null ? hoverInfo.toString() : null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.c.hover.AbstractCEditorTextHover#getHoverInfo2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
|
||||
*/
|
||||
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
|
||||
CMacroExpansionInput input= CMacroExpansionInput.create(getEditor(), hoverRegion, false);
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
fCache= new SoftReference(input);
|
||||
String result= input.fExplorer.getFullExpansion().getCodeAfterStep();
|
||||
if (result.length() == 0) {
|
||||
// expansion is empty - hover should show empty string
|
||||
result= "/* EMPTY */"; //$NON-NLS-1$
|
||||
}
|
||||
return result;
|
||||
return input;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -65,7 +59,7 @@ public class CMacroExpansionHover extends AbstractCEditorTextHover implements II
|
|||
}
|
||||
|
||||
/*
|
||||
* @see IInformationProviderExtension2#getInformationPresenterControlCreator()
|
||||
* @see org.eclipse.cdt.internal.ui.text.c.hover.AbstractCEditorTextHover#getInformationPresenterControlCreator()
|
||||
*/
|
||||
public IInformationControlCreator getInformationPresenterControlCreator() {
|
||||
return new IInformationControlCreator() {
|
||||
|
@ -81,7 +75,7 @@ public class CMacroExpansionHover extends AbstractCEditorTextHover implements II
|
|||
if (fCache == null) {
|
||||
return null;
|
||||
}
|
||||
CMacroExpansionInput input= (CMacroExpansionInput) fCache.get();
|
||||
CMacroExpansionInput input= fCache.get();
|
||||
fCache= null;
|
||||
if (input == null) {
|
||||
IEditorPart editor= getEditor();
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
@ -222,13 +223,19 @@ public class CMacroExpansionInput {
|
|||
}
|
||||
}
|
||||
|
||||
MacroExpansionExplorer fExplorer;
|
||||
final MacroExpansionExplorer fExplorer;
|
||||
boolean fStartWithFullExpansion= true;
|
||||
|
||||
private CMacroExpansionInput() {
|
||||
// forbidden
|
||||
private CMacroExpansionInput(MacroExpansionExplorer explorer) {
|
||||
Assert.isNotNull(explorer);
|
||||
fExplorer= explorer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return fExplorer.getFullExpansion().getCodeAfterStep();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an input object for the macro expansion exploration control {@link CMacroExpansionExplorationControl}.
|
||||
*
|
||||
|
@ -256,8 +263,7 @@ public class CMacroExpansionInput {
|
|||
return null;
|
||||
}
|
||||
|
||||
CMacroExpansionInput input= new CMacroExpansionInput();
|
||||
input.fExplorer= explorer;
|
||||
CMacroExpansionInput input= new CMacroExpansionInput(explorer);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
|
|
@ -35,12 +35,10 @@ import org.eclipse.jface.text.IDocument;
|
|||
import org.eclipse.jface.text.IInformationControl;
|
||||
import org.eclipse.jface.text.IInformationControlCreator;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITextHoverExtension;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.ITypedRegion;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.jface.text.TextUtilities;
|
||||
import org.eclipse.jface.text.information.IInformationProviderExtension2;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
|
@ -99,7 +97,7 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
|||
/**
|
||||
* A text hover presenting the source of the element under the cursor.
|
||||
*/
|
||||
public class CSourceHover extends AbstractCEditorTextHover implements ITextHoverExtension, IInformationProviderExtension2 {
|
||||
public class CSourceHover extends AbstractCEditorTextHover {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue