This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ui_delegate.go
185 lines (154 loc) · 4.56 KB
/
ui_delegate.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
* Copyright (C) 2015 Deepin Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
**/
package operations
import (
"fmt"
. "pkg.deepin.io/service/file-manager-backend/log"
)
// type DeletionType int
//
// const (
// DELETE DeletionType = iota
// TRASH
// EMPTY_TRASH
// )
//
// type ConfirmationType int
//
// const (
// DefaultConfirmation ConfirmationType = iota
// ForceConfirmation
// )
// ResponseCode is a type for the response of UIDelegate.
type ResponseCode int32
// the code for response of UIDelegate.
const (
ResponseCancel ResponseCode = 1 << iota
ResponseSkip
ResponseRetry
ResponseDelete
ResponseOverwrite
ResponseAutoRename // auto rename the conflict file/directory
ResponseYes
)
// String returns a human readable string for ResponseCode.
func (code ResponseCode) String() string {
switch code {
case ResponseCancel:
return "Cancel"
case ResponseSkip:
return "Skip"
case ResponseRetry:
return "Retry"
case ResponseDelete:
return "Delete"
case ResponseYes:
return "Yes"
case ResponseOverwrite:
return "Overwrite"
case ResponseAutoRename:
return "AutoRename"
}
return fmt.Sprintf("Unknown code: %d", int32(code))
}
// Response stores the response relavant information like ResponseCode.
type Response struct {
code int32
applyToAll bool
userData string
}
// NewResponse creates a new Response from response code and apply to all.
func NewResponse(code ResponseCode, applyToAll bool) Response {
return Response{
code: int32(code),
applyToAll: applyToAll,
}
}
// NewResponseWithUserData creates a Response from response code code, apply to all and user data.
func NewResponseWithUserData(code ResponseCode, applyToAll bool, userData string) Response {
return Response{
code: int32(code),
applyToAll: applyToAll,
userData: userData,
}
}
// String returns a human readable string for debuging or something like it.
func (response Response) String() string {
str := ResponseCode(response.code).String()
if response.applyToAll {
str += " to all"
}
return str
}
// Code returns response code.
func (response Response) Code() ResponseCode {
return ResponseCode(response.code)
}
// ApplyToAll returns whether apply to all.
func (response Response) ApplyToAll() bool {
return response.applyToAll
}
// UserData returns some extra data.
func (response Response) UserData() string {
return response.userData
}
type UIFlags int32
// UIFlags
const (
UIFlagsNone UIFlags = iota << 0
UIFlagsRetry
UIFlagsMulti
)
func (flags UIFlags) String() string {
strFlags := "UIFlags("
if flags&UIFlagsRetry != 0 {
strFlags += "retry"
}
if flags&UIFlagsMulti != 0 {
if strFlags != "UIFlags(" {
strFlags += "|"
}
strFlags += "multi"
}
if strFlags == "UIFlags(" {
strFlags += "NONE"
}
return strFlags + ")"
}
// IUIDelegate is the interface for ui delegate.
type IUIDelegate interface {
// TODO: using this internally, give a simpler interface, like kio,
// a.k.a: AskDeleteConfirmation(urls, deleteType, confirmationType))
// if necessary, ask user to confirm whether to delete or trash files.
AskDeleteConfirmation(primaryText string, secondaryText string, detailText string) bool
AskDelete(string, string, string, UIFlags) Response
AskSkip(primaryText string, secondaryText string, detailText string, uiFlags UIFlags) Response
AskRetry(primaryText string, secondaryText string, detailText string) Response
// TODO: decide arguments
ConflictDialog() Response
}
type _DefaultUIDelegate struct{}
func (*_DefaultUIDelegate) AskRetry(primaryText string, secondaryText string, detailText string) Response {
return NewResponse(ResponseCancel, false)
}
func (*_DefaultUIDelegate) AskDeleteConfirmation(primaryText string, secondaryText string, detailText string) bool {
return true
}
func (*_DefaultUIDelegate) AskDelete(primaryText string, secondaryText string, detailText string, flags UIFlags) Response {
return NewResponse(ResponseSkip, true)
}
func (*_DefaultUIDelegate) AskSkip(primaryText string, secondaryText string, detailText string, flags UIFlags) Response {
Log.Debugf("AskSkip:\n\tprimaryText: %s\n\tsecondaryText: %s\n\tdetailText: %s\n\tflags: %v\n", primaryText, secondaryText, detailText, flags)
// TODO:
return NewResponse(ResponseSkip, true)
}
func (*_DefaultUIDelegate) ConflictDialog() Response {
return NewResponse(ResponseSkip, true)
}
var _deafultUIDelegate = &_DefaultUIDelegate{}