From 5fb30fed8760051be739916b9d99790868030b6f Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Sat, 21 Dec 2024 18:29:13 -0800 Subject: [PATCH] sidebar action --- .../contrib/void/browser/sidebarActions.ts | 33 ++++++++++++++++++- .../void/browser/sidebarStateService.ts | 15 +++------ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/sidebarActions.ts b/src/vs/workbench/contrib/void/browser/sidebarActions.ts index 7f61c729..7939a46f 100644 --- a/src/vs/workbench/contrib/void/browser/sidebarActions.ts +++ b/src/vs/workbench/contrib/void/browser/sidebarActions.ts @@ -18,11 +18,13 @@ import { IEditorService } from '../../../services/editor/common/editorService.js import { ICodeEditorService } from '../../../../editor/browser/services/codeEditorService.js'; import { IRange } from '../../../../editor/common/core/range.js'; import { ITextModel } from '../../../../editor/common/model.js'; -import { VOID_VIEW_ID } from './sidebarPane.js'; +import { VOID_VIEW_CONTAINER_ID, VOID_VIEW_ID } from './sidebarPane.js'; import { IMetricsService } from '../../../../platform/void/common/metricsService.js'; import { ISidebarStateService } from './sidebarStateService.js'; import { ICommandService } from '../../../../platform/commands/common/commands.js'; import { OPEN_VOID_SETTINGS_ACTION_ID } from './voidSettingsPane.js'; +import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../common/contributions.js'; +import { IViewsService } from '../../../services/views/common/viewsService.js'; // ---------- Register commands and keybindings ---------- @@ -180,3 +182,32 @@ registerAction2(class extends Action2 { commandService.executeCommand(OPEN_VOID_SETTINGS_ACTION_ID) } }) + + +export const VOID_OPEN_SIDEBAR_ACTION_ID = 'void.openSidebar' +registerAction2(class extends Action2 { + constructor() { + super({ + id: VOID_OPEN_SIDEBAR_ACTION_ID, + title: 'Open Void Sidebar', + }) + } + run(accessor: ServicesAccessor): void { + const viewsService = accessor.get(IViewsService) + viewsService.openViewContainer(VOID_VIEW_CONTAINER_ID); + viewsService.openView(VOID_VIEW_ID); + } +}); + +// mount at start + + +export class SidebarStartContribution implements IWorkbenchContribution { + static readonly ID = 'workbench.contrib.startupVoidSidebar'; + constructor( + @ICommandService private readonly commandService: ICommandService, + ) { + this.commandService.executeCommand(VOID_OPEN_SIDEBAR_ACTION_ID) + } +} +registerWorkbenchContribution2(SidebarStartContribution.ID, SidebarStartContribution, WorkbenchPhase.BlockRestore); diff --git a/src/vs/workbench/contrib/void/browser/sidebarStateService.ts b/src/vs/workbench/contrib/void/browser/sidebarStateService.ts index 683a3ed4..e711002f 100644 --- a/src/vs/workbench/contrib/void/browser/sidebarStateService.ts +++ b/src/vs/workbench/contrib/void/browser/sidebarStateService.ts @@ -1,9 +1,9 @@ import { Emitter, Event } from '../../../../base/common/event.js'; import { Disposable } from '../../../../base/common/lifecycle.js'; +import { ICommandService } from '../../../../platform/commands/common/commands.js'; import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js'; import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js'; -import { IViewsService } from '../../../services/views/common/viewsService.js'; -import { VOID_VIEW_CONTAINER_ID, VOID_VIEW_ID } from './sidebarPane.js'; +import { VOID_OPEN_SIDEBAR_ACTION_ID } from './sidebarActions.js'; // service that manages sidebar's state @@ -23,8 +23,6 @@ export interface ISidebarStateService { onDidBlurChat: Event; fireFocusChat(): void; fireBlurChat(): void; - - openSidebarView(): void; } export const ISidebarStateService = createDecorator('voidSidebarStateService'); @@ -47,7 +45,7 @@ class VoidSidebarStateService extends Disposable implements ISidebarStateService state: VoidSidebarState constructor( - @IViewsService private readonly _viewsService: IViewsService, + @ICommandService private readonly commandService: ICommandService, ) { super() @@ -59,7 +57,7 @@ class VoidSidebarStateService extends Disposable implements ISidebarStateService setState(newState: Partial) { // make sure view is open if the tab changes if ('currentTab' in newState) { - this.openSidebarView() + this.commandService.executeCommand(VOID_OPEN_SIDEBAR_ACTION_ID) } this.state = { ...this.state, ...newState } @@ -74,11 +72,6 @@ class VoidSidebarStateService extends Disposable implements ISidebarStateService this._onBlurChat.fire() } - openSidebarView() { - this._viewsService.openViewContainer(VOID_VIEW_CONTAINER_ID); - this._viewsService.openView(VOID_VIEW_ID); - } - } registerSingleton(ISidebarStateService, VoidSidebarStateService, InstantiationType.Eager);