Added shortcuts to electron events.

This commit is contained in:
Martin Edenhofer 2016-04-05 23:49:45 +02:00
parent da3ce257d0
commit 691f2006b2
2 changed files with 70 additions and 42 deletions

View file

@ -4,31 +4,35 @@ class Widget
electron = window.require('electron') electron = window.require('electron')
return if !electron return if !electron
remote = electron.remote remote = electron.remote
ipc = electron.ipcRenderer
App.Event.bind('online_notification_counter', (e) -> App.Event.bind('online_notification_counter', (e) ->
setBadge(e) setBadge(e)
) )
ipc.on('global-shortcut', (e, arg) ->
App.Event.trigger('global-shortcut', arg)
)
Menu = remote.Menu Menu = remote.Menu
MenuItem = remote.MenuItem MenuItem = remote.MenuItem
createDefault = -> createDefault = ->
menu = new Menu() menu = new Menu()
menu.append(new MenuItem({ menu.append(new MenuItem(
label: 'Cut', label: 'Cut',
role: 'cut' role: 'cut'
})) ))
menu.append(new MenuItem({ menu.append(new MenuItem(
label: 'Copy', label: 'Copy',
role: 'copy' role: 'copy'
})) ))
menu.append(new MenuItem({ menu.append(new MenuItem(
label: 'Paste', label: 'Paste',
role: 'paste' role: 'paste'
})) ))
menu.append(new MenuItem({ menu.append(new MenuItem(
label: 'Select All', label: 'Select All',
role: 'selectall' role: 'selectall'
})) ))
menu menu
menu = createDefault() menu = createDefault()
@ -55,7 +59,7 @@ class Widget
ctx.fillStyle = '#ffffff' ctx.fillStyle = '#ffffff'
ctx.textAlign = 'center' ctx.textAlign = 'center'
ctx.textBaseline = 'middle' ctx.textBaseline = 'middle'
ctx.font = (11 * scale) + 'px sans-serif' ctx.font = (10 * scale) + 'px sans-serif'
ctx.fillText(text, size / 2, size / 2, size) ctx.fillText(text, size / 2, size / 2, size)
canvas.toDataURL() canvas.toDataURL()
@ -69,7 +73,7 @@ class Widget
}) })
if content isnt '' if content isnt ''
dataURL = badgeDataURL.createDataURL(content.toString()) dataURL = badgeDataURL(content.toString())
sendBadge(dataURL, 'You have unread messages (' + content + ')') sendBadge(dataURL, 'You have unread messages (' + content + ')')
else else
sendBadge(null, 'You have no unread messages') sendBadge(null, 'You have no unread messages')

View file

