1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.UserWorkingDirectoryProvider = void 0;
|
19 | const tslib_1 = require("tslib");
|
20 | const inversify_1 = require("inversify");
|
21 | const uri_1 = require("../common/uri");
|
22 | const common_1 = require("../common");
|
23 | const env_variables_1 = require("../common/env-variables");
|
24 | const navigatable_types_1 = require("./navigatable-types");
|
25 | let UserWorkingDirectoryProvider = class UserWorkingDirectoryProvider {
|
26 | configure(app) {
|
27 | app.shell.onDidChangeCurrentWidget(e => { var _a; return this.setLastOpenResource((_a = e.newValue) !== null && _a !== void 0 ? _a : undefined); });
|
28 | this.setLastOpenResource(app.shell.currentWidget);
|
29 | }
|
30 | setLastOpenResource(widget) {
|
31 | if (navigatable_types_1.Navigatable.is(widget)) {
|
32 | const uri = widget.getResourceUri();
|
33 | if (uri && uri.scheme !== common_1.UNTITLED_SCHEME) {
|
34 | this.lastOpenResource = uri;
|
35 | }
|
36 | }
|
37 | }
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 | async getUserWorkingDir() {
|
44 | var _a;
|
45 | return (_a = await this.getFromSelection()) !== null && _a !== void 0 ? _a : this.getFromUserHome();
|
46 | }
|
47 | getFromSelection() {
|
48 | const uri = common_1.UriSelection.getUri(this.selectionService.selection);
|
49 | if ((uri === null || uri === void 0 ? void 0 : uri.scheme) === common_1.UNTITLED_SCHEME) {
|
50 |
|
51 | return undefined;
|
52 | }
|
53 | return this.ensureIsDirectory(uri);
|
54 | }
|
55 | getFromLastOpenResource() {
|
56 | return this.ensureIsDirectory(this.lastOpenResource);
|
57 | }
|
58 | getFromUserHome() {
|
59 | return this.envVariables.getHomeDirUri().then(home => new uri_1.default(home));
|
60 | }
|
61 | ensureIsDirectory(uri) {
|
62 | return uri === null || uri === void 0 ? void 0 : uri.parent;
|
63 | }
|
64 | };
|
65 | (0, tslib_1.__decorate)([
|
66 | (0, inversify_1.inject)(common_1.SelectionService),
|
67 | (0, tslib_1.__metadata)("design:type", common_1.SelectionService)
|
68 | ], UserWorkingDirectoryProvider.prototype, "selectionService", void 0);
|
69 | (0, tslib_1.__decorate)([
|
70 | (0, inversify_1.inject)(env_variables_1.EnvVariablesServer),
|
71 | (0, tslib_1.__metadata)("design:type", Object)
|
72 | ], UserWorkingDirectoryProvider.prototype, "envVariables", void 0);
|
73 | UserWorkingDirectoryProvider = (0, tslib_1.__decorate)([
|
74 | (0, inversify_1.injectable)()
|
75 | ], UserWorkingDirectoryProvider);
|
76 | exports.UserWorkingDirectoryProvider = UserWorkingDirectoryProvider;
|
77 |
|
\ | No newline at end of file |