-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathresource.ts
258 lines (231 loc) · 6.56 KB
/
resource.ts
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import * as path from "path";
import {
Command,
DecorationData,
SourceControlResourceDecorations,
SourceControlResourceState,
ThemeColor,
Uri
} from "vscode";
import { PropStatus, Status } from "./common/types";
import { memoize } from "./decorators";
import { configuration } from "./helpers/configuration";
import { hasSupportToDecorationProvider } from "./util";
const iconsRootPath = path.join(__dirname, "..", "icons");
function getIconUri(iconName: string, theme: string): Uri {
return Uri.file(path.join(iconsRootPath, theme, `${iconName}.svg`));
}
export class Resource implements SourceControlResourceState {
private static icons: any = {
light: {
Added: getIconUri("status-added", "light"),
Conflicted: getIconUri("status-conflicted", "light"),
Deleted: getIconUri("status-deleted", "light"),
Ignored: getIconUri("status-ignored", "light"),
Missing: getIconUri("status-missing", "light"),
Modified: getIconUri("status-modified", "light"),
Renamed: getIconUri("status-renamed", "light"),
Replaced: getIconUri("status-replaced", "light"),
Unversioned: getIconUri("status-unversioned", "light")
},
dark: {
Added: getIconUri("status-added", "dark"),
Conflicted: getIconUri("status-conflicted", "dark"),
Deleted: getIconUri("status-deleted", "dark"),
Ignored: getIconUri("status-ignored", "dark"),
Missing: getIconUri("status-missing", "dark"),
Modified: getIconUri("status-modified", "dark"),
Renamed: getIconUri("status-renamed", "dark"),
Replaced: getIconUri("status-replaced", "dark"),
Unversioned: getIconUri("status-unversioned", "dark")
}
};
constructor(
private _resourceUri: Uri,
private _type: string,
private _renameResourceUri?: Uri,
private _props?: string,
private _remote: boolean = false
) {}
@memoize
get resourceUri(): Uri {
return this._resourceUri;
}
@memoize
get type(): string {
return this._type;
}
get renameResourceUri(): Uri | undefined {
return this._renameResourceUri;
}
get props(): string | undefined {
return this._props;
}
get remote(): boolean {
return this._remote;
}
get decorations(): SourceControlResourceDecorations {
// TODO@joh, still requires restart/redraw in the SCM viewlet
const decorations =
hasSupportToDecorationProvider() &&
configuration.get<boolean>("decorations.enabled");
const light = !decorations
? { iconPath: this.getIconPath("light") }
: undefined;
const dark = !decorations
? { iconPath: this.getIconPath("dark") }
: undefined;
const tooltip = this.tooltip;
const strikeThrough = this.strikeThrough;
const faded = this.faded;
const letter = this.letter;
const color = this.color;
return {
strikeThrough,
faded,
tooltip,
light,
dark,
letter,
color,
source: "svn.resource"
};
}
@memoize
get command(): Command {
const diffHead = configuration.get<boolean>("diff.withHead", true);
const changesLeftClick = configuration.get<string>(
"sourceControl.changesLeftClick",
"open diff"
);
if (!this.remote && changesLeftClick === "open") {
return {
command: "svn.openFile",
title: "Open file",
arguments: [this]
};
}
if (this.remote || diffHead) {
return {
command: "svn.openResourceHead",
title: "Open Diff With Head",
arguments: [this]
};
}
return {
command: "svn.openResourceBase",
title: "Open Diff With Base",
arguments: [this]
};
}
private getIconPath(theme: string): Uri | undefined {
if (this.type === Status.ADDED && this.renameResourceUri) {
return Resource.icons[theme].Renamed;
}
const type = this.type.charAt(0).toUpperCase() + this.type.slice(1);
if (typeof Resource.icons[theme][type] !== "undefined") {
return Resource.icons[theme][type];
}
return void 0;
}
private get tooltip(): string {
if (this.type === Status.ADDED && this.renameResourceUri) {
return "Renamed from " + this.renameResourceUri.fsPath;
}
if (
this.type === Status.NORMAL &&
this.props &&
this.props !== PropStatus.NONE
) {
return (
"Property " + this.props.charAt(0).toUpperCase() + this.props.slice(1)
);
}
return this.type.charAt(0).toUpperCase() + this.type.slice(1);
}
private get strikeThrough(): boolean {
if (this.type === Status.DELETED) {
return true;
}
return false;
}
private get faded(): boolean {
return false;
}
get letter(): string | undefined {
switch (this.type) {
case Status.ADDED:
if (this.renameResourceUri) {
return "R";
}
return "A";
case Status.CONFLICTED:
return "C";
case Status.DELETED:
return "D";
case Status.EXTERNAL:
return "E";
case Status.IGNORED:
return "I";
case Status.MODIFIED:
return "M";
case Status.REPLACED:
return "R";
case Status.UNVERSIONED:
return "U";
case Status.MISSING:
return "!";
default:
return undefined;
}
}
get color(): ThemeColor | undefined {
switch (this.type) {
case Status.MODIFIED:
case Status.REPLACED:
return new ThemeColor("gitDecoration.modifiedResourceForeground");
case Status.DELETED:
case Status.MISSING:
return new ThemeColor("gitDecoration.deletedResourceForeground");
case Status.ADDED:
case Status.UNVERSIONED:
return new ThemeColor("gitDecoration.untrackedResourceForeground");
case Status.EXTERNAL:
case Status.IGNORED:
return new ThemeColor("gitDecoration.ignoredResourceForeground");
case Status.CONFLICTED:
return new ThemeColor("gitDecoration.conflictingResourceForeground");
default:
return undefined;
}
}
get priority(): number {
switch (this.type) {
case Status.MODIFIED:
return 2;
case Status.IGNORED:
return 3;
case Status.DELETED:
case Status.ADDED:
case Status.REPLACED:
case Status.MISSING:
return 4;
default:
return 1;
}
}
get resourceDecoration(): DecorationData | undefined {
const title = this.tooltip;
const abbreviation = this.letter;
const color = this.color;
const priority = this.priority;
return {
bubble: true,
source: "svn.resource",
title,
abbreviation,
color,
priority
};
}
}