Skip to content

Commit

Permalink
feat(core): command service support get command type
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev committed May 19, 2024
1 parent 4e7b4c5 commit 6775a73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 8 additions & 1 deletion packages/core/src/services/command/command.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,19 @@ export const ICommandService = createIdentifier<ICommandService>('anywhere.comma
*/
export class CommandRegistry {
private readonly _commands = new Map<string, ICommand>();
private readonly _commandTypes = new Map<string, CommandType>();

registerCommand(command: ICommand): IDisposable {
if (this._commands.has(command.id)) {
throw new Error(`[CommandRegistry]: command "${command.id}" has been registered before.`);
}

this._commands.set(command.id, command);
this._commandTypes.set(command.id, command.type);

return toDisposable(() => {
this._commands.delete(command.id);
this._commandTypes.delete(command.id);

command.onDispose?.();
});
Expand All @@ -197,6 +200,10 @@ export class CommandRegistry {

return [this._commands.get(id)!];
}

getCommandType(id: string): CommandType | undefined {
return this._commandTypes.get(id);
}
}

interface ICommandExecutionStackItem extends ICommandInfo {}
Expand All @@ -208,7 +215,7 @@ export const NilCommand: ICommand = {
};

export class CommandService implements ICommandService {
private readonly _commandRegistry: CommandRegistry;
protected readonly _commandRegistry: CommandRegistry;

private readonly _beforeCommandExecutionListeners: CommandListener[] = [];
private readonly _commandExecutedListeners: CommandListener[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

import {
ICommandService,
IContextService,
ILogService,
IUniverInstanceService,
LifecycleStages,
LocaleService,
Expand Down Expand Up @@ -67,9 +65,7 @@ export class FindReplaceController extends RxDisposable {
@IShortcutService private readonly _shortcutService: IShortcutService,
@ICommandService private readonly _commandService: ICommandService,
@IFindReplaceService private readonly _findReplaceService: IFindReplaceService,
@ILogService private readonly _logService: ILogService,
@IDialogService private readonly _dialogService: IDialogService,
@IContextService private readonly _contextService: IContextService,
@ILayoutService private readonly _layoutService: ILayoutService,
@Inject(LocaleService) private readonly _localeService: LocaleService,
@Inject(ComponentManager) private readonly _componentManager: ComponentManager,
Expand Down

0 comments on commit 6775a73

Please sign in to comment.