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
|
* 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,6 +85,7 @@ 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();
|
||||||
|
if (styledText != null) {
|
||||||
styledText.addLineStyleListener(this);
|
styledText.addLineStyleListener(this);
|
||||||
styledText.addLineBackgroundListener(this);
|
styledText.addLineBackgroundListener(this);
|
||||||
styledText.addMouseTrackListener(this);
|
styledText.addMouseTrackListener(this);
|
||||||
|
@ -105,6 +94,7 @@ public class BuildConsoleViewer extends TextViewer
|
||||||
styledText.setEditable(false);
|
styledText.setEditable(false);
|
||||||
styledText.setWordWrap(true);
|
styledText.setWordWrap(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the SWT style flags used when instantiating this viewer
|
* Returns the SWT style flags used when instantiating this viewer
|
||||||
|
@ -119,12 +109,13 @@ public class BuildConsoleViewer extends TextViewer
|
||||||
*/
|
*/
|
||||||
protected void revealEndOfDocument() {
|
protected void revealEndOfDocument() {
|
||||||
if (isAutoScroll()) {
|
if (isAutoScroll()) {
|
||||||
|
StyledText widget = getTextWidget();
|
||||||
|
if (widget != null) {
|
||||||
IDocument doc = getDocument();
|
IDocument doc = getDocument();
|
||||||
int lines = doc.getNumberOfLines();
|
int lines = doc.getNumberOfLines();
|
||||||
try {
|
try {
|
||||||
// lines are 0-based
|
// lines are 0-based
|
||||||
int lineStartOffset = doc.getLineOffset(lines - 1);
|
int lineStartOffset = doc.getLineOffset(lines - 1);
|
||||||
StyledText widget = getTextWidget();
|
|
||||||
if (lineStartOffset > 0) {
|
if (lineStartOffset > 0) {
|
||||||
widget.setCaretOffset(lineStartOffset);
|
widget.setCaretOffset(lineStartOffset);
|
||||||
widget.showSelection();
|
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
|
@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,6 +184,8 @@ public class BuildConsoleViewer extends TextViewer
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectPartition(BuildConsolePartitioner partitioner, BuildConsolePartition p) {
|
public void selectPartition(BuildConsolePartitioner partitioner, BuildConsolePartition p) {
|
||||||
|
StyledText st = getTextWidget();
|
||||||
|
if (st != null) {
|
||||||
try {
|
try {
|
||||||
int start = partitioner.getDocument().getLineOfOffset(p.getOffset());
|
int start = partitioner.getDocument().getLineOfOffset(p.getOffset());
|
||||||
int end = partitioner.getDocument().getLineOfOffset(p.getOffset()+p.getLength()-1);
|
int end = partitioner.getDocument().getLineOfOffset(p.getOffset()+p.getLength()-1);
|
||||||
|
@ -218,22 +202,28 @@ public class BuildConsoleViewer extends TextViewer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select line
|
// Select line
|
||||||
StyledText st = getTextWidget();
|
|
||||||
st.redrawRange(0, partitioner.getDocument().getLength(), true);
|
st.redrawRange(0, partitioner.getDocument().getLength(), true);
|
||||||
|
|
||||||
} catch (BadLocationException e) {
|
} catch (BadLocationException e) {
|
||||||
CUIPlugin.log(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,14 +232,17 @@ public class BuildConsoleViewer extends TextViewer
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDoubleClick(MouseEvent e) {
|
public void mouseDoubleClick(MouseEvent e) {
|
||||||
|
StyledText widget = getTextWidget();
|
||||||
|
if (widget != null) {
|
||||||
int offset = -1;
|
int offset = -1;
|
||||||
try {
|
try {
|
||||||
Point p = new Point(e.x, e.y);
|
Point p = new Point(e.x, e.y);
|
||||||
offset = getTextWidget().getOffsetAtLocation(p);
|
offset = widget.getOffsetAtLocation(p);
|
||||||
BuildConsole.getCurrentPage().moveToError(offset);
|
BuildConsole.getCurrentPage().moveToError(offset);
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDown(MouseEvent e) {
|
public void mouseDown(MouseEvent e) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue