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] return unless @keycomb[fnk]
@keycomb[fnk][c] = f @keycomb[fnk][c] = f
shortcut: (fnk, c) -> shortcut: (fnk, c, e) ->
return true unless @keycomb[fnk] return true unless @keycomb[fnk]
return true unless @keycomb[fnk][c] return true unless @keycomb[fnk][c]
@keycomb[fnk][c]() @keycomb[fnk][c](e)
return false return false
applySetting: (k) -> applySetting: (k) ->

View File

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

View File

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

View File

@ -7,8 +7,9 @@ class PushNotification extends this.OS.GUI.BaseService
@pending = [] @pending = []
init: -> init: ->
@view = false @view = false
path = path = "#{@meta().path}/notifications.html" @_gui.htmlToScheme PushNotification.scheme, @, @host
@render path #path = path = "#{@meta().path}/notifications.html"
#@render path
spin: (b) -> spin: (b) ->
if b and @iconclass is "fa fa-bars" if b and @iconclass is "fa fa-bars"
@ -93,5 +94,16 @@ class PushNotification extends this.OS.GUI.BaseService
cleanup: (evt) -> cleanup: (evt) ->
# do nothing # 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 this.OS.register "PushNotification",PushNotification

View File

@ -3,8 +3,8 @@ class SpotlightDialog extends this.OS.GUI.BaseDialog
super "SpotlightDialog" super "SpotlightDialog"
init: () -> init: () ->
@render "#{@path()}/spotlight.html" #@render "#{@path()}/spotlight.html"
@_gui.htmlToScheme SpotlightDialog.scheme, @, @host
main: () -> main: () ->
me = @ me = @
@height = ($ @scheme).css("height") @height = ($ @scheme).css("height")
@ -37,7 +37,6 @@ class SpotlightDialog extends this.OS.GUI.BaseDialog
($ document).unbind "click", me.fn1 ($ document).unbind "click", me.fn1
($ document).unbind "keyup", me.fn ($ document).unbind "keyup", me.fn
me.quit() me.quit()
search: (e) -> search: (e) ->
@ -71,7 +70,17 @@ class SpotlightDialog extends this.OS.GUI.BaseDialog
@container.set "items", result @container.set "items", result
($ @scheme).css("height", @height) ($ @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 this.OS.register "SpotlightDialog", SpotlightDialog
class Spotlight extends this.OS.GUI.BaseService class Spotlight extends this.OS.GUI.BaseService
@ -80,6 +89,9 @@ class Spotlight extends this.OS.GUI.BaseService
@iconclass = "fa fa-search" @iconclass = "fa fa-search"
@show = false @show = false
init: -> init: ->
me = @
@_gui.bindKey "CTRL- ", (e) ->
me.awake(e)
#@child = [ #@child = [
# { # {
# text: "#{@.name} (#{@.pid}): dummy notif", # text: "#{@.name} (#{@.pid}): dummy notif",
@ -88,7 +100,7 @@ class Spotlight extends this.OS.GUI.BaseService
#] #]
# do nothing # do nothing
main: -> main: ->
awake: (e) -> awake: (e) ->
me = @ me = @
if not @show 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>