1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00
David Inglis 2004-06-03 15:52:16 +00:00
parent 017af57db2
commit 2989ee4537
6 changed files with 55 additions and 46 deletions

View file

@ -11,15 +11,18 @@ package org.eclipse.cdt.internal.ui.buildconsole;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage; import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IBuildConsole;
import org.eclipse.cdt.ui.IBuildConsoleListener; import org.eclipse.cdt.ui.IBuildConsoleListener;
import org.eclipse.cdt.ui.IBuildConsoleManager; import org.eclipse.cdt.ui.IBuildConsoleManager;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.text.Assert; import org.eclipse.jface.text.Assert;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
@ -45,8 +48,12 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
BuildConsole fConsole; BuildConsole fConsole;
private Map fConsoleMap = new HashMap(); private Map fConsoleMap = new HashMap();
private Color infoColor, outputColor, errorColor; private Color infoColor, outputColor, errorColor;
public BuildConsoleStream infoStream, outputStream, errorStream; private BuildConsoleStream infoStream, outputStream, errorStream;
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;
public BuildConsoleManager() { public BuildConsoleManager() {
} }
@ -161,11 +168,9 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
} }
public void startup() { public void startup() {
fConsole = new BuildConsole(this); infoStream = new BuildConsoleStream();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new org.eclipse.ui.console.IConsole[]{fConsole}); outputStream = new BuildConsoleStream();
infoStream = new BuildConsoleStream(fConsole); errorStream = new BuildConsoleStream();
outputStream = new BuildConsoleStream(fConsole);
errorStream = new BuildConsoleStream(fConsole);
runUI(new Runnable() { runUI(new Runnable() {
@ -176,10 +181,15 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
*/ */
public void run() { public void run() {
// install colors // install colors
fConsole = new BuildConsole(BuildConsoleManager.this);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new org.eclipse.ui.console.IConsole[]{fConsole});
infoStream.setConsole(fConsole);
infoColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR); infoColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR);
infoStream.setColor(infoColor); infoStream.setColor(infoColor);
outputStream.setConsole(fConsole);
outputColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR); outputColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR);
outputStream.setColor(outputColor); outputStream.setColor(outputColor);
errorStream.setConsole(fConsole);
errorColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR); errorColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR);
errorStream.setColor(errorColor); errorStream.setColor(errorColor);
} }
@ -213,6 +223,18 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
errorColor = newColor; errorColor = newColor;
} }
} }
public BuildConsoleStream getStream(int type) throws CoreException {
switch(type) {
case BUILD_STREAM_TYPE_ERROR:
return errorStream;
case BUILD_STREAM_TYPE_INFO:
return infoStream;
case BUILD_STREAM_TYPE_OUTPUT:
return outputStream;
}
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, -1, "No Such Console", null)); //$NON-NLS-1$
}
/** /**
* Returns a color instance based on data from a preference field. * Returns a color instance based on data from a preference field.
@ -225,7 +247,7 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
* Returns the console for the project, or <code>null</code> if none. * Returns the console for the project, or <code>null</code> if none.
*/ */
public IBuildConsole getConsole(IProject project) { public IConsole getConsole(IProject project) {
Assert.isNotNull(project); Assert.isNotNull(project);
return getConsolePartioner(project).getConsole(); return getConsolePartioner(project).getConsole();
} }

View file

