-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (61 loc) · 2.06 KB
/
main.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
package main
import (
"github.com/mattn/go-gtk/gdk"
"github.com/mattn/go-gtk/glib"
"github.com/mattn/go-gtk/gtk"
gsv "github.com/mattn/go-gtk/gtksourceview"
"micro-emacs-pp/editor"
ed "github.com/pilsprog/micro-emacs-pp/gtk/editor"
. "github.com/pilsprog/micro-emacs-pp/keyhandler"
kh "github.com/pilsprog/micro-emacs-pp/gtk/keyhandler"
"os"
"unsafe"
)
var (
textbuffer *gtk.TextBuffer
sourceview *gsv.SourceView
textview *gtk.TextView
fileName string
microemacs editor.Editor
keyh KeyHandler = MakeRoot(kh.CtrlXHandler)
)
func main() {
gtk.Init(&os.Args)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("µemacs/pp")
window.Connect("destroy", gtk.MainQuit)
window.Connect("key-press-event", handleKeyPress)
SetKeyReturn(kh.GTKKeyPressEvent{gdk.KEY_Return, 0})
swin := gtk.NewScrolledWindow(nil, nil)
sourcebuffer := gsv.NewSourceBufferWithLanguage(gsv.SourceLanguageManagerGetDefault().GetLanguage("cpp"))
sourceview = gsv.NewSourceViewWithBuffer(sourcebuffer)
var start gtk.TextIter
sourcebuffer.GetStartIter(&start)
sourcebuffer.Insert(&start, `writing stuff, awww yea!`)
textview = gtk.NewTextView()
textbuffer = textview.GetBuffer()
var bufiter gtk.TextIter
sourcebuffer.GetStartIter(&bufiter)
bufWrapper := ed.GtkTextBufferReadWriter{&sourceview.TextView.Container.Widget, bufiter, &sourcebuffer.TextBuffer}
var comiter gtk.TextIter
textbuffer.GetStartIter(&comiter)
comWrapper := ed.GtkTextBufferReadWriter{&textview.Container.Widget, comiter, textbuffer}
microemacs = editor.Editor{"", &bufWrapper, &comWrapper}
vbox := gtk.NewVBox(false, 0)
vbox.PackStart(swin, true, true, 0)
vbox.PackEnd(textview, false, true, 0)
swin.Add(sourceview)
window.Add(vbox)
window.SetSizeRequest(300, 300)
window.ShowAll()
gtk.Main()
}
func handleKeyPress(ctx *glib.CallbackContext) {
arg := ctx.Args(0)
kev := *(**gdk.EventKey)(unsafe.Pointer(&arg))
kpe := kh.GTKKeyPressEvent{int(kev.Keyval), 0}
if (gdk.ModifierType(kev.State) & gdk.CONTROL_MASK) != 0 {
kpe.Modifier = gdk.CONTROL_MASK
}
_, keyh = keyh.Handle(kpe, µemacs)
}