From 828f217f36bb805b42a6817b9475fb3d8c09aa30 Mon Sep 17 00:00:00 2001 From: Marco Maccaferri Date: Tue, 23 Apr 2024 09:37:45 +0200 Subject: [PATCH] Allow edit functions on focused editor control --- .../com/maccasoft/propeller/EditorTab.java | 16 ------ .../com/maccasoft/propeller/SpinTools.java | 50 ++++++++----------- 2 files changed, 22 insertions(+), 44 deletions(-) diff --git a/modules/spin-tools/src/com/maccasoft/propeller/EditorTab.java b/modules/spin-tools/src/com/maccasoft/propeller/EditorTab.java index 27beeb0c..1b77f06d 100644 --- a/modules/spin-tools/src/com/maccasoft/propeller/EditorTab.java +++ b/modules/spin-tools/src/com/maccasoft/propeller/EditorTab.java @@ -831,22 +831,6 @@ public CTabItem getTabItem() { return tabItem; } - public void cut() { - editor.cut(); - } - - public void copy() { - editor.copy(); - } - - public void paste() { - editor.paste(); - } - - public void selectAll() { - editor.selectAll(); - } - public void undo() { editor.undo(); } diff --git a/modules/spin-tools/src/com/maccasoft/propeller/SpinTools.java b/modules/spin-tools/src/com/maccasoft/propeller/SpinTools.java index 1eba34ec..ce9b3dfd 100644 --- a/modules/spin-tools/src/com/maccasoft/propeller/SpinTools.java +++ b/modules/spin-tools/src/com/maccasoft/propeller/SpinTools.java @@ -82,6 +82,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.program.Program; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.FileDialog; @@ -1271,10 +1272,9 @@ public void widgetSelected(SelectionEvent e) { @Override public void widgetSelected(SelectionEvent e) { - CTabItem tabItem = tabFolder.getSelection(); - if (tabItem != null) { - EditorTab editorTab = (EditorTab) tabItem.getData(); - editorTab.cut(); + Control focusControl = shell.getDisplay().getFocusControl(); + if (focusControl instanceof StyledText) { + ((StyledText) focusControl).cut(); } } }); @@ -1286,10 +1286,9 @@ public void widgetSelected(SelectionEvent e) { @Override public void widgetSelected(SelectionEvent e) { - CTabItem tabItem = tabFolder.getSelection(); - if (tabItem != null) { - EditorTab editorTab = (EditorTab) tabItem.getData(); - editorTab.copy(); + Control focusControl = shell.getDisplay().getFocusControl(); + if (focusControl instanceof StyledText) { + ((StyledText) focusControl).copy(); } } }); @@ -1301,10 +1300,9 @@ public void widgetSelected(SelectionEvent e) { @Override public void widgetSelected(SelectionEvent e) { - CTabItem tabItem = tabFolder.getSelection(); - if (tabItem != null) { - EditorTab editorTab = (EditorTab) tabItem.getData(); - editorTab.paste(); + Control focusControl = shell.getDisplay().getFocusControl(); + if (focusControl instanceof StyledText) { + ((StyledText) focusControl).paste(); } } }); @@ -2133,10 +2131,9 @@ public void handleEvent(Event e) { @Override public void handleEvent(Event e) { - CTabItem tabItem = tabFolder.getSelection(); - if (tabItem != null) { - EditorTab editorTab = (EditorTab) tabItem.getData(); - editorTab.cut(); + Control focusControl = shell.getDisplay().getFocusControl(); + if (focusControl instanceof StyledText) { + ((StyledText) focusControl).cut(); } } }); @@ -2148,10 +2145,9 @@ public void handleEvent(Event e) { @Override public void handleEvent(Event e) { - CTabItem tabItem = tabFolder.getSelection(); - if (tabItem != null) { - EditorTab editorTab = (EditorTab) tabItem.getData(); - editorTab.copy(); + Control focusControl = shell.getDisplay().getFocusControl(); + if (focusControl instanceof StyledText) { + ((StyledText) focusControl).copy(); } } }); @@ -2163,10 +2159,9 @@ public void handleEvent(Event e) { @Override public void handleEvent(Event e) { - CTabItem tabItem = tabFolder.getSelection(); - if (tabItem != null) { - EditorTab editorTab = (EditorTab) tabItem.getData(); - editorTab.paste(); + Control focusControl = shell.getDisplay().getFocusControl(); + if (focusControl instanceof StyledText) { + ((StyledText) focusControl).paste(); } } }); @@ -2178,10 +2173,9 @@ public void handleEvent(Event e) { @Override public void handleEvent(Event e) { - CTabItem tabItem = tabFolder.getSelection(); - if (tabItem != null) { - EditorTab editorTab = (EditorTab) tabItem.getData(); - editorTab.selectAll(); + Control focusControl = shell.getDisplay().getFocusControl(); + if (focusControl instanceof StyledText) { + ((StyledText) focusControl).selectAll(); } } });