1
/*******************************************************************************
2
* Copyright (c) 2000, 2010 QNX Software Systems and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* QNX Software Systems - Initial API and implementation
10
* Dmitry Kozlov (CodeSourcery) - Build error highlighting and navigation
11
*******************************************************************************/
12
package org.eclipse.cdt.internal.ui.preferences;
14
import org.eclipse.cdt.ui.CUIPlugin;
16
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
18
import org.eclipse.jface.preference.BooleanFieldEditor;
19
import org.eclipse.jface.preference.ColorFieldEditor;
20
import org.eclipse.jface.preference.FieldEditorPreferencePage;
21
import org.eclipse.jface.preference.IPreferenceStore;
22
import org.eclipse.jface.preference.IntegerFieldEditor;
23
import org.eclipse.jface.preference.PreferenceConverter;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.graphics.RGB;
26
import org.eclipse.swt.layout.GridData;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Label;
29
import org.eclipse.ui.IWorkbench;
30
import org.eclipse.ui.IWorkbenchPreferencePage;
31
import org.eclipse.ui.PlatformUI;
33
public class BuildConsolePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
35
private static final String PREF_CLEAR_CONSOLE = "clearConsole"; //$NON-NLS-1$
36
private static final String PREF_CONSOLE_ON_TOP = "consoleOnTop"; //$NON-NLS-1$
37
private static final String PREF_AUTO_OPEN_CONSOLE = "autoOpenConsole"; //$NON-NLS-1$
40
public static final String PREF_BUILDCONSOLE_FONT = "org.eclipse.cdt.ui.buildconsole.ConsoleFont"; //$NON-NLS-1$
42
public static final String PREF_BUILDCONSOLE_TAB_WIDTH = "buildConsoleTabWith"; //$NON-NLS-1$
43
public static final String PREF_BUILDCONSOLE_LINES = "buildConsoleLines"; //$NON-NLS-1$
44
public static final String PREF_BUILDCONSOLE_INFO_COLOR = "buildConsoleInfoStreamColor"; //$NON-NLS-1$
45
public static final String PREF_BUILDCONSOLE_OUTPUT_COLOR = "buildConsoleOutputStreamColor"; //$NON-NLS-1$
46
public static final String PREF_BUILDCONSOLE_ERROR_COLOR = "buildConsoleErrorStreamColor"; //$NON-NLS-1$
47
public static final String PREF_BUILDCONSOLE_BACKGROUND_COLOR = "buildConsoleBackgroundColor"; //$NON-NLS-1$
48
public static final String PREF_BUILDCONSOLE_PROBLEM_BACKGROUND_COLOR = "buildConsoleProblemBackgroundColor"; //$NON-NLS-1$
49
public static final String PREF_BUILDCONSOLE_PROBLEM_WARNING_BACKGROUND_COLOR = "buildConsoleProblemWarningBackgroundColor"; //$NON-NLS-1$
50
public static final String PREF_BUILDCONSOLE_PROBLEM_INFO_BACKGROUND_COLOR = "buildConsoleProblemInfoBackgroundColor"; //$NON-NLS-1$
51
public static final String PREF_BUILDCONSOLE_PROBLEM_HIGHLIGHTED_COLOR = "buildConsoleProblemHighlightedColor"; //$NON-NLS-1$
53
public BuildConsolePreferencePage() {
55
setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
59
public void createControl(Composite parent) {
60
super.createControl(parent);
61
PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), ICHelpContextIds.BUILD_CONSOLE_PREFERENCE_PAGE);
65
protected void createFieldEditors() {
66
Composite parent = getFieldEditorParent();
67
BooleanFieldEditor clearConsole = new BooleanFieldEditor(PREF_CLEAR_CONSOLE,
68
CUIPlugin.getResourceString("ConsolePreferencePage.clearConsole.label"), parent); //$NON-NLS-1$
69
addField(clearConsole);
71
BooleanFieldEditor autoOpenConsole = new BooleanFieldEditor(PREF_AUTO_OPEN_CONSOLE,
72
CUIPlugin.getResourceString("ConsolePreferencePage.autoOpenConsole.label"), parent); //$NON-NLS-1$
73
addField(autoOpenConsole);
74
BooleanFieldEditor consoleOnTop = new BooleanFieldEditor(PREF_CONSOLE_ON_TOP,
75
CUIPlugin.getResourceString("ConsolePreferencePage.consoleOnTop.label"), parent); //$NON-NLS-1$
76
addField(consoleOnTop);
78
IntegerFieldEditor buildCount = new IntegerFieldEditor(PREF_BUILDCONSOLE_LINES,
79
CUIPlugin.getResourceString("ConsolePreferencePage.consoleLines.label"), parent); //$NON-NLS-1$
80
buildCount.setErrorMessage(CUIPlugin.getResourceString("ConsolePreferencePage.consoleLines.errorMessage")); //$NON-NLS-1$
81
buildCount.setValidRange(10, Integer.MAX_VALUE);
84
IntegerFieldEditor tabSize = new IntegerFieldEditor(PREF_BUILDCONSOLE_TAB_WIDTH,
85
CUIPlugin.getResourceString("ConsolePreferencePage.tabWidth.label"), parent); //$NON-NLS-1$
87
tabSize.setValidRange(1, 100);
88
tabSize.setErrorMessage(CUIPlugin.getResourceString("ConsolePreferencePage.tabWidth.errorMessage")); //$NON-NLS-1$
90
createLabel(parent, CUIPlugin.getResourceString("ConsolePreferencePage.colorSettings.label")); //$NON-NLS-1$
92
addField(createColorFieldEditor(PREF_BUILDCONSOLE_OUTPUT_COLOR,
93
CUIPlugin.getResourceString("ConsolePreferencePage.outputColor.label"), parent)); //$NON-NLS-1$
94
addField(createColorFieldEditor(PREF_BUILDCONSOLE_INFO_COLOR,
95
CUIPlugin.getResourceString("ConsolePreferencePage.infoColor.label"), parent)); //$NON-NLS-1$
96
addField(createColorFieldEditor(PREF_BUILDCONSOLE_ERROR_COLOR,
97
CUIPlugin.getResourceString("ConsolePreferencePage.errorColor.label"), parent)); //$NON-NLS-1$
98
addField(createColorFieldEditor(PREF_BUILDCONSOLE_BACKGROUND_COLOR,
99
CUIPlugin.getResourceString("ConsolePreferencePage.backgroundColor.label"), parent)); //$NON-NLS-1$
100
addField(createColorFieldEditor(PREF_BUILDCONSOLE_PROBLEM_BACKGROUND_COLOR,
101
CUIPlugin.getResourceString("ConsolePreferencePage.problemBackgroundColor.label"), parent)); //$NON-NLS-1$
102
addField(createColorFieldEditor(PREF_BUILDCONSOLE_PROBLEM_WARNING_BACKGROUND_COLOR,
103
CUIPlugin.getResourceString("ConsolePreferencePage.problemWarningBackgroundColor.label"), parent)); //$NON-NLS-1$
104
addField(createColorFieldEditor(PREF_BUILDCONSOLE_PROBLEM_INFO_BACKGROUND_COLOR,
105
CUIPlugin.getResourceString("ConsolePreferencePage.problemInfoBackgroundColor.label"), parent)); //$NON-NLS-1$
106
addField(createColorFieldEditor(PREF_BUILDCONSOLE_PROBLEM_HIGHLIGHTED_COLOR,
107
CUIPlugin.getResourceString("ConsolePreferencePage.problemHighlightedColor.label"), parent)); //$NON-NLS-1$
110
private Label createLabel(Composite parent, String text) {
111
Label label = new Label(parent, SWT.LEFT);
113
GridData data = new GridData();
114
data.horizontalSpan = 2;
115
data.horizontalAlignment = GridData.FILL;
116
label.setLayoutData(data);
120
* Creates a new color field editor.
122
private ColorFieldEditor createColorFieldEditor(String preferenceName, String label, Composite parent) {
123
ColorFieldEditor editor = new ColorFieldEditor(preferenceName, label, parent);
124
editor.setPage(this);
125
editor.setPreferenceStore(getPreferenceStore());
130
* Returns the current preference setting if the build console should be
131
* cleared before each build.
133
public static boolean isClearBuildConsole() {
134
return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PREF_CLEAR_CONSOLE);
136
public static boolean isAutoOpenConsole() {
137
return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PREF_AUTO_OPEN_CONSOLE);
140
public static boolean isConsoleOnTop() {
141
return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PREF_CONSOLE_ON_TOP);
144
public static int buildConsoleLines() {
145
return CUIPlugin.getDefault().getPreferenceStore().getInt(PREF_BUILDCONSOLE_LINES);
148
public void init(IWorkbench workbench) {
151
public static void initDefaults(IPreferenceStore prefs) {
152
prefs.setDefault(PREF_CLEAR_CONSOLE, true);
153
prefs.setDefault(PREF_AUTO_OPEN_CONSOLE, true);
154
prefs.setDefault(PREF_CONSOLE_ON_TOP, false);
155
prefs.setDefault(PREF_BUILDCONSOLE_LINES, 500);
156
prefs.setDefault(PREF_BUILDCONSOLE_TAB_WIDTH, 4);
157
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_OUTPUT_COLOR, new RGB(0, 0, 0));
158
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_INFO_COLOR, new RGB(0, 0, 255));
159
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_ERROR_COLOR, new RGB(255, 0, 0));
160
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_BACKGROUND_COLOR, new RGB(255, 255, 255));
161
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_PROBLEM_BACKGROUND_COLOR, new RGB(254, 231, 224));
162
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_PROBLEM_WARNING_BACKGROUND_COLOR, new RGB(254, 243, 218));
163
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_PROBLEM_INFO_BACKGROUND_COLOR, new RGB(244, 247, 254));
164
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_PROBLEM_HIGHLIGHTED_COLOR, new RGB(255, 0, 0));