diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 6de89752acd..7381cdfdbe1 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,44 @@ +2004-03-12 David Inglis + + Implemented new build console using the Eclipse 3 generic console, supporting multiple + streams with colorizing. + + * plugin.properties + * plugin.xml + + moved to src/org/eclipse/cdt/internal/ui/buildconsole + + * src/org/eclipse/cdt/internal/ui/BuildConsole.java + * src/org/eclipse/cdt/internal/ui/BuildConsoleManager.java + + removed + * src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleAction.java + * src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleView.java + * src/org/eclipse/cdt/internal/ui/buildconsole/ClearConsoleAction.java + + modified + * src/org/eclipse/cdt/internal/ui/CPluginImages.java + * src/org/eclipse/cdt/internal/ui/CPluginResources.properties + * src/org/eclipse/cdt/internal/ui/preferences/BuildConsolePreferencePage.java + * src/org/eclipse/cdt/ui/CUIPlugin.java + * src/org/eclipse/cdt/ui/IBuildConsoleManager.java + + new + * src/org/eclipse/cdt/ui/IBuildConsole.java + * src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsole.java + * src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleDocument.java + * src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleManager.java + * src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePage.java + * src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartition.java + * src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartitioner.java + * src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleStream.java + * src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleViewer.java + * src/org/eclipse/cdt/internal/ui/buildconsole/CBuildConsole.java + * src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleMessages.java + * src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleMessages.properties + * src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleOutputTextStore.java + * src/org/eclipse/cdt/internal/ui/buildconsole/ScrollLockAction.java + 2004-03-11 Hoda Amer Added the undo manager for the renaming refactor. diff --git a/core/org.eclipse.cdt.ui/icons/full/clcl16/lock_co.gif b/core/org.eclipse.cdt.ui/icons/full/clcl16/lock_co.gif new file mode 100644 index 00000000000..d47ecfd8b6c Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/full/clcl16/lock_co.gif differ diff --git a/core/org.eclipse.cdt.ui/icons/full/dlcl16/lock_co.gif b/core/org.eclipse.cdt.ui/icons/full/dlcl16/lock_co.gif new file mode 100644 index 00000000000..c67c0d87e12 Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/full/dlcl16/lock_co.gif differ diff --git a/core/org.eclipse.cdt.ui/icons/full/elcl16/lock_co.gif b/core/org.eclipse.cdt.ui/icons/full/elcl16/lock_co.gif new file mode 100644 index 00000000000..be3943a46c5 Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/full/elcl16/lock_co.gif differ diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 7f1020f8105..e9fe7303cc1 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -9,7 +9,6 @@ completionContributorName=Completion Contribution nature.name=C Nature perspective.name=C/C++ Development viewsCategory.name=&C -BuildConsoleView.name=C-Build CView.name=C/C++ Projects # The Wizards @@ -112,3 +111,6 @@ ActionDefinition.openType.name= Open Type ActionDefinition.openType.description= Open a type in a C editor CElementWorkingSetPage.name = C/C++ + +BuildConsoleFontDefinition.description= The C-Build console font is used by the C-Build console +BuildConsoleFontDefinition.label= C-Build Console Text Font diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 864644fec2d..4a013da6c40 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -20,14 +20,14 @@ - - + + @@ -123,13 +123,6 @@ name="%viewsCategory.name" id="org.eclipse.cdt.ui.views"> - - + class="org.eclipse.cdt.internal.ui.buildconsole.CBuildConsole"> - + + + + %BuildConsoleFontDefinition.description + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BuildConsole.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BuildConsole.java deleted file mode 100644 index c6e24b5865e..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BuildConsole.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * (c) Copyright QNX Software System Ltd. 2002. - * All Rights Reserved. - */ -package org.eclipse.cdt.internal.ui; - -import org.eclipse.cdt.core.ConsoleOutputStream; -import org.eclipse.cdt.core.resources.IConsole; -import org.eclipse.cdt.ui.*; -import org.eclipse.core.resources.IProject; - -public class BuildConsole implements IConsole { - IProject project; - IBuildConsoleManager fConsoleManager; - - /** - * Constructor for BuildConsole. - */ - public BuildConsole() { - fConsoleManager = CUIPlugin.getDefault().getConsoleManager(); - } - - public void start(IProject project ) { - this.project = project; - fConsoleManager.getConsole(project).start(project); - } - - /** - * @see org.eclipse.cdt.core.resources.IConsole#clear() - */ - public void clear() { - fConsoleManager.getConsole(project).clear(); - } - - /** - * @see org.eclipse.cdt.core.resources.IConsole#getOutputStream() - */ - public ConsoleOutputStream getOutputStream() { - return fConsoleManager.getConsole(project).getOutputStream(); - } -} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BuildConsoleManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BuildConsoleManager.java deleted file mode 100644 index cd88e5dc7cd..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BuildConsoleManager.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * (c) Copyright QNX Software System Ltd. 2002. - * All Rights Reserved. - */ -package org.eclipse.cdt.internal.ui; - -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; - -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.ui.CUIPlugin; -import org.eclipse.cdt.ui.IBuildConsoleListener; -import org.eclipse.cdt.ui.IBuildConsoleManager; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.ListenerList; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; - -public class BuildConsoleManager implements IBuildConsoleManager, IResourceChangeListener, IPropertyChangeListener { - private HashMap fConsoleDocumentMap; - ListenerList listeners = new ListenerList(1); - - private class BuildConsoleDocument extends Document { - - private int fMaxLines; - - public BuildConsoleDocument(int nLines) { - super(); - fMaxLines = nLines; - } - - public void setDocumentSize(int nLines) { - fMaxLines = nLines; - nLines = getNumberOfLines(); - if (nLines > fMaxLines) { - try { - int start = getLineOffset(nLines - fMaxLines); - String part = get(start, getLength() - start); - set(part); - } catch (BadLocationException e) { - } - } - } - - public BuildConsoleDocument(String initialContent) { - super(initialContent); - } - - public void replace(int offset, int length, String text) throws BadLocationException { - super.replace(offset, length, text); - int nLines = getNumberOfLines(); - if (nLines > fMaxLines) { - int start = getLineOffset(nLines - fMaxLines); - String part = get(start, getLength() - start); - set(part); - } - } - } - - private class BuildConsole extends ConsoleOutputStream implements IConsole { - protected BuildConsoleDocument fDocument; - - public BuildConsole() { - fDocument = new BuildConsoleDocument(BuildConsolePreferencePage.buildConsoleLines()); - } - - public void setConsoleSize(int nLines) { - fDocument.setDocumentSize(nLines); - } - - public void start(IProject project) { - if (BuildConsolePreferencePage.isClearBuildConsole()) { - clear(); - } - Object[] list = listeners.getListeners(); - if (list.length > 0) { - for (int i = 0; i < list.length; i++) { - IBuildConsoleListener listener = (IBuildConsoleListener) list[i]; - ConsoleEvent event = new ConsoleEvent(BuildConsoleManager.this, project, ConsoleEvent.CONSOLE_START); - listener.consoleChange(event); - } - } - } - - public void clear() { - super.clear(); - Display.getDefault().syncExec(new Runnable() { - public void run() { - fDocument.set(""); //$NON-NLS-1$ - } - }); - } - - public ConsoleOutputStream getOutputStream() { - return this; - } - - public IDocument getDocument() { - return fDocument; - } - - public void flush() throws IOException { - Display.getDefault().syncExec(new Runnable() { - public void run() { - bringConsoleOnTop(); - try { - int len = fDocument.getLength(); - fDocument.replace(len, 0, readBuffer()); - } catch (BadLocationException x) { - } - } - }); - } - - void bringConsoleOnTop() { - IWorkbenchWindow window = CUIPlugin.getDefault().getActiveWorkbenchWindow(); - if (window == null) - return; - IWorkbenchPage page = window.getActivePage(); - if (page != null) { - try { - // show the build console - IViewPart cBuild = page.findView(CUIPlugin.CONSOLE_ID); - if (cBuild == null) { - if (BuildConsolePreferencePage.isAutoOpenConsole()) { - IWorkbenchPart activePart = page.getActivePart(); - cBuild = page.showView(CUIPlugin.CONSOLE_ID); - //restore focus - page.activate(activePart); - } - } - if (cBuild != null && BuildConsolePreferencePage.isConsoleOnTop()) { - page.bringToTop(cBuild); - } - } catch (PartInitException pie) { - } - } - } - - public void close() throws IOException { - flush(); - } - - } - - public BuildConsoleManager() { - fConsoleDocumentMap = new HashMap(); - } - - /** - * Traverses the delta looking for added/removed/changed launch - * configuration files. - * - * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent) - */ - public void resourceChanged(IResourceChangeEvent event) { - if (fConsoleDocumentMap == null) { - return; - } - IResource resource = event.getResource(); - if (resource != null && resource.getType() == IResource.PROJECT) { - if (event.getType() == IResourceChangeEvent.PRE_DELETE || event.getType() == IResourceChangeEvent.PRE_CLOSE) { - fConsoleDocumentMap.remove(resource); - Object[] list = listeners.getListeners(); - if (list.length > 0) { - for (int i = 0; i < list.length; i++) { - IBuildConsoleListener listener = (IBuildConsoleListener) list[i]; - ConsoleEvent consoleEvent = new ConsoleEvent(this, (IProject) resource, ConsoleEvent.CONSOLE_CLOSE); - listener.consoleChange(consoleEvent); - } - } - } - } - } - - public void shutdown() { - CUIPlugin.getWorkspace().removeResourceChangeListener(this); - CUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); - } - - public void startup() { - CUIPlugin.getWorkspace().addResourceChangeListener(this); - CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); - } - - private BuildConsole getBuildConsole(IProject project) { - BuildConsole console = (BuildConsole) fConsoleDocumentMap.get(project); - if (console == null) { - console = new BuildConsole(); - fConsoleDocumentMap.put(project, console); - } - return console; - } - - public IConsole getConsole(IProject project) { - return getBuildConsole(project); - } - - public IDocument getConsoleDocument(IProject project) { - return getBuildConsole(project).getDocument(); - } - - public void addConsoleListener(IBuildConsoleListener listener) { - listeners.add(listener); - } - - public void removeConsoleListener(IBuildConsoleListener listener) { - listeners.remove(listener); - } - - public void propertyChange(PropertyChangeEvent event) { - if (event.getProperty() == BuildConsolePreferencePage.PREF_BUILDCONSOLE_LINES) { - Collection consoles = fConsoleDocumentMap.values(); - Iterator iter = consoles.iterator(); - while (iter.hasNext()) { - BuildConsole console = (BuildConsole) iter.next(); - console.setConsoleSize(BuildConsolePreferencePage.buildConsoleLines()); - } - } - } - -} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java index 942b38adab8..03d430f573d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java @@ -24,6 +24,7 @@ public class CPluginImages { // Subdirectory (under the package containing this class) where 16 color images are private static URL fgIconBaseURL; + static { try { fgIconBaseURL= new URL(CUIPlugin.getDefault().getDescriptor().getInstallURL(), "icons/" ); //$NON-NLS-1$ @@ -39,7 +40,7 @@ public class CPluginImages { public static final String T_WIZBAN= T + "wizban/"; //$NON-NLS-1$ public static final String T_LCL= "lcl16/"; //$NON-NLS-1$ public static final String T_TOOL= "tool16/"; //$NON-NLS-1$ - public static final String T_VIEW= "view16/"; //$NON-NLS-1$ + public static final String T_VIEW= T + "cview16/"; //$NON-NLS-1$ public static final String T_OVR= T + "ovr16/"; //$NON-NLS-1$ public static final String IMG_OBJS_TEMPLATE= NAME_PREFIX + "template_obj.gif"; //$NON-NLS-1$ @@ -81,6 +82,10 @@ public class CPluginImages { public static final String IMG_OBJS_BREAKPOINT_DISABLED = NAME_PREFIX + "breakpoint_disabled.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_BREAKPOINT_ACTIVE = NAME_PREFIX + "breakpoint_active.gif"; //$NON-NLS-1$ + // build console + public static final String IMG_VIEW_BUILD = NAME_PREFIX + "buildconsole.gif"; //$NON-NLS-1$ + public static final ImageDescriptor DESC_BUILD_CONSOLE = createManaged(T_VIEW, IMG_VIEW_BUILD); + public static final ImageDescriptor DESC_OBJS_VARIABLE= createManaged(T_OBJ, IMG_OBJS_VARIABLE); public static final ImageDescriptor DESC_OBJS_LOCAL_VARIABLE= createManaged(T_OBJ, IMG_OBJS_LOCAL_VARIABLE); public static final ImageDescriptor DESC_OBJS_CLASS= createManaged(T_OBJ, IMG_OBJS_CLASS); @@ -125,6 +130,7 @@ public class CPluginImages { public static final String IMG_MENU_CODE_ASSIST= NAME_PREFIX + "metharg_obj.gif"; //$NON-NLS-1$ public static final String IMG_MENU_COLLAPSE_ALL= NAME_PREFIX + "collapseall.gif"; //$NON-NLS-1$ public static final String IMG_CLEAR_CONSOLE= NAME_PREFIX + "clear_co.gif"; //$NON-NLS-1$ + public static final String IMG_SCROLL_LOCK= NAME_PREFIX + "lock_co.gif"; //$NON-NLS-1$ public static final String IMG_ALPHA_SORTING= NAME_PREFIX + "alphab_sort_co.gif"; //$NON-NLS-1$ public static final String IMG_TOOL_GOTO_PREV_ERROR= NAME_PREFIX + "prev_error_nav.gif"; //$NON-NLS-1$ public static final String IMG_TOOL_GOTO_NEXT_ERROR= NAME_PREFIX + "next_error_nav.gif"; //$NON-NLS-1$ 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 02e22e4484a..de07d5f1028 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 @@ -8,19 +8,23 @@ CView.make_edit_action =Project properties # ------- Preference Page ------- -#CBasePreferencePage.description=The build command is an executable program which will be used by the builder\nto build your C project. If the build command is not on the current system\nenvironment path, you have to enter an absolute path name.\nThe command given here will be filled in new C projects by default.\nTo change the builder for a specific project, use the project's property page. -CBasePreferencePage.description=The build command is an executable program which will be used by the builder\nto build your C/C++ project. If the build command is not on the current system\nenvironment path, you have to enter an absolute path name.\nThe command given here will be filled in new C/C++ projects by default. -CBasePreferencePage.buildLocation.label=Default build command: -CBasePreferencePage.clearConsole.label=Always clear C-Build view before building -CBasePreferencePage.autoOpenConsole.label=Open C-Build view when building -CBasePreferencePage.consoleOnTop.label=Bring C-Build view to top when building (if present) -CBasePreferencePage.buildConsole.errorMessage=Value must be an integer between 10 and 2147483647 +ConsolePreferencePage.clearConsole.label=Always clear console before building +ConsolePreferencePage.autoOpenConsole.label=Open console when building +ConsolePreferencePage.consoleOnTop.label=Bring console to top when building (if present) +ConsolePreferencePage.consoleLines.label=Limit console ouput (# lines): +ConsolePreferencePage.consoleLines.errorMessage=Value must be an integer between 10 and 2147483647 +ConsolePreferencePage.tabWidth.label=Display tab with: +ConsolePreferencePage.tabWidth.errorMessage=Value must be an integer between 1 and 100 +ConsolePreferencePage.colorSettings.label=Console text color settings +ConsolePreferencePage.outputColor.label=Output text color +ConsolePreferencePage.infoColor.label=Information message text color +ConsolePreferencePage.errorColor.label=Error message text color + CBasePreferencePage.linkToEditor.label=Link view selection to active editor CBasePreferencePage.CUChildren.label=Show file members in Project View CBasePreferencePage.OutlineView.structuralParseMode.label=Use Structural-Parse mode to build the CModel CBasePreferencePage.editorFont.label=C Editor font: -CBasePreferencePage.consoleFont.label=C-Build view font: CBasePreferencePage.bracketHighlightBox.label=Highlight matching brackets with box CBasePreferencePage.bracketHighlightClr.label=Highlight matching brackets with color 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 new file mode 100644 index 00000000000..7aa7f81a05c --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsole.java @@ -0,0 +1,49 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IProject; +import org.eclipse.ui.console.AbstractConsole; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.part.IPageBookViewPage; + +public class BuildConsole extends AbstractConsole { + + /** + * Property constant indicating the color of a stream has changed. + */ + public static final String P_STREAM_COLOR = CUIPlugin.PLUGIN_ID + ".CONSOLE_P_STREAM_COLOR"; //$NON-NLS-1$ + + private BuildConsoleManager fConsoleManager; + + public BuildConsole(BuildConsoleManager manager) { + super(ConsoleMessages.getString("BuildConsole.buildConsole"), CPluginImages.DESC_BUILD_CONSOLE); //$NON-NLS-1$ + fConsoleManager = manager; + } + + public IPageBookViewPage createPage(IConsoleView view) { + return new BuildConsolePage(view, this); + } + + public void setTitle(IProject project) { + String title = ConsoleMessages.getString("BuildConsole.buildConsole"); //$NON-NLS-1$ + if (project != null) { + title += " [" + project.getName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } + setName(title); + } + + public BuildConsoleManager getConsoleManager() { + return fConsoleManager; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleAction.java deleted file mode 100644 index fa792acda60..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleAction.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.eclipse.cdt.internal.ui.buildconsole; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import java.util.ResourceBundle; - - -import org.eclipse.jface.text.ITextOperationTarget; -import org.eclipse.jface.text.TextViewer; - - -import org.eclipse.ui.texteditor.TextEditorAction; - - -public class BuildConsoleAction extends TextEditorAction { - - - private int fOperationCode= -1; - private ITextOperationTarget fOperationTarget; - - - public BuildConsoleAction(ResourceBundle bundle, String prefix, TextViewer viewer, int operationCode) { - super(bundle, prefix, null); - fOperationCode= operationCode; - fOperationTarget= viewer.getTextOperationTarget(); - update(); - } - /** - * @see Action - */ - public void run() { - if (fOperationCode != -1 && fOperationTarget != null) { - fOperationTarget.doOperation(fOperationCode); - } - } - /** - * @see TextEditorAction - */ - public void update() { - - boolean wasEnabled= isEnabled(); - boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); - - if (wasEnabled != isEnabled) { - setEnabled(isEnabled); - } - } -} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleDocument.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleDocument.java new file mode 100644 index 00000000000..ea5792a6c8d --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleDocument.java @@ -0,0 +1,23 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import org.eclipse.jface.text.DefaultLineTracker; +import org.eclipse.jface.text.Document; + +public class BuildConsoleDocument extends Document { + + public BuildConsoleDocument() { + setTextStore(new ConsoleOutputTextStore(2500)); + setLineTracker(new DefaultLineTracker()); + completeInitialization(); + } +} 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 new file mode 100644 index 00000000000..449c2e07f98 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleManager.java @@ -0,0 +1,236 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.cdt.internal.ui.ConsoleEvent; +import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.IBuildConsole; +import org.eclipse.cdt.ui.IBuildConsoleListener; +import org.eclipse.cdt.ui.IBuildConsoleManager; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.text.Assert; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.ListenerList; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleView; + +public class BuildConsoleManager implements IBuildConsoleManager, IResourceChangeListener, IPropertyChangeListener { + + ListenerList listeners = new ListenerList(1); + BuildConsole fConsole; + private Map fConsoleMap = new HashMap(); + private Color infoColor, outputColor, errorColor; + public BuildConsoleStream infoStream, outputStream, errorStream; + + public BuildConsoleManager() { + } + + /** + * Notifies the console manager that console activity has started on the project + * The manager will open the console if the preference is set to show the console, and notify listeners + */ + protected void startConsoleActivity(IProject project) { + Object[] list = listeners.getListeners(); + if (list.length > 0) { + for (int i = 0; i < list.length; i++) { + IBuildConsoleListener listener = (IBuildConsoleListener) list[i]; + ConsoleEvent event = new ConsoleEvent(BuildConsoleManager.this, project, ConsoleEvent.CONSOLE_START); + listener.consoleChange(event); + } + } + showConsole(); + } + + /** + * Opens the console view. If the view is already open, it is brought to + * the front. + */ + protected void showConsole() { + CUIPlugin.getStandardDisplay().asyncExec(new Runnable() { + + public void run() { + IWorkbenchWindow window = CUIPlugin.getDefault().getActiveWorkbenchWindow(); + if (window != null) { + IWorkbenchPage page = window.getActivePage(); + if (page != null) { + IViewPart consoleView = page.findView(IConsoleConstants.ID_CONSOLE_VIEW); + if (consoleView == null && BuildConsolePreferencePage.isAutoOpenConsole()) { + IWorkbenchPart activePart = page.getActivePart(); + try { + consoleView = page.showView(IConsoleConstants.ID_CONSOLE_VIEW); + } catch (PartInitException pie) { + CUIPlugin.getDefault().log(pie); + } + //restore focus stolen by the creation of the + // console + page.activate(activePart); + } else { + boolean bringToTop = shouldBringToTop(consoleView); + if (bringToTop) { + page.bringToTop(consoleView); + } + } + if (consoleView instanceof IConsoleView) { + ((IConsoleView) consoleView).display(fConsole); + } + } + } + } + }); + } + + boolean shouldBringToTop(IViewPart consoleView) { + boolean bringToTop = false; + if (consoleView instanceof IConsoleView) { + IConsoleView cView = (IConsoleView) consoleView; + return !cView.isPinned() && BuildConsolePreferencePage.isConsoleOnTop(); + } + return bringToTop; + } + + /** + * Traverses the delta looking for added/removed/changed launch + * configuration files. + * + * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent) + */ + public void resourceChanged(IResourceChangeEvent event) { + IResource resource = event.getResource(); + if (resource != null && resource.getType() == IResource.PROJECT) { + if (event.getType() == IResourceChangeEvent.PRE_DELETE || event.getType() == IResourceChangeEvent.PRE_CLOSE) { + IDocumentPartitioner partioner = (IDocumentPartitioner) fConsoleMap.remove(resource); + partioner.disconnect(); + Object[] list = listeners.getListeners(); + if (list.length > 0) { + for (int i = 0; i < list.length; i++) { + IBuildConsoleListener listener = (IBuildConsoleListener) list[i]; + ConsoleEvent consoleEvent = new ConsoleEvent(this, (IProject) resource, ConsoleEvent.CONSOLE_CLOSE); + listener.consoleChange(consoleEvent); + } + } + } + } + } + + public void shutdown() { + infoColor.dispose(); + outputColor.dispose(); + errorColor.dispose(); + ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new org.eclipse.ui.console.IConsole[]{fConsole}); + CUIPlugin.getWorkspace().removeResourceChangeListener(this); + CUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); + } + + public void startup() { + fConsole = new BuildConsole(this); + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new org.eclipse.ui.console.IConsole[]{fConsole}); + + // install colors + infoColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR); + infoStream = new BuildConsoleStream(fConsole); + infoStream.setColor(infoColor); + outputColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR); + outputStream = new BuildConsoleStream(fConsole); + outputStream.setColor(outputColor); + errorColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR); + errorStream = new BuildConsoleStream(fConsole); + errorStream.setColor(errorColor); + + CUIPlugin.getWorkspace().addResourceChangeListener(this); + CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent event) { + String property = event.getProperty(); + // colors + if(property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR)) { + Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_INFO_COLOR); + infoStream.setColor(newColor); + infoColor.dispose(); + infoColor = newColor; + } else if(property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR)) { + Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_OUTPUT_COLOR); + outputStream.setColor(newColor); + outputColor.dispose(); + outputColor = newColor; + } else if(property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR)) { + Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_ERROR_COLOR); + errorStream.setColor(newColor); + errorColor.dispose(); + errorColor = newColor; + } + } + + /** + * Returns a color instance based on data from a preference field. + */ + private Color createColor(Display display, String preference) { + RGB rgb = PreferenceConverter.getColor(CUIPlugin.getDefault().getPreferenceStore(), preference); + return new Color(display, rgb); + } + /** + * Returns the console for the project, or null if none. + */ + + public IBuildConsole getConsole(IProject project) { + Assert.isNotNull(project); + return getConsolePartioner(project).getConsole(); + } + + private BuildConsolePartitioner getConsolePartioner(IProject project) { + BuildConsolePartitioner partioner = (BuildConsolePartitioner) fConsoleMap.get(project); + if ( partioner == null) { + partioner = new BuildConsolePartitioner(this); + fConsoleMap.put(project, partioner); + } + return partioner; + } + + /** + * Returns the document for the projects console, or null if none. + */ + public IDocument getConsoleDocument(IProject project) { + Assert.isNotNull(project); + return getConsolePartioner(project).getDocument(); + } + + public void addConsoleListener(IBuildConsoleListener listener) { + listeners.add(listener); + } + + public void removeConsoleListener(IBuildConsoleListener listener) { + listeners.remove(listener); + } + +} 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 new file mode 100644 index 00000000000..957bad6d733 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePage.java @@ -0,0 +1,399 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +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.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextOperationTarget; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.console.actions.ClearOutputAction; +import org.eclipse.ui.console.actions.TextViewerAction; +import org.eclipse.ui.console.actions.TextViewerGotoLineAction; +import org.eclipse.ui.part.IPageSite; +import org.eclipse.ui.part.Page; +import org.eclipse.ui.texteditor.FindReplaceAction; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.ui.texteditor.IUpdate; + +public class BuildConsolePage extends Page implements ISelectionListener, IPropertyChangeListener, IBuildConsoleListener { + + private BuildConsole fConsole; + private IConsoleView fConsoleView; + private BuildConsoleViewer fViewer; + private IProject fProject; + + // text selection listener + private ISelectionChangedListener fTextListener = new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + updateSelectionDependentActions(); + } + }; + + // actions + private ClearOutputAction fClearOutputAction; + private Map fGlobalActions = new HashMap(10); + private List fSelectionActions = new ArrayList(3); + + // menus + private Menu fMenu; + private ScrollLockAction fScrollLockAction; + private boolean fIsLocked; + + /** + * @param view + * @param console + */ + public BuildConsolePage(IConsoleView view, BuildConsole console) { + fConsole = console; + fConsoleView = view; + } + + protected void setProject(IProject project) { + fProject = project; + } + + protected IProject getProject() { + return fProject; + } + + protected BuildConsole getConsole() { + return fConsole; + } + + protected IDocument setDocument() { + IProject project = getProject(); + if (project != null) { + getViewer().setDocument(getConsole().getConsoleManager().getConsoleDocument(project)); + } + return null; + } + + public void consoleChange(IBuildConsoleEvent event) { + if (event.getType() == IBuildConsoleEvent.CONSOLE_START || event.getType() == IBuildConsoleEvent.CONSOLE_CLOSE) { + if (isAvailable()) { + Display display = getControl().getDisplay(); + if (event.getType() == IBuildConsoleEvent.CONSOLE_CLOSE && getProject() != event.getProject()) { + return; + } + setProject(event.getProject()); + display.asyncExec(new Runnable() { + + public void run() { + if (isAvailable()) { + setDocument(); + getConsole().setTitle(getProject()); + } + } + }); + } + } + } + + boolean isAvailable() { + return getControl() != null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + fViewer = new BuildConsoleViewer(parent); + + MenuManager manager = new MenuManager("#MessageConsole", "#MessageConsole"); //$NON-NLS-1$ //$NON-NLS-2$ + manager.setRemoveAllWhenShown(true); + manager.addMenuListener(new IMenuListener() { + + public void menuAboutToShow(IMenuManager m) { + contextMenuAboutToShow(m); + } + }); + fMenu = manager.createContextMenu(getControl()); + getControl().setMenu(fMenu); + IPageSite site = getSite(); + site.registerContextMenu(CUIPlugin.PLUGIN_ID + ".CBuildConole", manager, getViewer()); //$NON-NLS-1$ + site.setSelectionProvider(getViewer()); + createActions(); + configureToolBar(site.getActionBars().getToolBarManager()); + fViewer.getSelectionProvider().addSelectionChangedListener(fTextListener); + + JFaceResources.getFontRegistry().addListener(this); + setFont(JFaceResources.getFont(BuildConsolePreferencePage.PREF_BUILDCONSOLE_FONT)); + setTabs(CUIPlugin.getDefault().getPluginPreferences().getInt(BuildConsolePreferencePage.PREF_BUILDCONSOLE_TAB_WIDTH)); + + getConsole().addPropertyChangeListener(this); + + setDocument(); + getConsole().setTitle(getProject()); + } + + /** + * Fill the context menu + * + * @param menu + * menu + */ + protected void contextMenuAboutToShow(IMenuManager menu) { + menu.add((IAction) fGlobalActions.get(ActionFactory.COPY.getId())); + menu.add((IAction) fGlobalActions.get(ActionFactory.SELECT_ALL.getId())); + menu.add(new Separator("FIND")); //$NON-NLS-1$ + menu.add((IAction) fGlobalActions.get(ActionFactory.FIND.getId())); + menu.add((IAction) fGlobalActions.get(ITextEditorActionConstants.GOTO_LINE)); + menu.add(fClearOutputAction); + menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent event) { + Object source = event.getSource(); + String property = event.getProperty(); + if (BuildConsole.P_STREAM_COLOR.equals(property) && source instanceof BuildConsoleStream) { + BuildConsoleStream stream = (BuildConsoleStream) source; + if (stream.getConsole().equals(getConsole())) { + getViewer().getTextWidget().redraw(); + } + } else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_FONT)) { + setFont(JFaceResources.getFont(BuildConsolePreferencePage.PREF_BUILDCONSOLE_FONT)); + } else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_TAB_WIDTH)) { + setTabs(CUIPlugin.getDefault().getPluginPreferences().getInt(BuildConsolePreferencePage.PREF_BUILDCONSOLE_TAB_WIDTH)); + } + + } + + protected void createActions() { + fClearOutputAction = new ClearOutputAction(getViewer()); + fScrollLockAction = new ScrollLockAction(getViewer()); + fScrollLockAction.setChecked(fIsLocked); + getViewer().setAutoScroll(!fIsLocked); + // In order for the clipboard actions to accessible via their shortcuts + // (e.g., Ctrl-C, Ctrl-V), we *must* set a global action handler for + // each action + IActionBars actionBars = getSite().getActionBars(); + TextViewerAction action = new TextViewerAction(getViewer(), ITextOperationTarget.COPY); + action.configureAction(ConsoleMessages.getString("BuildConsolePage.&Copy@Ctrl+C_6"), //$NON-NLS-1$ + ConsoleMessages.getString("BuildConsolePage.Copy_7"), ConsoleMessages.getString("BuildConsolePage.Copy_7")); //$NON-NLS-1$ //$NON-NLS-2$ + action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + action.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( + ISharedImages.IMG_TOOL_COPY_DISABLED)); + action.setHoverImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( + ISharedImages.IMG_TOOL_COPY_HOVER)); + setGlobalAction(actionBars, ActionFactory.COPY.getId(), action); + action = new TextViewerAction(getViewer(), ITextOperationTarget.SELECT_ALL); + action.configureAction(ConsoleMessages.getString("BuildConsolePage.Select_&All@Ctrl+A_12"), //$NON-NLS-1$ + ConsoleMessages.getString("BuildConsolePage.Select_All"), //$NON-NLS-1$ + ConsoleMessages.getString("BuildConsolePage.Select_All")); //$NON-NLS-1$ + setGlobalAction(actionBars, ActionFactory.SELECT_ALL.getId(), action); + //XXX Still using "old" resource access + ResourceBundle bundle = ResourceBundle.getBundle(ConsoleMessages.BUNDLE_NAME); //$NON-NLS-1$ + setGlobalAction(actionBars, ActionFactory.FIND.getId(), new FindReplaceAction(bundle, "find_replace_action.", //$NON-NLS-1$ + getConsoleView())); //$NON-NLS-1$ + action = new TextViewerGotoLineAction(getViewer()); + setGlobalAction(actionBars, ITextEditorActionConstants.GOTO_LINE, action); + actionBars.updateActionBars(); + fSelectionActions.add(ActionFactory.COPY.getId()); + fSelectionActions.add(ActionFactory.FIND.getId()); + } + + protected void updateSelectionDependentActions() { + Iterator iterator = fSelectionActions.iterator(); + while (iterator.hasNext()) { + updateAction((String) iterator.next()); + } + } + + protected void updateAction(String actionId) { + IAction action = (IAction) fGlobalActions.get(actionId); + if (action instanceof IUpdate) { + ((IUpdate) action).update(); + } + } + + protected void setGlobalAction(IActionBars actionBars, String actionID, IAction action) { + fGlobalActions.put(actionID, action); + actionBars.setGlobalActionHandler(actionID, action); + } + + protected void configureToolBar(IToolBarManager mgr) { + mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fScrollLockAction); + mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fClearOutputAction); + } + + protected BuildConsoleViewer getViewer() { + return fViewer; + } + + /** + * Returns the view this page is contained in + * + * @return the view this page is contained in + */ + protected IConsoleView getConsoleView() { + return fConsoleView; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.part.IPage#dispose() + */ + public void dispose() { + super.dispose(); + getSite().getPage().removeSelectionListener(this); + getConsole().getConsoleManager().addConsoleListener(this); + } + + public void init(IPageSite pageSite) { + super.init(pageSite); + setProject(convertSelectionToProject(getSite().getPage().getSelection())); + + getSite().getPage().addSelectionListener(this); + getConsole().getConsoleManager().addConsoleListener(this); + } + + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + IProject newProject = convertSelectionToProject(selection); + IProject oldProject = getProject(); + if (oldProject == null || (newProject != null && !newProject.equals(oldProject))) { + setProject(newProject); + setDocument(); + getConsole().setTitle(getProject()); + } + } + + IProject convertSelectionToProject(ISelection selection) { + IProject project = null; + if (selection == null || !(selection instanceof IStructuredSelection)) { + return project; + } + IStructuredSelection ssel = (IStructuredSelection) selection; + Object element = ssel.getFirstElement(); + if (element instanceof IAdaptable) { + IAdaptable input = (IAdaptable) element; + 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(); + } + } + } + return project; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.part.IPage#getControl() + */ + public Control getControl() { + if (fViewer != null) { + return fViewer.getControl(); + } + return null; + } + + // /* + // * (non-Javadoc) + // * + // * @see + // org.eclipse.ui.part.IPage#setActionBars(org.eclipse.ui.IActionBars) + // */ + // public void setActionBars(IActionBars actionBars) { + // } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.part.IPage#setFocus() + */ + public void setFocus() { + Control control = getControl(); + if (control != null) { + control.setFocus(); + } + updateSelectionDependentActions(); + } + + /** + * Sets the font for this page. + * + * @param font + * font + */ + protected void setFont(Font font) { + getViewer().getTextWidget().setFont(font); + } + + /** + * Sets the tab width for this page. + * + * @param int + * tab width + */ + protected void setTabs(int tabs) { + getViewer().getTextWidget().setTabs(tabs); + } + + /** + * Refreshes this page + */ + protected void refresh() { + getViewer().refresh(); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartition.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartition.java new file mode 100644 index 00000000000..a71027bc1fb --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartition.java @@ -0,0 +1,103 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.jface.text.TypedRegion; + +public class BuildConsolePartition extends TypedRegion { + + /** + * Associated stream + */ + private BuildConsoleStream fStream; + + /** + * Partition type + */ + public static final String CONSOLE_PARTITION_TYPE = CUIPlugin.getPluginId() + ".CONSOLE_PARTITION_TYPE"; //$NON-NLS-1$ + + public BuildConsolePartition(BuildConsoleStream stream, int offset, int length) { + super(offset, length, CONSOLE_PARTITION_TYPE); + fStream = stream; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object partition) { + if (super.equals(partition)) { + fStream.equals(((BuildConsolePartition) partition).getStream()); + } + return false; + } + + /** + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return super.hashCode() + fStream.hashCode(); + } + + /** + * Returns this partition's stream + * + * @return this partition's stream + */ + public BuildConsoleStream getStream() { + return fStream; + } + + /** + * Returns whether this partition is allowed to be combined with the given + * partition. + * + * @param partition + * @return boolean + */ + public boolean canBeCombinedWith(BuildConsolePartition partition) { + int start = getOffset(); + int end = start + getLength(); + int otherStart = partition.getOffset(); + int otherEnd = otherStart + partition.getLength(); + boolean overlap = (otherStart >= start && otherStart <= end) || (start >= otherStart && start <= otherEnd); + return overlap && getType().equals(partition.getType()) && getStream().equals(partition.getStream()); + } + + /** + * Returns a new partition representing this and the given parition + * combined. + * + * @param partition + * @return partition + */ + public BuildConsolePartition combineWith(BuildConsolePartition partition) { + int start = getOffset(); + int end = start + getLength(); + int otherStart = partition.getOffset(); + int otherEnd = otherStart + partition.getLength(); + int theStart = Math.min(start, otherStart); + int theEnd = Math.max(end, otherEnd); + return createNewPartition(theStart, theEnd - theStart); + } + + /** + * Creates a new patition of this type with the given color, offset, and + * length. + * + * @param offset + * @param length + * @return a new partition with the given range + */ + public BuildConsolePartition createNewPartition(int offset, int length) { + return new BuildConsolePartition(getStream(), offset, length); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartitioner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartitioner.java new file mode 100644 index 00000000000..5c2b9f63f54 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsolePartitioner.java @@ -0,0 +1,332 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.cdt.core.ConsoleOutputStream; +import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.IBuildConsole; +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.text.IDocumentPartitionerExtension; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.text.Region; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.widgets.Display; + +public class BuildConsolePartitioner + implements + IDocumentPartitioner, + IDocumentPartitionerExtension, + IBuildConsole, + IPropertyChangeListener { + + /** + * List of partitions + */ + List fPartitions = new ArrayList(5); + + private int fMaxLines; + + /** + * The stream that was last appended to + */ + BuildConsoleStream fLastStream = null; + + BuildConsoleDocument fDocument; + boolean killed; + BuildConsoleManager fManager; + + public BuildConsolePartitioner(BuildConsoleManager manager) { + fManager = manager; + fMaxLines = BuildConsolePreferencePage.buildConsoleLines(); + fDocument = new BuildConsoleDocument(); + fDocument.setDocumentPartitioner(this); + connect(fDocument); + } + + /** + * Adds the new text to the document. + * + * @param text + * the text to append + * @param stream + * the stream to append to + */ + + public void appendToDocument(final String text, final BuildConsoleStream stream) { + Runnable r = new Runnable() { + + public void run() { + fLastStream = stream; + try { + if (stream == null) { + fDocument.set(text); + } else { + fDocument.replace(fDocument.getLength(), 0, text); + checkOverflow(); + } + } catch (BadLocationException e) { + } + } + }; + Display display = CUIPlugin.getStandardDisplay(); + if (display != null) { + display.asyncExec(r); + } + } + + public IDocument getDocument() { + return fDocument; + } + + public void setDocumentSize(int nLines) { + fMaxLines = nLines; + nLines = fDocument.getNumberOfLines(); + checkOverflow(); + } + + public void connect(IDocument document) { + CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); + } + + public void disconnect() { + fDocument.setDocumentPartitioner(null); + CUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); + killed = true; + } + + public void documentAboutToBeChanged(DocumentEvent event) { + } + + public boolean documentChanged(DocumentEvent event) { + return documentChanged2(event) != null; + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#getLegalContentTypes() + */ + public String[] getLegalContentTypes() { + return new String[]{BuildConsolePartition.CONSOLE_PARTITION_TYPE}; + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#getContentType(int) + */ + public String getContentType(int offset) { + ITypedRegion partition = getPartition(offset); + if (partition != null) { + return partition.getType(); + } + return null; + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#computePartitioning(int, + * int) + */ + public ITypedRegion[] computePartitioning(int offset, int length) { + if (offset == 0 && length == fDocument.getLength()) { + return (ITypedRegion[]) fPartitions.toArray(new ITypedRegion[fPartitions.size()]); + } else { + int end = offset + length; + List list = new ArrayList(); + for (int i = 0; i < fPartitions.size(); i++) { + ITypedRegion partition = (ITypedRegion) fPartitions.get(i); + int partitionStart = partition.getOffset(); + int partitionEnd = partitionStart + partition.getLength(); + if ((offset >= partitionStart && offset <= partitionEnd) || (offset < partitionStart && end >= partitionStart)) { + list.add(partition); + } + } + return (ITypedRegion[]) list.toArray(new ITypedRegion[list.size()]); + } + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#getPartition(int) + */ + public ITypedRegion getPartition(int offset) { + for (int i = 0; i < fPartitions.size(); i++) { + ITypedRegion partition = (ITypedRegion) fPartitions.get(i); + int start = partition.getOffset(); + int end = start + partition.getLength(); + if (offset >= start && offset < end) { + return partition; + } + } + return null; + } + + public IRegion documentChanged2(DocumentEvent event) { + String text = event.getText(); + if (getDocument().getLength() == 0) { + // cleared + fPartitions.clear(); + return new Region(0, 0); + } + addPartition(new BuildConsolePartition(fLastStream, event.getOffset(), text.length())); + ITypedRegion[] affectedRegions = computePartitioning(event.getOffset(), text.length()); + if (affectedRegions.length == 0) { + return null; + } + if (affectedRegions.length == 1) { + return affectedRegions[0]; + } + int affectedLength = affectedRegions[0].getLength(); + for (int i = 1; i < affectedRegions.length; i++) { + ITypedRegion region = affectedRegions[i]; + affectedLength += region.getLength(); + } + + return new Region(affectedRegions[0].getOffset(), affectedLength); + } + + /** + * Checks to see if the console buffer has overflowed, and empties the + * overflow if needed, updating partitions and hyperlink positions. + */ + protected void checkOverflow() { + if (fMaxLines >= 0) { + int nLines = fDocument.getNumberOfLines(); + if (nLines > fMaxLines + 1) { + int overflow = 0; + try { + overflow = fDocument.getLineOffset(nLines - fMaxLines); + } catch (BadLocationException e1) { + } + // update partitions + List newParitions = new ArrayList(fPartitions.size()); + Iterator partitions = fPartitions.iterator(); + while (partitions.hasNext()) { + ITypedRegion region = (ITypedRegion) partitions.next(); + if (region instanceof BuildConsolePartition) { + BuildConsolePartition messageConsolePartition = (BuildConsolePartition)region; + + ITypedRegion newPartition = null; + int offset = region.getOffset(); + if (offset < overflow) { + int endOffset = offset + region.getLength(); + if (endOffset < overflow) { + // remove partition + } else { + // split partition + int length = endOffset - overflow; + newPartition = messageConsolePartition.createNewPartition(0, length); + } + } else { + // modify parition offset + newPartition = messageConsolePartition.createNewPartition(messageConsolePartition.getOffset()-overflow, messageConsolePartition.getLength()); + } + if (newPartition != null) { + newParitions.add(newPartition); + } + } + } + fPartitions = newParitions; + + //called from GUI Thread (see startUpdaterThread()), no asyncExec needed. + try { + fDocument.replace(0, overflow, ""); //$NON-NLS-1$ + } catch (BadLocationException e) { + } + } + } + } + + + + /** + * Adds a new colored input partition, combining with the previous + * partition if possible. + */ + private BuildConsolePartition addPartition(BuildConsolePartition partition) { + if (fPartitions.isEmpty()) { + fPartitions.add(partition); + } else { + int index = fPartitions.size() - 1; + BuildConsolePartition last = (BuildConsolePartition) fPartitions.get(index); + if (last.canBeCombinedWith(partition)) { + // replace with a single partition + partition = last.combineWith(partition); + fPartitions.set(index, partition); + } else { + // different kinds - add a new parition + fPartitions.add(partition); + } + } + return partition; + } + + public IBuildConsole getConsole() { + return this; + } + + public void propertyChange(PropertyChangeEvent event) { + if (event.getProperty() == BuildConsolePreferencePage.PREF_BUILDCONSOLE_LINES) { + setDocumentSize(BuildConsolePreferencePage.buildConsoleLines()); + } + } + + public void start(IProject project) { + if (BuildConsolePreferencePage.isClearBuildConsole()) { + appendToDocument("", null); //$NON-NLS-1$ + } + fManager.startConsoleActivity(project); + } + + public class BuildOutputStream extends ConsoleOutputStream { + + final BuildConsoleStream fStream; + + public BuildOutputStream(BuildConsoleStream stream) { + fStream = stream; + } + + public void flush() throws IOException { + appendToDocument(readBuffer(), fStream); + fManager.showConsole(); + } + + public void close() throws IOException { + flush(); + } + + + public synchronized void write(byte[] b, int off, int len) throws IOException { + super.write(b, off, len); + flush(); + } + } + + public ConsoleOutputStream getOutputStream() { + return new BuildOutputStream(fManager.outputStream); + } + + public ConsoleOutputStream getInfoStream() { + return new BuildOutputStream(fManager.infoStream); + } + + public ConsoleOutputStream getErrorStream() { + return new BuildOutputStream(fManager.errorStream); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleStream.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleStream.java new file mode 100644 index 00000000000..f36dc270661 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleStream.java @@ -0,0 +1,59 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import org.eclipse.swt.graphics.Color; + + +public class BuildConsoleStream { + private BuildConsole fConsole = null; + + private Color fColor = null; + + /** + * Constructs a new stream connected to the given console. + * + * @param console the console to write messages to + */ + public BuildConsoleStream(BuildConsole console) { + fConsole = console; + } + + /** + * Sets the color of this message stream + * + * @param color color of this message stream, possibly null + */ + public void setColor(Color color) { + Color old = fColor; + fColor = color; + fConsole.firePropertyChange(this, BuildConsole.P_STREAM_COLOR, old, color); + } + + /** + * Returns the color of this message stream, or null + * if default. + * + * @return the color of this message stream, or null + */ + public Color getColor() { + return fColor; + } + + /** + * Returns the console this stream is connected to. + * + * @return the console this stream is connected to + */ + public BuildConsole getConsole() { + return fConsole; + } +} 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 deleted file mode 100644 index 8719c4efbd4..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleView.java +++ /dev/null @@ -1,313 +0,0 @@ -package org.eclipse.cdt.internal.ui.buildconsole; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ResourceBundle; - -import org.eclipse.cdt.internal.ui.ICHelpContextIds; -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.cdt.ui.IBuildConsoleManager; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextListener; -import org.eclipse.jface.text.ITextOperationTarget; -import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.text.TextViewer; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.ui.part.ViewPart; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.ui.texteditor.TextEditorAction; - -/** - -/** - * Console view for the desktop. Registered using XML. - */ -public class BuildConsoleView extends ViewPart implements ISelectionListener, IBuildConsoleListener { - private IProject selProject; - private Font fFont; - private IPropertyChangeListener fPropertyChangeListener; - protected TextViewer fTextViewer; - IBuildConsoleManager fConsoleManager; - ClearConsoleAction fClearOutputAction; - TextEditorAction fCopyAction; - TextEditorAction fSelectAllAction; - String origTitle; - - public BuildConsoleView() { - super(); - fFont = null; - fPropertyChangeListener = new IPropertyChangeListener() { - public void propertyChange(PropertyChangeEvent event) { - if (fTextViewer != null && event.getProperty().equals(BuildConsolePreferencePage.PREF_CONSOLE_FONT)) { - initializeWidgetFont(fTextViewer.getTextWidget()); - } - } - }; - IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore(); - store.addPropertyChangeListener(fPropertyChangeListener); - fConsoleManager = CUIPlugin.getDefault().getConsoleManager(); - } - - private void initializeActions() { - ResourceBundle bundle = CUIPlugin.getResourceBundle(); - - IActionBars actionBars = getViewSite().getActionBars(); - fClearOutputAction = new ClearConsoleAction(this); - fCopyAction = new BuildConsoleAction(bundle, "Editor.Copy.", fTextViewer, ITextOperationTarget.COPY); //$NON-NLS-1$ - fSelectAllAction = new BuildConsoleAction(bundle, "Editor.SelectAll.", fTextViewer, ITextOperationTarget.SELECT_ALL); //$NON-NLS-1$ - - actionBars.setGlobalActionHandler(ITextEditorActionConstants.COPY, fCopyAction); - actionBars.setGlobalActionHandler(ITextEditorActionConstants.SELECT_ALL, fSelectAllAction); - - fTextViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent e) { - // ensures that the copyAction updates is doability when the selections tate changes - fCopyAction.update(); - } - }); - } - - /** - * @see ViewPart#createPartControl - */ - public void createPartControl(Composite parent) { - fTextViewer = new TextViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP | SWT.MULTI); - fTextViewer.addTextListener(new ITextListener() { - public void textChanged(TextEvent event) { - revealEndOfDocument(); - } - }); - fTextViewer.setEditable(false); - origTitle = getTitle(); - initializeWidgetFont(fTextViewer.getTextWidget()); - - initializeActions(); - initializeContextMenu(fTextViewer.getControl()); - initializeToolBar(); - - WorkbenchHelp.setHelp(fTextViewer.getControl(), ICHelpContextIds.CLEAR_CONSOLE_VIEW); - - setProject(getSite().getPage().getSelection()); - setDocument(); - setTitle(); - getSite().getPage().addSelectionListener(this); - fConsoleManager.addConsoleListener(this); - } - - protected void setProject(ISelection selection) { - selProject = convertSelectionToProject(selection); - } - - protected void setProject(IProject project) { - selProject = project; - } - - protected IProject getProject() { - return selProject; - } - - protected IDocument setDocument() { - IProject project = getProject(); - if (project != null) { - fTextViewer.setDocument(fConsoleManager.getConsoleDocument(project)); - } - return null; - } - - protected void setTitle() { - String title = origTitle; - IProject project = getProject(); - if (project != null) { - title += " [" + project.getName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - setTitle(title); - } - - protected void initializeWidgetFont(StyledText styledText) { - IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore(); - String prefKey = BuildConsolePreferencePage.PREF_CONSOLE_FONT; - FontData data = null; - if (store.contains(prefKey) && !store.isDefault(prefKey)) { - data = PreferenceConverter.getFontData(store, prefKey); - } else { - data = PreferenceConverter.getDefaultFontData(store, prefKey); - } - if (data != null) { - Font font = new Font(styledText.getDisplay(), data); - styledText.setFont(font); - - if (fFont != null) - fFont.dispose(); - - fFont = font; - } else { - // if all the preferences failed - styledText.setFont(JFaceResources.getTextFont()); - } - } - - /** - * @see IWorkbenchPart#setFocus() - */ - public void setFocus() { - fTextViewer.getControl().setFocus(); - } - - /** - * Initializes the context menu - */ - protected void initializeContextMenu(Control parent) { - MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ - menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener(new IMenuListener() { - public void menuAboutToShow(IMenuManager manager) { - fillContextMenu(manager); - } - }); - Menu menu = menuMgr.createContextMenu(parent); - parent.setMenu(menu); - } - - /** - * Adds the text manipulation actions to the ConsoleViewer - */ - protected void fillContextMenu(IMenuManager menu) { - fCopyAction.update(); - menu.add(fCopyAction); - menu.add(fSelectAllAction); - menu.add(new Separator()); - menu.add(fClearOutputAction); - } - - /** - * Configures the toolBar. - */ - private void initializeToolBar() { - IActionBars actionBars = getViewSite().getActionBars(); - actionBars.getToolBarManager().add(fClearOutputAction); - actionBars.updateActionBars(); - } - /** - * Reveals (makes visible) the end of the current document - */ - protected void revealEndOfDocument() { - IDocument doc = fTextViewer.getDocument(); - int docLength = doc.getLength(); - if (docLength > 0) { - fTextViewer.revealRange(docLength - 1, 1); - StyledText widget = fTextViewer.getTextWidget(); - widget.setCaretOffset(docLength); - widget.showSelection(); - } - } - /** - * @see WorkbenchPart#dispose() - */ - public void dispose() { - super.dispose(); - if (fPropertyChangeListener != null) { - IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore(); - store.removePropertyChangeListener(fPropertyChangeListener); - fPropertyChangeListener = null; - } - if (fFont != null) { - fFont.dispose(); - fFont = null; - } - getSite().getPage().removeSelectionListener(this); - fConsoleManager.removeConsoleListener(this); - } - - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - IProject newProject = convertSelectionToProject(selection); - IProject oldProject = getProject(); - if (oldProject == null || (newProject != null && !newProject.equals(oldProject))) { - setProject(newProject); - setDocument(); - setTitle(); - } - } - - public void consoleChange(IBuildConsoleEvent event) { - if (event.getType() == IBuildConsoleEvent.CONSOLE_START || event.getType() == IBuildConsoleEvent.CONSOLE_CLOSE) { - Display display = fTextViewer.getControl().getDisplay(); - selProject = event.getProject(); - if (event.getType() == IBuildConsoleEvent.CONSOLE_CLOSE && selProject != event.getProject()) { - return; - } - display.asyncExec(new Runnable() { - public void run() { - setDocument(); - setTitle(); - } - }); - } - } - - IProject convertSelectionToProject(ISelection selection) { - IProject project = null; - if (selection == null || !(selection instanceof IStructuredSelection)) { - return project; - } - IStructuredSelection ssel = (IStructuredSelection) selection; - Object element = ssel.getFirstElement(); - if (element instanceof IAdaptable) { - IAdaptable input = (IAdaptable) element; - 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(); - } - } - } - return project; - } - - /** - * Clears the console - */ - void clear() { - if (selProject != null) { - fConsoleManager.getConsole(selProject).clear(); - } - } - -} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleViewer.java new file mode 100644 index 00000000000..32b6fd5686f --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/BuildConsoleViewer.java @@ -0,0 +1,188 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentListener; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.text.TextViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.LineStyleEvent; +import org.eclipse.swt.custom.LineStyleListener; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; + +public class BuildConsoleViewer extends TextViewer implements LineStyleListener { + + protected InternalDocumentListener fInternalDocumentListener = new InternalDocumentListener(); + /** + * Whether the console scrolls as output is appended. + */ + private boolean fAutoScroll = true; + /** + * Internal document listener. + */ + class InternalDocumentListener implements IDocumentListener { + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) + */ + public void documentAboutToBeChanged(DocumentEvent e) { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent) + */ + public void documentChanged(DocumentEvent e) { + revealEndOfDocument(); + } + } + + /** + * Sets whether this viewer should auto-scroll as output is appended to the + * document. + * + * @param scroll + */ + public void setAutoScroll(boolean scroll) { + fAutoScroll = scroll; + } + + /** + * Returns whether this viewer should auto-scroll as output is appended to + * the document. + */ + public boolean isAutoScroll() { + return fAutoScroll; + } + + /** + * Creates a new console viewer and adds verification checking to only + * allow text modification if the text is being modified in the editable + * portion of the underlying document. + * + * @see org.eclipse.swt.events.VerifyListener + */ + public BuildConsoleViewer(Composite parent) { + super(parent, getSWTStyles()); + getTextWidget().setDoubleClickEnabled(true); + getTextWidget().setFont(parent.getFont()); + getTextWidget().addLineStyleListener(this); + getTextWidget().setEditable(false); + } + + + /** + * Returns the SWT style flags used when instantiating this viewer + */ + private static int getSWTStyles() { + int styles = SWT.H_SCROLL | SWT.V_SCROLL; + return styles; + } + + /** + * Reveals (makes visible) the end of the current document + */ + protected void revealEndOfDocument() { + if (isAutoScroll()) { + IDocument doc = getDocument(); + int lines = doc.getNumberOfLines(); + try { + // lines are 0-based + int lineStartOffset = doc.getLineOffset(lines - 1); + StyledText widget = getTextWidget(); + if (lineStartOffset > 0) { + widget.setCaretOffset(lineStartOffset); + widget.showSelection(); + } + int lineEndOffset = lineStartOffset + doc.getLineLength(lines - 1); + if (lineEndOffset > 0) { + widget.setCaretOffset(lineEndOffset); + } + } catch (BadLocationException e) { + } + } + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.text.ITextViewer#setDocument(org.eclipse.jface.text.IDocument) + */ + public void setDocument(IDocument doc) { + IDocument oldDoc = getDocument(); + IDocument document = doc; + if (oldDoc == null && document == null) { + return; + } + if (oldDoc != null) { + oldDoc.removeDocumentListener(fInternalDocumentListener); + if (oldDoc.equals(document)) { + document.addDocumentListener(fInternalDocumentListener); + return; + } + } + + super.setDocument(document); + if (document != null) { + revealEndOfDocument(); + document.addDocumentListener(fInternalDocumentListener); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.text.TextViewer#canPerformFind() + */ + protected boolean canPerformFind() { + return (getTextWidget() != null && getVisibleDocument() != null && getVisibleDocument().getLength() > 0); + } + + /** + * Dispose this viewer and resources + */ + public void dispose() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.custom.LineStyleListener#lineGetStyle(org.eclipse.swt.custom.LineStyleEvent) + */ + public void lineGetStyle(LineStyleEvent event) { + IDocument document = getDocument(); + if (document != null) { + BuildConsolePartitioner partitioner = (BuildConsolePartitioner) document.getDocumentPartitioner(); + if (partitioner != null) { + ITypedRegion[] regions = partitioner.computePartitioning(event.lineOffset, event.lineOffset + + event.lineText.length()); + StyleRange[] styles = new StyleRange[regions.length]; + for (int i = 0; i < regions.length; i++) { + BuildConsolePartition partition = (BuildConsolePartition) regions[i]; + Color color = partition.getStream().getColor(); + styles[i] = new StyleRange(partition.getOffset(), partition.getLength(), color, null); + } + event.styles = styles; + } + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/CBuildConsole.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/CBuildConsole.java new file mode 100644 index 00000000000..d96455f78a4 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/CBuildConsole.java @@ -0,0 +1,49 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import org.eclipse.cdt.core.ConsoleOutputStream; +import org.eclipse.cdt.core.resources.IConsole; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.IBuildConsoleManager; +import org.eclipse.core.resources.IProject; + +public class CBuildConsole implements IConsole { + IProject project; + IBuildConsoleManager fConsoleManager; + + /** + * Constructor for BuildConsole. + */ + public CBuildConsole() { + fConsoleManager = CUIPlugin.getDefault().getConsoleManager(); + } + + public void start(IProject project ) { + this.project = project; + fConsoleManager.getConsole(project).start(project); + } + + /** + * @see org.eclipse.cdt.core.resources.IConsole#getOutputStream() + */ + public ConsoleOutputStream getOutputStream() { + return fConsoleManager.getConsole(project).getOutputStream(); + } + + public ConsoleOutputStream getInfoStream() { + return fConsoleManager.getConsole(project).getInfoStream(); + } + + public ConsoleOutputStream getErrorStream() { + return fConsoleManager.getConsole(project).getErrorStream(); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ClearConsoleAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ClearConsoleAction.java deleted file mode 100644 index bd229947373..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ClearConsoleAction.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.eclipse.cdt.internal.ui.buildconsole; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.internal.ui.CPluginImages; -import org.eclipse.cdt.internal.ui.ICHelpContextIds; -import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.jface.action.Action; - -import org.eclipse.ui.help.WorkbenchHelp; - - -/** - * Clears the output of the selected launches - */ -public class ClearConsoleAction extends Action { - - - private BuildConsoleView fConsoleView; - - - public ClearConsoleAction(BuildConsoleView view) { - super(CUIPlugin.getResourceString("ClearOutputAction.label")); //$NON-NLS-1$ - CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_CLEAR_CONSOLE); - fConsoleView= view; - setToolTipText(CUIPlugin.getResourceString("ClearOutputAction.tooltip")); //$NON-NLS-1$ - WorkbenchHelp.setHelp(this, ICHelpContextIds.CLEAR_CONSOLE_ACTION); - } - - /** - * @see Action - */ - public void run() { - fConsoleView.clear(); - } -} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleMessages.java new file mode 100644 index 00000000000..6a0b2683984 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleMessages.java @@ -0,0 +1,32 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class ConsoleMessages { + + public static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.buildconsole.ConsoleMessages";//$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private ConsoleMessages() { + + } + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} \ No newline at end of file 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 new file mode 100644 index 00000000000..281ce02eda3 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleMessages.properties @@ -0,0 +1,13 @@ +BuildConsole.buildConsole=C-Build + +find_replace_action.label=&Find/Replace...@Ctrl+F +find_replace_action.tooltip=Find/Replace +find_replace_action.image= +find_replace_action.description=Find/Replace + +BuildConsolePage.&Copy@Ctrl+C_6=&Copy@Ctrl+C +BuildConsolePage.Copy_7=Copy +BuildConsolePage.Select_&All@Ctrl+A_12=Select &All@Ctrl+A +BuildConsolePage.Select_All=Select All + +ScrollLockAction.Scroll_Lock_1=Scroll Lock \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleOutputTextStore.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleOutputTextStore.java new file mode 100644 index 00000000000..ed70267ff4a --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ConsoleOutputTextStore.java @@ -0,0 +1,67 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import org.eclipse.jface.text.ITextStore; + +public class ConsoleOutputTextStore implements ITextStore { + + private StringBuffer fBuffer; + + public ConsoleOutputTextStore(int bufferSize) { + fBuffer = new StringBuffer(bufferSize); + } + + /** + * @see ITextStore#get(int) + */ + public char get(int pos) { + return fBuffer.charAt(pos); + } + + /** + * @see ITextStore#get(int, int) + */ + public String get(int pos, int length) { + return fBuffer.substring(pos, pos + length); + } + + /** + * @see ITextStore#getLength() + */ + public int getLength() { + return fBuffer.length(); + } + + /** + * @see ITextStore#replace(int, int, String) + */ + public void replace(int pos, int length, String text) { + if (text == null) { + text = ""; //$NON-NLS-1$ + } + fBuffer.replace(pos, pos + length, text); + } + + /** + * @see ITextStore#set(String) + */ + public void set(String text) { + fBuffer = new StringBuffer(text); + } + + /** + * @see StringBuffer#ensureCapacity(int) + */ + public void setMinimalBufferSize(int bufferSize) { + fBuffer.ensureCapacity(bufferSize); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ScrollLockAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ScrollLockAction.java new file mode 100644 index 00000000000..09b1c7a2730 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/buildconsole/ScrollLockAction.java @@ -0,0 +1,39 @@ +/********************************************************************** + * 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.internal.ui.buildconsole; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.jface.action.Action; + +/** + * Toggles console auto-scroll + */ + +public class ScrollLockAction extends Action { + + private BuildConsoleViewer fConsoleViewer; + + public ScrollLockAction(BuildConsoleViewer viewer) { + super(ConsoleMessages.getString("ScrollLockAction.Scroll_Lock_1")); //$NON-NLS-1$ + fConsoleViewer = viewer; + setToolTipText(ConsoleMessages.getString("ScrollLockAction.Scroll_Lock_1")); //$NON-NLS-1$ + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_SCROLL_LOCK); + setChecked(false); + } + + /** + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + fConsoleViewer.setAutoScroll(!isChecked()); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/BuildConsolePreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/BuildConsolePreferencePage.java index 407f6e49c69..d596053a7e2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/BuildConsolePreferencePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/BuildConsolePreferencePage.java @@ -6,31 +6,33 @@ package org.eclipse.cdt.internal.ui.preferences; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.ColorFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; -import org.eclipse.jface.preference.FontFieldEditor; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IntegerFieldEditor; import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; public class BuildConsolePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { - public static final String PREF_CONSOLE_FONT = "consoleFont"; //$NON-NLS-1$ private static final String PREF_CLEAR_CONSOLE = "clearConsole"; //$NON-NLS-1$ private static final String PREF_CONSOLE_ON_TOP = "consoleOnTop"; //$NON-NLS-1$ private static final String PREF_AUTO_OPEN_CONSOLE = "autoOpenConsole"; //$NON-NLS-1$ - public static final String PREF_BUILDCONSOLE_LINES = "buildConsoleLines"; //$NON-NLS-1$ - public static final String PREF_BUILDCONSOLE_LINES_ERROR = "CBasePreferencePage.buildConsole.errorMessage"; //$NON-NLS-1$ - private static final String CLEAR_CONSOLE_LABEL= "CBasePreferencePage.clearConsole.label"; //$NON-NLS-1$ - private static final String CONSOLE_ON_TOP_LABEL= "CBasePreferencePage.consoleOnTop.label"; //$NON-NLS-1$ - private static final String AUTO_OPEN_CONSOLE_LABEL= "CBasePreferencePage.autoOpenConsole.label"; //$NON-NLS-1$ - private static final String CONSOLE_FONT_LABEL= "CBasePreferencePage.consoleFont.label"; //$NON-NLS-1$ + // In font registry + public static final String PREF_BUILDCONSOLE_FONT = "org.eclipse.cdt.ui.buildconsole.ConsoleFont"; //$NON-NLS-1$ + + public static final String PREF_BUILDCONSOLE_TAB_WIDTH = "buildConsoleTabWith"; //$NON-NLS-1$ + public static final String PREF_BUILDCONSOLE_LINES = "buildConsoleLines"; //$NON-NLS-1$ + public static final String PREF_BUILDCONSOLE_INFO_COLOR = "buildConsoleInfoStreamColor"; //$NON-NLS-1$ + public static final String PREF_BUILDCONSOLE_OUTPUT_COLOR = "buildConsoleOutputStreamColor"; //$NON-NLS-1$ + public static final String PREF_BUILDCONSOLE_ERROR_COLOR = "buildConsoleErrorStreamColor"; //$NON-NLS-1$ public BuildConsolePreferencePage() { super(GRID); @@ -39,28 +41,61 @@ public class BuildConsolePreferencePage extends FieldEditorPreferencePage implem protected void createFieldEditors() { Composite parent = getFieldEditorParent(); - BooleanFieldEditor clearConsole = - new BooleanFieldEditor(PREF_CLEAR_CONSOLE, CUIPlugin.getResourceString(CLEAR_CONSOLE_LABEL), parent); + BooleanFieldEditor clearConsole = new BooleanFieldEditor(PREF_CLEAR_CONSOLE, + CUIPlugin.getResourceString("ConsolePreferencePage.clearConsole.label"), parent); //$NON-NLS-1$ addField(clearConsole); - BooleanFieldEditor autoOpenConsole = - new BooleanFieldEditor(PREF_AUTO_OPEN_CONSOLE, CUIPlugin.getResourceString(AUTO_OPEN_CONSOLE_LABEL), parent); + BooleanFieldEditor autoOpenConsole = new BooleanFieldEditor(PREF_AUTO_OPEN_CONSOLE, + CUIPlugin.getResourceString("ConsolePreferencePage.autoOpenConsole.label"), parent); //$NON-NLS-1$ addField(autoOpenConsole); - BooleanFieldEditor consoleOnTop = - new BooleanFieldEditor(PREF_CONSOLE_ON_TOP, CUIPlugin.getResourceString(CONSOLE_ON_TOP_LABEL), parent); + BooleanFieldEditor consoleOnTop = new BooleanFieldEditor(PREF_CONSOLE_ON_TOP, + CUIPlugin.getResourceString("ConsolePreferencePage.consoleOnTop.label"), parent); //$NON-NLS-1$ addField(consoleOnTop); - IntegerFieldEditor buildCount = new IntegerFieldEditor( PREF_BUILDCONSOLE_LINES, PreferencesMessages.getString("BuildConsolePreferencePage.fieldEditors.buildConsoleLines"), parent ); //$NON-NLS-1$ - buildCount.setErrorMessage(CUIPlugin.getResourceString(PREF_BUILDCONSOLE_LINES_ERROR)); - buildCount.setValidRange( 10, Integer.MAX_VALUE ); - addField( buildCount ); + IntegerFieldEditor buildCount = new IntegerFieldEditor(PREF_BUILDCONSOLE_LINES, + CUIPlugin.getResourceString("ConsolePreferencePage.consoleLines.label"), parent); //$NON-NLS-1$ + buildCount.setErrorMessage(CUIPlugin.getResourceString("ConsolePreferencePage.consoleLines.errorMessage")); //$NON-NLS-1$ + buildCount.setValidRange(10, Integer.MAX_VALUE); + addField(buildCount); - addField(new FontFieldEditor(PREF_CONSOLE_FONT, CUIPlugin.getResourceString(CONSOLE_FONT_LABEL), parent)); + IntegerFieldEditor tabSize = new IntegerFieldEditor(PREF_BUILDCONSOLE_TAB_WIDTH, + CUIPlugin.getResourceString("ConsolePreferencePage.tabWidth.label"), parent); //$NON-NLS-1$ + addField(tabSize); + tabSize.setValidRange(1, 100); + tabSize.setErrorMessage(CUIPlugin.getResourceString("ConsolePreferencePage.tabWidth.errorMessage")); //$NON-NLS-1$ + + createLabel(parent, CUIPlugin.getResourceString("ConsolePreferencePage.colorSettings.label")); //$NON-NLS-1$ + + addField(createColorFieldEditor(PREF_BUILDCONSOLE_OUTPUT_COLOR, + CUIPlugin.getResourceString("ConsolePreferencePage.outputColor.label"), parent)); //$NON-NLS-1$ + addField(createColorFieldEditor(PREF_BUILDCONSOLE_INFO_COLOR, + CUIPlugin.getResourceString("ConsolePreferencePage.infoColor.label"), parent)); //$NON-NLS-1$ + addField(createColorFieldEditor(PREF_BUILDCONSOLE_ERROR_COLOR, + CUIPlugin.getResourceString("ConsolePreferencePage.errorColor.label"), parent)); //$NON-NLS-1$ + } + + private Label createLabel(Composite parent, String text) { + Label label = new Label(parent, SWT.LEFT); + label.setText(text); + GridData data = new GridData(); + data.horizontalSpan = 2; + data.horizontalAlignment = GridData.FILL; + label.setLayoutData(data); + return label; + } + /** + * Creates a new color field editor. + */ + private ColorFieldEditor createColorFieldEditor(String preferenceName, String label, Composite parent) { + ColorFieldEditor editor = new ColorFieldEditor(preferenceName, label, parent); + editor.setPreferencePage(this); + editor.setPreferenceStore(getPreferenceStore()); + return editor; } /** - * Returns the current preference setting if the build console should - * be cleared before each build. + * Returns the current preference setting if the build console should be + * cleared before each build. */ public static boolean isClearBuildConsole() { return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PREF_CLEAR_CONSOLE); @@ -85,14 +120,10 @@ public class BuildConsolePreferencePage extends FieldEditorPreferencePage implem prefs.setDefault(PREF_AUTO_OPEN_CONSOLE, false); prefs.setDefault(PREF_CONSOLE_ON_TOP, true); prefs.setDefault(PREF_BUILDCONSOLE_LINES, 500); - Font font = JFaceResources.getTextFont(); - if (font != null) { - FontData[] data = font.getFontData(); - if (data != null && data.length > 0) { - PreferenceConverter.setDefault(prefs, PREF_CONSOLE_FONT, data[0]); - } - } - + prefs.setDefault(PREF_BUILDCONSOLE_TAB_WIDTH, 4); + PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_OUTPUT_COLOR, new RGB(0, 0, 0)); + PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_INFO_COLOR, new RGB(0, 0, 255)); + PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_ERROR_COLOR, new RGB(255, 0, 0)); } } 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 b6ac7e72d40..b9e7f45aed6 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 @@ -26,10 +26,10 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.corext.refactoring.base.Refactoring; -import org.eclipse.cdt.internal.ui.BuildConsoleManager; import org.eclipse.cdt.internal.ui.CElementAdapterFactory; import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.ResourceAdapterFactory; +import org.eclipse.cdt.internal.ui.buildconsole.BuildConsoleManager; import org.eclipse.cdt.internal.ui.cview.CView; import org.eclipse.cdt.internal.ui.editor.CDocumentProvider; import org.eclipse.cdt.internal.ui.editor.SharedTextColors; @@ -457,5 +457,17 @@ public class CUIPlugin extends AbstractUIPlugin { } return (IEditorPart[])result.toArray(new IEditorPart[result.size()]); } - + + /** + * Returns the standard display to be used. The method first checks, if + * the thread calling this method has an associated display. If so, this + * display is returned. Otherwise the method returns the default display. + */ + public static Display getStandardDisplay() { + Display display= Display.getCurrent(); + if (display == null) { + display= Display.getDefault(); + } + return display; + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsole.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsole.java new file mode 100644 index 00000000000..1127ce66efd --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsole.java @@ -0,0 +1,21 @@ +/********************************************************************** + * 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(); +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsoleManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsoleManager.java index e853e6fd539..c4ae161ea73 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsoleManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IBuildConsoleManager.java @@ -1,15 +1,20 @@ -/* - * (c) Copyright QNX Software System Ltd. 2002. - * All Rights Reserved. - */ +/********************************************************************** + * 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.resources.IConsole; import org.eclipse.core.resources.IProject; import org.eclipse.jface.text.IDocument; public interface IBuildConsoleManager { - IConsole getConsole(IProject project); + IBuildConsole getConsole(IProject project); IDocument getConsoleDocument(IProject project); void addConsoleListener(IBuildConsoleListener listener); void removeConsoleListener(IBuildConsoleListener listener);