-
Notifications
You must be signed in to change notification settings - Fork 8
/
window.go
102 lines (86 loc) · 2.13 KB
/
window.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
// Copyright 2013 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 (
"fmt"
"github.com/limetext/backend"
)
type (
// NewWindow command opens a new window.
NewWindow struct {
backend.DefaultCommand
}
// CloseAll command closes all the
// open views inside the current window.
CloseAll struct {
backend.DefaultCommand
}
// CloseWindow command lets us close the current window.
CloseWindow struct {
backend.DefaultCommand
}
// NewWindowApp creates a new window, setting it as active.
NewWindowApp struct {
backend.DefaultCommand
}
// CloseWindowApp command closes all the active windows.
CloseWindowApp struct {
backend.DefaultCommand
}
)
// Run executes the NewWindow command.
func (c *NewWindow) Run(w *backend.Window) error {
ed := backend.GetEditor()
ed.SetActiveWindow(ed.NewWindow())
return nil
}
// Run executes the CloseAll command.
func (c *CloseAll) Run(w *backend.Window) error {
if !w.CloseAllViews() {
return fmt.Errorf("Window{id:%d} failed to close all windows", w.Id())
}
return nil
}
// Run executes the CloseWindow command.
func (c *CloseWindow) Run(w *backend.Window) error {
if !w.Close() {
return fmt.Errorf("Window{id:%d} failed to close window", w.Id())
}
return nil
}
// Run executes the NewWindowApp command.
func (c *NewWindowApp) Run() error {
ed := backend.GetEditor()
ed.SetActiveWindow(ed.NewWindow())
return nil
}
// Run executes the CloseWindowApp command.
func (c *CloseWindowApp) Run() error {
ed := backend.GetEditor()
if !ed.ActiveWindow().Close() {
return fmt.Errorf("Failed to close window app")
}
return nil
}
// IsChecked shows if NewWindowApp has a
// checkbox in the frontend.
func (c *NewWindowApp) IsChecked() bool {
return false
}
// IsChecked shows if CloseWindowApp has a
// checkbox in the frontend.
func (c *CloseWindowApp) IsChecked() bool {
return false
}
func init() {
register([]backend.Command{
&NewWindow{},
&CloseAll{},
&CloseWindow{},
})
registerByName([]namedCmd{
{"new_window", &NewWindowApp{}},
{"close_window", &CloseWindowApp{}},
})
}