Project

General

Profile

3080_clipboard_10.txt

Sergey Ivanovskiy, 06/03/2016 06:23 AM

Download (21 KB)

 
1
=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/index.html'
2
--- src/com/goldencode/p2j/ui/client/driver/web/index.html	2016-05-27 18:49:09 +0000
3
+++ src/com/goldencode/p2j/ui/client/driver/web/index.html	2016-06-03 08:37:42 +0000
4
@@ -7,7 +7,7 @@
5
       <style type="text/css">
6
          .wait, .wait * { cursor: wait !important; }
7
          .hidden   {
8
-                      position: absolute;
9
+                      position: fixed;
10
                       bottom: 0;
11
                       left: 0;
12
                       width: 10px;
13
@@ -17,7 +17,7 @@
14
                       z-index: -1;
15
                       color: transparent;
16
                       background: transparent;
17
-                       overflow: hidden;
18
+                      overflow: hidden;
19
                       border: none;
20
                       padding: 0;
21
                       resize: none;
22

    
23
=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.clipboard.js'
24
--- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.clipboard.js	2016-05-30 20:05:14 +0000
25
+++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.clipboard.js	2016-06-03 10:03:24 +0000
26
@@ -25,6 +25,7 @@
27
 ** 005 SBI 20151014 Implemented to set the current editors selection.
28
 ** 006 SBI 20160301 The CHUI editor code requires EOL's simulating.
29
 ** 007 SBI 20160523 Fixed copy/cut/paste work flow.
30
+**     SBI 20160603 Added Safari COMMAND+C processing.
31
 */
32
 
33
 "use strict";
34
@@ -306,11 +307,13 @@
35
                "writeClipboard",
36
                1000 + maxZIndex,
37
                document.body,
38
-               p2j.copyNotification,
39
-               "Press CTRL-C to close this dialog.",
40
+               p2j.prompts("copy"),
41
+               p2j.hints("copy"),
42
                function (evt)
43
                {
44
-                  if (evt.ctrlKey && ((evt.keyCode === keys.C) || (evt.keyCode === keys.INSERT)))
45
+                  if ((evt.metaKey && (evt.keyCode === keys.C) && p2j.isSafari) ||
46
+                      (evt.ctrlKey && (evt.keyCode === keys.C || evt.keyCode === keys.INSERT) &&
47
+                            !p2j.isSafari))
48
                   {
49
                      p2j.closeDialog();
50
                      p2j.clipboard.prepareCopy();
51

    
52
=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.js'
53
--- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.js	2016-05-30 20:05:14 +0000
54
+++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.js	2016-06-03 10:02:15 +0000
55
@@ -31,7 +31,7 @@
56
 **                  functions).  Can be used only when the P2J client runs embedded in a 
57
 **                  customer-specific application.
58
 ** 011 SBI 20160519 Added the Safari detection.
59
-**     SBI 20160523 Added createDialog function to open the modal dialog.
60
+**     SBI 20160603 Added createDialog function to open the modal dialog, added prompts and hints.
61
 */
62
 
63
 "use strict";
64
@@ -77,13 +77,45 @@
65
    /** The instance of the unique copy/cut/paste notification dialog. */
66
    var dialog;
67
    
68
-   /** The notification message for the copy action */
69
-   var copyNotification = "The application is requesting a COPY action." +
70
-                          " Press CTRL-C to complete the COPY action.";
71
-   
72
-   /** The notification message for the paste action */
73
-   var pasteNotification = "The application is requesting a PASTE action." +
74
-                           " Press CTRL-V to complete the PASTE action.";
75
+   /** The notification templates to prompt a user to do an action */
76
+   var prompts = {};
77
+   
78
+   /** The hint templates to help a user to perform an action */
79
+   var hints = {};
80
+   
81
+   /** The templates parameters */
82
+   var parameters = {};
83
+   
84
+   /** The notification template for the copy action */
85
+   prompts["copy"] = "The application is requesting a COPY action." +
86
+                     " Press {0} to complete the COPY action.";
87
+   
88
+   /** The hint for the copy action */
89
+   hints["copy"] = "Press {0} to complete the COPY action and to close this dialog.";
90
+   
91
+   /** copy template parameter */
92
+   parameters["copy"] = me.isSafari ? "COMMAND-C" : "CTRL-C";
93
+   
94
+   /** The notification template for the paste action */
95
+   prompts["paste"] = "The application is requesting a PASTE action." +
96
+                      " Press {0} to complete the PASTE action.";
97
+   
98
+   /** The hint for the paste action */
99
+   hints["paste"] = "Press {0} to complete the PASTE action and to close this dialog.";
100
+   
101
+   /** copy template parameter */
102
+   parameters["paste"] = me.isSafari ? "COMMAND-V" : "CTRL-V";
103
+   
104
+   /** The notification template for the cut action */
105
+   prompts["cut"] = "The application is requesting a CUT action." +
106
+                    " Press {0} to complete the CUT action.";
107
+   
108
+   /** The hint for the cut action */
109
+   hints["cut"] = "Press {0} to complete the CUT action and to close this dialog.";
110
+   
111
+   /** cut template parameter */
112
+   parameters["cut"] = me.isSafari ? "COMMAND-X" : "CTRL-X";
113
+   
114
    /** its properties define if copy, cut and paste commands are supported by this browser */
115
    var queryCommandSupported = {};
116
    
117
@@ -172,23 +204,41 @@
118
       
119
       Object.defineProperty(
120
             p2j,
121
-            "copyNotification",
122
+            "prompts",
123
             {
124
                get: function ()
125
                {
126
-                  // localization is possible here
127
-                  return copyNotification;
128
+                  return function(cmd)
129
+                  {
130
+                     var prompt;
131
+                     var template = prompts[cmd];
132
+                     if (template)
133
+                     {
134
+                        prompt = template.replace("{0}", parameters[cmd]);
135
+                     }
136
+                     
137
+                     return prompt;
138
+                  }
139
                }
140
             });
141
       
142
       Object.defineProperty(
143
             p2j,
144
-            "pasteNotification",
145
+            "hints",
146
             {
147
                get: function ()
148
                {
149
-                  // localization is possible here
150
-                  return pasteNotification;
151
+                  return function(cmd)
152
+                  {
153
+                     var hint;
154
+                     var template = hints[cmd];
155
+                     if (template)
156
+                     {
157
+                        hint = template.replace("{0}", parameters[cmd]);
158
+                     }
159
+                     
160
+                     return hint;
161
+                  }
162
                }
163
             });
164
       
165

    
166
=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keyboard.js'
167
--- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keyboard.js	2016-05-30 20:05:14 +0000
168
+++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keyboard.js	2016-06-03 10:01:07 +0000
169
@@ -31,6 +31,7 @@
170
 ** 012 SBI 20160119 Changed to support Chrome and IE.
171
 **     SBI 20160125 Fixed CTRL + CTRL + key, the permitted default actions are copy, paste and cut. 
172
 ** 013 SBI 20160523 Fixed copy/cut/paste work flow.
173
+**     SBI 20160603 Changed to process Safari COMMAND as it would be a CTRL key pressed.
174
 */
175
 
176
 "use strict";
177
@@ -116,8 +117,7 @@
178
       else if (evt.altKey)
179
       {
180
          // ALT keys are not used on VT100
181
-         evt.preventDefault();
182
-         evt.stopImmediatePropagation();
183
+         p2j.consumeEvent(evt);
184
       }
185
       else
186
       {
187
@@ -219,8 +219,7 @@
188
       }
189
       sendKeyCode(key);
190
       
191
-      evt.preventDefault();
192
-      evt.stopImmediatePropagation();
193
+      p2j.consumeEvent(evt);
194
    };
195
 
196
    /**
197
@@ -245,8 +244,7 @@
198
    {
199
       p2j.socket.sendKeyPair(keyCode, charCode);
200
       
201
-      evt.preventDefault();
202
-      evt.stopImmediatePropagation();
203
+      p2j.consumeEvent(evt);
204
    };
205
    
206
    /**
207
@@ -306,8 +304,7 @@
208
          }
209
          
210
          // stop event propagation
211
-         evt.preventDefault();
212
-         evt.stopImmediatePropagation();
213
+         p2j.consumeEvent(evt);
214
       };
215
 
216
       this.onkeydown = onkeydown;
217
@@ -525,7 +522,9 @@
218
       
219
       /**
220
        * Tests if the keys strokes can invoke the permitted default actions: cut (shift + del,
221
-       * ctrl + x), copy (ctrl + ins, ctrl + c) and paste (shift + ins, ctrl + v).
222
+       * ctrl + x), copy (ctrl + ins, ctrl + c) and paste (shift + ins, ctrl + v). For Safari,
223
+       * pressing COMMAND + C, COMMAND + X and COMMAND + V can invoke the system clipboard copy,
224
+       * cut and paste actions.
225
        * 
226
        * @param    {Event} evt
227
        *           The merged key stroke event that represents two pressed keys: a modifier and 
228
@@ -536,14 +535,25 @@
229
        */
230
       function permittedKeyStrokes(evt)
231
       {
232
-         if (evt.shiftKey && (evt.keyCode === keys.DELETE || evt.keyCode === keys.INSERT))
233
+         if (p2j.isSafari)
234
          {
235
-            return true;
236
+            if (evt.metaKey &&
237
+                (evt.keyCode === keys.X || evt.keyCode === keys.C || evt.keyCode === keys.V))
238
+            {
239
+               return true;
240
+            }
241
          }
242
-         else if ((evt.ctrlKey && (evt.keyCode === keys.X || evt.keyCode === keys.C ||
243
-                     evt.keyCode === keys.V || evt.keyCode === keys.INSERT)))
244
+         else
245
          {
246
-            return true;
247
+            if (evt.shiftKey && (evt.keyCode === keys.DELETE || evt.keyCode === keys.INSERT))
248
+            {
249
+               return true;
250
+            }
251
+            else if ((evt.ctrlKey && (evt.keyCode === keys.X || evt.keyCode === keys.C ||
252
+                        evt.keyCode === keys.V || evt.keyCode === keys.INSERT)))
253
+            {
254
+               return true;
255
+            }
256
          }
257
          
258
          return false;
259
@@ -556,11 +566,14 @@
260
        *           The browser code of the pressed key
261
        * 
262
        * @return   {Boolean}
263
-       *           True iff a key is from the following set: SHIFT, ALT, CTRL.
264
+       *           True iff a key is from the following set: SHIFT, ALT, CTRL, COMMAND.
265
        */
266
       function isModifier(key)
267
       {
268
-         return key === keys.SHIFT || key === keys.CTRL || key === keys.ALT;
269
+         return key === keys.SHIFT ||
270
+                key === keys.CTRL  ||
271
+                key === keys.ALT   ||
272
+                key === keys.LEFT_WINDOW || key === keys.RIGHT_WINDOW;
273
       }
274
       
275
       /**
276
@@ -592,6 +605,10 @@
277
             last.ctrlKey = true;
278
             last.ctrlCount++;
279
          }
280
+         if (evt.metaKey || evt.keyCode === keys.LEFT_WINDOW || evt.keyCode === keys.RIGHT_WINDOW)
281
+         {
282
+            last.metaKey = true;
283
+         }
284
       }
285
 
286
       this.onkeydown = onkeydown;
287
@@ -609,7 +626,6 @@
288
             return false;
289
          }
290
          var last = queue.peek();
291
-         
292
          if (last === undefined)
293
          {
294
             last = {
295
@@ -617,6 +633,7 @@
296
                   shiftKey  : evt.shiftKey,
297
                   altKey    : evt.altKey,
298
                   ctrlKey   : evt.ctrlKey,
299
+                  metaKey   : evt.metaKey,
300
                   charCode  : evt.charCode,
301
                   ctrlCount : (evt.ctrlKey || evt.keyCode === keys.CTRL) ? 1 : 0
302
                };
303
@@ -642,6 +659,7 @@
304
                      shiftKey  : evt.shiftKey,
305
                      altKey    : evt.altKey,
306
                      ctrlKey   : evt.ctrlKey,
307
+                     metaKey   : evt.metaKey,
308
                      charCode  : evt.charCode,
309
                      ctrlCount : last.ctrlCount
310
                   };
311
@@ -662,6 +680,7 @@
312
                          shiftKey  : evt.shiftKey,
313
                          altKey    : evt.altKey,
314
                          ctrlKey   : evt.ctrlKey,
315
+                         metaKey   : evt.metaKey,
316
                          charCode  : evt.charCode,
317
                          ctrlCount : (evt.ctrlKey || evt.keyCode === keys.CTRL) ? 1 : 0
318
                       };
319
@@ -789,6 +808,12 @@
320
             return false;
321
          }
322
          var lastKey = queue.pop();
323
+         
324
+         if (lastKey === undefined)
325
+         {
326
+            return false;
327
+         }
328
+         
329
          handleKeyPress(evt, lastKey);
330
       };
331
       
332
@@ -809,14 +834,17 @@
333
        *           The flag indicating the alt modifier is active or not.
334
        * @param    {Boolean} shift
335
        *           The flag indicating the shift modifier is active or not.
336
+       * @param    {Boolean} meta
337
+       *           The flag indicating the meta modifier is active or not.
338
        */
339
-      function handleTypedKey(evt, lastKey, printedCode, mappedCode, ctrl, alt, shift)
340
+      function handleTypedKey(evt, lastKey, printedCode, mappedCode, ctrl, alt, shift, meta)
341
       {
342
          // In general (printedCode === evt.charCode) is true but if the keys are permuted,
343
          // then we can rely on the lastKey that is merged with keys modifiers
344
          var charCode = evt.charCode > 0 ? evt.charCode : printedCode;
345
          var code = -1;
346
-         if (ctrl)
347
+         var metaToCtrl = p2j.isSafari && meta;
348
+         if (ctrl || metaToCtrl)
349
          {
350
             if (isAlphabeticCharacter(lastKey))
351
             {
352
@@ -832,7 +860,8 @@
353
                code = lastKey.keyCode;
354
                code = code | 1 << 11;
355
             }
356
-            if (lastKey.ctrlCount && lastKey.ctrlCount > 1) // CTRL + CTRL + key
357
+            // CTRL + CTRL + key
358
+            if (lastKey.ctrlCount && lastKey.ctrlCount > 1 || (lastKey.ctrlCount && metaToCtrl))
359
             {
360
                code = code | 1 << 11;
361
             }
362
@@ -896,14 +925,17 @@
363
        *           The flag indicating the alt modifier is active or not.
364
        * @param    {Boolean} shift
365
        *           The flag indicating the shift modifier is active or not.
366
+       * @param    {Boolean} meta
367
+       *           The flag indicating the meta modifier is active or not.
368
        */
369
-      function handleNonTypedKey(evt, lastKey, mappedCode, ctrl, alt, shift)
370
+      function handleNonTypedKey(evt, lastKey, mappedCode, ctrl, alt, shift, meta)
371
       {
372
          // In general (lastKey.keyCode === evt.keyCode) is true but if the keys are permuted,
373
          // then we can rely on the lastKey that is merged with keys modifiers
374
          var code = mappedCode === undefined ? lastKey.keyCode : mappedCode;
375
+         var metaToCtrl = p2j.isSafari && meta;
376
          
377
-         if (ctrl)
378
+         if (ctrl || metaToCtrl)
379
          {
380
             if (lastKey.keyCode === keys.PAUSE)
381
             {
382
@@ -913,7 +945,8 @@
383
             {
384
                code = code | 1 << 11;
385
             }
386
-            if (lastKey.ctrlCount && lastKey.ctrlCount > 1) // CTRL + CTRL + key
387
+            // CTRL + CTRL + key
388
+            if (lastKey.ctrlCount && lastKey.ctrlCount > 1 || (lastKey.ctrlCount && metaToCtrl))
389
             {
390
                code = code | 1 << 11;
391
             }
392
@@ -950,6 +983,7 @@
393
           var ctrl  = lastKey.ctrlKey  || evt.ctrlKey;
394
           var alt   = lastKey.altKey   || evt.altKey;
395
           var shift = lastKey.shiftKey || evt.shiftKey;
396
+          var meta  = lastKey.metaKey  || evt.metaKey;
397
           // in general (lastKey.keyCode === evt.keyCode) is true but if the keys are permuted,
398
           // then we can rely on the lastKey that is merged with keys modifiers
399
           var mappedCode  = p2j.keymap.xlate[lastKey.keyCode];
400
@@ -958,12 +992,12 @@
401
           if (printedCode === -1)
402
           {
403
              //  a non printed key is pressed 
404
-             handleNonTypedKey(evt, lastKey, mappedCode, ctrl, alt, shift);
405
+             handleNonTypedKey(evt, lastKey, mappedCode, ctrl, alt, shift, meta);
406
           }
407
           else
408
           {
409
              // a printed key is pressed
410
-             handleTypedKey(evt, lastKey, printedCode, mappedCode, ctrl, alt, shift);
411
+             handleTypedKey(evt, lastKey, printedCode, mappedCode, ctrl, alt, shift, meta);
412
           }
413
       }
414
       
415
@@ -982,10 +1016,12 @@
416
             return false;
417
          }
418
          var lastKey = findKeyEventByKeyCode(evt.keyCode);
419
+         
420
          if (lastKey === undefined)
421
          {
422
-            return;
423
+            return false;
424
          }
425
+         
426
          handleKeyPress(evt, lastKey);
427
       };
428
 
429
@@ -1005,9 +1041,12 @@
430
          {
431
             var evt = queue[pos];
432
             // modifier key down events are merged
433
-            if (evt.keyCode === keyCode || (evt.altKey && keyCode == keys.ALT)
434
-                     || (evt.shiftKey && keyCode == keys.SHIFT)
435
-                     || (evt.ctrlKey && keyCode == keys.CTRL))
436
+            if ((evt.keyCode === keyCode)               ||
437
+                (evt.altKey   && keyCode == keys.ALT)   ||
438
+                (evt.shiftKey && keyCode == keys.SHIFT) ||
439
+                (evt.ctrlKey  && keyCode == keys.CTRL)  ||
440
+                (evt.metaKey  && keyCode === keys.LEFT_WINDOW) ||
441
+                (evt.metaKey  && keyCode === keys.RIGHT_WINDOW))
442
             {
443
                queue.splice(pos, 1);
444
                return evt;
445

    
446
=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keymap.js'
447
--- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keymap.js	2016-04-05 19:31:13 +0000
448
+++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.keymap.js	2016-06-03 10:00:55 +0000
449
@@ -20,6 +20,7 @@
450
 ** 008 SBI 20151011 Added SHIFT + DEL key label to return 639 as its key code.
451
 ** 009 SBI 20160120 Chrome and IE support.
452
 **     SBI 20160212 Fixes for copy/paste and cut default actions.
453
+** 010 SBI 20160603 Changed to process Safari COMMAND as it would be a CTRL key pressed.
454
 */
455
 
456
 "use strict";
457
@@ -795,7 +796,7 @@
458
    {
459
       var ctrlCode = -1;
460
       
461
-      if (evt.ctrlKey)
462
+      if (evt.ctrlKey || (p2j.isSafari && evt.metaKey))
463
       {         
464
          if (code === 50 || code === 64) //'2'
465
          {
466

    
467
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.mouse.js'
468
--- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.mouse.js	2016-05-30 20:05:14 +0000
469
+++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.mouse.js	2016-06-03 10:06:34 +0000
470
@@ -26,8 +26,8 @@
471
 ** 008 HC  20160406 Overhaul of window-activation logic.
472
 ** 009 SBI 20160505 Fixed MousePopupable to catch "click" and "contextmenu" events depending on
473
 **                  the popup activation button.
474
-**     SBI 20160523 Added system action listeners to handle mouse clicks on the copy, cut, paste
475
-**                  system menu items.
476
+**     SBI 20160603 Added system action listeners to handle mouse clicks on the copy, cut, paste
477
+**                  system menu items, added Safari copy, cut and paste support.
478
 */
479
 
480
 "use strict";
481
@@ -1339,6 +1339,46 @@
482
                {
483
                   console.debug("document.execCommand(" + osOp + ")");
484
                }
485
+               else
486
+               {
487
+                  var dialogCloseHandler;
488
+                  if (osOp === "cut")
489
+                  {
490
+                     dialogCloseHandler = function(evt)
491
+                     {
492
+                        if ((evt.metaKey  && (evt.keyCode === keys.X) && p2j.isSafari) ||
493
+                              (((evt.shiftKey && (evt.keyCode === keys.DELETE)) ||
494
+                                ( evt.ctrlKey && (evt.keyCode === keys.X))
495
+                               ) && !p2j.isSafari))
496
+                        {
497
+                           p2j.closeDialog();
498
+                           p2j.clipboard.prepareCopy();
499
+                        }
500
+                     }
501
+                  }
502
+                  else
503
+                  {
504
+                     dialogCloseHandler = function(evt)
505
+                     {
506
+                        if ((evt.metaKey && (evt.keyCode === keys.C) && p2j.isSafari) ||
507
+                            (evt.ctrlKey &&
508
+                             (evt.keyCode === keys.C || evt.keyCode === keys.INSERT) &&
509
+                                    !p2j.isSafari))
510
+                        {
511
+                           p2j.closeDialog();
512
+                           p2j.clipboard.prepareCopy();
513
+                        }
514
+                     }
515
+                  }
516
+                  var maxZIndex = p2j.getMaxZIndex();
517
+                  p2j.createDialog(
518
+                        "writeClipboard",
519
+                        1000 + maxZIndex,
520
+                        document.body,
521
+                        p2j.prompts(osOp),
522
+                        p2j.hints(osOp),
523
+                        dialogCloseHandler);
524
+               }
525
             }
526
             else if (osOp === "paste")
527
             {
528
@@ -1355,12 +1395,14 @@
529
                         "readClipboard",
530
                         1000 + maxZIndex,
531
                         document.body,
532
-                        p2j.pasteNotification,
533
-                        "Press CTRL-V to close this dialog.",
534
+                        p2j.prompts("paste"),
535
+                        p2j.hints("paste"),
536
                         function (evt)
537
                         {
538
-                           if ((evt.shiftKey && (evt.keyCode === keys.INSERT)) ||
539
-                               (evt.ctrlKey && (evt.keyCode === keys.V)))
540
+                           if ((evt.metaKey  && (evt.keyCode === keys.V) && p2j.isSafari) ||
541
+                               (((evt.shiftKey && (evt.keyCode === keys.INSERT)) ||
542
+                                 ( evt.ctrlKey && (evt.keyCode === keys.V))
543
+                                ) && !p2j.isSafari))
544
                            {
545
                               p2j.closeDialog();
546
                               p2j.clipboard.preparePaste();
547