/
close_tab.go
72 lines (59 loc) · 1.31 KB
/
close_tab.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
// This is free and unencumbered software released into the public
// domain. For more information, see <http://unlicense.org> or the
// accompanying UNLICENSE file.
package command
import (
"fmt"
"github.com/nelsam/gxui"
"github.com/nelsam/vidar/commander/bind"
"github.com/nelsam/vidar/commander/text"
)
type CurrentEditorCloser interface {
CloseCurrentEditor() (string, text.Editor)
CurrentEditor() text.Editor
}
type BindPopper interface {
Pop() []bind.Bindable
}
type CloseTab struct {
closer CurrentEditorCloser
binder BindPopper
}
func NewCloseTab() *CloseTab {
return &CloseTab{}
}
func (s *CloseTab) Name() string {
return "close-current-tab"
}
func (s *CloseTab) Menu() string {
return "File"
}
func (s *CloseTab) Defaults() []fmt.Stringer {
return []fmt.Stringer{gxui.KeyboardEvent{
Modifier: gxui.ModControl,
Key: gxui.KeyW,
}}
}
func (s *CloseTab) Reset() {
s.closer = nil
s.binder = nil
}
func (s *CloseTab) Store(target interface{}) bind.Status {
switch src := target.(type) {
case CurrentEditorCloser:
s.closer = src
case BindPopper:
s.binder = src
}
if s.closer != nil && s.binder != nil {
return bind.Done
}
return bind.Waiting
}
func (s *CloseTab) Exec() error {
s.closer.CloseCurrentEditor()
if s.closer.CurrentEditor() == nil {
s.binder.Pop()
}
return nil
}