cdt/cdt_6_0_x/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/editors/AbstractDebugTextHover.java
author dadubrow
Tue, 10 Nov 2009 09:58:50 -0600
changeset 111 c2563c416525
parent 110 9262ca4bdfff
permissions -rw-r--r--
merge debug text hover support with CDT
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     1
/*******************************************************************************
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     2
 * Copyright (c) 2000, 2007 QNX Software Systems and others.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     3
 * All rights reserved. This program and the accompanying materials
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     4
 * are made available under the terms of the Eclipse Public License v1.0
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     5
 * which accompanies this distribution, and is available at
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     6
 * http://www.eclipse.org/legal/epl-v10.html
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     7
 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     8
 * Contributors:
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     9
 *     QNX Software Systems - Initial API and implementation
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    10
 *     Nokia - Refactored from DebugTextHover to remove CDI dependency
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    11
 *     
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    12
 *******************************************************************************/
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    13
package org.eclipse.cdt.debug.ui.editors;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    14
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    15
import java.util.regex.Matcher;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    16
import java.util.regex.Pattern;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    17
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    18
import org.eclipse.cdt.debug.internal.ui.CDebugUIUtils;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    19
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    20
import org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover;
111
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
    21
import org.eclipse.core.runtime.IAdaptable;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    22
import org.eclipse.debug.core.DebugException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    23
import org.eclipse.debug.ui.IDebugUIConstants;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    24
import org.eclipse.jface.text.BadLocationException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    25
import org.eclipse.jface.text.IDocument;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    26
import org.eclipse.jface.text.IInformationControlCreator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    27
import org.eclipse.jface.text.IRegion;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    28
import org.eclipse.jface.text.ITextHoverExtension;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    29
import org.eclipse.jface.text.ITextViewer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    30
import org.eclipse.jface.viewers.ISelection;
111
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
    31
