You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/10/28 17:00:14 UTC
svn commit: r830653 - in
/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: TextArea.java
skin/TextAreaSkin.java text/Node.java
Author: gbrown
Date: Wed Oct 28 16:00:14 2009
New Revision: 830653
URL: http://svn.apache.org/viewvc?rev=830653&view=rev
Log:
Add cut/copy/paste support to TextArea.
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Node.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java?rev=830653&r1=830652&r2=830653&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Wed Oct 28 16:00:14 2009
@@ -591,15 +591,90 @@
}
public void cut() {
- // TODO
+ if (document == null) {
+ throw new IllegalStateException();
+ }
+
+ if (selectionLength > 0) {
+ // Copy selection to clipboard
+ Document selection = (Document)document.removeRange(selectionStart, selectionLength);
+
+ String selectedText = null;
+ try {
+ PlainTextSerializer serializer = new PlainTextSerializer();
+ StringWriter writer = new StringWriter();
+ serializer.writeObject(selection, writer);
+ selectedText = writer.toString();
+ } catch(SerializationException exception) {
+ throw new RuntimeException(exception);
+ } catch(IOException exception) {
+ throw new RuntimeException(exception);
+ }
+
+ if (selectedText != null) {
+ LocalManifest clipboardContent = new LocalManifest();
+ clipboardContent.putText(selectedText);
+ Clipboard.setContent(clipboardContent);
+ }
+ }
+
+ setSelection(selectionStart, 0);
}
public void copy() {
- // TODO
+ if (document == null) {
+ throw new IllegalStateException();
+ }
+
+ if (selectionLength > 0) {
+ // Copy selection to clipboard
+ Document selection = (Document)document.getRange(selectionStart, selectionLength);
+
+ String selectedText = null;
+ try {
+ PlainTextSerializer serializer = new PlainTextSerializer();
+ StringWriter writer = new StringWriter();
+ serializer.writeObject(selection, writer);
+ selectedText = writer.toString();
+ } catch(SerializationException exception) {
+ throw new RuntimeException(exception);
+ } catch(IOException exception) {
+ throw new RuntimeException(exception);
+ }
+
+ if (selectedText != null) {
+ LocalManifest clipboardContent = new LocalManifest();
+ clipboardContent.putText(selectedText);
+ Clipboard.setContent(clipboardContent);
+ }
+ }
}
public void paste() {
- // TODO
+ Manifest clipboardContent = Clipboard.getContent();
+
+ if (clipboardContent != null
+ && clipboardContent.containsText()) {
+ // Paste the string representation of the content
+ String text = null;
+ try {
+ text = clipboardContent.getText();
+ } catch(IOException exception) {
+ // No-op
+ }
+
+ if (text != null) {
+ // Remove any existing selection
+ if (selectionLength > 0) {
+ // TODO Make this part of the undoable action (for all such
+ // actions)
+ delete(Direction.BACKWARD);
+ }
+
+ // Insert the clipboard contents
+ insertText(text);
+ }
+ }
}
public void undo() {
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java?rev=830653&r1=830652&r2=830653&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java Wed Oct 28 16:00:14 2009
@@ -216,6 +216,10 @@
return node.getOffset();
}
+ public int getDocumentOffset() {
+ return (parent == null) ? 0 : parent.getDocumentOffset() + getOffset();
+ }
+
public int getCharacterCount() {
return node.getCharacterCount();
}
@@ -1019,15 +1023,9 @@
int selectionStart = textArea.getSelectionStart();
Span selectionRange = new Span(selectionStart, selectionStart + selectionLength - 1);
- // TODO Move this to a method?
- int documentOffset = getOffset();
- ElementView parent = getParent();
- while (parent != null) {
- documentOffset += parent.getOffset();
- parent = parent.getParent();
- }
-
+ int documentOffset = getDocumentOffset();
Span characterRange = new Span(documentOffset, documentOffset + getCharacterCount() - 1);
+
if (characterRange.intersects(selectionRange)) {
int width = getWidth();
int height = getHeight();
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Node.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Node.java?rev=830653&r1=830652&r2=830653&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Node.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Node.java Wed Oct 28 16:00:14 2009
@@ -101,7 +101,6 @@
* Returns the node's offset within the document.
*/
public int getDocumentOffset() {
- Element parent = getParent();
return (parent == null) ? 0 : parent.getDocumentOffset() + offset;
}