mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-13 12:05:21 +02:00
bug 205879: [terminal] clicking into the terminal creates a selection of one character
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205879 The user has to drag at least one character to make a selection
This commit is contained in:
parent
74215bde26
commit
e48c0ba278
2 changed files with 55 additions and 33 deletions
|
@ -1,11 +1,11 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
* Copyright (c) 2007 Wind River Systems, Inc. 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
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Michael Scharf (Wind River) - initial API and implementation
|
* Michael Scharf (Wind River) - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.tm.internal.terminal.textcanvas;
|
package org.eclipse.tm.internal.terminal.textcanvas;
|
||||||
|
@ -16,10 +16,10 @@ import org.eclipse.tm.terminal.model.ITerminalTextDataReadOnly;
|
||||||
public interface ITextCanvasModel {
|
public interface ITextCanvasModel {
|
||||||
void addCellCanvasModelListener(ITextCanvasModelListener listener);
|
void addCellCanvasModelListener(ITextCanvasModelListener listener);
|
||||||
void removeCellCanvasModelListener(ITextCanvasModelListener listener);
|
void removeCellCanvasModelListener(ITextCanvasModelListener listener);
|
||||||
|
|
||||||
ITerminalTextDataReadOnly getTerminalText();
|
ITerminalTextDataReadOnly getTerminalText();
|
||||||
/**
|
/**
|
||||||
* This is is
|
* This is is
|
||||||
* @param startLine
|
* @param startLine
|
||||||
* @param startCol
|
* @param startCol
|
||||||
* @param height
|
* @param height
|
||||||
|
@ -36,48 +36,49 @@ public interface ITextCanvasModel {
|
||||||
* @param visible
|
* @param visible
|
||||||
*/
|
*/
|
||||||
void setCursorEnabled(boolean visible);
|
void setCursorEnabled(boolean visible);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the cursor is shown.
|
* @return true if the cursor is shown.
|
||||||
*/
|
*/
|
||||||
boolean isCursorEnabled();
|
boolean isCursorEnabled();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the line of the cursor
|
* @return the line of the cursor
|
||||||
*/
|
*/
|
||||||
int getCursorLine();
|
int getCursorLine();
|
||||||
/**
|
/**
|
||||||
* @return the column of the cursor
|
* @return the column of the cursor
|
||||||
*/
|
*/
|
||||||
int getCursorColumn();
|
int getCursorColumn();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the start of the selection or null if nothing is selected
|
* @return the start of the selection or null if nothing is selected
|
||||||
* {@link Point#x} is the column and {@link Point#y} is the line.
|
* {@link Point#x} is the column and {@link Point#y} is the line.
|
||||||
*/
|
*/
|
||||||
Point getSelectionStart();
|
Point getSelectionStart();
|
||||||
/**
|
/**
|
||||||
* @return the end of the selection or null if nothing is selected
|
* @return the end of the selection or null if nothing is selected
|
||||||
* {@link Point#x} is the column and {@link Point#y} is the line.
|
* {@link Point#x} is the column and {@link Point#y} is the line.
|
||||||
*/
|
*/
|
||||||
Point getSelectionEnd();
|
Point getSelectionEnd();
|
||||||
|
|
||||||
Point getSelectionAnchor();
|
Point getSelectionAnchor();
|
||||||
|
|
||||||
void setSelectionAnchor(Point anchor);
|
void setSelectionAnchor(Point anchor);
|
||||||
/**
|
/**
|
||||||
|
* Sets the selection. A negative startLine clears the selection.
|
||||||
* @param startLine
|
* @param startLine
|
||||||
* @param endLine
|
* @param endLine
|
||||||
* @param startColumn
|
* @param startColumn
|
||||||
* @param endColumn
|
* @param endColumn
|
||||||
*/
|
*/
|
||||||
void setSelection(int startLine, int endLine, int startColumn, int endColumn);
|
void setSelection(int startLine, int endLine, int startColumn, int endColumn);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param line
|
* @param line
|
||||||
* @return true if line is part of the selection
|
* @return true if line is part of the selection
|
||||||
*/
|
*/
|
||||||
boolean hasLineSelection(int line);
|
boolean hasLineSelection(int line);
|
||||||
|
|
||||||
String getSelectedText();
|
String getSelectedText();
|
||||||
}
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
* Copyright (c) 2007 Wind River Systems, Inc. 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
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Michael Scharf (Wind River) - initial API and implementation
|
* Michael Scharf (Wind River) - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.tm.internal.terminal.textcanvas;
|
package org.eclipse.tm.internal.terminal.textcanvas;
|
||||||
|
@ -37,6 +37,7 @@ public class TextCanvas extends GridCanvas {
|
||||||
private boolean fScrollLock;
|
private boolean fScrollLock;
|
||||||
private Point fDraggingStart;
|
private Point fDraggingStart;
|
||||||
private Point fDraggingEnd;
|
private Point fDraggingEnd;
|
||||||
|
private boolean fHasSelection;
|
||||||
private ResizeListener fResizeListener;
|
private ResizeListener fResizeListener;
|
||||||
private int fMinColumns=20;
|
private int fMinColumns=20;
|
||||||
private int fMinLines=4;
|
private int fMinLines=4;
|
||||||
|
@ -56,7 +57,7 @@ public class TextCanvas extends GridCanvas {
|
||||||
setCellHeight(fCellRenderer.getCellHeight());
|
setCellHeight(fCellRenderer.getCellHeight());
|
||||||
|
|
||||||
calculateGrid();
|
calculateGrid();
|
||||||
|
|
||||||
}
|
}
|
||||||
public void rangeChanged(int col, int line, int width, int height) {
|
public void rangeChanged(int col, int line, int width, int height) {
|
||||||
repaintRange(col,line,width,height);
|
repaintRange(col,line,width,height);
|
||||||
|
@ -84,6 +85,7 @@ public class TextCanvas extends GridCanvas {
|
||||||
public void mouseDown(MouseEvent e) {
|
public void mouseDown(MouseEvent e) {
|
||||||
if(e.button==1) { // left button
|
if(e.button==1) { // left button
|
||||||
fDraggingStart=screenPointToCell(e.x, e.y);
|
fDraggingStart=screenPointToCell(e.x, e.y);
|
||||||
|
fHasSelection=false;
|
||||||
if((e.stateMask&SWT.SHIFT)!=0) {
|
if((e.stateMask&SWT.SHIFT)!=0) {
|
||||||
Point anchor=fCellCanvasModel.getSelectionAnchor();
|
Point anchor=fCellCanvasModel.getSelectionAnchor();
|
||||||
if(anchor!=null)
|
if(anchor!=null)
|
||||||
|
@ -94,9 +96,13 @@ public class TextCanvas extends GridCanvas {
|
||||||
fDraggingEnd=null;
|
fDraggingEnd=null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void mouseUp(MouseEvent e) {
|
public void mouseUp(MouseEvent e) {
|
||||||
if(e.button==1) { // left button
|
if(e.button==1) { // left button
|
||||||
setSelection(screenPointToCell(e.x, e.y));
|
updateHasSelection(e);
|
||||||
|
if(fHasSelection)
|
||||||
|
setSelection(screenPointToCell(e.x, e.y));
|
||||||
|
else
|
||||||
|
fCellCanvasModel.setSelection(-1,-1,-1,-1);
|
||||||
fDraggingStart=null;
|
fDraggingStart=null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,6 +111,7 @@ public class TextCanvas extends GridCanvas {
|
||||||
|
|
||||||
public void mouseMove(MouseEvent e) {
|
public void mouseMove(MouseEvent e) {
|
||||||
if (fDraggingStart != null) {
|
if (fDraggingStart != null) {
|
||||||
|
updateHasSelection(e);
|
||||||
setSelection(screenPointToCell(e.x, e.y));
|
setSelection(screenPointToCell(e.x, e.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,6 +120,20 @@ public class TextCanvas extends GridCanvas {
|
||||||
setHorizontalBarVisible(false);
|
setHorizontalBarVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user has to drag the mouse to at least one character to make a selection.
|
||||||
|
* Once this is done, even a one char selection is OK.
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
*/
|
||||||
|
private void updateHasSelection(MouseEvent e) {
|
||||||
|
if(fDraggingStart!=null) {
|
||||||
|
Point p=screenPointToCell(e.x, e.y);
|
||||||
|
if(fDraggingStart.x!=p.x||fDraggingStart.y!=p.y)
|
||||||
|
fHasSelection=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setSelection(Point p) {
|
void setSelection(Point p) {
|
||||||
if (fDraggingStart !=null && !p.equals(fDraggingEnd)) {
|
if (fDraggingStart !=null && !p.equals(fDraggingEnd)) {
|
||||||
fDraggingEnd = p;
|
fDraggingEnd = p;
|
||||||
|
@ -143,7 +164,7 @@ public class TextCanvas extends GridCanvas {
|
||||||
public ILinelRenderer getCellRenderer() {
|
public ILinelRenderer getCellRenderer() {
|
||||||
return fCellRenderer;
|
return fCellRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinColumns() {
|
public int getMinColumns() {
|
||||||
return fMinColumns;
|
return fMinColumns;
|
||||||
}
|
}
|
||||||
|
@ -212,15 +233,15 @@ public class TextCanvas extends GridCanvas {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return true if the cursor should be shown on output....
|
* @return true if the cursor should be shown on output....
|
||||||
*/
|
*/
|
||||||
public boolean isScrollLock() {
|
public boolean isScrollLock() {
|
||||||
return fScrollLock;
|
return fScrollLock;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* If set then if the size changes
|
* If set then if the size changes
|
||||||
* @param scrollLock
|
* @param scrollLock
|
||||||
*/
|
*/
|
||||||
public void setScrollLock(boolean scrollLock) {
|
public void setScrollLock(boolean scrollLock) {
|
||||||
fScrollLock=scrollLock;
|
fScrollLock=scrollLock;
|
||||||
|
@ -232,7 +253,7 @@ public class TextCanvas extends GridCanvas {
|
||||||
}
|
}
|
||||||
protected void drawLine(GC gc, int line, int x, int y, int colFirst, int colLast) {
|
protected void drawLine(GC gc, int line, int x, int y, int colFirst, int colLast) {
|
||||||
fCellRenderer.drawLine(fCellCanvasModel, gc,line,x,y,colFirst, colLast);
|
fCellRenderer.drawLine(fCellCanvasModel, gc,line,x,y,colFirst, colLast);
|
||||||
|
|
||||||
}
|
}
|
||||||
protected void visibleCellRectangleChanged(int x, int y, int width, int height) {
|
protected void visibleCellRectangleChanged(int x, int y, int width, int height) {
|
||||||
fCellCanvasModel.setVisibleRectangle(y,x,height,width);
|
fCellCanvasModel.setVisibleRectangle(y,x,height,width);
|
||||||
|
@ -278,6 +299,6 @@ public class TextCanvas extends GridCanvas {
|
||||||
throw new IllegalArgumentException("There can be at most one listener at the moment!"); //$NON-NLS-1$
|
throw new IllegalArgumentException("There can be at most one listener at the moment!"); //$NON-NLS-1$
|
||||||
fResizeListener=listener;
|
fResizeListener=listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue