-
Notifications
You must be signed in to change notification settings - Fork 8
/
view.go
90 lines (77 loc) · 1.7 KB
/
view.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
// Copyright 2014 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import "github.com/limetext/backend"
type (
// Close command closes the currently opened view.
Close struct {
backend.DefaultCommand
}
// NextView command switches to the view which is
// immediately to the next of the current view.
NextView struct {
backend.DefaultCommand
}
// PrevView command switches to the view
// which is immediately before hte current view.
PrevView struct {
backend.DefaultCommand
}
// SetFileType command will let us set the file type
// for the currently active view, eg: for Syntax highlighting.
SetFileType struct {
backend.DefaultCommand
Syntax string
}
)
// Run executes the Close command.
func (c *Close) Run(w *backend.Window) error {
if v := w.ActiveView(); v != nil {
v.Close()
} else {
w.Close()
}
return nil
}
// Run executes the NextView command.
func (c *NextView) Run(w *backend.Window) error {
for i, v := range w.Views() {
if v == w.ActiveView() {
i++
if i == len(w.Views()) {
i = 0
}
w.SetActiveView(w.Views()[i])
break
}
}
return nil
}
// Run executes the PrevView command.
func (c *PrevView) Run(w *backend.Window) error {
for i, v := range w.Views() {
if v == w.ActiveView() {
if i == 0 {
i = len(w.Views())
}
i--
w.SetActiveView(w.Views()[i])
break
}
}
return nil
}
// Run executes the SetFileType command.
func (c *SetFileType) Run(v *backend.View, e *backend.Edit) error {
v.SetSyntaxFile(c.Syntax)
return nil
}
func init() {
register([]backend.Command{
&Close{},
&NextView{},
&PrevView{},
&SetFileType{},
})
}