Commit a981bb37 authored by Benoît Minisini's avatar Benoît Minisini
Browse files

Menu shortcuts do not propagate to the browser.

[GB.WEB.GUI]
* NEW: Menu shortcuts do not propagate to the browser.
parent 5b8ef31f
Pipeline #359640949 passed with stage
in 26 minutes and 50 seconds
comp/src/gb.web.gui/.icon.png

11.9 KB | W: | H:

comp/src/gb.web.gui/.icon.png

11.9 KB | W: | H:

comp/src/gb.web.gui/.icon.png
comp/src/gb.web.gui/.icon.png
comp/src/gb.web.gui/.icon.png
comp/src/gb.web.gui/.icon.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -10,6 +10,7 @@ Component=gb.signal
Component=gb.util.web
Component=gb.web
Arguments=[["","TEST"]]
Environment="GB_WEB_GUI_DEBUG=1"
TabSize=2
Translate=1
Language=en_US
......@@ -17,3 +18,4 @@ RunAfter=cp -f $(FILE) /home/guygle/guygle/cgi-bin/test && gbi3 gb.web.gui
Type=Component
Packager=1
DoNotTranslate=".src/Test"
CompressedFiles="lib.js","ac.js","style.css"
......@@ -50,7 +50,7 @@ Static Private Function Normal_Read() As Boolean
End
Static Private Sub TranslateCode(sCode As String) As String
Static Private Sub CodeFromDOM(sCode As String) As String
Dim sTrans As String
......@@ -75,13 +75,39 @@ Static Private Sub TranslateCode(sCode As String) As String
End
Static Public Sub _ShortcutToDOM(sShortcut As String) As String
Static cTrans As Collection
Dim aShortcut As String[]
Dim sKey As String
aShortcut = Split(sShortcut, "+")
If Not cTrans Then
cTrans = [
"Down": "ArrowDown",
"Up": "ArrowUp",
"Left": "ArrowLeft",
"Right": "ArrowRight",
"Space": " "
]
Endif
sKey = aShortcut.Last
If cTrans.Exist(sKey) Then aShortcut.Last = cTrans[sKey]
Return String.UCase(aShortcut.Join("+"))
End
Static Private Function Code_Read() As String
Dim sCode As String
If Not _Event Then Error.Raise("No keyboard data")
sCode = TranslateCode(_Event["key"])
sCode = CodeFromDOM(_Event["key"])
If String.Len(sCode) = 1 Then sCode = String.UCase(sCode)
Return sCode
......
......@@ -9,7 +9,7 @@
{ WebMenu3 WebMenu
Text = ("Open")
Image = "icon:/small/open"
Shortcut = "Ctrl+Alt+O"
Shortcut = "Ctrl+O"
}
{ WebMenu11 WebMenu
Text = ("Open recent")
......
......@@ -745,6 +745,8 @@ Public Sub _BeforeRender()
Print Me._GetKeyPressHandler();
Print ">"
DisableShortcuts()
End
Public Sub Render()
......@@ -1383,6 +1385,39 @@ Public Sub _GetHeaders() As String[]
End
Private Sub FindShortcut(hParent As WebContainer, cShortcut As Collection)
Dim hChild As WebControl
Dim hMenu As WebMenu
Dim sShortcut As String
For Each hChild In hParent.Children
hMenu = hChild
If Not hMenu.Enabled Then Continue
sShortcut = hMenu.Shortcut
If sShortcut Then
sShortcut = Key._ShortcutToDOM(sShortcut)
cShortcut[sShortcut] = True
Endif
If hMenu.HasChildren() Then FindShortcut(hChild, cShortcut)
Next
End
Private Sub DisableShortcuts()
Dim cShortcut As Collection
cShortcut = New Collection
FindShortcut($hMenuBar, cShortcut)
If cShortcut.Count = 0 Then Return
_AddJavascript("gw.shortcuts = " & JS(cShortcut))
End
Private Sub TriggerShortcut(hParent As WebContainer, sShortcut As String) As Boolean
Dim hChild As WebControl
......@@ -1390,10 +1425,11 @@ Private Sub TriggerShortcut(hParent As WebContainer, sShortcut As String) As Boo
For Each hChild In hParent.Children
hMenu = hChild
If Not hMenu.Enabled Then Continue
If String.UCase(hMenu.Shortcut) = sShortcut Then
Object.Raise(hChild, "Click")
Return True
Else If TriggerShortcut(hChild, sShortcut) Then
Else If hMenu.HasChildren() And If TriggerShortcut(hChild, sShortcut) Then
Return True
Endif
Next
......
......@@ -1592,10 +1592,20 @@ gw = {
}
},
makeShortcut: function(event)
{
var shortcut = '';
if (event.ctrlKey && event.key != 'Control') shortcut += 'CTRL+';
if (event.shiftKey && event.key != 'Shift') shortcut += 'SHIFT+';
if (event.altKey && event.key != 'Alt') shortcut += 'ALT+';
if (event.meta && event.key != 'Meta') shortcut += 'META+';
shortcut += event.key.toUpperCase();
return shortcut;
},
onkeydown: function(event)
{
console.log('onkeydown: ' + event);
if (!event.bubbles)
return;
......@@ -1620,8 +1630,14 @@ gw = {
'shiftKey': event.shiftKey
}],
null);
if (gw.shortcuts)
{
var shortcut = gw.makeShortcut(event);
console.log('shortcut -> ' + shortcut);
if (gw.shortcuts[shortcut])
event.preventDefault();
}
}
}
document.onkeydown = gw.onkeydown;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment