1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +02:00

Fix for 185221 by Ed Swartz, show errors when open call|type hierarchy fails.

This commit is contained in:
Markus Schorn 2007-05-04 06:08:11 +00:00
parent 60ba6f2213
commit 39e4ee536e
8 changed files with 98 additions and 42 deletions

View file

@ -16,6 +16,7 @@ import org.eclipse.osgi.util.NLS;
public class CHMessages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.callhierarchy.CHMessages"; //$NON-NLS-1$
public static String CallHierarchyUI_label;
public static String CallHierarchyUI_openFailureMessage;
public static String CallHierarchyUI_selectMessage;
public static String CHHistoryListAction_HistoryDialog_title;
public static String CHHistoryListAction_HistoryList_label;

View file

@ -44,6 +44,7 @@ OpenCallHierarchyAction_label=Open Call H&ierarchy
OpenCallHierarchyAction_tooltip=Open Call Hierarchy
CallHierarchyUI_label=Open Call Hierarchy
CallHierarchyUI_selectMessage=Select one element from the list
CallHierarchyUI_openFailureMessage=Cannot resolve selected text to a defined function or member
OpenElementInCallHierarchyAction_errorDlgTitle=Open Element in Call Hierarchy
OpenElementInCallHierarchyAction_title=Open Element in Call Hierarchy
OpenElementInCallHierarchyAction_upperListLabel=&Matching Elements:

View file

