/
shortcutsdialog.go
105 lines (96 loc) · 3.48 KB
/
shortcutsdialog.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
package gui
import (
"fmt"
"github.com/gotk3/gotk3/gdk"
"github.com/gotk3/gotk3/gtk"
)
var shortcutsDialogUIFile = `
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkShortcutsWindow" id="shortcuts-uwunote">
<property name="modal">0</property>
<child>
<object class="GtkShortcutsSection">
<property name="visible">1</property>
<property name="section-name">shortcuts</property>
<property name="max-height">12</property>
<child>
<object class="GtkShortcutsGroup">
<property name="visible">1</property>
<property name="title" translatable="yes">General</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator">F1</property>
<property name="title" translatable="yes">Show shortcuts</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator"><ctrl>O</property>
<property name="title" translatable="yes">Open Settings</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkShortcutsGroup">
<property name="visible">1</property>
<property name="title" translatable="yes">Notes</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator"><ctrl>n</property>
<property name="title" translatable="yes">New</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator"><ctrl>s</property>
<property name="title" translatable="yes">Save</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator"><ctrl>d</property>
<property name="title" translatable="yes">Delete</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
`
//ShowShortcutsDialog shows the applications shortcuts dialog.
func ShowShortcutsDialog() {
builder, _ := gtk.BuilderNew()
builder.AddFromString(shortcutsDialogUIFile)
showErrorDialog := func(errorMessage string) {
message := fmt.Sprintf("Error showing shortcuts dialog (%s).", errorMessage)
dialog := gtk.MessageDialogNew(nil, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message)
dialog.Run()
dialog.Destroy()
}
window, builderError := builder.GetObject("shortcuts-uwunote")
if builderError != nil {
showErrorDialog(builderError.Error())
return
}
windowCast, ok := window.(*gtk.ShortcutsWindow)
if ok {
pixbufLoader, _ := gdk.PixbufLoaderNew()
iconAsPixbuf, _ := pixbufLoader.WriteAndReturnPixbuf(AppIcon)
windowCast.SetIcon(iconAsPixbuf)
windowCast.SetSkipTaskbarHint(true)
windowCast.SetSkipPagerHint(true)
windowCast.SetResizable(true)
windowCast.ShowAll()
} else {
showErrorDialog("Casting to ShortcutsWindow failed.")
}
}