1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 21:05:37 +02:00

bug 307211: Different colors for info, warning and errors in the build console

This commit is contained in:
Andrew Gvozdev 2010-09-16 22:28:33 +00:00
parent e5a1e9060f
commit c5b4c65418
7 changed files with 125 additions and 40 deletions

View file

@ -29,7 +29,9 @@ ConsolePreferencePage.outputColor.label=Output text color
ConsolePreferencePage.infoColor.label=Information message text color
ConsolePreferencePage.errorColor.label=Error message text color
ConsolePreferencePage.backgroundColor.label=Background color
ConsolePreferencePage.problemBackgroundColor.label=Background color for build problems
ConsolePreferencePage.problemBackgroundColor.label=Background color for build errors
ConsolePreferencePage.problemWarningBackgroundColor.label=Background color for build warnings
ConsolePreferencePage.problemInfoBackgroundColor.label=Background color for build informational messages
ConsolePreferencePage.problemHighlightedColor.label=Highlighting color for build problems
# ------- Project/Prefernces/Wizards COnfiguration blocks -------

View file

@ -63,20 +63,43 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
public static final String KEY_LOG_LOCATION = "logLocation"; //$NON-NLS-1$
public static final boolean CONSOLE_KEEP_LOG_DEFAULT = true;
ListenerList listeners = new ListenerList();
BuildConsole fConsole;
private ListenerList listeners = new ListenerList();
private BuildConsole fConsole;
private Map<IProject, BuildConsolePartitioner> fConsoleMap = new HashMap<IProject, BuildConsolePartitioner>();
Color infoColor, outputColor, errorColor, backgroundColor, problemHighlightedColor, problemBackgroundColor;
private Color infoColor;
private Color outputColor;
private Color errorColor;
private Color backgroundColor;
private Color problemHighlightedColor;
private Color problemErrorBackgroundColor;
private Color problemInfoBackgroundColor;
private Color problemWarningBackgroundColor;
public Color getProblemHighlightedColor() {
return problemHighlightedColor;
}
/**
* This function returns background color for errors only now
*/
public Color getProblemBackgroundColor() {
return problemBackgroundColor;
return problemErrorBackgroundColor;
}
BuildConsoleStreamDecorator infoStream, outputStream, errorStream;
String fName, fContextMenuId;
public Color getWarningBackgroundColor() {
return problemWarningBackgroundColor;
}
public Color getInfoBackgroundColor() {
return problemInfoBackgroundColor;
}
private BuildConsoleStreamDecorator infoStream;
private BuildConsoleStreamDecorator outputStream;
private BuildConsoleStreamDecorator errorStream;
private String fName;
private String fContextMenuId;
static public final int BUILD_STREAM_TYPE_INFO = 0;
static public final int BUILD_STREAM_TYPE_OUTPUT = 1;
@ -180,7 +203,9 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
outputColor.dispose();
errorColor.dispose();
backgroundColor.dispose();
problemBackgroundColor.dispose();
problemErrorBackgroundColor.dispose();
problemWarningBackgroundColor.dispose();
problemInfoBackgroundColor.dispose();
problemHighlightedColor.dispose();
}
ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new org.eclipse.ui.console.IConsole[]{fConsole});
@ -229,7 +254,9 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
backgroundColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_BACKGROUND_COLOR);
fConsole.setBackground(backgroundColor);
problemHighlightedColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_PROBLEM_HIGHLIGHTED_COLOR);
problemBackgroundColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_PROBLEM_BACKGROUND_COLOR);
problemErrorBackgroundColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_PROBLEM_BACKGROUND_COLOR);
problemWarningBackgroundColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_PROBLEM_WARNING_BACKGROUND_COLOR);
problemInfoBackgroundColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_PROBLEM_INFO_BACKGROUND_COLOR);
}
});
CUIPlugin.getWorkspace().addResourceChangeListener(this);
@ -271,8 +298,18 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
redrawTextViewer();
} else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_PROBLEM_BACKGROUND_COLOR)) {
Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_PROBLEM_BACKGROUND_COLOR);
problemBackgroundColor.dispose();
problemBackgroundColor = newColor;
problemErrorBackgroundColor.dispose();
problemErrorBackgroundColor = newColor;
redrawTextViewer();
} else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_PROBLEM_WARNING_BACKGROUND_COLOR)) {
Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_PROBLEM_WARNING_BACKGROUND_COLOR);
problemWarningBackgroundColor.dispose();
problemWarningBackgroundColor = newColor;
redrawTextViewer();
} else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_PROBLEM_INFO_BACKGROUND_COLOR)) {
Color newColor = createColor(CUIPlugin.getStandardDisplay(), BuildConsolePreferencePage.PREF_BUILDCONSOLE_PROBLEM_INFO_BACKGROUND_COLOR);
problemInfoBackgroundColor.dispose();
problemInfoBackgroundColor = newColor;
redrawTextViewer();
}
}