import org.eclipse.jface.viewers.IStructuredSelection;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    32
import org.eclipse.ui.IEditorPart;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    33
import org.eclipse.ui.IPartListener;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    34
import org.eclipse.ui.ISelectionListener;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    35
import org.eclipse.ui.IWorkbenchPage;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    36
import org.eclipse.ui.IWorkbenchPart;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    38
/* The class LanguageOperators protects some language specific
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    39
 * operator information used by the DebugTextHover class.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    40
 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    41
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    42
class LanguageOperators {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    43
	public String getAssignmentOperator() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    44
		return "="; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    45
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    46
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    47
	public String getGreaterThanEqualToOperator() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    48
		return ">="; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    49
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    50
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    51
	public String getEqualToOperator() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    52
		return "=="; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    53
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    54
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    55
	public String getNotEqualToOperator() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    56
		return "!="; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    57
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    58
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    59
	public String getLessThenEqualToOperator() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    60
		return "<="; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    61
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    62
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    63
	public String getValueChangeOperatorsRegex() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    64
		return "(\\+\\+)|(\\-\\-)|(\\+\\=)|" //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    65
				+ "(\\-\\=)|(\\*\\=)|(/\\=)|(\\&\\=)" //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    66
				+ "(\\%\\=)|(\\^\\=)|(\\|\\=)|(\\<\\<\\=)|(\\>\\>\\=)"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    67
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    68
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    69
	public String getEqualToOperatorsRegex() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    70
		return "\\=\\=|\\<\\=|\\>\\=|!\\="; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    71
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    72
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    73
	public String getIdentifierRegex() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    74
		return "[_A-Za-z][_A-Za-z0-9]*"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    75
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    76
}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    77
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    78
/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    79
 * The text hovering support for C/C++ debugger.
111
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
    80
 * 
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
    81
 * @since 6.1
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    82
 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    83
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    84
public abstract class AbstractDebugTextHover implements ICEditorTextHover, ITextHoverExtension,
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    85
		ISelectionListener, IPartListener {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    86
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    87
	static final private int MAX_HOVER_INFO_SIZE = 100;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    88
111
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
    89
	private ISelection fSelection = null;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    90
111
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
    91
	private IEditorPart fEditor;
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    92
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    93
	protected abstract boolean canEvaluate();
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    94
	
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    95
	protected abstract String evaluateExpression(String expression);
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    96
	
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    97
	public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
    98
		if (canEvaluate()) {
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    99
			try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   100
				IDocument document = textViewer.getDocument();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   101
				if (document == null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   102
					return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   103
				String expression = document.get(hoverRegion.getOffset(),
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   104
						hoverRegion.getLength());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   105
				if (expression == null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   106
					return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   107
				expression = expression.trim();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   108
				if (expression.length() == 0)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   109
					return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   110
				LanguageOperators operatorsObj = new LanguageOperators();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   111
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   112
				Pattern pattern = Pattern.compile(operatorsObj
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   113
						.getValueChangeOperatorsRegex());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   114
				Matcher matcher = pattern.matcher(expression);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   115
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   116
				boolean match_found = matcher.find();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   117
				// Get matching string
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   118
				// If the expression has some operators which can change the
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   119
				// value of a variable, that expresssion should not be
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   120
				// evaluated.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   121
				if (match_found) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   122
					return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   123
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   124
				pattern = Pattern.compile(operatorsObj
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   125
						.getEqualToOperatorsRegex());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   126
				String[] tokens = pattern.split(expression);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   127
				for (int i = 0; i < tokens.length; i++) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   128
					//If the expression contains assignment operator that
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   129
					// can change the value of a variable, the expression
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   130
					// should not be evaluated.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   131
					if (tokens[i].indexOf(operatorsObj
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   132
							.getAssignmentOperator()) != -1)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   133
						return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   134
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   135
				//Supressing function calls from evaluation.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   136
				String functionCallRegex = operatorsObj.getIdentifierRegex() + "\\s*\\("; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   137
				pattern = Pattern.compile(functionCallRegex);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   138
				matcher = pattern.matcher(expression);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   139
				match_found = matcher.find();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   140
				if (match_found) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   141
					return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   142
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   143
				StringBuffer buffer = new StringBuffer();
110
9262ca4bdfff Bug 10071 - add support for debug hovers to DSF
dadubrow
parents: 37
diff changeset
   144
				String result = evaluateExpression(expression);
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   145
				if (result == null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   146
					return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   147
				try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   148
					appendVariable(buffer, makeHTMLSafe(expression), makeHTMLSafe(result.trim()));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   149
				} catch (DebugException x) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   150
					CDebugUIPlugin.log(x);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   151
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   152
				if (buffer.length() > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   153
					return buffer.toString();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   154
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   155
			} catch (BadLocationException x) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   156
				CDebugUIPlugin.log(x);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   157
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   158
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   159
		return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   160
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   161
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   162
	public IRegion getHoverRegion(ITextViewer viewer, int offset) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   163
		/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   164
		 * Point selectedRange = viewer.getSelectedRange(); if ( selectedRange.x >= 0 && selectedRange.y > 0 && offset >= selectedRange.x && offset <=
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   165
		 * selectedRange.x + selectedRange.y ) return new Region( selectedRange.x, selectedRange.y );
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   166
		 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   167
		if (viewer != null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   168
			return CDebugUIUtils.findWord(viewer.getDocument(), offset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   169
		return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   170
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   171
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   172
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   173
	 * Append HTML for the given variable to the given buffer
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   174
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   175
	private static void appendVariable(StringBuffer buffer, String expression, String value) throws DebugException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   176
		if (value.length() > MAX_HOVER_INFO_SIZE)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   177
			value = value.substring(0, MAX_HOVER_INFO_SIZE) + " ..."; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   178
		buffer.append("<p>"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   179
		buffer.append("<pre>").append(expression).append("</pre>"); //$NON-NLS-1$ //$NON-NLS-2$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   180
		buffer.append(" = "); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   181
		buffer.append("<b><pre>").append(value).append("</pre></b>"); //$NON-NLS-1$ //$NON-NLS-2$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   182
		buffer.append("</p>"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   183
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   184
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   185
	public void setEditor(IEditorPart editor) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   186
		if (editor != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   187
			fEditor = editor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   188
			final IWorkbenchPage page = editor.getSite().getPage();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   189
			page.addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   190
			page.addPartListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   191
			// initialize selection
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   192
			Runnable r = new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   193
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   194
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   195
					fSelection = page
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   196
							.getSelection(IDebugUIConstants.ID_DEBUG_VIEW);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   197
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   198
			};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   199
			CDebugUIPlugin.getStandardDisplay().asyncExec(r);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   200
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   201
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   202
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   203
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   204
		fSelection = selection;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   205
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   206
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   207
	public void partActivated(IWorkbenchPart part) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   208
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   209
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   210
	public void partBroughtToTop(IWorkbenchPart part) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   211
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   212
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   213
	public void partClosed(IWorkbenchPart part) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   214
		if (part.equals(fEditor)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   215
			IWorkbenchPage page = fEditor.getSite().getPage();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   216
			page.removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   217
			page.removePartListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   218
			fSelection = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   219
			fEditor = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   220
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   221
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   222
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   223
	public void partDeactivated(IWorkbenchPart part) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   224
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   225
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   226
	public void partOpened(IWorkbenchPart part) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   227
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   228
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   229
	public IInformationControlCreator getHoverControlCreator() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   230
		return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   231
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   232
111
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   233
	protected ISelection getSelection() {
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   234
	    return fSelection;
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   235
	}
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   236
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   237
	protected IAdaptable getSelectionAdaptable() {
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   238
        if (fSelection instanceof IStructuredSelection) {
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   239
            IStructuredSelection selection = (IStructuredSelection) fSelection;
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   240
            if (selection.size() == 1) {
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   241
                Object element = selection.getFirstElement();
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   242
                if (element instanceof IAdaptable) {
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   243
                    return (IAdaptable) element;
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   244
                }
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   245
            }
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   246
        }
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   247
        return null;
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   248
    }
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   249
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   250
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   251
	protected IEditorPart getEditor() {
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   252
	    return fEditor;
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   253
	}
c2563c416525 merge debug text hover support with CDT
dadubrow
parents: 110
diff changeset
   254
	
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   255
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   256
	 * Replace any characters in the given String that would confuse an HTML parser with their escape sequences.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   257
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   258
	private static String makeHTMLSafe(String string) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   259
		StringBuffer buffer = new StringBuffer(string.length());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   260
		for (int i = 0; i != string.length(); i++) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   261
			char ch = string.charAt(i);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   262
			switch (ch) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   263
			case '&':
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   264
				buffer.append("&amp;"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   265
				break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   266
			case '<':
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   267
				buffer.append("&lt;"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   268
				break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   269
			case '>':
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   270
				buffer.append("&gt;"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   271
				break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   272
			default:
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   273
				buffer.append(ch);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   274
				break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   275
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   276
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   277
		return buffer.toString();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   278
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   279
}