@ -40,7 +40,18 @@ class App.KeyboardShortcutWidget extends Spine.Module
modifier += shortcut.key modifier += shortcut.key
if shortcut.callback if shortcut.callback
@log 'debug', 'bind for', modifier @log 'debug', 'bind for', modifier
$(document).bind('keydown', modifier, shortcut.callback) $(document).bind('keydown', modifier, (e) ->
e.preventDefault()
shortcut.callback()
)
App.Event.bind('global-shortcut', (e) ->
for area in areas
for item in area.content
for shortcut in item.shortcuts
if shortcut.globalEvent is e
shortcut.callback()
)
App.Config.set('keyboard_shortcuts', App.KeyboardShortcutWidget, 'Widgets') App.Config.set('keyboard_shortcuts', App.KeyboardShortcutWidget, 'Widgets')
App.Config.set( App.Config.set(
@ -57,8 +68,8 @@ App.Config.set(
key: 'd' key: 'd'
hotkeys: true hotkeys: true
description: 'Dashboard' description: 'Dashboard'
callback: (e) -> globalEvent: 'dashboard'
e.preventDefault() callback: ->
$('#global-search').blur() $('#global-search').blur()
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
window.location.hash = '#dashboard' window.location.hash = '#dashboard'
@ -67,8 +78,8 @@ App.Config.set(
key: 'o' key: 'o'
hotkeys: true hotkeys: true
description: 'Overviews' description: 'Overviews'
callback: (e) -> globalEvent: 'overview'
e.preventDefault() callback: ->
$('#global-search').blur() $('#global-search').blur()
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
window.location.hash = '#ticket/view' window.location.hash = '#ticket/view'
@ -77,8 +88,8 @@ App.Config.set(
key: 's' key: 's'
hotkeys: true hotkeys: true
description: 'Search' description: 'Search'
callback: (e) -> globalEvent: 'search'
e.preventDefault() callback: ->
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
$('#global-search').focus() $('#global-search').focus()
} }
@ -86,8 +97,8 @@ App.Config.set(
key: 'a' key: 'a'
hotkeys: true hotkeys: true
description: 'Notifications' description: 'Notifications'
callback: (e) -> globalEvent: 'notification'
e.preventDefault() callback: ->
$('#global-search').blur() $('#global-search').blur()
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
$('#navigation .js-toggleNotifications').click() $('#navigation .js-toggleNotifications').click()
@ -96,8 +107,8 @@ App.Config.set(
key: 'n' key: 'n'
hotkeys: true hotkeys: true
description: 'New Ticket' description: 'New Ticket'
callback: (e) -> globalEvent: 'new-ticket'
e.preventDefault() callback: ->
$('#global-search').blur() $('#global-search').blur()
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
window.location.hash = '#ticket/create' window.location.hash = '#ticket/create'
@ -106,8 +117,8 @@ App.Config.set(
key: 'e' key: 'e'
hotkeys: true hotkeys: true
description: 'Logout' description: 'Logout'
callback: (e) -> globalEvent: 'logout'
e.preventDefault() callback: ->
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
window.location.hash = '#logout' window.location.hash = '#logout'
} }
@ -115,8 +126,8 @@ App.Config.set(
key: 'h' key: 'h'
hotkeys: true hotkeys: true
description: 'List of shortcuts' description: 'List of shortcuts'
globalEvent: 'list-of-shortcuts'
callback: (e) => callback: (e) =>
e.preventDefault()
if @dialog && @dialog.exists() if @dialog && @dialog.exists()
@dialog.close() @dialog.close()
@dialog = false @dialog = false
@ -127,8 +138,8 @@ App.Config.set(
key: 'x' key: 'x'
hotkeys: true hotkeys: true
description: 'Close current tab' description: 'Close current tab'
callback: (e) -> globalEvent: 'close-current-tab'
e.preventDefault() callback: ->
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
$('#navigation .tasks .is-active .js-close').click() $('#navigation .tasks .is-active .js-close').click()
} }
@ -136,8 +147,8 @@ App.Config.set(
key: 'tab' key: 'tab'
hotkeys: true hotkeys: true
description: 'Next in tab' description: 'Next in tab'
callback: (e) -> globalEvent: 'next-in-tab'
e.preventDefault() callback: ->
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
scollIfNeeded = (element) -> scollIfNeeded = (element) ->
return if !element return if !element
@ -159,8 +170,8 @@ App.Config.set(
key: 'shift+tab' key: 'shift+tab'
hotkeys: true hotkeys: true
description: 'Previous tab' description: 'Previous tab'
callback: (e) -> globalEvent: 'previous-in-tab'
e.preventDefault() callback: ->
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
scollIfNeeded = (element) -> scollIfNeeded = (element) ->
return if !element return if !element
@ -182,8 +193,8 @@ App.Config.set(
key: 'return' key: 'return'
hotkeys: true hotkeys: true
description: 'Confirm/submit dialog' description: 'Confirm/submit dialog'
callback: (e) -> globalEvent: 'submit'
e.preventDefault() callback: ->
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
# check of primary modal exists # check of primary modal exists
@ -242,6 +253,7 @@ App.Config.set(
key: 't' key: 't'
hotkeys: true hotkeys: true
description: 'Enable/disable inline translations' description: 'Enable/disable inline translations'
globalEvent: 'translation-mode'
} }
] ]
} }
@ -258,8 +270,8 @@ App.Config.set(
key: 'm' key: 'm'
hotkeys: true hotkeys: true
description: 'Open note box' description: 'Open note box'
callback: (e) -> globalEvent: 'article-note-open'
e.preventDefault() callback: ->
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
$('.active.content .editControls .js-articleTypes [data-value="note"]').click() $('.active.content .editControls .js-articleTypes [data-value="note"]').click()
$('.active.content .article-new .articleNewEdit-body').first().focus() $('.active.content .article-new .articleNewEdit-body').first().focus()
@ -268,8 +280,8 @@ App.Config.set(
key: 'g' key: 'g'
hotkeys: true hotkeys: true
description: 'Reply to last article' description: 'Reply to last article'
callback: (e) -> globalEvent: 'article-reply'
e.preventDefault() callback: ->
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
lastArticleWithReply = $('.active.content .ticket-article .icon-reply').last() lastArticleWithReply = $('.active.content .ticket-article .icon-reply').last()
lastArticleWithReplyAll = lastArticleWithReply.parent().find('.icon-reply-all') lastArticleWithReplyAll = lastArticleWithReply.parent().find('.icon-reply-all')
@ -282,8 +294,8 @@ App.Config.set(
key: 'j' key: 'j'
hotkeys: true hotkeys: true
description: 'Set article to internal/public' description: 'Set article to internal/public'
callback: (e) -> globalEvent: 'article-internal-public'
e.preventDefault() callback: ->
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
$('.active.content .editControls .js-selectInternalPublic').click() $('.active.content .editControls .js-selectInternalPublic').click()
} }
@ -291,16 +303,16 @@ App.Config.set(
# key: 'm' # key: 'm'
# hotkeys: true # hotkeys: true
# description: 'Open macro selection' # description: 'Open macro selection'
# callback: (e) -> # globalEvent: 'macro-open'
# e.preventDefault() # callback: ->
# window.location.hash = '#ticket/create' # window.location.hash = '#ticket/create'
#} #}
{ {
key: 'c' key: 'c'
hotkeys: true hotkeys: true
description: 'Update as closed' description: 'Update as closed'
callback: (e) -> globalEvent: 'task-update-close'
e.preventDefault() callback: ->
App.Event.trigger('keyboard_shortcuts_close') App.Event.trigger('keyboard_shortcuts_close')
return if !$('.active.content .edit').get(0) return if !$('.active.content .edit').get(0)
$('.active.content .edit [name="state_id"]').val(4) $('.active.content .edit [name="state_id"]').val(4)
@ -322,61 +334,73 @@ App.Config.set(
key: 'u' key: 'u'
hotkeys: true hotkeys: true
description: 'Format as _underlined_' description: 'Format as _underlined_'
globalEvent: 'richtext-underline'
} }
{ {
key: 'b' key: 'b'
hotkeys: true hotkeys: true
description: 'Format as |bold|' description: 'Format as |bold|'
globalEvent: 'richtext-bold'
} }
{ {
key: 'i' key: 'i'
hotkeys: true hotkeys: true
description: 'Format as ||italic||' description: 'Format as ||italic||'
globalEvent: 'richtext-italic'
} }
{ {
key: 'v' key: 'v'
hotkeys: true hotkeys: true
description: 'Format as //strikethrough//' description: 'Format as //strikethrough//'
globalEvent: 'richtext-strikethrough'
} }
{ {
key: 'f' key: 'f'
hotkeys: true hotkeys: true
description: 'Removes the formatting' description: 'Removes the formatting'
globalEvent: 'richtext-remove-formating'
} }
{ {
key: 'z' key: 'z'
hotkeys: true, hotkeys: true,
description: 'Inserts a horizontal rule' description: 'Inserts a horizontal rule'
globalEvent: 'richtext-hr'
} }
{ {
key: 'l' key: 'l'
hotkeys: true, hotkeys: true,
description: 'Format as unordered list' description: 'Format as unordered list'
globalEvent: 'richtext-ul'
} }
{ {
key: 'k' key: 'k'
hotkeys: true, hotkeys: true,
description: 'Format as ordered list' description: 'Format as ordered list'
globalEvent: 'richtext-ol'
} }
{ {
key: '1' key: '1'
hotkeys: true, hotkeys: true,
description: 'Format as h1 heading' description: 'Format as h1 heading'
globalEvent: 'richtext-h1'
} }
{ {
key: '2' key: '2'
hotkeys: true, hotkeys: true,
description: 'Format as h2 heading' description: 'Format as h2 heading'
globalEvent: 'richtext-h2'
} }
{ {
key: '3' key: '3'
hotkeys: true, hotkeys: true,
description: 'Format as h3 heading' description: 'Format as h3 heading'
globalEvent: 'richtext-h3'
} }
{ {
key: 'w' key: 'w'
hotkeys: true, hotkeys: true,
description: 'Removes any hyperlink' description: 'Removes any hyperlink'
globalEvent: 'richtext-remove-hyperlink'
} }
] ]
} }