COMMON: COMMAND BAR: Introduces IFocusService handler for 07/15807/1
authorkh5325.kim <kh5325.kim@samsung.com>
Tue, 28 Jan 2014 14:52:09 +0000 (23:52 +0900)
committerkh5325.kim <kh5325.kim@samsung.com>
Tue, 28 Jan 2014 14:52:09 +0000 (23:52 +0900)
cut/copy/paste/selectAll

Introduces IFocusService handler for cut/copy/paste/selectAll.
Custom listener for SWT.KeyUp can cause duplicate behavior with default
hadler.

Change-Id: If2a52e3600db307af3f949d93fa7b594bf5cc4c7
Signed-off-by: kh5325.kim <kh5325.kim@samsung.com>
org.tizen.common.ui/plugin.xml
org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/CopyHandler.java [new file with mode: 0644]
org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/CutHandler.java [new file with mode: 0644]
org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/PasteHandler.java [new file with mode: 0644]
org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/SelectAllHandler.java [new file with mode: 0644]
org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/TextAssist.java

index 30b5316..1fb2395 100644 (file)
        </key>\r
     </extension>
     <extension\r
+       point="org.eclipse.ui.handlers">\r
+       <handler\r
+          class="org.tizen.common.ui.commandbar.textAssist.SelectAllHandler"\r
+          commandId="org.eclipse.ui.edit.selectAll">\r
+         <activeWhen>\r
+            <or>\r
+                  <with variable="activeFocusControlId">\r
+                     <equals value="org.tizen.common.ui.commandbar.textAssist.TextAssist"/>\r
+                  </with>\r
+            </or>\r
+         </activeWhen>\r
+       </handler>\r
+       <handler\r
+          class="org.tizen.common.ui.commandbar.textAssist.CopyHandler"\r
+          commandId="org.eclipse.ui.edit.copy">\r
+         <activeWhen>\r
+            <or>\r
+                  <with variable="activeFocusControlId">\r
+                     <equals value="org.tizen.common.ui.commandbar.textAssist.TextAssist"/>\r
+                  </with>\r
+            </or>\r
+         </activeWhen>\r
+       </handler>\r
+       <handler\r
+          class="org.tizen.common.ui.commandbar.textAssist.CutHandler"\r
+          commandId="org.eclipse.ui.edit.cut">\r
+         <activeWhen>\r
+            <or>\r
+                  <with variable="activeFocusControlId">\r
+                     <equals value="org.tizen.common.ui.commandbar.textAssist.TextAssist"/>\r
+                  </with>\r
+            </or>\r
+         </activeWhen>\r
+       </handler>\r
+       <handler\r
+          class="org.tizen.common.ui.commandbar.textAssist.PasteHandler"\r
+          commandId="org.eclipse.ui.edit.paste">\r
+         <activeWhen>\r
+            <or>\r
+                  <with variable="activeFocusControlId">\r
+                     <equals value="org.tizen.common.ui.commandbar.textAssist.TextAssist"/>\r
+                  </with>\r
+            </or>\r
+         </activeWhen>\r
+       </handler>\r
+    </extension>\r
+    <!-- /Command Bar -->\r
+\r
+    <extension\r
          point="org.tizen.common.ui.tipoftheday">\r
        <tip\r
             file="resources/tips/commandbar.html">\r
