From 43d2e77123b77be4bde6c1c1dc1f0db5fe686dde Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Wed, 31 Jan 2007 10:07:58 +0000 Subject: [PATCH] Fix for Bug 153816 - Support for multiple build consoles (Patch by Jeff Johnston) --- .../internal/ui/CPluginResources.properties | 3 +- .../ui/buildconsole/BuildConsole.java | 15 ++++--- .../ui/buildconsole/BuildConsoleManager.java | 13 ++++-- .../ui/buildconsole/BuildConsolePage.java | 21 ++++++--- .../buildconsole/ConsoleMessages.properties | 3 +- .../src/org/eclipse/cdt/ui/CUIPlugin.java | 43 +++++++++++++++---- 6 files changed, 71 insertions(+), 27 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties index 278296a4fb7..cda6d0ed827 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2005, 2006 IBM Corporation and others. +# Copyright (c) 2005, 2007 IBM Corporation 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 @@ -160,6 +160,7 @@ CProjectPropertyPage.closedproject=C information is not available for a closed p # ------- Building ------- +BuildConsole.name=C-Build CBuilder.build_error=Could not execute builder "{0}" configured in the project property page. # ------- Properties------- diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsole.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsole.java index b2a99269a46..1a6696e2c32 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsole.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsole.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2006 QNX Software Systems and others. + * Copyright (c) 2002, 2007 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 @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Red Hat Inc. - Multiple build console support *******************************************************************************/ package org.eclipse.cdt.internal.ui.buildconsole; @@ -26,18 +27,22 @@ public class BuildConsole extends AbstractConsole { public static final String P_STREAM_COLOR = CUIPlugin.PLUGIN_ID + ".CONSOLE_P_STREAM_COLOR"; //$NON-NLS-1$ private IBuildConsoleManager fConsoleManager; + private String fConsoleName; + private String fConsoleId; - public BuildConsole(IBuildConsoleManager manager) { - super(ConsoleMessages.getString("BuildConsole.buildConsole"), CPluginImages.DESC_BUILD_CONSOLE); //$NON-NLS-1$ + public BuildConsole(IBuildConsoleManager manager, String name, String id) { + super(name, CPluginImages.DESC_BUILD_CONSOLE); fConsoleManager = manager; + fConsoleName = name; + fConsoleId = id; } public IPageBookViewPage createPage(IConsoleView view) { - return new BuildConsolePage(view, this); + return new BuildConsolePage(view, this, fConsoleId); } public void setTitle(IProject project) { - String title = ConsoleMessages.getString("BuildConsole.buildConsole"); //$NON-NLS-1$ + String title = fConsoleName; if (project != null) { title += " [" + project.getName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleManager.java index bd4edc2ff69..fa4f44dca6f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2006 QNX Software Systems and others. + * Copyright (c) 2002, 2007 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 @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - initial API and implementation + * Red Hat Inc. - multiple build console support *******************************************************************************/ package org.eclipse.cdt.internal.ui.buildconsole; @@ -54,10 +55,14 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang private Map fConsoleMap = new HashMap(); Color infoColor, outputColor, errorColor; BuildConsoleStream infoStream, outputStream, errorStream; + String fName, fContextMenuId; static public final int BUILD_STREAM_TYPE_INFO = 0; static public final int BUILD_STREAM_TYPE_OUTPUT = 1; static public final int BUILD_STREAM_TYPE_ERROR = 2; + + static public final String DEFAULT_CONTEXT_MENU_ID = CUIPlugin.PLUGIN_ID + ".CBuildConole"; //$NON-NLS-1$ + private IProject fLastProject; public BuildConsoleManager() { @@ -170,10 +175,12 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang } } - public void startup() { + public void startup(String name, String id) { infoStream = new BuildConsoleStream(); outputStream = new BuildConsoleStream(); errorStream = new BuildConsoleStream(); + fName = name; + fContextMenuId = id; runUI(new Runnable() { @@ -184,7 +191,7 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang */ public void run() { // install colors - fConsole = new BuildConsole(BuildConsoleManager.this); + fConsole = new BuildConsole(BuildConsoleManager.this, fName, fContextMenuId); ConsolePlugin.getDefault().getConsoleManager().addConsoles(new org.eclipse.ui.console.IConsole[]{fConsole}); infoStream.setConsole(fConsole); infoColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePage.java index b79a53dc8b9..aec0192f03f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2006 QNX Software Systems and others. + * Copyright (c) 2002, 2007 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 @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - initial API and implementation + * Red Hat Inc. - multiple build console support *******************************************************************************/ package org.eclipse.cdt.internal.ui.buildconsole; @@ -17,10 +18,6 @@ import java.util.List; import java.util.Map; import java.util.ResourceBundle; -import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage; -import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.ui.IBuildConsoleEvent; -import org.eclipse.cdt.ui.IBuildConsoleListener; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -75,6 +72,12 @@ import org.eclipse.ui.texteditor.FindReplaceAction; import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.IUpdate; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.IBuildConsoleEvent; +import org.eclipse.cdt.ui.IBuildConsoleListener; + +import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage; + public class BuildConsolePage extends Page implements ISelectionListener, @@ -85,6 +88,7 @@ public class BuildConsolePage extends Page private BuildConsole fConsole; private IConsoleView fConsoleView; + private String fContextMenuId; private BuildConsoleViewer fViewer; private IProject fProject; @@ -109,10 +113,13 @@ public class BuildConsolePage extends Page /** * @param view * @param console + * @param contextId */ - public BuildConsolePage(IConsoleView view, BuildConsole console) { + public BuildConsolePage(IConsoleView view, BuildConsole console, + String contextId) { fConsole = console; fConsoleView = view; + fContextMenuId = contextId; } protected void setProject(IProject project) { @@ -187,7 +194,7 @@ public class BuildConsolePage extends Page fMenu = manager.createContextMenu(getControl()); getControl().setMenu(fMenu); IPageSite site = getSite(); - site.registerContextMenu(CUIPlugin.PLUGIN_ID + ".CBuildConole", manager, getViewer()); //$NON-NLS-1$ + site.registerContextMenu(fContextMenuId, manager, getViewer()); site.setSelectionProvider(getViewer()); createActions(); configureToolBar(site.getActionBars().getToolBarManager()); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleMessages.properties index 6e9c16e7ce9..d8b079fbe43 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2003, 2006 QNX Software Systems and others. +# Copyright (c) 2003, 2007 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 @@ -8,7 +8,6 @@ # Contributors: # QNX Software Systems - Initial API and implementation ############################################################################### -BuildConsole.buildConsole=C-Build find_replace_action.label=&Find/Replace...@Ctrl+F find_replace_action.tooltip=Find/Replace diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java index d160f2d877d..b854289d32a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java @@ -10,14 +10,17 @@ * IBM Corp. - Rational Software * Markus Schorn (Wind River Systems) * Anton Leherbauer (Wind River Systems) + * Jeff Johnston (Red Hat Inc.) *******************************************************************************/ package org.eclipse.cdt.ui; import java.io.IOException; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Set; @@ -330,7 +333,7 @@ public class CUIPlugin extends AbstractUIPlugin { private CTextTools fTextTools; private AsmTextTools fAsmTextTools; private ProblemMarkerManager fProblemMarkerManager; - private BuildConsoleManager fBuildConsoleManager; + private Map fBuildConsoleManagers; private ResourceAdapterFactory fResourceAdapterFactory; private CElementAdapterFactory fCElementAdapterFactory; @@ -356,7 +359,8 @@ public class CUIPlugin extends AbstractUIPlugin { public CUIPlugin() { fgCPlugin = this; fDocumentProvider = null; - fTextTools = null; + fTextTools = null; + fBuildConsoleManagers = new HashMap(); } /** @@ -408,12 +412,28 @@ public class CUIPlugin extends AbstractUIPlugin { return fAsmTextTools; } + /** + * Return the default console manager. + * @return IBuildConsoleManager + */ public IBuildConsoleManager getConsoleManager() { - if ( fBuildConsoleManager == null ) { - fBuildConsoleManager = new BuildConsoleManager(); - fBuildConsoleManager.startup(); + return getConsoleManager(getResourceString("BuildConsole.name"), BuildConsoleManager.DEFAULT_CONTEXT_MENU_ID); //$NON-NLS-1$ + } + + /** + * Return a console manager specified by id. + * @param name console name + * @param id console id + * @return IBuildConsoleManager + */ + public IBuildConsoleManager getConsoleManager(String name, String id) { + BuildConsoleManager manager = (BuildConsoleManager)fBuildConsoleManagers.get(id); + if (manager == null ) { + manager = new BuildConsoleManager(); + fBuildConsoleManagers.put(id, manager); + manager.startup(name, id); } - return fBuildConsoleManager; + return manager; } /* (non-Javadoc) @@ -453,9 +473,14 @@ public class CUIPlugin extends AbstractUIPlugin { fImageDescriptorRegistry.dispose(); fImageDescriptorRegistry= null; } - if ( fBuildConsoleManager != null ) { - fBuildConsoleManager.shutdown(); - fBuildConsoleManager = null; + if (fBuildConsoleManagers != null ) { + Object[] bcm = fBuildConsoleManagers.values().toArray(); + for (int i = 0; i < bcm.length; ++i) { + BuildConsoleManager m = (BuildConsoleManager)bcm[i]; + if (m != null) + m.shutdown(); + } + fBuildConsoleManagers.clear(); } unregisterAdapters();