forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistoryProvider.ts
More file actions
46 lines (36 loc) · 1.35 KB
/
Copy pathhistoryProvider.ts
File metadata and controls
46 lines (36 loc) · 1.35 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { IDisposableRegistry } from '../common/types';
import { IServiceContainer } from '../ioc/types';
import { IHistory, IHistoryProvider } from './types';
@injectable()
export class HistoryProvider implements IHistoryProvider {
private activeHistory : IHistory | undefined;
constructor(
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(IDisposableRegistry) private disposables: IDisposableRegistry) {
}
public getActive() : IHistory | undefined {
return this.activeHistory;
}
public getOrCreateActive() : IHistory {
if (!this.activeHistory) {
this.activeHistory = this.create();
}
return this.activeHistory;
}
private create = () => {
const result = this.serviceContainer.get<IHistory>(IHistory);
const handler = result.closed(this.onHistoryClosed);
this.disposables.push(result);
this.disposables.push(handler);
return result;
}
private onHistoryClosed = (history: IHistory) => {
if (this.activeHistory === history) {
this.activeHistory = undefined;
}
}
}