diff --git a/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/CopyHandler.java b/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/CopyHandler.java
new file mode 100644 (file)
index 0000000..8bd4775
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Changhyun Lee <changhyun1.lee@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.common.ui.commandbar.textAssist;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class CopyHandler extends AbstractHandler {
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        Object activeFocusControl = HandlerUtil.getVariable(event, "activeFocusControl");
+        if (activeFocusControl instanceof StyledText) {
+            StyledText textWidget = (StyledText) activeFocusControl;
+            textWidget.copy();
+        }
+        return null;
+    }
+}
diff --git a/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/CutHandler.java b/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/CutHandler.java
new file mode 100644 (file)
index 0000000..537e52d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Changhyun Lee <changhyun1.lee@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.common.ui.commandbar.textAssist;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class CutHandler extends AbstractHandler {
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        Object activeFocusControl = HandlerUtil.getVariable(event, "activeFocusControl");
+        if (activeFocusControl instanceof StyledText) {
+            StyledText textWidget = (StyledText) activeFocusControl;
+            textWidget.cut();
+        }
+        return null;
+    }
+}
diff --git a/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/PasteHandler.java b/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/PasteHandler.java
new file mode 100644 (file)
index 0000000..f3c7161
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Changhyun Lee <changhyun1.lee@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.common.ui.commandbar.textAssist;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class PasteHandler extends AbstractHandler {
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        Object activeFocusControl = HandlerUtil.getVariable(event, "activeFocusControl");
+        if (activeFocusControl instanceof StyledText) {
+            StyledText textWidget = (StyledText) activeFocusControl;
+            textWidget.paste();
+        }
+        return null;
+    }
+}
diff --git a/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/SelectAllHandler.java b/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/SelectAllHandler.java
new file mode 100644 (file)
index 0000000..8668393
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Changhyun Lee <changhyun1.lee@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.common.ui.commandbar.textAssist;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class SelectAllHandler extends AbstractHandler {
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        Object activeFocusControl = HandlerUtil.getVariable(event, "activeFocusControl");
+        if (activeFocusControl instanceof StyledText) {
+            StyledText textWidget = (StyledText) activeFocusControl;
+            textWidget.selectAll();
+        }
+        return null;
+    }
+}
index 82395bf..2bca2f1 100644 (file)
@@ -37,6 +37,8 @@ import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;\r
 import org.eclipse.swt.widgets.TableItem;\r
 import org.eclipse.swt.widgets.Widget;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.swt.IFocusService;\r
 import org.tizen.common.util.ArrayUtil;\r
 import org.tizen.common.util.CollectionUtil;\r
 import org.tizen.common.util.ObjectUtil;\r
@@ -198,28 +200,11 @@ public class TextAssist extends Composite {
         // For example,\r
         //  it works when Connection Explorer view is selected (org.eclipse.ui.internal.handlers.WidgetMethodHandler)\r
         //  it does not work when Console view is selected (org.eclipse.ui.console.actions.TextViewerAction)\r
-        // So, I should implement key listener for CTRL-A, CTRL-C and CTRL-V.\r
-        // cf.)) http://wiki.eclipse.org/FAQ_How_do_I_hook_into_global_actions,_such_as_Copy_and_Delete%3F\r
-        //  Each view or editor is allowed to contribute a handler for these actions; when a new part becomes active, its handler takes control of that action.\r
-        text.addListener(SWT.KeyUp, new Listener() {\r
-            @Override\r
-            public void handleEvent(Event event) {\r
-                if (event.stateMask == SWT.MOD1) {\r
-                    if (event.keyCode == 'A' || event.keyCode == 'a') {\r
-                        text.selectAll();\r
-                    }\r
-                    else if (event.keyCode == 'C' || event.keyCode == 'c') {\r
-                        text.copy();\r
-                    }\r
-                    else if (event.keyCode == 'V' || event.keyCode == 'v') {\r
-                        text.paste();\r
-                    }\r
-                    else if (event.keyCode == 'X' || event.keyCode == 'x') {\r
-                        text.cut();\r
-                    }\r
-                }\r
-            }\r
-        });\r
+        // http://www.eclipsezone.com/eclipse/forums/t98133.html\r
+        IFocusService focusService = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class);\r
+        // cf.)) plugin.xml 'org.eclipse.ui.handlers' extension\r
+        focusService.addFocusTracker(text, "org.tizen.common.ui.commandbar.textAssist.TextAssist");\r
+\r
         addSelectOnFocusToText(text);\r
         // Removed gradient by the error 'BadPixmap (invalid Pixmap parameter)'\r
         //  cf.)) https://bugs.eclipse.org/bugs/show_bug.cgi?id=236324\r