=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.clipboard.js' --- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.clipboard.js 2015-08-12 18:07:06 +0000 +++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.clipboard.js 2015-10-13 22:04:19 +0000 @@ -140,12 +140,12 @@ p2j.clipboard_helpers.init(cfg); // the event handlers must have been defined above the init() function - window.addEventListener("copy", copyHandler); - window.addEventListener("paste", pasteHandler); + document.addEventListener("copy", copyHandler); + document.addEventListener("paste", pasteHandler); // ChUI doesn't use CUT for system clipboard integration if (p2j.isGui) - window.addEventListener("cut", copyHandler); + document.addEventListener("cut", copyHandler); }; /** @@ -232,12 +232,17 @@ */ me.writeClipboard = function(text) { - // TODO: find a way to arbitrarily write the contents of the clipboard on non-IE - if (window.clipboardData) - { - window.clipboardData.clearData(); - window.clipboardData.setData("Text", text); - } + // copy selection to clipboard + inputText.value = encodeURIComponent(text); // to escape "\n" + inputText.focus(); + inputText.select(); +// TODO: find a way to arbitrarily write the contents of the clipboard on non-IE +// if (window.clipboardData) +// { +// console.log("window.clipboardData"); +// window.clipboardData.clearData(); +// window.clipboardData.setData("Text", text); +// } }; /** === modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keyboard.js' --- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keyboard.js 2015-10-09 19:15:11 +0000 +++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keyboard.js 2015-10-13 22:49:10 +0000 @@ -161,28 +161,39 @@ // if have clipboard if (p2j.clipboard.enabled) { - // TODO: in GUI, alternate cut (shift-del), copy (ctrl-ins) and paste (shift-ins) keys - // will generate the clipboard events; we need processing here for those events - // when we generate them properly (shift-ins == 1022, shift-del == 639 and - // ctrl-ins == 2558) - - // CTRL-C (copy) or CTRL-X (cut), CUT to system clipboard is not supported for ChUI - if ((key === 3 && (!p2j.clipboard.needsSelection() || p2j.clipboard.haveSelection())) || - (key === 24 && !p2j.clipboard.needsSelection())) + // in GUI, alternate cut (shift-del), copy (ctrl-ins) and paste (shift-ins) keys + // will generate the clipboard events; we need processing here for those events + // when we generate them properly (shift-ins == 1022, shift-del == 639 and + // ctrl-ins == 2558) + if (p2j.isGui) { - // prepare clipboard operations on CTRL key down (copies selected text into a - // hidden input field, focuses that field and selects the text) - p2j.clipboard.prepareCopy(); + if (((key === 3 || key === 2558) && (!p2j.clipboard.needsSelection() || p2j.clipboard.haveSelection())) || + ((key === 24 || key === 639) && !p2j.clipboard.needsSelection())) + { + sendKeyCode(key); + return; + } + } + else + { + // CTRL-C (copy) or CTRL-X (cut), CUT to system clipboard is not supported for ChUI + if ((key === 3 && (!p2j.clipboard.needsSelection() || p2j.clipboard.haveSelection())) || + (key === 24 && !p2j.clipboard.needsSelection())) + { + // prepare clipboard operations on CTRL key down (copies selected text into a + // hidden input field, focuses that field and selects the text) + p2j.clipboard.prepareCopy(); + + // let the browser generate the corresponding clipboard event by not suppressing the + // default processing + // TODO: GUI needs to see these keys regardless and the code below would disable the + // default processing + return; + } + } - // let the browser generate the corresponding clipboard event by not suppressing the - // default processing - // TODO: GUI needs to see these keys regardless and the code below would disable the - // default processing - return; - } - // CTRL-V (paste) - if (key === 22) + if (key === 22 || (p2j.isGui && (key === 1022))) { // use a not-visible input field and select all contents of that field p2j.clipboard.preparePaste(); @@ -195,20 +206,30 @@ return; } } + sendKeyCode(key); + evt.preventDefault(); + evt.stopImmediatePropagation(); + }; + + /** + * Sends a compatible Progress 4GL key code message. + * + * @param {number} keyCode + * The key code + */ + function sendKeyCode(keyCode) + { var data = new Uint8Array(3); data[0] = 0x01; - var c = key; + var c = keyCode; data[2] = c & 0xff; c = c >> 8; data[1] = c & 0xff; p2j.socket.send(data); - - evt.preventDefault(); - evt.stopImmediatePropagation(); - }; - + } + /** * Send key code and character code. * === modified file 'src/com/goldencode/p2j/ui/client/gui/EditorGuiImpl.java' --- src/com/goldencode/p2j/ui/client/gui/EditorGuiImpl.java 2015-10-08 19:17:34 +0000 +++ src/com/goldencode/p2j/ui/client/gui/EditorGuiImpl.java 2015-10-13 21:41:47 +0000 @@ -2462,6 +2462,7 @@ config.selectionEnd = parsedText.get(selectionEnd.y).getOffset() + selectionEnd.x + 1; config.selectionText = getSelectedText(false); + gd.setCurrentSelection(config.selectionText); } } === modified file 'src/com/goldencode/p2j/ui/client/gui/FillInGuiImpl.java' --- src/com/goldencode/p2j/ui/client/gui/FillInGuiImpl.java 2015-10-08 17:42:19 +0000 +++ src/com/goldencode/p2j/ui/client/gui/FillInGuiImpl.java 2015-10-13 21:56:42 +0000 @@ -472,6 +472,8 @@ { config.selectionEnd = Math.min(config.selectionEnd + 1, lastOffset + 1); } + // notify about the current selection + gd.setCurrentSelection(getSelectedText()); ke.setKeyCode(Keyboard.KA_CURSOR_RIGHT); ke.setActionCode(Keyboard.KA_CURSOR_RIGHT); @@ -504,6 +506,8 @@ { config.selectionStart = Math.max(config.selectionStart - 1, 0); } + // notify about the current selection + gd.setCurrentSelection(getSelectedText()); ke.setKeyCode(Keyboard.KA_CURSOR_LEFT); ke.setActionCode(Keyboard.KA_CURSOR_LEFT); @@ -521,6 +525,8 @@ config.selectionEnd = config.selectionStart; } config.selectionStart = 0; + // notify about the current selection + gd.setCurrentSelection(getSelectedText()); ke.setKeyCode(Keyboard.KA_HOME); ke.setActionCode(Keyboard.KA_HOME); @@ -539,6 +545,8 @@ } config.selectionEnd = lastOffset + 1; + // notify about the current selection + gd.setCurrentSelection(getSelectedText()); ke.setKeyCode(Keyboard.KA_END); ke.setActionCode(Keyboard.KA_END); @@ -554,6 +562,9 @@ { config.selectionStart = 0; config.selectionEnd = lastOffset + 1; + // notify about the current selection + gd.setCurrentSelection(getSelectedText()); + repaint(); } === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java 2015-10-13 17:07:58 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java 2015-10-13 21:36:25 +0000 @@ -1031,6 +1031,14 @@ public String clipboardContents(); /** + * Sets the current selection. + * + * @param txt + * The current selection. + */ + public void setCurrentSelection(String txt); + + /** * Register all the mouse-aware widgets (in all Windows) with the driver. */ public void registerMouseWidgets(); === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingGuiDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingGuiDriver.java 2015-10-13 17:07:58 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingGuiDriver.java 2015-10-13 21:41:00 +0000 @@ -459,4 +459,15 @@ sew.restoreFocusListeners(); } } + + /** + * Sets the current selection. + * + * @param txt + * The current selection. + */ + @Override + public void setCurrentSelection(String txt) + { + } } === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java 2015-10-13 17:07:58 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java 2015-10-13 22:22:58 +0000 @@ -520,7 +520,7 @@ @Override public void copyToCliboard(String txt) { - // TODO + websock.writeClipboard(txt); } /** @@ -1214,4 +1214,16 @@ } } } + + /** + * Sets the current selection. + * + * @param txt + * The current selection. + */ + @Override + public void setCurrentSelection(String txt) + { + copyToCliboard(txt); + } } === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2015-10-13 17:07:58 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2015-10-13 22:28:59 +0000 @@ -913,6 +913,23 @@ } /** + * Writes to the current selection to the application clipboard and notify the JS client + * about the current selection. + * + * @param text + * The current selection. + */ + public void writeClipboard(String text) + { + synchronized (clipboardLock) + { + clipboardContents = text; + clipboardLock.notify(); + } + sendBinaryMessage(MSG_WRITE_CLIPBOARD, (text == null) ? "" : text); + } + + /** * This is the worker method which is called when a binary message is received. * * @param message