From 531756c4f1a4a5bf002f2ec2f978923ac845bb34 Mon Sep 17 00:00:00 2001 From: "kh5325.kim" Date: Tue, 28 Jan 2014 23:52:09 +0900 Subject: [PATCH] COMMON: COMMAND BAR: Introduces IFocusService handler for 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 --- org.tizen.common.ui/plugin.xml | 49 ++++++++++++++++++++++ .../ui/commandbar/textAssist/CopyHandler.java | 46 ++++++++++++++++++++ .../ui/commandbar/textAssist/CutHandler.java | 46 ++++++++++++++++++++ .../ui/commandbar/textAssist/PasteHandler.java | 46 ++++++++++++++++++++ .../ui/commandbar/textAssist/SelectAllHandler.java | 46 ++++++++++++++++++++ .../ui/commandbar/textAssist/TextAssist.java | 29 ++++--------- 6 files changed, 240 insertions(+), 22 deletions(-) create mode 100644 org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/CopyHandler.java create mode 100644 org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/CutHandler.java create mode 100644 org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/PasteHandler.java create mode 100644 org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/SelectAllHandler.java diff --git a/org.tizen.common.ui/plugin.xml b/org.tizen.common.ui/plugin.xml index 30b5316..1fb2395 100644 --- a/org.tizen.common.ui/plugin.xml +++ b/org.tizen.common.ui/plugin.xml @@ -110,6 +110,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 index 0000000..8bd4775 --- /dev/null +++ b/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/CopyHandler.java @@ -0,0 +1,46 @@ +/* + * Common + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Changhyun Lee + * Hyeongseok Heo + * BonYong Lee + * Kangho Kim + * + * 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 index 0000000..537e52d --- /dev/null +++ b/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/CutHandler.java @@ -0,0 +1,46 @@ +/* + * Common + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Changhyun Lee + * Hyeongseok Heo + * BonYong Lee + * Kangho Kim + * + * 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 index 0000000..f3c7161 --- /dev/null +++ b/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/PasteHandler.java @@ -0,0 +1,46 @@ +/* + * Common + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Changhyun Lee + * Hyeongseok Heo + * BonYong Lee + * Kangho Kim + * + * 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 index 0000000..8668393 --- /dev/null +++ b/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/SelectAllHandler.java @@ -0,0 +1,46 @@ +/* + * Common + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Changhyun Lee + * Hyeongseok Heo + * BonYong Lee + * Kangho Kim + * + * 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; + } +} diff --git a/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/TextAssist.java b/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/TextAssist.java index 82395bf..2bca2f1 100644 --- a/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/TextAssist.java +++ b/org.tizen.common.ui/src/org/tizen/common/ui/commandbar/textAssist/TextAssist.java @@ -37,6 +37,8 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.swt.IFocusService; import org.tizen.common.util.ArrayUtil; import org.tizen.common.util.CollectionUtil; import org.tizen.common.util.ObjectUtil; @@ -198,28 +200,11 @@ public class TextAssist extends Composite { // For example, // it works when Connection Explorer view is selected (org.eclipse.ui.internal.handlers.WidgetMethodHandler) // it does not work when Console view is selected (org.eclipse.ui.console.actions.TextViewerAction) - // So, I should implement key listener for CTRL-A, CTRL-C and CTRL-V. - // cf.)) http://wiki.eclipse.org/FAQ_How_do_I_hook_into_global_actions,_such_as_Copy_and_Delete%3F - // 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. - text.addListener(SWT.KeyUp, new Listener() { - @Override - public void handleEvent(Event event) { - if (event.stateMask == SWT.MOD1) { - if (event.keyCode == 'A' || event.keyCode == 'a') { - text.selectAll(); - } - else if (event.keyCode == 'C' || event.keyCode == 'c') { - text.copy(); - } - else if (event.keyCode == 'V' || event.keyCode == 'v') { - text.paste(); - } - else if (event.keyCode == 'X' || event.keyCode == 'x') { - text.cut(); - } - } - } - }); + // http://www.eclipsezone.com/eclipse/forums/t98133.html + IFocusService focusService = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class); + // cf.)) plugin.xml 'org.eclipse.ui.handlers' extension + focusService.addFocusTracker(text, "org.tizen.common.ui.commandbar.textAssist.TextAssist"); + addSelectOnFocusToText(text); // Removed gradient by the error 'BadPixmap (invalid Pixmap parameter)' // cf.)) https://bugs.eclipse.org/bugs/show_bug.cgi?id=236324 -- 2.7.4