-
Notifications
You must be signed in to change notification settings - Fork 87
/
command.go
127 lines (104 loc) · 3.34 KB
/
command.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// 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 backend
type (
// The Args type is just a generic string key and interface{} value
// map type used to serialize command arguments.
Args map[string]interface{}
// The CustomSet interface can be optionally implemented
// by struct members of a concrete command struct.
//
// If implemented, it'll be called by the default
// Command initialization code with the data gotten
// from the Args map.
CustomSet interface {
Set(v interface{}) error
}
CustomDefault interface {
Default(key string) interface{}
}
// The CustomInit interface can be optionally implemented
// by a Command and will be called instead of the default
// command initialization code.
CustomInit interface {
Init(args Args) error
}
// The Command interface implements the basic interface
// that is shared between the different more specific
// command type interfaces.
//
// In the traditional Model-view-controller design,
// Commands are roughly equivalent to the action-taking
// controller piece.
Command interface {
// Returns whether the Command is enabled or not.
IsEnabled() bool
// Returns whether the Command is visible in menus,
// the goto anything panel or other user interface
// that lists available commands.
IsVisible() bool
// Returns the textual description of the command.
Description() string
// Whether or not this Command bypasses the undo stack.
BypassUndo() bool
}
// The WindowCommand interface extends the base Command interface
// with functionality specific for WindowCommands.
WindowCommand interface {
Command
// Execute this command with the specified window as the
// argument
Run(*Window) error
}
// The TextCommand interface extends the base Command interface
// with functionality specific for TextCommands.
TextCommand interface {
Command
// Execute this command with the specified View and Edit object
// as the arguments
Run(*View, *Edit) error
}
// The ApplicationCommand interface extends the base Command interface
// with functionality specific for ApplicationCommands.
ApplicationCommand interface {
Command
// Execute this command
Run() error
// Returns whether this command is checked or not.
// Used to display a checkbox in the user interface
// for boolean commands.
IsChecked() bool
}
// The DefaultCommand implements the default operation
// of the basic Command interface and is recommended to
// be used as the base when creating new Commands.
DefaultCommand struct{}
// The BypassUndoCommand is the same as the DefaultCommand
// type, except that its implementation of BypassUndo returns
// true rather than false.
BypassUndoCommand struct {
DefaultCommand
}
)
// The default is to not bypass the undo stack.
func (d *DefaultCommand) BypassUndo() bool {
return false
}
// By default a command is enabled.
func (d *DefaultCommand) IsEnabled() bool {
return true
}
// By default a command is visible.
func (d *DefaultCommand) IsVisible() bool {
return true
}
// By default the string "TODO" is return as the description.
func (d *DefaultCommand) Description() string {
return "TODO"
}
// The BypassUndoCommand defaults to bypassing the
// undo stack.
func (b *BypassUndoCommand) BypassUndo() bool {
return true
}