View file

@ -26,8 +26,10 @@ public class BuildConsolePartition extends TypedRegion {
/** Partition type */
public static final String CONSOLE_PARTITION_TYPE = CUIPlugin.getPluginId() + ".CONSOLE_PARTITION_TYPE"; //$NON-NLS-1$
/** Partition type to report errors in console */
/** Partition types to report build problems in the console */
public static final String ERROR_PARTITION_TYPE = CUIPlugin.getPluginId() + ".ERROR_PARTITION_TYPE"; //$NON-NLS-1$
public static final String INFO_PARTITION_TYPE = CUIPlugin.getPluginId() + ".INFO_PARTITION_TYPE"; //$NON-NLS-1$
public static final String WARNING_PARTITION_TYPE = CUIPlugin.getPluginId() + ".WARNING_PARTITION_TYPE"; //$NON-NLS-1$
public BuildConsolePartition(BuildConsoleStreamDecorator stream, int offset, int length, String type) {
super(offset, length, type);
@ -77,14 +79,17 @@ public class BuildConsolePartition extends TypedRegion {
*/
public boolean canBeCombinedWith(BuildConsolePartition partition) {
// Error partitions never can be combined together
if ( getType() == ERROR_PARTITION_TYPE ) return false;
String type = getType();
if (isProblemPartitionType(type)) {
return false;
}
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 getStream() != null && overlap && getType().equals(partition.getType()) && getStream().equals(partition.getStream());
return getStream() != null && overlap && type.equals(partition.getType()) && getStream().equals(partition.getStream());
}
/**
@ -117,4 +122,12 @@ public class BuildConsolePartition extends TypedRegion {
public ProblemMarkerInfo getMarker() {
return fMarker;
}
public static boolean isProblemPartitionType(String type) {
return type==BuildConsolePartition.ERROR_PARTITION_TYPE
|| type==BuildConsolePartition.WARNING_PARTITION_TYPE
|| type==BuildConsolePartition.INFO_PARTITION_TYPE;
}
}

View file

@ -23,6 +23,7 @@ import java.util.Vector;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
@ -327,7 +328,8 @@ public class BuildConsolePartitioner
}
private void addStreamEntryToDocument(StreamEntry entry) throws BadLocationException {
if ( entry.getMarker() == null ) {
ProblemMarkerInfo marker = entry.getMarker();
if (marker==null) {
// It is plain unmarkered console output
addPartition(new BuildConsolePartition(fLastStream,
fDocument.getLength(),
@ -336,10 +338,18 @@ public class BuildConsolePartitioner
} else {
// this text line in entry is markered with ProblemMarkerInfo,
// create special partition for it.
String errorPartitionType;
if (marker.severity==IMarker.SEVERITY_INFO) {
errorPartitionType = BuildConsolePartition.INFO_PARTITION_TYPE;
} else if (marker.severity==IMarker.SEVERITY_WARNING) {
errorPartitionType = BuildConsolePartition.WARNING_PARTITION_TYPE;
} else {
errorPartitionType = BuildConsolePartition.ERROR_PARTITION_TYPE;
}
addPartition(new BuildConsolePartition(fLastStream,
fDocument.getLength(),
entry.getText().length(),
BuildConsolePartition.ERROR_PARTITION_TYPE, entry.getMarker()));
errorPartitionType, marker));
}
fDocument.replace(fDocument.getLength(), 0, entry.getText());
}
@ -479,21 +489,21 @@ public class BuildConsolePartitioner
ITypedRegion newPartition = null;
int offset = region.getOffset();
String type = messageConsolePartition.getType();
if (offset < overflow) {
int endOffset = offset + region.getLength();
if (endOffset < overflow ||
messageConsolePartition.getType() == BuildConsolePartition.ERROR_PARTITION_TYPE ) {
if (endOffset < overflow || BuildConsolePartition.isProblemPartitionType(type)) {
// remove partition,
// partitions with problem markers can't be split - remove them too
} else {
// split partition
int length = endOffset - overflow;
newPartition = messageConsolePartition.createNewPartition(0, length, messageConsolePartition.getType());
newPartition = messageConsolePartition.createNewPartition(0, length, type);
}
} else {
// modify partition offset
newPartition = messageConsolePartition.createNewPartition(messageConsolePartition.getOffset()
- overflow, messageConsolePartition.getLength(), messageConsolePartition.getType());
offset = messageConsolePartition.getOffset() - overflow;
newPartition = messageConsolePartition.createNewPartition(offset, messageConsolePartition.getLength(), type);
}
if (newPartition != null) {
newParitions.add(newPartition);
@ -572,31 +582,35 @@ public class BuildConsolePartitioner
return new BuildOutputStream(this, fManager.getStreamDecorator(BuildConsoleManager.BUILD_STREAM_TYPE_ERROR));
}
/** This method is useful for future debugging and bugfixing */
@SuppressWarnings("unused")
/** This method is useful for future debugging and bug-fixing */
@SuppressWarnings({ "unused", "nls" })
private void printDocumentPartitioning() {
System.out.println("Document partitioning: "); //$NON-NLS-1$
System.out.println("Document partitioning: ");
for (ITypedRegion tr : fPartitions) {
BuildConsolePartition p = (BuildConsolePartition) tr;
int start = p.getOffset();
int end = p.getOffset() + p.getLength();
String text;
String isError = "U"; //$NON-NLS-1$
if (p.getType() == BuildConsolePartition.ERROR_PARTITION_TYPE) {
isError = "E"; //$NON-NLS-1$
} else if (p.getType() == BuildConsolePartition.CONSOLE_PARTITION_TYPE) {
isError = "C"; //$NON-NLS-1$
String isError = "U";
String type = p.getType();
if (type == BuildConsolePartition.ERROR_PARTITION_TYPE) {
isError = "E";
} else if (type == BuildConsolePartition.WARNING_PARTITION_TYPE) {
isError = "W";
} else if (type == BuildConsolePartition.INFO_PARTITION_TYPE) {
isError = "I";
} else if (type == BuildConsolePartition.CONSOLE_PARTITION_TYPE) {
isError = "C";
}
try {
text = fDocument.get(p.getOffset(), p.getLength());
} catch (BadLocationException e) {
text = "N/A"; //$NON-NLS-1$
text = "N/A";
}
if (text.endsWith("\n")) { //$NON-NLS-1$
if (text.endsWith("\n")) {
text = text.substring(0, text.length() - 1);
}
System.out.println(" " + isError + " " + start + "-" + end + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
":[" + text + "]"); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println(" " + isError + " " + start + "-" + end + ":[" + text + "]");
}
}

View file

@ -258,8 +258,15 @@ public class BuildConsoleViewer extends TextViewer
BuildConsolePartition partition = (BuildConsolePartition) partitioner.getPartition(event.lineOffset);
// Set background for error partitions
if ( partition != null && partition.getType() == BuildConsolePartition.ERROR_PARTITION_TYPE ) {
if (partition!=null) {
String type = partition.getType();
if (type==BuildConsolePartition.ERROR_PARTITION_TYPE) {
event.lineBackground = partitioner.fManager.getProblemBackgroundColor();
} else if (type==BuildConsolePartition.WARNING_PARTITION_TYPE) {
event.lineBackground = partitioner.fManager.getWarningBackgroundColor();
} else if (type==BuildConsolePartition.INFO_PARTITION_TYPE) {
event.lineBackground = partitioner.fManager.getInfoBackgroundColor();
}
}
}

View file

@ -42,7 +42,8 @@ class DocumentMarkerManager {
if ( i == fPartitioner.fPartitions.size() ) {
i = 0;
}
if ( fPartitioner.fPartitions.get(i).getType() == BuildConsolePartition.ERROR_PARTITION_TYPE ) {
String type = fPartitioner.fPartitions.get(i).getType();
if (BuildConsolePartition.isProblemPartitionType(type)) {
highlightedPartitionIndex = i;
return;
} else {
@ -64,7 +65,8 @@ class DocumentMarkerManager {
if ( i == -1 ) {
i = fPartitioner.fPartitions.size() - 1;
}
if ( fPartitioner.fPartitions.get(i).getType() == BuildConsolePartition.ERROR_PARTITION_TYPE ) {
String type = fPartitioner.fPartitions.get(i).getType();
if (BuildConsolePartition.isProblemPartitionType(type)) {
highlightedPartitionIndex = i;
return;
} else {
@ -75,7 +77,8 @@ class DocumentMarkerManager {
void moveToFirstError() {
for (int i=0; i<fPartitioner.fPartitions.size(); i++) {
if ( fPartitioner.fPartitions.get(i).getType() == BuildConsolePartition.ERROR_PARTITION_TYPE ) {
String type = fPartitioner.fPartitions.get(i).getType();
if (BuildConsolePartition.isProblemPartitionType(type)) {
highlightedPartitionIndex = i;
return;
}
@ -86,7 +89,8 @@ class DocumentMarkerManager {
/** Returns true if offset points to error partition and false otherwise */
boolean moveToErrorByOffset(int offset) {
ITypedRegion p = fPartitioner.getPartition(offset);
if ( BuildConsolePartition.ERROR_PARTITION_TYPE.equals(p.getType()) ) {
String type = p.getType();
if (BuildConsolePartition.isProblemPartitionType(type)) {
highlightedPartitionIndex = fPartitioner.fPartitions.indexOf(p);
return true;
}

View file

@ -42,6 +42,8 @@ public class BuildConsolePreferencePage extends FieldEditorPreferencePage implem
public static final String PREF_BUILDCONSOLE_ERROR_COLOR = "buildConsoleErrorStreamColor"; //$NON-NLS-1$
public static final String PREF_BUILDCONSOLE_BACKGROUND_COLOR = "buildConsoleBackgroundColor"; //$NON-NLS-1$
public static final String PREF_BUILDCONSOLE_PROBLEM_BACKGROUND_COLOR = "buildConsoleProblemBackgroundColor"; //$NON-NLS-1$
public static final String PREF_BUILDCONSOLE_PROBLEM_WARNING_BACKGROUND_COLOR = "buildConsoleProblemWarningBackgroundColor"; //$NON-NLS-1$
public static final String PREF_BUILDCONSOLE_PROBLEM_INFO_BACKGROUND_COLOR = "buildConsoleProblemInfoBackgroundColor"; //$NON-NLS-1$
public static final String PREF_BUILDCONSOLE_PROBLEM_HIGHLIGHTED_COLOR = "buildConsoleProblemHighlightedColor"; //$NON-NLS-1$
public BuildConsolePreferencePage() {
@ -87,6 +89,10 @@ public class BuildConsolePreferencePage extends FieldEditorPreferencePage implem
CUIPlugin.getResourceString("ConsolePreferencePage.backgroundColor.label"), parent)); //$NON-NLS-1$
addField(createColorFieldEditor(PREF_BUILDCONSOLE_PROBLEM_BACKGROUND_COLOR,
CUIPlugin.getResourceString("ConsolePreferencePage.problemBackgroundColor.label"), parent)); //$NON-NLS-1$
addField(createColorFieldEditor(PREF_BUILDCONSOLE_PROBLEM_WARNING_BACKGROUND_COLOR,
CUIPlugin.getResourceString("ConsolePreferencePage.problemWarningBackgroundColor.label"), parent)); //$NON-NLS-1$
addField(createColorFieldEditor(PREF_BUILDCONSOLE_PROBLEM_INFO_BACKGROUND_COLOR,
CUIPlugin.getResourceString("ConsolePreferencePage.problemInfoBackgroundColor.label"), parent)); //$NON-NLS-1$
addField(createColorFieldEditor(PREF_BUILDCONSOLE_PROBLEM_HIGHLIGHTED_COLOR,
CUIPlugin.getResourceString("ConsolePreferencePage.problemHighlightedColor.label"), parent)); //$NON-NLS-1$
}
@ -143,6 +149,8 @@ public class BuildConsolePreferencePage extends FieldEditorPreferencePage implem
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_ERROR_COLOR, new RGB(255, 0, 0));
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_BACKGROUND_COLOR, new RGB(255, 255, 255));
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_PROBLEM_BACKGROUND_COLOR, new RGB(254, 231, 224));
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_PROBLEM_WARNING_BACKGROUND_COLOR, new RGB(254, 243, 218));
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_PROBLEM_INFO_BACKGROUND_COLOR, new RGB(244, 247, 254));
PreferenceConverter.setDefault(prefs, PREF_BUILDCONSOLE_PROBLEM_HIGHLIGHTED_COLOR, new RGB(255, 0, 0));
}