@ -20,6 +20,7 @@ import org.eclipse.jface.text.ITextSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.texteditor.ITextEditor;
@ -40,6 +41,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.actions.OpenActionUtil;
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
import org.eclipse.cdt.internal.ui.util.StatusLineHandler;
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
public class CallHierarchyUI {
@ -68,7 +70,9 @@ public class CallHierarchyUI {
return null;
}
private static CHViewPart openInViewPart(IWorkbenchWindow window, ICElement[] input) {
private static CHViewPart openInViewPart(IWorkbenchSite site, ICElement[] input) {
IWorkbenchWindow window = site.getWorkbenchWindow();
StatusLineHandler.clearStatusLine(site);
ICElement elem = null;
switch (input.length) {
case 0:
@ -87,6 +91,9 @@ public class CallHierarchyUI {
}
if (elem != null) {
return openInViewPart(window, elem);
} else {
StatusLineHandler.showStatusLineMessage(site,
CHMessages.CallHierarchyUI_openFailureMessage);
}
return null;
}
@ -102,12 +109,16 @@ public class CallHierarchyUI {
Job job= new Job(CHMessages.CallHierarchyUI_label) {
protected IStatus run(IProgressMonitor monitor) {
try {
StatusLineHandler.clearStatusLine(editor.getSite());
final ICElement[] elems= findDefinitions(project, editorInput, sel);
if (elems != null && elems.length > 0) {
display.asyncExec(new Runnable() {
public void run() {
openInViewPart(editor.getSite().getWorkbenchWindow(), elems);
openInViewPart(editor.getSite(), elems);
}});
} else {
StatusLineHandler.showStatusLineMessage(editor.getSite(),
CHMessages.CallHierarchyUI_openFailureMessage);
}
return Status.OK_STATUS;
}

View file

@ -19,15 +19,12 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
@ -35,11 +32,11 @@ import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.internal.ui.util.StatusLineHandler;
/**
* @author aniefer
@ -74,44 +71,10 @@ public class SelectionParseAction extends Action {
}
protected void showStatusLineMessage(final String message) {
// run the code to update the status line on the Display thread
// this way any other thread can invoke operationNotAvailable(String)
CUIPlugin.getStandardDisplay().asyncExec(new Runnable(){
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
IStatusLineManager statusManager = null;
if (fSite instanceof IViewSite){
statusManager = ((IViewSite) fSite).getActionBars().getStatusLineManager();
}
else if (fSite instanceof IEditorSite){
statusManager = ((IEditorSite) fSite).getActionBars().getStatusLineManager();
}
if( statusManager != null )
statusManager.setErrorMessage(message);
}
});
StatusLineHandler.showStatusLineMessage(fSite, message);
}
protected void clearStatusLine() {
// run the code to update the status line on the Display thread
// this way any other thread can invoke clearStatusLine()
CUIPlugin.getStandardDisplay().asyncExec(new Runnable(){
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
IStatusLineManager statusManager = null;
if (fSite instanceof IViewSite){
statusManager = ((IViewSite) fSite).getActionBars().getStatusLineManager();
}
else if (fSite instanceof IEditorSite){
statusManager = ((IEditorSite) fSite).getActionBars().getStatusLineManager();
}
if( statusManager != null )
statusManager.setErrorMessage( "" ); //$NON-NLS-1$
}
});
StatusLineHandler.clearStatusLine(fSite);
}
//TODO: Change this to work with qualified identifiers

View file

@ -63,6 +63,7 @@ public class Messages extends NLS {
public static String THViewPart_SupertypeHierarchy;
public static String THViewPart_SupertypeHierarchy_tooltip;
public static String THViewPart_VerticalOrientation;
public static String TypeHierarchyUI_OpenFailure_message;
public static String TypeHierarchyUI_OpenTypeHierarchy;
public static String TypeHierarchyUI_SelectFromList;
static {

View file

@ -49,6 +49,7 @@ import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
import org.eclipse.cdt.internal.ui.util.StatusLineHandler;
import org.eclipse.cdt.internal.ui.viewsupport.FindNameForSelectionVisitor;
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
@ -115,6 +116,7 @@ public class TypeHierarchyUI {
Job job= new Job(Messages.TypeHierarchyUI_OpenTypeHierarchy) {
protected IStatus run(IProgressMonitor monitor) {
try {
StatusLineHandler.clearStatusLine(editor.getSite());
IRegion reg= new Region(sel.getOffset(), sel.getLength());
final ICElement[] elems= findInput(project, editorInput, reg);
if (elems != null && elems.length == 2) {
@ -122,6 +124,9 @@ public class TypeHierarchyUI {
public void run() {
openInViewPart(editor.getSite().getWorkbenchWindow(), elems[0], elems[1]);
}});
} else {
StatusLineHandler.showStatusLineMessage(editor.getSite(),
Messages.TypeHierarchyUI_OpenFailure_message);
}
return Status.OK_STATUS;
}

View file

@ -48,6 +48,7 @@ THViewPart_LayoutMenu=Layout
THViewPart_FocusOn=Focus On ''{0}''
THViewPart_Cancel=Cancel
TypeHierarchyUI_OpenTypeHierarchy=Open Type Hierarchy
TypeHierarchyUI_OpenFailure_message=Cannot resolve selected text to a defined type
TypeHierarchyUI_SelectFromList=Select one element from the list
OpenTypeHierarchyAction_label=Open Type Hierarchy
OpenTypeHierarchyAction_tooltip=Open Type Hierarchy

View file

@ -0,0 +1,73 @@
/*******************************************************************************
* Copyright (c) 2004, 2006 IBM Corporation and others.
* Copyright (c) 2007 Nokia, Inc.
* 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:
* IBM Corp. - Rational Software - initial implementation
* Markus Schorn (Wind River Systems)
* Ed Swartz (Nokia)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.util;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.cdt.ui.CUIPlugin;
/**
* Utilities for clearing and setting status line. Client should
* invoke {@link #clearStatusLine(IWorkbenchSite)} before an operation
* and invoke {@link #showStatusLineMessage(IWorkbenchSite, String)} on
* error.
* @author eswartz
*
*/
public abstract class StatusLineHandler {
public static void showStatusLineMessage(final IWorkbenchSite site, final String message) {
// run the code to update the status line on the Display thread
// this way any other thread can invoke operationNotAvailable(String)
CUIPlugin.getStandardDisplay().asyncExec(new Runnable(){
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
IStatusLineManager statusManager = null;
if (site instanceof IViewSite){
statusManager = ((IViewSite) site).getActionBars().getStatusLineManager();
}
else if (site instanceof IEditorSite){
statusManager = ((IEditorSite) site).getActionBars().getStatusLineManager();
}
if( statusManager != null )
statusManager.setErrorMessage(message);
}
});
}
public static void clearStatusLine(final IWorkbenchSite site) {
// run the code to update the status line on the Display thread
// this way any other thread can invoke clearStatusLine()
CUIPlugin.getStandardDisplay().asyncExec(new Runnable(){
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
IStatusLineManager statusManager = null;
if (site instanceof IViewSite){
statusManager = ((IViewSite) site).getActionBars().getStatusLineManager();
}
else if (site instanceof IEditorSite){
statusManager = ((IEditorSite) site).getActionBars().getStatusLineManager();
}
if( statusManager != null )
statusManager.setErrorMessage( "" ); //$NON-NLS-1$
}
});
}
}