mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Merge "Bug 517358 - RFE: method to read TextCanvas content"
This commit is contained in:
commit
a3e0c996a1
3 changed files with 70 additions and 11 deletions
|
@ -277,6 +277,22 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
public String getSelectedText() {
|
public String getSelectedText() {
|
||||||
return fCurrentSelection;
|
return fCurrentSelection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper to sanitize text copied out of a snapshot
|
||||||
|
private static String scrubLine(String text) {
|
||||||
|
// get rid of the empty space at the end of the lines
|
||||||
|
// text=text.replaceAll("\000+$",""); //$NON-NLS-1$//$NON-NLS-2$
|
||||||
|
// <J2ME-CDC-1.1 version>
|
||||||
|
int i = text.length() - 1;
|
||||||
|
while (i >= 0 && text.charAt(i) == '\000') {
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
text = text.substring(0, i + 1);
|
||||||
|
// </J2ME-CDC-1.1 version>
|
||||||
|
// null means space
|
||||||
|
return text.replace('\000', ' ');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the currently selected text
|
* Calculates the currently selected text
|
||||||
* @return the currently selected text
|
* @return the currently selected text
|
||||||
|
@ -294,17 +310,7 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
text=text.substring(0, Math.min(fSelectionEndColumn+1,text.length()));
|
text=text.substring(0, Math.min(fSelectionEndColumn+1,text.length()));
|
||||||
if(line==fSelectionStartLine)
|
if(line==fSelectionStartLine)
|
||||||
text=text.substring(Math.min(fSelectionStartCoumn,text.length()));
|
text=text.substring(Math.min(fSelectionStartCoumn,text.length()));
|
||||||
// get rid of the empty space at the end of the lines
|
text=scrubLine(text);
|
||||||
// text=text.replaceAll("\000+$",""); //$NON-NLS-1$//$NON-NLS-2$
|
|
||||||
// <J2ME-CDC-1.1 version>
|
|
||||||
int i = text.length() - 1;
|
|
||||||
while (i >= 0 && text.charAt(i) == '\000') {
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
text = text.substring(0, i + 1);
|
|
||||||
// </J2ME-CDC-1.1 version>
|
|
||||||
// null means space
|
|
||||||
text=text.replace('\000', ' ');
|
|
||||||
} else {
|
} else {
|
||||||
text=""; //$NON-NLS-1$
|
text=""; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
@ -345,4 +351,30 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAllText() {
|
||||||
|
|
||||||
|
// Make a snapshot of the whole text data
|
||||||
|
ITerminalTextDataSnapshot snapshot = fSnapshot.getTerminalTextData().makeSnapshot();
|
||||||
|
snapshot.updateSnapshot(true);
|
||||||
|
snapshot.detach();
|
||||||
|
|
||||||
|
// Extract the data
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
for (int line = 0; line < snapshot.getHeight(); line++) {
|
||||||
|
char[] chars = snapshot.getChars(line);
|
||||||
|
String text;
|
||||||
|
if (chars != null) {
|
||||||
|
text = scrubLine(new String(chars)); // take care of NULs
|
||||||
|
} else {
|
||||||
|
text = ""; //$NON-NLS-1$ null arrays represent empty lines
|
||||||
|
}
|
||||||
|
sb.append(text);
|
||||||
|
// terminate lines except (1) the last one and (2) wrapped lines
|
||||||
|
if ((line < snapshot.getHeight() - 1) && !snapshot.isWrappedLine(line)) {
|
||||||
|
sb.append('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -81,4 +81,15 @@ public interface ITextCanvasModel {
|
||||||
boolean hasLineSelection(int line);
|
boolean hasLineSelection(int line);
|
||||||
|
|
||||||
String getSelectedText();
|
String getSelectedText();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect and return all text present in the model.
|
||||||
|
*
|
||||||
|
* <p>Individual lines of the returned text are separated by '\n'.
|
||||||
|
*
|
||||||
|
* <p>The method is primarily designed for test automation.
|
||||||
|
*
|
||||||
|
* @since 4.3
|
||||||
|
*/
|
||||||
|
String getAllText();
|
||||||
}
|
}
|
|
@ -382,6 +382,22 @@ public class TextCanvas extends GridCanvas {
|
||||||
fCellCanvasModel.setSelection(-1,-1,-1,-1);
|
fCellCanvasModel.setSelection(-1,-1,-1,-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect and return all text present in the widget.
|
||||||
|
*
|
||||||
|
* <p>Individual lines of the returned text are separated by '\n'.
|
||||||
|
*
|
||||||
|
* <p>The method is primarily designed for test automation. Tests need
|
||||||
|
* to check what happens in a terminal (e.g. if and how a CDT Debugger
|
||||||
|
* Console reacts in a GDB session) and this method allows to read the
|
||||||
|
* text present in the terminal.
|
||||||
|
*
|
||||||
|
* @since 4.3
|
||||||
|
*/
|
||||||
|
public String getAllText() {
|
||||||
|
return fCellCanvasModel.getAllText();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue