From 5ff7d8b5e96af86e695bc90b27914e684e56cc96 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Thu, 14 Nov 2002 15:20:07 +0000 Subject: [PATCH] convertSelectionToProject() new methiod. Only reset document if Project change. --- .../ui/buildconsole/BuildConsoleView.java | 87 ++++++++++--------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleView.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleView.java index 237de30e1f7..22a4bd3a473 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleView.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleView.java @@ -126,33 +126,14 @@ public class BuildConsoleView extends ViewPart implements ISelectionListener, IB fConsoleManager.addConsoleListener(this); } - protected IProject setProject(ISelection selection) { - if ( selection == null ) { - return null; - } - try { - IStructuredSelection ssel = (IStructuredSelection) selection; - IAdaptable input = (IAdaptable) ssel.getFirstElement(); - if (input != null) { - IResource resource = null; - if (input instanceof IResource) { - resource = (IResource) input; - } - else { - resource = (IResource) input.getAdapter(IResource.class); - } - if (resource != null) { - selProject = resource.getProject(); - return selProject; - } - } - } - catch (ClassCastException e) { - } - selProject = null; - return selProject; + protected void setProject(ISelection selection) { + selProject = convertSelectionToProject(selection); } - + + protected void setProject(IProject project) { + selProject = project; + } + protected IProject getProject() { return selProject; } @@ -240,16 +221,6 @@ public class BuildConsoleView extends ViewPart implements ISelectionListener, IB actionBars.getToolBarManager().add(fClearOutputAction); actionBars.updateActionBars(); } - - /** - * Clears the console - */ - void clear() { - if (selProject != null) { - fConsoleManager.getConsole(selProject).clear(); - } - } - /** * Reveals (makes visible) the end of the current document */ @@ -282,9 +253,14 @@ public class BuildConsoleView extends ViewPart implements ISelectionListener, IB } public void selectionChanged(IWorkbenchPart part, ISelection selection) { - setProject(selection); - setDocument(); - setTitle(); + IProject newProject = convertSelectionToProject(selection); + IProject oldProject = getProject(); + if (oldProject == null || + (newProject != null && !newProject.equals(oldProject))) { + setProject(newProject); + setDocument(); + setTitle(); + } } public void consoleChange(IBuildConsoleEvent event) { @@ -300,4 +276,37 @@ public class BuildConsoleView extends ViewPart implements ISelectionListener, IB } } + IProject convertSelectionToProject(ISelection selection) { + IProject project = null; + if ( selection == null ) { + return project; + } + try { + IStructuredSelection ssel = (IStructuredSelection) selection; + IAdaptable input = (IAdaptable) ssel.getFirstElement(); + if (input != null) { + IResource resource = null; + if (input instanceof IResource) { + resource = (IResource) input; + } else { + resource = (IResource) input.getAdapter(IResource.class); + } + if (resource != null) { + project = resource.getProject(); + } + } + } catch (ClassCastException e) { + } + return project; + } + + /** + * Clears the console + */ + void clear() { + if (selProject != null) { + fConsoleManager.getConsole(selProject).clear(); + } + } + }