Merge "441140 - Added copy/cut/paste to description field in Project settings"
diff --git a/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/projectsettings/Q7ProjectEditor.java b/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/projectsettings/Q7ProjectEditor.java
index b9601cd..3c7e3d5 100644
--- a/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/projectsettings/Q7ProjectEditor.java
+++ b/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/projectsettings/Q7ProjectEditor.java
@@ -11,10 +11,6 @@
 package org.eclipse.rcptt.ui.editors.projectsettings;
 
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.PartInitException;
-
 import org.eclipse.rcptt.core.model.IQ7ProjectMetadata;
 import org.eclipse.rcptt.core.model.ModelException;
 import org.eclipse.rcptt.core.scenario.ProjectMetadata;
@@ -22,6 +18,10 @@
 import org.eclipse.rcptt.ui.editors.NamedElementEditor;
 import org.eclipse.rcptt.ui.editors.NamedElementEditorActions;
 import org.eclipse.rcptt.ui.editors.NamedElementEditorActions.INamedElementActions;
+import org.eclipse.rcptt.ui.editors.TextUtils;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
 
 public class Q7ProjectEditor extends NamedElementEditor {
 
@@ -81,51 +81,6 @@
 	public void createActions() {
 		actions = new NamedElementEditorActions(new INamedElementActions() {
 
-			@Override
-			public void undo() {
-				page.undo();
-				updateEnablement();
-			}
-
-			@Override
-			public void redo() {
-				page.redo();
-				updateEnablement();
-			}
-
-			@Override
-			public void paste() {
-				if (isContextsFocus()) {
-					page.getContextTable().paste();
-				}
-				if (isVerificationFocus()) {
-					page.getVerificationsTable().paste();
-				}
-				updateEnablement();
-			}
-
-			@Override
-			public void cut() {
-				if (isContextsFocus()) {
-					page.getContextTable().cut();
-				}
-				if (isVerificationFocus()) {
-					page.getVerificationsTable().cut();
-				}
-				updateEnablement();
-			}
-
-			@Override
-			public void copy() {
-				if (isContextsFocus()) {
-					page.getContextTable().copy();
-				}
-				if (isVerificationFocus()) {
-					page.getVerificationsTable().copy();
-				}
-				updateEnablement();
-			}
-
 			private boolean isContextsFocus() {
 				return page.getContextTable().getControl().isFocusControl();
 			}
@@ -134,16 +89,76 @@
 				return page.getVerificationsTable().getControl().isFocusControl();
 			}
 
+			private boolean isDescriptionFocus() {
+				return page.getDescriptionComposite().getDescriptionControl().isFocusControl();
+			}
+
+			@Override
+			public void undo() {
+				if (isDescriptionFocus()) {
+					page.getDescriptionComposite().undo();
+				}
+				updateEnablement();
+			}
+
+			@Override
+			public void redo() {
+				if (isDescriptionFocus()) {
+					page.getDescriptionComposite().redo();
+				}
+				updateEnablement();
+			}
+
+			@Override
+			public void paste() {
+				if (isContextsFocus()) {
+					page.getContextTable().paste();
+				} else if (isVerificationFocus()) {
+					page.getVerificationsTable().paste();
+				} else if (isDescriptionFocus()) {
+					TextUtils.paste(page.getDescriptionComposite().getDescriptionControl());
+				}
+				updateEnablement();
+			}
+
+			@Override
+			public void cut() {
+				if (isContextsFocus()) {
+					page.getContextTable().cut();
+				} else if (isVerificationFocus()) {
+					page.getVerificationsTable().cut();
+				} else if (isDescriptionFocus()) {
+					TextUtils.cut(page.getDescriptionComposite().getDescriptionControl());
+				}
+				updateEnablement();
+			}
+
+			@Override
+			public void copy() {
+				if (isContextsFocus()) {
+					page.getContextTable().copy();
+				} else if (isVerificationFocus()) {
+					page.getVerificationsTable().copy();
+				} else if (isDescriptionFocus()) {
+					TextUtils.copy(page.getDescriptionComposite().getDescriptionControl());
+				}
+				updateEnablement();
+			}
+
 			@Override
 			public boolean canUndo() {
-				boolean ctxOrVerif = isContextsFocus() || isVerificationFocus();
-				return page.canUndo() && !ctxOrVerif;
+				if (isDescriptionFocus()) {
+					return page.getDescriptionComposite().canUndo();
+				}
+				return false;
 			}
 
 			@Override
 			public boolean canRedo() {
-				boolean ctxOrVerif = isContextsFocus() || isVerificationFocus();
-				return page.canRedo() && !ctxOrVerif;
+				if (isDescriptionFocus()) {
+					return page.getDescriptionComposite().canRedo();
+				}
+				return false;
 			}
 
 			@Override
@@ -154,6 +169,9 @@
 				if (isVerificationFocus()) {
 					return page.getVerificationsTable().canPaste();
 				}
+				if (isDescriptionFocus()) {
+					return TextUtils.canPaste(page.getDescriptionComposite().getDescriptionControl());
+				}
 				return false;
 			}
 
@@ -165,6 +183,9 @@
 				if (isVerificationFocus()) {
 					return page.getVerificationsTable().canCut();
 				}
+				if (isDescriptionFocus()) {
+					return TextUtils.canCut(page.getDescriptionComposite().getDescriptionControl());
+				}
 				return false;
 			}
 
@@ -176,6 +197,9 @@
 				if (isVerificationFocus()) {
 					return page.getVerificationsTable().canCopy();
 				}
+				if (isDescriptionFocus()) {
+					return TextUtils.canCopy(page.getDescriptionComposite().getDescriptionControl());
+				}
 				return false;
 			}
 		}, getEditorSite().getActionBars());
