mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
bug 205443: [terminal] Workbench terminal view refresh problem between perspectives
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205443
This commit is contained in:
parent
a26aaa1e71
commit
384a4bd15b
5 changed files with 107 additions and 40 deletions
|
@ -148,15 +148,12 @@ public class VT100Emulator implements ControlListener {
|
||||||
else
|
else
|
||||||
text=new VT100EmulatorBackend(data);
|
text=new VT100EmulatorBackend(data);
|
||||||
|
|
||||||
text.setDimensions(24, 80);
|
// text.setDimensions(24, 80);
|
||||||
Style style=Style.getStyle("BLACK", "WHITE"); //$NON-NLS-1$ //$NON-NLS-2$
|
Style style=Style.getStyle("BLACK", "WHITE"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
text.setDefaultStyle(style);
|
text.setDefaultStyle(style);
|
||||||
text.setStyle(style);
|
text.setStyle(style);
|
||||||
}
|
}
|
||||||
public void setDimensions(int lines,int cols) {
|
public void setDimensions(int lines,int cols) {
|
||||||
// TODO allow to set the dimension in the UI and or prefs
|
|
||||||
lines=Math.max(3, lines);
|
|
||||||
cols=Math.max(10, cols);
|
|
||||||
text.setDimensions(lines, cols);
|
text.setDimensions(lines, cols);
|
||||||
ITerminalConnector telnetConnection = getConnector();
|
ITerminalConnector telnetConnection = getConnector();
|
||||||
if (telnetConnection != null) {
|
if (telnetConnection != null) {
|
||||||
|
|
|
@ -37,14 +37,12 @@ import org.eclipse.swt.events.KeyAdapter;
|
||||||
import org.eclipse.swt.events.KeyEvent;
|
import org.eclipse.swt.events.KeyEvent;
|
||||||
import org.eclipse.swt.events.KeyListener;
|
import org.eclipse.swt.events.KeyListener;
|
||||||
import org.eclipse.swt.graphics.Font;
|
import org.eclipse.swt.graphics.Font;
|
||||||
import org.eclipse.swt.graphics.Rectangle;
|
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Control;
|
import org.eclipse.swt.widgets.Control;
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.swt.widgets.Event;
|
import org.eclipse.swt.widgets.Event;
|
||||||
import org.eclipse.swt.widgets.Listener;
|
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
import org.eclipse.tm.internal.terminal.control.ICommandInputField;
|
import org.eclipse.tm.internal.terminal.control.ICommandInputField;
|
||||||
import org.eclipse.tm.internal.terminal.control.ITerminalListener;
|
import org.eclipse.tm.internal.terminal.control.ITerminalListener;
|
||||||
|
@ -114,7 +112,6 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
||||||
fConnectors=connectors;
|
fConnectors=connectors;
|
||||||
fTerminalListener=target;
|
fTerminalListener=target;
|
||||||
fTerminalModel=TerminalTextDataFactory.makeTerminalTextData();
|
fTerminalModel=TerminalTextDataFactory.makeTerminalTextData();
|
||||||
fTerminalModel.setDimensions(24, 80);
|
|
||||||
fTerminalModel.setMaxHeight(1000);
|
fTerminalModel.setMaxHeight(1000);
|
||||||
fInputStream=new PipedInputStream(8*1024);
|
fInputStream=new PipedInputStream(8*1024);
|
||||||
fTerminalText=new VT100Emulator(fTerminalModel,this,fInputStream);
|
fTerminalText=new VT100Emulator(fTerminalModel,this,fInputStream);
|
||||||
|
@ -494,11 +491,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
||||||
|
|
||||||
fCtlText.setLayoutData(new GridData(GridData.FILL_BOTH));
|
fCtlText.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||||
fCtlText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
fCtlText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||||
fCtlText.addListener(SWT.Resize, new Listener() {
|
fCtlText.addResizeHandler(new TextCanvas.ResizeListener() {
|
||||||
public void handleEvent(Event e) {
|
public void sizeChanged(int lines, int columns) {
|
||||||
Rectangle bonds=fCtlText.getClientArea();
|
|
||||||
int lines=bonds.height/fCtlText.getCellHeight();
|
|
||||||
int columns=bonds.width/fCtlText.getCellWidth();
|
|
||||||
fTerminalText.setDimensions(lines, columns);
|
fTerminalText.setDimensions(lines, columns);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,6 +39,7 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
* do not update while update is running
|
* do not update while update is running
|
||||||
*/
|
*/
|
||||||
boolean fInUpdate;
|
boolean fInUpdate;
|
||||||
|
private int fCols;
|
||||||
|
|
||||||
public AbstractTextCanvasModel(ITerminalTextDataSnapshot snapshot) {
|
public AbstractTextCanvasModel(ITerminalTextDataSnapshot snapshot) {
|
||||||
fSnapshot=snapshot;
|
fSnapshot=snapshot;
|
||||||
|
@ -72,6 +73,7 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITerminalTextDataReadOnly getTerminalText() {
|
public ITerminalTextDataReadOnly getTerminalText() {
|
||||||
return fSnapshot;
|
return fSnapshot;
|
||||||
}
|
}
|
||||||
|
@ -88,9 +90,10 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
// TODO why does hasDimensionsChanged not work??????
|
// TODO why does hasDimensionsChanged not work??????
|
||||||
// if(fSnapshot.hasDimensionsChanged())
|
// if(fSnapshot.hasDimensionsChanged())
|
||||||
// fireDimensionsChanged();
|
// fireDimensionsChanged();
|
||||||
if(fLines!=fSnapshot.getHeight()) {
|
if(fLines!=fSnapshot.getHeight() || fCols!=fSnapshot.getWidth()) {
|
||||||
fireDimensionsChanged(fSnapshot.getWidth(),fSnapshot.getHeight());
|
fireDimensionsChanged(fSnapshot.getWidth(),fSnapshot.getHeight());
|
||||||
fLines=fSnapshot.getHeight();
|
fLines=fSnapshot.getHeight();
|
||||||
|
fCols=fSnapshot.getWidth();
|
||||||
}
|
}
|
||||||
int y=fSnapshot.getFirstChangedLine();
|
int y=fSnapshot.getFirstChangedLine();
|
||||||
// has any line changed?
|
// has any line changed?
|
||||||
|
|
|
@ -24,8 +24,6 @@ import org.eclipse.swt.graphics.GC;
|
||||||
import org.eclipse.swt.graphics.Point;
|
import org.eclipse.swt.graphics.Point;
|
||||||
import org.eclipse.swt.graphics.Rectangle;
|
import org.eclipse.swt.graphics.Rectangle;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Event;
|
|
||||||
import org.eclipse.swt.widgets.Listener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cell oriented Canvas. Maintains a list of "cells".
|
* A cell oriented Canvas. Maintains a list of "cells".
|
||||||
|
@ -39,6 +37,9 @@ public class TextCanvas extends GridCanvas {
|
||||||
private boolean fScrollLock;
|
private boolean fScrollLock;
|
||||||
private Point fDraggingStart;
|
private Point fDraggingStart;
|
||||||
private Point fDraggingEnd;
|
private Point fDraggingEnd;
|
||||||
|
private ResizeListener fResizeListener;
|
||||||
|
private int fMinColumns=20;
|
||||||
|
private int fMinLines=4;
|
||||||
/**
|
/**
|
||||||
* Create a new CellCanvas with the given SWT style bits.
|
* Create a new CellCanvas with the given SWT style bits.
|
||||||
* (SWT.H_SCROLL and SWT.V_SCROLL are automatically added).
|
* (SWT.H_SCROLL and SWT.V_SCROLL are automatically added).
|
||||||
|
@ -58,6 +59,7 @@ public class TextCanvas extends GridCanvas {
|
||||||
repaintRange(col,line,width,height);
|
repaintRange(col,line,width,height);
|
||||||
}
|
}
|
||||||
public void dimensionsChanged(int cols, int rows) {
|
public void dimensionsChanged(int cols, int rows) {
|
||||||
|
setVirtualExtend(cols+getCellWidth(), rows+getCellHeight());
|
||||||
calculateGrid();
|
calculateGrid();
|
||||||
}
|
}
|
||||||
public void terminalDataChanged() {
|
public void terminalDataChanged() {
|
||||||
|
@ -66,11 +68,6 @@ public class TextCanvas extends GridCanvas {
|
||||||
scrollToEnd();
|
scrollToEnd();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addListener(SWT.Resize, new Listener() {
|
|
||||||
public void handleEvent(Event e) {
|
|
||||||
calculateGrid();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
addFocusListener(new FocusListener(){
|
addFocusListener(new FocusListener(){
|
||||||
public void focusGained(FocusEvent e) {
|
public void focusGained(FocusEvent e) {
|
||||||
fCellCanvasModel.setCursorEnabled(true);
|
fCellCanvasModel.setCursorEnabled(true);
|
||||||
|
@ -109,6 +106,8 @@ public class TextCanvas extends GridCanvas {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
serVerticalBarVisible(true);
|
||||||
|
setHorizontalBarVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSelection(Point p) {
|
void setSelection(Point p) {
|
||||||
|
@ -146,6 +145,55 @@ public class TextCanvas extends GridCanvas {
|
||||||
public ILinelRenderer getCellRenderer() {
|
public ILinelRenderer getCellRenderer() {
|
||||||
return fCellRenderer;
|
return fCellRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMinColumns() {
|
||||||
|
return fMinColumns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinColumns(int minColumns) {
|
||||||
|
fMinColumns = minColumns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinLines() {
|
||||||
|
return fMinLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinLines(int minLines) {
|
||||||
|
fMinLines = minLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onResize() {
|
||||||
|
// if(!isShowHScrollBar()) {
|
||||||
|
if(fResizeListener!=null) {
|
||||||
|
Rectangle bonds=getClientArea();
|
||||||
|
int lines=bonds.height/getCellHeight();
|
||||||
|
int columns=bonds.width/getCellWidth();
|
||||||
|
if(columns<fMinColumns) {
|
||||||
|
if(!isHorizontalBarVisble()) {
|
||||||
|
setHorizontalBarVisible(true);
|
||||||
|
bonds=getClientArea();
|
||||||
|
lines=bonds.height/getCellHeight();
|
||||||
|
}
|
||||||
|
columns=fMinColumns;
|
||||||
|
} else if(columns>=fMinColumns && isHorizontalBarVisble()) {
|
||||||
|
setHorizontalBarVisible(false);
|
||||||
|
bonds=getClientArea();
|
||||||
|
lines=bonds.height/getCellHeight();
|
||||||
|
columns=bonds.width/getCellWidth();
|
||||||
|
|
||||||
|
}
|
||||||
|
if(lines<fMinLines)
|
||||||
|
lines=fMinLines;
|
||||||
|
// if(lines>0 && columns>0 && (lines!=getRows()||columns!=getCols())) {
|
||||||
|
if(lines>0 && columns>0) {
|
||||||
|
fResizeListener.sizeChanged(lines, columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
super.onResize();
|
||||||
|
calculateGrid();
|
||||||
|
}
|
||||||
|
|
||||||
private void calculateGrid() {
|
private void calculateGrid() {
|
||||||
setVirtualExtend(getCols()*getCellWidth(),getRows()*getCellHeight());
|
setVirtualExtend(getCols()*getCellWidth(),getRows()*getCellHeight());
|
||||||
// scroll to end
|
// scroll to end
|
||||||
|
@ -154,7 +202,6 @@ public class TextCanvas extends GridCanvas {
|
||||||
scrollY(getVerticalBar());
|
scrollY(getVerticalBar());
|
||||||
scrollX(getHorizontalBar());
|
scrollX(getHorizontalBar());
|
||||||
|
|
||||||
updateViewRectangle();
|
|
||||||
getParent().layout();
|
getParent().layout();
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
@ -163,7 +210,7 @@ public class TextCanvas extends GridCanvas {
|
||||||
int y=-(getRows()*getCellHeight()-getClientArea().height);
|
int y=-(getRows()*getCellHeight()-getClientArea().height);
|
||||||
Rectangle v=getViewRectangle();
|
Rectangle v=getViewRectangle();
|
||||||
if(v.y!=y) {
|
if(v.y!=y) {
|
||||||
setVirtualOrigin(0,y);
|
setVirtualOrigin(v.x,y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,5 +263,24 @@ public class TextCanvas extends GridCanvas {
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Gets notified when the visible size of the terminal changes.
|
||||||
|
* This should update the model!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface ResizeListener {
|
||||||
|
void sizeChanged(int lines, int columns);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param listener this listener gets notified, when the size of
|
||||||
|
* the widget changed. It should change the dimensions of the underlying
|
||||||
|
* terminaldata
|
||||||
|
*/
|
||||||
|
public void addResizeHandler(ResizeListener listener) {
|
||||||
|
if(fResizeListener!=null)
|
||||||
|
throw new IllegalArgumentException("There can be at most one listener at the moment!"); //$NON-NLS-1$
|
||||||
|
fResizeListener=listener;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ public abstract class VirtualCanvas extends Canvas {
|
||||||
* prevent infinite loop in {@link #updateScrollbars()}
|
* prevent infinite loop in {@link #updateScrollbars()}
|
||||||
*/
|
*/
|
||||||
private boolean fInUpdateScrollbars;
|
private boolean fInUpdateScrollbars;
|
||||||
|
|
||||||
public VirtualCanvas(Composite parent, int style) {
|
public VirtualCanvas(Composite parent, int style) {
|
||||||
super(parent, style|SWT.NO_BACKGROUND|SWT.NO_REDRAW_RESIZE);
|
super(parent, style|SWT.NO_BACKGROUND|SWT.NO_REDRAW_RESIZE);
|
||||||
fPaintGC= new GC(this);
|
fPaintGC= new GC(this);
|
||||||
|
@ -51,7 +51,7 @@ public abstract class VirtualCanvas extends Canvas {
|
||||||
addListener(SWT.Resize, new Listener() {
|
addListener(SWT.Resize, new Listener() {
|
||||||
public void handleEvent(Event event) {
|
public void handleEvent(Event event) {
|
||||||
fClientArea=getClientArea();
|
fClientArea=getClientArea();
|
||||||
updateViewRectangle();
|
onResize();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
getVerticalBar().addListener(SWT.Selection, new Listener() {
|
getVerticalBar().addListener(SWT.Selection, new Listener() {
|
||||||
|
@ -77,6 +77,9 @@ public abstract class VirtualCanvas extends Canvas {
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
protected void onResize() {
|
||||||
|
updateViewRectangle();
|
||||||
|
}
|
||||||
protected void scrollX(ScrollBar hBar) {
|
protected void scrollX(ScrollBar hBar) {
|
||||||
int hSelection = hBar.getSelection ();
|
int hSelection = hBar.getSelection ();
|
||||||
int destX = -hSelection - fVirtualBounds.x;
|
int destX = -hSelection - fVirtualBounds.x;
|
||||||
|
@ -209,7 +212,7 @@ public abstract class VirtualCanvas extends Canvas {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the extend of the virtual dieplay ares
|
* Sets the extend of the virtual display ares
|
||||||
* @param width
|
* @param width
|
||||||
* @param height
|
* @param height
|
||||||
*/
|
*/
|
||||||
|
@ -255,7 +258,7 @@ public abstract class VirtualCanvas extends Canvas {
|
||||||
}
|
}
|
||||||
/** called when the viewed part is changing */
|
/** called when the viewed part is changing */
|
||||||
private Rectangle fViewRectangle=new Rectangle(0,0,0,0);
|
private Rectangle fViewRectangle=new Rectangle(0,0,0,0);
|
||||||
void updateViewRectangle() {
|
protected void updateViewRectangle() {
|
||||||
if(
|
if(
|
||||||
fViewRectangle.x==-fVirtualBounds.x
|
fViewRectangle.x==-fVirtualBounds.x
|
||||||
&& fViewRectangle.y==-fVirtualBounds.y
|
&& fViewRectangle.y==-fVirtualBounds.y
|
||||||
|
@ -303,32 +306,36 @@ public abstract class VirtualCanvas extends Canvas {
|
||||||
private void doUpdateScrollbar() {
|
private void doUpdateScrollbar() {
|
||||||
Point size= getSize();
|
Point size= getSize();
|
||||||
Rectangle clientArea= getClientArea();
|
Rectangle clientArea= getClientArea();
|
||||||
|
|
||||||
ScrollBar horizontal= getHorizontalBar();
|
ScrollBar horizontal= getHorizontalBar();
|
||||||
if (fVirtualBounds.width <= clientArea.width) {
|
if(horizontal.isVisible()) {
|
||||||
// TODO IMPORTANT in ScrollBar.setVisible comment out the line
|
|
||||||
// that checks 'isvisible' and returns (at the beginning)
|
|
||||||
horizontal.setVisible(false);
|
|
||||||
horizontal.setSelection(0);
|
|
||||||
} else {
|
|
||||||
horizontal.setPageIncrement(clientArea.width - horizontal.getIncrement());
|
horizontal.setPageIncrement(clientArea.width - horizontal.getIncrement());
|
||||||
int max= fVirtualBounds.width + (size.x - clientArea.width);
|
int max= fVirtualBounds.width + (size.x - clientArea.width);
|
||||||
horizontal.setMaximum(max);
|
horizontal.setMaximum(max);
|
||||||
horizontal.setThumb(size.x > max ? max : size.x);
|
horizontal.setThumb(size.x > max ? max : size.x);
|
||||||
horizontal.setVisible(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollBar vertical= getVerticalBar();
|
ScrollBar vertical= getVerticalBar();
|
||||||
if (fVirtualBounds.height <= clientArea.height) {
|
if(vertical.isVisible()) {
|
||||||
vertical.setVisible(false);
|
|
||||||
vertical.setSelection(0);
|
|
||||||
} else {
|
|
||||||
vertical.setPageIncrement(clientArea.height - vertical.getIncrement());
|
vertical.setPageIncrement(clientArea.height - vertical.getIncrement());
|
||||||
int max= fVirtualBounds.height + (size.y - clientArea.height);
|
int max= fVirtualBounds.height + (size.y - clientArea.height);
|
||||||
vertical.setMaximum(max);
|
vertical.setMaximum(max);
|
||||||
vertical.setThumb(size.y > max ? max : size.y);
|
vertical.setThumb(size.y > max ? max : size.y);
|
||||||
vertical.setVisible(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected boolean isVertialBarVisible() {
|
||||||
|
return getVerticalBar().isVisible();
|
||||||
|
}
|
||||||
|
protected void serVerticalBarVisible(boolean showVScrollBar) {
|
||||||
|
ScrollBar vertical= getVerticalBar();
|
||||||
|
vertical.setVisible(showVScrollBar);
|
||||||
|
vertical.setSelection(0);
|
||||||
|
}
|
||||||
|
protected boolean isHorizontalBarVisble() {
|
||||||
|
return getHorizontalBar().isVisible();
|
||||||
|
}
|
||||||
|
protected void setHorizontalBarVisible(boolean showHScrollBar) {
|
||||||
|
ScrollBar horizontal= getHorizontalBar();
|
||||||
|
horizontal.setVisible(showHScrollBar);
|
||||||
|
horizontal.setSelection(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue