From 5d0d03119af95dde8593e6eb66a4598d51d17326 Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Sun, 4 Mar 2018 13:34:31 +0100 Subject: [PATCH] add support for Global shortcut binding, Spotlight now can be called using CTRL+SPACE --- src/core/BaseApplication.coffee | 4 +-- src/core/gui.coffee | 25 ++++++++++++++++--- src/packages/CoreServices/Makefile | 2 +- .../CoreServices/PushNotification.coffee | 18 ++++++++++--- src/packages/CoreServices/Spotlight.coffee | 22 ++++++++++++---- src/packages/CoreServices/notifications.html | 10 -------- src/packages/CoreServices/spotlight.html | 14 ----------- 7 files changed, 56 insertions(+), 39 deletions(-) delete mode 100644 src/packages/CoreServices/notifications.html delete mode 100644 src/packages/CoreServices/spotlight.html diff --git a/src/core/BaseApplication.coffee b/src/core/BaseApplication.coffee index 3f47808..effe421 100644 --- a/src/core/BaseApplication.coffee +++ b/src/core/BaseApplication.coffee @@ -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) -> diff --git a/src/core/gui.coffee b/src/core/gui.coffee index 23712ed..fb158f0 100644 --- a/src/core/gui.coffee +++ b/src/core/gui.coffee @@ -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: [] } diff --git a/src/packages/CoreServices/Makefile b/src/packages/CoreServices/Makefile index 2fc5eaf..1d51ce4 100644 --- a/src/packages/CoreServices/Makefile +++ b/src/packages/CoreServices/Makefile @@ -4,7 +4,7 @@ jsfiles = cssfiles = main.css -copyfiles = package.json notifications.html spotlight.html +copyfiles = package.json PKG_NAME=CoreServices diff --git a/src/packages/CoreServices/PushNotification.coffee b/src/packages/CoreServices/PushNotification.coffee index f4f79ba..4482379 100644 --- a/src/packages/CoreServices/PushNotification.coffee +++ b/src/packages/CoreServices/PushNotification.coffee @@ -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 = """ + + + + + + + + + + +""" this.OS.register "PushNotification",PushNotification \ No newline at end of file diff --git a/src/packages/CoreServices/Spotlight.coffee b/src/packages/CoreServices/Spotlight.coffee index a17ca71..6bd7711 100644 --- a/src/packages/CoreServices/Spotlight.coffee +++ b/src/packages/CoreServices/Spotlight.coffee @@ -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 = """ + + + +
+ +
+ +
+
+""" 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 diff --git a/src/packages/CoreServices/notifications.html b/src/packages/CoreServices/notifications.html deleted file mode 100644 index f28a3c2..0000000 --- a/src/packages/CoreServices/notifications.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/src/packages/CoreServices/spotlight.html b/src/packages/CoreServices/spotlight.html deleted file mode 100644 index 030f449..0000000 --- a/src/packages/CoreServices/spotlight.html +++ /dev/null @@ -1,14 +0,0 @@ - - - -
- -
- - -
-
\ No newline at end of file