@ -14,10 +14,11 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.ConsoleOutputStream; import org.eclipse.cdt.core.ConsoleOutputStream;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage; import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IBuildConsole;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
@ -34,7 +35,7 @@ public class BuildConsolePartitioner
implements implements
IDocumentPartitioner, IDocumentPartitioner,
IDocumentPartitionerExtension, IDocumentPartitionerExtension,
IBuildConsole, IConsole,
IPropertyChangeListener { IPropertyChangeListener {
/** /**
@ -271,7 +272,7 @@ public class BuildConsolePartitioner
return partition; return partition;
} }
public IBuildConsole getConsole() { public IConsole getConsole() {
return this; return this;
} }
@ -311,16 +312,16 @@ public class BuildConsolePartitioner
} }
} }
public ConsoleOutputStream getOutputStream() { public ConsoleOutputStream getOutputStream() throws CoreException {
return new BuildOutputStream(fManager.outputStream); return new BuildOutputStream(fManager.getStream(BuildConsoleManager.BUILD_STREAM_TYPE_OUTPUT));
} }
public ConsoleOutputStream getInfoStream() { public ConsoleOutputStream getInfoStream() throws CoreException {
return new BuildOutputStream(fManager.infoStream); return new BuildOutputStream(fManager.getStream(BuildConsoleManager.BUILD_STREAM_TYPE_INFO));
} }
public ConsoleOutputStream getErrorStream() { public ConsoleOutputStream getErrorStream() throws CoreException {
return new BuildOutputStream(fManager.errorStream); return new BuildOutputStream(fManager.getStream(BuildConsoleManager.BUILD_STREAM_TYPE_INFO));
} }
} }

View file

@ -21,12 +21,14 @@ public class BuildConsoleStream {
/** /**
* Constructs a new stream connected to the given console. * Constructs a new stream connected to the given console.
* *
* @param console the console to write messages to
*/ */
public BuildConsoleStream(BuildConsole console) { public BuildConsoleStream() {
}
public void setConsole(BuildConsole console) {
fConsole = console; fConsole = console;
} }
/** /**
* Sets the color of this message stream * Sets the color of this message stream
* *
@ -35,7 +37,9 @@ public class BuildConsoleStream {
public void setColor(Color color) { public void setColor(Color color) {
Color old = fColor; Color old = fColor;
fColor = color; fColor = color;
fConsole.firePropertyChange(this, BuildConsole.P_STREAM_COLOR, old, color); if (fConsole != null) {
fConsole.firePropertyChange(this, BuildConsole.P_STREAM_COLOR, old, color);
}
} }
/** /**

View file

@ -15,6 +15,7 @@ import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IBuildConsoleManager; import org.eclipse.cdt.ui.IBuildConsoleManager;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
public class CBuildConsole implements IConsole { public class CBuildConsole implements IConsole {
IProject project; IProject project;
@ -33,17 +34,18 @@ public class CBuildConsole implements IConsole {
} }
/** /**
* @throws CoreException
* @see org.eclipse.cdt.core.resources.IConsole#getOutputStream() * @see org.eclipse.cdt.core.resources.IConsole#getOutputStream()
*/ */
public ConsoleOutputStream getOutputStream() { public ConsoleOutputStream getOutputStream() throws CoreException {
return fConsoleManager.getConsole(project).getOutputStream(); return fConsoleManager.getConsole(project).getOutputStream();
} }
public ConsoleOutputStream getInfoStream() { public ConsoleOutputStream getInfoStream() throws CoreException {
return fConsoleManager.getConsole(project).getInfoStream(); return fConsoleManager.getConsole(project).getInfoStream();
} }
public ConsoleOutputStream getErrorStream() { public ConsoleOutputStream getErrorStream() throws CoreException {
return fConsoleManager.getConsole(project).getErrorStream(); return fConsoleManager.getConsole(project).getErrorStream();
} }
} }

View file

@ -1,21 +0,0 @@
/**********************************************************************
* Copyright (c) 2002,2003,2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.ui;
import org.eclipse.cdt.core.ConsoleOutputStream;
import org.eclipse.core.resources.IProject;
public interface IBuildConsole {
void start(IProject project);
ConsoleOutputStream getOutputStream();
ConsoleOutputStream getInfoStream();
ConsoleOutputStream getErrorStream();
}

View file

@ -10,11 +10,12 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.ui; package org.eclipse.cdt.ui;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
public interface IBuildConsoleManager { public interface IBuildConsoleManager {
IBuildConsole getConsole(IProject project); IConsole getConsole(IProject project);
IDocument getConsoleDocument(IProject project); IDocument getConsoleDocument(IProject project);
void addConsoleListener(IBuildConsoleListener listener); void addConsoleListener(IBuildConsoleListener listener);
void removeConsoleListener(IBuildConsoleListener listener); void removeConsoleListener(IBuildConsoleListener listener);