forked from coyim/coyim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shortcuts.go
54 lines (43 loc) · 1.72 KB
/
shortcuts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package gui
import "github.com/twstrike/coyim/Godeps/_workspace/src/github.com/twstrike/gotk3adapter/gtki"
func (u *gtkUI) increaseFontSize(w gtki.Window) {
u.displaySettings.increaseFontSize()
}
func (u *gtkUI) decreaseFontSize(w gtki.Window) {
u.displaySettings.decreaseFontSize()
}
func (u *gtkUI) closeApplication(w gtki.Window) {
u.quit()
}
func (u *gtkUI) closeWindow(w gtki.Window) {
w.Hide()
}
func connectShortcut(accel string, w gtki.Window, action func(gtki.Window)) {
gr, _ := g.gtk.AccelGroupNew()
key, mod := g.gtk.AcceleratorParse(accel)
// Do not remove the closure here - there is a limitation
// in gtk that makes it necessary to have different functions for different accelerator groups
gr.Connect2(key, mod, gtki.ACCEL_VISIBLE, func() {
action(w)
})
w.AddAccelGroup(gr)
}
func (u *gtkUI) connectShortcutsMainWindow(w gtki.Window) {
// <Primary> maps to Command on OS X, but Control on other platforms
connectShortcut("<Primary>q", w, u.closeApplication)
connectShortcut("<Primary>w", w, u.closeApplication)
connectShortcut("<Alt>F4", w, u.closeApplication)
}
func (u *gtkUI) connectShortcutsChildWindow(w gtki.Window) {
// <Primary> maps to Command on OS X, but Control on other platforms
connectShortcut("<Primary>q", w, u.closeApplication)
connectShortcut("<Primary>w", w, u.closeWindow)
connectShortcut("<Primary>F4", w, u.closeWindow)
connectShortcut("<Alt>F4", w, u.closeApplication)
connectShortcut("Escape", w, u.closeWindow)
}
func (u *gtkUI) connectShortcutsConversationWindow(c *conversationWindow) {
// <Primary> maps to Command on OS X, but Control on other platforms
connectShortcut("<Primary>plus", c.win, u.increaseFontSize)
connectShortcut("<Primary>minus", c.win, u.decreaseFontSize)
}