1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 395976: NPE in BuildConsoleViewer when widget is already disposed

This commit is contained in:
Andrew Gvozdev 2012-12-06 14:33:52 -05:00
parent 2c0a41d671
commit d60a5ef6d1

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2010 QNX Software Systems and others. * Copyright (c) 2002, 2012 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -48,21 +48,9 @@ public class BuildConsoleViewer extends TextViewer
* Internal document listener. * Internal document listener.
*/ */
class InternalDocumentListener implements IDocumentListener { class InternalDocumentListener implements IDocumentListener {
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
*/
@Override @Override
public void documentAboutToBeChanged(DocumentEvent e) { public void documentAboutToBeChanged(DocumentEvent e) {
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
*/
@Override @Override
public void documentChanged(DocumentEvent e) { public void documentChanged(DocumentEvent e) {
revealEndOfDocument(); revealEndOfDocument();
@ -97,13 +85,15 @@ public class BuildConsoleViewer extends TextViewer
public BuildConsoleViewer(Composite parent) { public BuildConsoleViewer(Composite parent) {
super(parent, getSWTStyles()); super(parent, getSWTStyles());
StyledText styledText = getTextWidget(); StyledText styledText = getTextWidget();
styledText.addLineStyleListener(this); if (styledText != null) {
styledText.addLineBackgroundListener(this); styledText.addLineStyleListener(this);
styledText.addMouseTrackListener(this); styledText.addLineBackgroundListener(this);
styledText.setFont(parent.getFont()); styledText.addMouseTrackListener(this);
styledText.setDoubleClickEnabled(true); styledText.setFont(parent.getFont());
styledText.setEditable(false); styledText.setDoubleClickEnabled(true);
styledText.setWordWrap(true); styledText.setEditable(false);
styledText.setWordWrap(true);
}
} }
/** /**
@ -119,30 +109,27 @@ public class BuildConsoleViewer extends TextViewer
*/ */
protected void revealEndOfDocument() { protected void revealEndOfDocument() {
if (isAutoScroll()) { if (isAutoScroll()) {
IDocument doc = getDocument(); StyledText widget = getTextWidget();
int lines = doc.getNumberOfLines(); if (widget != null) {
try { IDocument doc = getDocument();
// lines are 0-based int lines = doc.getNumberOfLines();
int lineStartOffset = doc.getLineOffset(lines - 1); try {
StyledText widget = getTextWidget(); // lines are 0-based
if (lineStartOffset > 0) { int lineStartOffset = doc.getLineOffset(lines - 1);
widget.setCaretOffset(lineStartOffset); if (lineStartOffset > 0) {
widget.showSelection(); widget.setCaretOffset(lineStartOffset);
widget.showSelection();
}
int lineEndOffset = lineStartOffset + doc.getLineLength(lines - 1);
if (lineEndOffset > 0) {
widget.setCaretOffset(lineEndOffset);
}
} catch (BadLocationException e) {
} }
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)
*/
@Override @Override
public void setDocument(IDocument doc) { public void setDocument(IDocument doc) {
IDocument oldDoc = getDocument(); IDocument oldDoc = getDocument();
@ -165,11 +152,6 @@ public class BuildConsoleViewer extends TextViewer
} }
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.custom.LineStyleListener#lineGetStyle(org.eclipse.swt.custom.LineStyleEvent)
*/
@Override @Override
public void lineGetStyle(LineStyleEvent event) { public void lineGetStyle(LineStyleEvent event) {
IDocument document = getDocument(); IDocument document = getDocument();
@ -202,38 +184,46 @@ public class BuildConsoleViewer extends TextViewer
} }
public void selectPartition(BuildConsolePartitioner partitioner, BuildConsolePartition p) { public void selectPartition(BuildConsolePartitioner partitioner, BuildConsolePartition p) {
try { StyledText st = getTextWidget();
int start = partitioner.getDocument().getLineOfOffset(p.getOffset()); if (st != null) {
int end = partitioner.getDocument().getLineOfOffset(p.getOffset()+p.getLength()-1); try {
int start = partitioner.getDocument().getLineOfOffset(p.getOffset());
if ( fAutoScroll ) { int end = partitioner.getDocument().getLineOfOffset(p.getOffset()+p.getLength()-1);
// Check if area around this line is visible, scroll if needed
int top = getTopIndex(); if ( fAutoScroll ) {
int bottom = getBottomIndex(); // Check if area around this line is visible, scroll if needed
if ( start < top + 1 ) { int top = getTopIndex();
setTopIndex(start - 1 > 0 ? start - 1 : 0); int bottom = getBottomIndex();
} else if ( end > bottom -1 ) { if ( start < top + 1 ) {
setTopIndex(top + start - bottom + 1); setTopIndex(start - 1 > 0 ? start - 1 : 0);
} else if ( end > bottom -1 ) {
setTopIndex(top + start - bottom + 1);
}
} }
// Select line
st.redrawRange(0, partitioner.getDocument().getLength(), true);
} catch (BadLocationException e) {
CUIPlugin.log(e);
} }
// Select line
StyledText st = getTextWidget();
st.redrawRange(0, partitioner.getDocument().getLength(), true);
} catch (BadLocationException e) {
CUIPlugin.log(e);
} }
} }
@Override @Override
public void mouseEnter(MouseEvent e) { public void mouseEnter(MouseEvent e) {
getTextWidget().addMouseListener(this); StyledText widget = getTextWidget();
if (widget != null) {
widget.addMouseListener(this);
}
} }
@Override @Override
public void mouseExit(MouseEvent e) { public void mouseExit(MouseEvent e) {
getTextWidget().removeMouseListener(this); StyledText widget = getTextWidget();
if (widget != null) {
widget.removeMouseListener(this);
}
} }
@Override @Override
@ -242,12 +232,15 @@ public class BuildConsoleViewer extends TextViewer
@Override @Override
public void mouseDoubleClick(MouseEvent e) { public void mouseDoubleClick(MouseEvent e) {
int offset = -1; StyledText widget = getTextWidget();
try { if (widget != null) {
Point p = new Point(e.x, e.y); int offset = -1;
offset = getTextWidget().getOffsetAtLocation(p); try {
BuildConsole.getCurrentPage().moveToError(offset); Point p = new Point(e.x, e.y);
} catch (IllegalArgumentException ex) { offset = widget.getOffsetAtLocation(p);
BuildConsole.getCurrentPage().moveToError(offset);
} catch (IllegalArgumentException ex) {
}
} }
} }