diff --git a/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/projectsettings/Q7ProjectEditorPage.java b/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/projectsettings/Q7ProjectEditorPage.java
index 98c5da8..22063e2 100644
--- a/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/projectsettings/Q7ProjectEditorPage.java
+++ b/rcp/org.eclipse.rcptt.ui/src/org/eclipse/rcptt/ui/editors/projectsettings/Q7ProjectEditorPage.java
@@ -12,16 +12,6 @@
 
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.eclipse.ui.forms.widgets.Section;
-
 import org.eclipse.rcptt.core.model.IQ7ProjectMetadata;
 import org.eclipse.rcptt.core.model.ModelException;
 import org.eclipse.rcptt.core.scenario.ProjectMetadata;
@@ -34,6 +24,15 @@
 import org.eclipse.rcptt.ui.controls.VerificationsTable;
 import org.eclipse.rcptt.ui.editors.IQ7NamedElementEditorPage;
 import org.eclipse.rcptt.ui.editors.NamedElementEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.Section;
 
 public class Q7ProjectEditorPage extends FormPage implements
 		IQ7NamedElementEditorPage {
@@ -57,6 +56,10 @@
 		return verificationsTable;
 	}
 
+	public DescriptionComposite getDescriptionComposite() {
+		return descriptionComposite;
+	}
+
 	@Override
 	protected void createFormContent(IManagedForm managedForm) {
 		ScrolledForm form = managedForm.getForm();
@@ -143,32 +146,6 @@
 	public void refreshPage() {
 	}
 
-	public boolean canUndo() {
-		if (descriptionComposite.getDescriptionControl().isFocusControl()) {
-			return descriptionComposite.canUndo();
-		}
-		return false;
-	}
-
-	public boolean canRedo() {
-		if (descriptionComposite.getDescriptionControl().isFocusControl()) {
-			return descriptionComposite.canRedo();
-		}
-		return false;
-	}
-
-	public void undo() {
-		if (descriptionComposite.getDescriptionControl().isFocusControl()) {
-			descriptionComposite.undo();
-		}
-	}
-
-	public void redo() {
-		if (descriptionComposite.getDescriptionControl().isFocusControl()) {
-			descriptionComposite.redo();
-		}
-	}
-
 	@Override
 	public void createPartControl(Composite parent) {
 		super.createPartControl(parent);
diff --git a/rcpttTests/platform_tests/Contexts/DefaultContext/Edit/CopyCutPasteDescriptionInDefaultContext.test b/rcpttTests/platform_tests/Contexts/DefaultContext/Edit/CopyCutPasteDescriptionInDefaultContext.test
new file mode 100644
index 0000000..a44f1fe
--- /dev/null
+++ b/rcpttTests/platform_tests/Contexts/DefaultContext/Edit/CopyCutPasteDescriptionInDefaultContext.test
@@ -0,0 +1,66 @@
+--- RCPTT testcase ---
+Format-Version: 1.0
+Contexts: _ymiyse5IEeCU6db9MgIBkA,_OKTjMYxiEeK4jYsIiM8Vnw
+Element-Name: CopyCutPasteDescriptionInDefaultContext
+Element-Type: testcase
+Element-Version: 3.0
+External-Reference: 
+Id: _Nk5VcDQyEeS8BeHVT1fREw
+Runtime-Version: 1.5.0.201406020630
+Save-Time: 9/4/14 8:05 PM
+Testcase-Type: ecl
+
+------=_.description-216f885c-d591-38ce-8ea2-e4f8cb4d6ffa
+Content-Type: text/plain
+Entry-Name: .description
+
+Copyright (c) 2009, 2014 Xored Software Inc and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+    Xored Software Inc - initial creation and/or initial documentation
+--------------------------------------------------------------------------------
+
+TEST STEPS:
+
+1. Enter description in Default Context
+2. Copy and Paste using hotkeys 
+3. Make sure that changes are displayed
+4. Select all and cut using menu
+5. Make sure that description is empty
+6. Paste
+7. Make sure that cutted text is in description
+------=_.description-216f885c-d591-38ce-8ea2-e4f8cb4d6ffa--
+------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac
+Content-Type: text/ecl
+Entry-Name: .content
+
+get-view "Test Explorer" | get-tree | select "TestProject/Project Settings" | double-click
+with [get-editor "TestProject - Project Settings" | get-section Description | get-text-viewer] {
+    type-text "Test description"
+    key-type "M1+a"
+    select-range 1 1 1 17
+    key-type "M1+c"
+    key-type Right
+    key-type "M1+v"
+}
+get-editor "TestProject - Project Settings" | get-section Description | get-editbox | get-property text 
+    | equals "Test descriptionTest description" | verify-true
+    
+with [get-editor "TestProject - Project Settings" | get-section Description | get-text-viewer] {
+    set-caret-pos 1 33
+    key-type "M1+a"
+    select-range 1 1 1 33
+}
+get-menu "Edit/Cut" | click
+get-editor "TestProject - Project Settings" | get-section Description | get-editbox | get-property text 
+    | equals "" | verify-true
+
+get-menu "Edit/Paste" | click
+get-editor "TestProject - Project Settings" | get-section Description | get-editbox | get-property text 
+    | equals "Test descriptionTest description" | verify-true
+
+------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac--