add support for Global shortcut binding, Spotlight now can be called using CTRL+SPACE

This commit is contained in:
Xuan Sang LE 2018-03-04 13:34:31 +01:00
parent b35096bcca
commit 5d0d03119a
7 changed files with 56 additions and 39 deletions

View File

@ -42,10 +42,10 @@ class BaseApplication extends this.OS.GUI.BaseModel
return unless @keycomb[fnk]
@keycomb[fnk][c] = f
shortcut: (fnk, c) ->
shortcut: (fnk, c, e) ->
return true unless @keycomb[fnk]
return true unless @keycomb[fnk][c]
@keycomb[fnk][c]()
@keycomb[fnk][c](e)
return false
applySetting: (k) ->

View File

@ -2,6 +2,11 @@ self.OS.GUI =
subwindows: new Object()
dialog: undefined
fullscreen: false
shortcut:
ALT: {}
CTRL: {}
SHIFT: {}
META: {}
htmlToScheme: (html, app, parent) ->
scheme = $.parseHTML html
($ parent).append scheme
@ -188,6 +193,14 @@ self.OS.GUI =
handler event.target
event.preventDefault()
bindKey: (k, f) ->
arr = k.split "-"
return unless arr.length is 2
fnk = arr[0].toUpperCase()
c = arr[1].toUpperCase()
return unless _GUI.shortcut[fnk]
_GUI.shortcut[fnk][c] = f
initDM: ->
($ document).on 'webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange', ()->
_GUI.fullscreen = not _GUI.fullscreen
@ -202,7 +215,7 @@ self.OS.GUI =
dock = ($ "#sysdock")[0]
return unless dock
app = dock.get "selectedApp"
return true unless app
#return true unless app
c = String.fromCharCode(event.which).toUpperCase()
fnk = undefined
if event.ctrlKey
@ -214,9 +227,13 @@ self.OS.GUI =
else if event.altKey
fnk = "ALT"
return unless fnk
r = app.shortcut fnk, c
event.preventDefault() if not r
return unless fnk
r = if app then app.shortcut fnk, c, event else true
return event.preventDefault() if not r
return unless _GUI.shortcut[fnk]
return unless _GUI.shortcut[fnk][c]
_GUI.shortcut[fnk][c](event)
event.preventDefault()
# system menu and dock
riot.mount ($ "#syspanel", $ "#wrapper")
riot.mount ($ "#sysdock", $ "#wrapper"), { items: [] }

View File

@ -4,7 +4,7 @@ jsfiles =
cssfiles = main.css
copyfiles = package.json notifications.html spotlight.html
copyfiles = package.json
PKG_NAME=CoreServices

View File

@ -7,8 +7,9 @@ class PushNotification extends this.OS.GUI.BaseService
@pending = []
init: ->
@view = false
path = path = "#{@meta().path}/notifications.html"
@render path
@_gui.htmlToScheme PushNotification.scheme, @, @host
#path = path = "#{@meta().path}/notifications.html"
#@render path
spin: (b) ->
if b and @iconclass is "fa fa-bars"
@ -93,5 +94,16 @@ class PushNotification extends this.OS.GUI.BaseService
cleanup: (evt) ->
# do nothing
PushNotification.scheme = """
<afx-dummy>
<afx-overlay data-id = "notifyzone" width = "250">
<afx-button text = "Clear all" data-id = "btclear"></afx-button>
<afx-list-view data-id="notifylist"></afx-list-view>
</afx-overlay>
<afx-overlay data-id = "feedzone" width = "250">
<afx-list-view data-id = "notifeed">
</afx-list-view>
</afx-overlay>
</afx-dummy>
"""
this.OS.register "PushNotification",PushNotification

View File

@ -3,8 +3,8 @@ class SpotlightDialog extends this.OS.GUI.BaseDialog
super "SpotlightDialog"
init: () ->
@render "#{@path()}/spotlight.html"
#@render "#{@path()}/spotlight.html"
@_gui.htmlToScheme SpotlightDialog.scheme, @, @host
main: () ->
me = @
@height = ($ @scheme).css("height")
@ -37,7 +37,6 @@ class SpotlightDialog extends this.OS.GUI.BaseDialog
($ document).unbind "click", me.fn1
($ document).unbind "keyup", me.fn
me.quit()
search: (e) ->
@ -71,7 +70,17 @@ class SpotlightDialog extends this.OS.GUI.BaseDialog
@container.set "items", result
($ @scheme).css("height", @height)
SpotlightDialog.scheme = """
<afx-app-window data-id = "spotlight-win" apptitle="" minimizable="false" resizable = "false" width="500" height="300">
<afx-vbox>
<afx-hbox data-height="45">
<div data-id = "searchicon" data-width="45"></div>
<input type = "text" data-id="searchbox"/>
</afx-hbox>
<afx-list-view data-id="container"></afx-list-view>
</afx-vbox>
</afx-app-window>
"""
this.OS.register "SpotlightDialog", SpotlightDialog
class Spotlight extends this.OS.GUI.BaseService
@ -80,6 +89,9 @@ class Spotlight extends this.OS.GUI.BaseService
@iconclass = "fa fa-search"
@show = false
init: ->
me = @
@_gui.bindKey "CTRL- ", (e) ->
me.awake(e)
#@child = [
# {
# text: "#{@.name} (#{@.pid}): dummy notif",
@ -88,7 +100,7 @@ class Spotlight extends this.OS.GUI.BaseService
#]
# do nothing
main: ->
awake: (e) ->
me = @
if not @show

View File

@ -1,10 +0,0 @@
<afx-dummy>
<afx-overlay data-id = "notifyzone" width = "250">
<afx-button text = "Clear all" data-id = "btclear"></afx-button>
<afx-list-view data-id="notifylist"></afx-list-view>
</afx-overlay>
<afx-overlay data-id = "feedzone" width = "250">
<afx-list-view data-id = "notifeed">
</afx-list-view>
</afx-overlay>
</afx-dummy>

View File

@ -1,14 +0,0 @@
<afx-app-window data-id = "spotlight-win" apptitle="" minimizable="false" resizable = "false" width="500" height="300">
<afx-vbox>
<afx-hbox data-height="45">
<div data-id = "searchicon" data-width="45"></div>
<input type = "text" data-id="searchbox"/>
</afx-hbox>
<afx-list-view data-id="container"></afx-list-view>
<!--afx-hbox data-id="container">
<afx-resizer data-width ="5"></afx-resizer>
<div data-id="preview"></div>
</afx-hbox-->
</afx-vbox>
</afx-app-window>