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:
parent
2c0a41d671
commit
d60a5ef6d1
1 changed files with 64 additions and 71 deletions
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -48,21 +48,9 @@ public class BuildConsoleViewer extends TextViewer
|
|||
* Internal document listener.
|
||||
*/
|
||||
class InternalDocumentListener implements IDocumentListener {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
|
||||
*/
|
||||
@Override
|
||||
public void documentAboutToBeChanged(DocumentEvent e) {
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
|
||||
*/
|
||||
@Override
|
||||
public void documentChanged(DocumentEvent e) {
|
||||
revealEndOfDocument();
|
||||
|
@ -97,6 +85,7 @@ public class BuildConsoleViewer extends TextViewer
|
|||
public BuildConsoleViewer(Composite parent) {
|
||||
super(parent, getSWTStyles());
|
||||
StyledText styledText = getTextWidget();
|
||||
if (styledText != null) {
|
||||
styledText.addLineStyleListener(this);
|
||||
styledText.addLineBackgroundListener(this);
|
||||
styledText.addMouseTrackListener(this);
|
||||
|
@ -105,6 +94,7 @@ public class BuildConsoleViewer extends TextViewer
|
|||
styledText.setEditable(false);
|
||||
styledText.setWordWrap(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SWT style flags used when instantiating this viewer
|
||||
|
@ -119,12 +109,13 @@ public class BuildConsoleViewer extends TextViewer
|
|||
*/
|
||||
protected void revealEndOfDocument() {
|
||||
if (isAutoScroll()) {
|
||||
StyledText widget = getTextWidget();
|
||||
if (widget != null) {
|
||||
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();
|
||||
|
@ -137,12 +128,8 @@ public class BuildConsoleViewer extends TextViewer
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.text.ITextViewer#setDocument(org.eclipse.jface.text.IDocument)
|
||||
*/
|
||||
@Override
|
||||
public void setDocument(IDocument doc) {
|
||||
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
|
||||
public void lineGetStyle(LineStyleEvent event) {
|
||||
IDocument document = getDocument();
|
||||
|
@ -202,6 +184,8 @@ public class BuildConsoleViewer extends TextViewer
|
|||
}
|
||||
|
||||
public void selectPartition(BuildConsolePartitioner partitioner, BuildConsolePartition p) {
|
||||
StyledText st = getTextWidget();
|
||||
if (st != null) {
|
||||
try {
|
||||
int start = partitioner.getDocument().getLineOfOffset(p.getOffset());
|
||||
int end = partitioner.getDocument().getLineOfOffset(p.getOffset()+p.getLength()-1);
|
||||
|
@ -218,22 +202,28 @@ public class BuildConsoleViewer extends TextViewer
|
|||
}
|
||||
|
||||
// Select line
|
||||
StyledText st = getTextWidget();
|
||||
st.redrawRange(0, partitioner.getDocument().getLength(), true);
|
||||
|
||||
} catch (BadLocationException e) {
|
||||
CUIPlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEnter(MouseEvent e) {
|
||||
getTextWidget().addMouseListener(this);
|
||||
StyledText widget = getTextWidget();
|
||||
if (widget != null) {
|
||||
widget.addMouseListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExit(MouseEvent e) {
|
||||
getTextWidget().removeMouseListener(this);
|
||||
StyledText widget = getTextWidget();
|
||||
if (widget != null) {
|
||||
widget.removeMouseListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -242,14 +232,17 @@ public class BuildConsoleViewer extends TextViewer
|
|||
|
||||
@Override
|
||||
public void mouseDoubleClick(MouseEvent e) {
|
||||
StyledText widget = getTextWidget();
|
||||
if (widget != null) {
|
||||
int offset = -1;
|
||||
try {
|
||||
Point p = new Point(e.x, e.y);
|
||||
offset = getTextWidget().getOffsetAtLocation(p);
|
||||
offset = widget.getOffsetAtLocation(p);
|
||||
BuildConsole.getCurrentPage().moveToError(offset);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDown(MouseEvent e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue