-
Notifications
You must be signed in to change notification settings - Fork 80
/
shortcuts.go
145 lines (120 loc) · 3.48 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package gui
import (
"io/ioutil"
"path/filepath"
"github.com/coyim/coyim/config"
"github.com/coyim/gotk3adapter/gtki"
)
var emacsKeyConf string
func init() {
path := "Emacs/gtk-3.0/gtk-keys.css"
toLook := []string{
filepath.Join(config.XdgDataHome(), "themes", path),
filepath.Join(config.WithHome(".themes"), path),
}
for _, dd := range config.XdgDataDirs() {
toLook = append(toLook, filepath.Join(dd, "themes", path))
}
toLook = append(toLook, filepath.Join("/usr/share/themes", path))
ek, ok := config.FindFile(toLook)
if ok {
content, _ := ioutil.ReadFile(ek)
emacsKeyConf = string(content)
}
}
type keyboardSettings struct {
emacs bool
provider gtki.CssProvider
}
func (ks *keyboardSettings) control(w gtki.Widget) {
doInUIThread(func() {
styleContext, _ := w.GetStyleContext()
styleContext.AddProvider(ks.provider, 9999)
})
}
func (ks *keyboardSettings) update() {
doInUIThread(func() {
if ks.emacs {
ks.provider.LoadFromData(emacsKeyConf)
} else {
ks.provider.LoadFromData("")
}
})
}
func newKeyboardSettings() *keyboardSettings {
ks := &keyboardSettings{}
prov, _ := g.gtk.CssProviderNew()
ks.provider = prov
return ks
}
func (u *gtkUI) increaseFontSize(w gtki.Window) {
u.displaySettings.increaseFontSize()
}
func (u *gtkUI) decreaseFontSize(w gtki.Window) {
u.displaySettings.decreaseFontSize()
}
func (u *gtkUI) showSearchBar(w gtki.Window) {
u.search.SetSearchMode(true)
u.searchEntry.GrabFocus()
}
func (u *gtkUI) closeApplication(w gtki.Window) {
u.quit()
}
func (u *gtkUI) closeWindow(w gtki.Window) {
w.Hide()
}
func (u *gtkUI) closeApplicationOrConversation(w gtki.Window) {
if u.settings.GetSingleWindow() {
page := u.unified.notebook.GetCurrentPage()
if page < 0 {
u.quit()
} else {
u.unified.onCloseClicked()
}
} else {
u.quit()
}
}
func (u *gtkUI) closeWindowOrConversation(w gtki.Window) {
if u.settings.GetSingleWindow() {
page := u.unified.notebook.GetCurrentPage()
if page < 0 {
w.Hide()
} else {
u.unified.onCloseClicked()
}
} else {
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>F", w, u.showSearchBar)
connectShortcut("<Primary>f", w, u.showSearchBar)
connectShortcut("<Primary>q", w, u.closeApplication)
connectShortcut("<Primary>w", w, u.closeApplicationOrConversation)
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.closeWindowOrConversation)
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)
}