提交 5a61ae11 编写于 作者: B Benjamin Pasero

💄

上级 db592233
...@@ -22,7 +22,6 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; ...@@ -22,7 +22,6 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen'; import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { registerEditorAction, EditorAction, IEditorCommandMenuOptions } from 'vs/editor/browser/editorExtensions'; import { registerEditorAction, EditorAction, IEditorCommandMenuOptions } from 'vs/editor/browser/editorExtensions';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { once } from 'vs/base/common/event';
import { LRUCache } from 'vs/base/common/map'; import { LRUCache } from 'vs/base/common/map';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ResolvedKeybinding } from 'vs/base/common/keyCodes'; import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
...@@ -32,6 +31,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; ...@@ -32,6 +31,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { INotificationService } from 'vs/platform/notification/common/notification'; import { INotificationService } from 'vs/platform/notification/common/notification';
import { CancellationToken } from 'vs/base/common/cancellation'; import { CancellationToken } from 'vs/base/common/cancellation';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { Disposable } from 'vs/base/common/lifecycle';
export const ALL_COMMANDS_PREFIX = '>'; export const ALL_COMMANDS_PREFIX = '>';
...@@ -55,7 +55,7 @@ function resolveCommandHistory(configurationService: IConfigurationService): num ...@@ -55,7 +55,7 @@ function resolveCommandHistory(configurationService: IConfigurationService): num
return commandHistory; return commandHistory;
} }
class CommandsHistory { class CommandsHistory extends Disposable {
static readonly DEFAULT_COMMANDS_HISTORY_LENGTH = 50; static readonly DEFAULT_COMMANDS_HISTORY_LENGTH = 50;
...@@ -68,12 +68,19 @@ class CommandsHistory { ...@@ -68,12 +68,19 @@ class CommandsHistory {
@IStorageService private storageService: IStorageService, @IStorageService private storageService: IStorageService,
@IConfigurationService private configurationService: IConfigurationService @IConfigurationService private configurationService: IConfigurationService
) { ) {
super();
this.updateConfiguration(); this.updateConfiguration();
this.load(); this.load();
this.registerListeners(); this.registerListeners();
} }
private registerListeners(): void {
this._register(this.configurationService.onDidChangeConfiguration(e => this.updateConfiguration()));
this._register(this.storageService.onWillSaveState(() => this.saveState()));
}
private updateConfiguration(): void { private updateConfiguration(): void {
this.commandHistoryLength = resolveCommandHistory(this.configurationService); this.commandHistoryLength = resolveCommandHistory(this.configurationService);
...@@ -107,9 +114,12 @@ class CommandsHistory { ...@@ -107,9 +114,12 @@ class CommandsHistory {
commandCounter = this.storageService.getInteger(CommandsHistory.PREF_KEY_COUNTER, StorageScope.GLOBAL, commandCounter); commandCounter = this.storageService.getInteger(CommandsHistory.PREF_KEY_COUNTER, StorageScope.GLOBAL, commandCounter);
} }
private registerListeners(): void { push(commandId: string): void {
this.configurationService.onDidChangeConfiguration(e => this.updateConfiguration()); commandHistory.set(commandId, commandCounter++); // set counter to command
once(this.storageService.onWillSaveState)(() => this.saveState()); }
peek(commandId: string): number {
return commandHistory.peek(commandId);
} }
private saveState(): void { private saveState(): void {
...@@ -119,14 +129,6 @@ class CommandsHistory { ...@@ -119,14 +129,6 @@ class CommandsHistory {
this.storageService.store(CommandsHistory.PREF_KEY_CACHE, JSON.stringify(serializedCache), StorageScope.GLOBAL); this.storageService.store(CommandsHistory.PREF_KEY_CACHE, JSON.stringify(serializedCache), StorageScope.GLOBAL);
this.storageService.store(CommandsHistory.PREF_KEY_COUNTER, commandCounter, StorageScope.GLOBAL); this.storageService.store(CommandsHistory.PREF_KEY_COUNTER, commandCounter, StorageScope.GLOBAL);
} }
push(commandId: string): void {
commandHistory.set(commandId, commandCounter++); // set counter to command
}
peek(commandId: string): number {
return commandHistory.peek(commandId);
}
} }
export class ShowAllCommandsAction extends Action { export class ShowAllCommandsAction extends Action {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册