Skip to content

Commit 8c27833

Browse files
authored
Merge pull request microsoft#261139 from microsoft/osortega/adding-actions-chat-sessions-toolbar
Adding actions to local chats toolbar
2 parents 7c8f422 + 7263131 commit 8c27833

File tree

1 file changed

+101
-2
lines changed

1 file changed

+101
-2
lines changed

src/vs/workbench/contrib/chat/browser/actions/chatActions.ts

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ import { ToggleTitleBarConfigAction } from '../../../../browser/parts/titlebar/t
4444
import { ActiveEditorContext, IsCompactTitleBarContext } from '../../../../common/contextkeys.js';
4545
import { IWorkbenchContribution } from '../../../../common/contributions.js';
4646
import { IViewDescriptorService, ViewContainerLocation } from '../../../../common/views.js';
47-
import { IEditorGroupsService } from '../../../../services/editor/common/editorGroupsService.js';
48-
import { ACTIVE_GROUP, IEditorService } from '../../../../services/editor/common/editorService.js';
47+
import { GroupDirection, IEditorGroupsService } from '../../../../services/editor/common/editorGroupsService.js';
48+
import { ACTIVE_GROUP, AUX_WINDOW_GROUP, IEditorService } from '../../../../services/editor/common/editorService.js';
4949
import { IHostService } from '../../../../services/host/browser/host.js';
5050
import { IWorkbenchLayoutService, Parts } from '../../../../services/layout/browser/layoutService.js';
5151
import { IViewsService } from '../../../../services/views/common/viewsService.js';
@@ -67,6 +67,7 @@ import { ILanguageModelToolsService } from '../../common/languageModelToolsServi
6767
import { ChatViewId, IChatWidget, IChatWidgetService, showChatView, showCopilotView } from '../chat.js';
6868
import { IChatEditorOptions } from '../chatEditor.js';
6969
import { ChatEditorInput, shouldShowClearEditingSessionConfirmation, showClearEditingSessionConfirmation } from '../chatEditorInput.js';
70+
import { VIEWLET_ID } from '../chatSessions.js';
7071
import { ChatViewPane } from '../chatViewPane.js';
7172
import { convertBufferToScreenshotVariable } from '../contrib/screenshot.js';
7273
import { clearChatEditor } from './chatClear.js';
@@ -903,6 +904,104 @@ export function registerChatActions() {
903904
}
904905
});
905906

907+
registerAction2(class OpenChatEditorInNewWindowAction extends Action2 {
908+
constructor() {
909+
super({
910+
id: `workbench.action.chat.newChatInNewWindow`,
911+
title: localize2('chatSessions.openNewChatInNewWindow', 'Open New Chat in New Window'),
912+
f1: false,
913+
category: CHAT_CATEGORY,
914+
precondition: ChatContextKeys.enabled,
915+
menu: {
916+
id: MenuId.ViewTitle,
917+
group: 'submenu',
918+
order: 1,
919+
when: ContextKeyExpr.equals('view', `${VIEWLET_ID}.local`),
920+
}
921+
});
922+
}
923+
924+
async run(accessor: ServicesAccessor) {
925+
const editorService = accessor.get(IEditorService);
926+
await editorService.openEditor({
927+
resource: ChatEditorInput.getNewEditorUri(),
928+
options: {
929+
pinned: true,
930+
auxiliary: { compact: false }
931+
} satisfies IChatEditorOptions
932+
}, AUX_WINDOW_GROUP);
933+
}
934+
});
935+
936+
registerAction2(class NewChatInSideBarAction extends Action2 {
937+
constructor() {
938+
super({
939+
id: `workbench.action.chat.newChatInWidget`,
940+
title: localize2('chatSessions.newChatInWidget', 'Open New Chat in Widget'),
941+
f1: false,
942+
category: CHAT_CATEGORY,
943+
precondition: ChatContextKeys.enabled,
944+
menu: {
945+
id: MenuId.ViewTitle,
946+
group: 'submenu',
947+
order: 1,
948+
when: ContextKeyExpr.equals('view', `${VIEWLET_ID}.local`),
949+
}
950+
});
951+
}
952+
953+
async run(accessor: ServicesAccessor) {
954+
const viewsService = accessor.get(IViewsService);
955+
956+
// Open the chat view in the sidebar and get the widget
957+
const chatWidget = await showChatView(viewsService);
958+
959+
if (chatWidget) {
960+
// Clear the current chat to start a new one
961+
chatWidget.clear();
962+
await chatWidget.waitForReady();
963+
chatWidget.attachmentModel.clear(true);
964+
chatWidget.input.relatedFiles?.clear();
965+
966+
// Focus the input area
967+
chatWidget.focusInput();
968+
}
969+
}
970+
});
971+
972+
registerAction2(class OpenChatInNewEditorGroupAction extends Action2 {
973+
constructor() {
974+
super({
975+
id: 'workbench.action.chat.openNewChatToTheSide',
976+
title: localize2('chat.openNewChatToTheSide.label', "Open New Chat to the Side"),
977+
category: CHAT_CATEGORY,
978+
precondition: ChatContextKeys.enabled,
979+
f1: false,
980+
menu: {
981+
id: MenuId.ViewTitle,
982+
group: 'submenu',
983+
order: 1,
984+
when: ContextKeyExpr.equals('view', `${VIEWLET_ID}.local`),
985+
}
986+
});
987+
}
988+
989+
async run(accessor: ServicesAccessor, ...args: any[]) {
990+
const editorService = accessor.get(IEditorService);
991+
const editorGroupService = accessor.get(IEditorGroupsService);
992+
993+
// Create a new editor group to the right
994+
const newGroup = editorGroupService.addGroup(editorGroupService.activeGroup, GroupDirection.RIGHT);
995+
editorGroupService.activateGroup(newGroup);
996+
997+
// Open a new chat editor in the new group
998+
await editorService.openEditor(
999+
{ resource: ChatEditorInput.getNewEditorUri(), options: { pinned: true } },
1000+
newGroup.id
1001+
);
1002+
}
1003+
});
1004+
9061005
registerAction2(class ChatAddAction extends Action2 {
9071006
constructor() {
9081007
super({

0 commit comments

Comments
 (0)