From f7c4d28d55e6bb08a2df3bad647a5df93c115bc9 Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Thu, 9 Jan 2025 21:20:09 -0800 Subject: [PATCH] toggle vs open settings --- .../src/void-settings-tsx/ModelDropdown.tsx | 28 ++++----- .../react/src/void-settings-tsx/Settings.tsx | 20 +++--- .../contrib/void/browser/sidebarActions.ts | 62 ++++++++++++++++++- .../contrib/void/browser/voidSettingsPane.ts | 33 ++++++++-- 4 files changed, 112 insertions(+), 31 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/ModelDropdown.tsx b/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/ModelDropdown.tsx index 33d28374..4a938f8c 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/ModelDropdown.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/ModelDropdown.tsx @@ -9,7 +9,7 @@ import { useSettingsState, useRefreshModelState, useAccessor } from '../util/ser import { _VoidSelectBox, VoidCustomSelectBox } from '../util/inputs.js' import { SelectBox } from '../../../../../../../base/browser/ui/selectBox/selectBox.js' import { IconWarning } from '../sidebar-tsx/SidebarChat.js' -import { VOID_OPEN_SETTINGS_ACTION_ID } from '../../../voidSettingsPane.js' +import { VOID_OPEN_SETTINGS_ACTION_ID, VOID_TOGGLE_SETTINGS_ACTION_ID } from '../../../voidSettingsPane.js' import { ModelOption } from '../../../../../../../platform/void/common/voidSettingsService.js' @@ -91,26 +91,17 @@ const MemoizedModelSelectBox = ({ featureName }: { featureName: FeatureName }) = } -export const WarningBox = ({ text, className }: { text: string, className?: string }) => { - - const accessor = useAccessor() - const commandService = accessor.get('ICommandService') - - const openSettings = () => { - commandService.executeCommand(VOID_OPEN_SETTINGS_ACTION_ID); - }; +export const WarningBox = ({ text, onClick, className }: { text: string; onClick?: () => void; className?: string }) => { return
{ const settingsState = useSettingsState() + + const accessor = useAccessor() + const commandService = accessor.get('ICommandService') + + const openSettings = () => { commandService.executeCommand(VOID_OPEN_SETTINGS_ACTION_ID); }; + return <> - {settingsState._modelOptions.length === 0 ? : } + {settingsState._modelOptions.length === 0 ? + + : + } } diff --git a/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx b/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx index 1062c1cf..0cd7f611 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx @@ -497,7 +497,7 @@ const OneClickSwitchButton = () => { const accessor = useAccessor() const fileService = accessor.get('IFileService') - const [state, setState] = useState<{ type: 'done' | 'loading' | 'justfinished' } | { type: 'justerrored', error: string }>({ type: 'done' }) + const [state, setState] = useState<{ type: 'done', error?: string } | { type: | 'loading' | 'justfinished' }>({ type: 'done' }) if (transferTheseFiles.length === 0) return <> @@ -520,10 +520,13 @@ const OneClickSwitchButton = () => { catch (e) { errAcc += e + '\n' } } const hadError = !!errAcc - if (hadError) setState({ type: 'justerrored', error: errAcc }) - else setState({ type: 'justfinished' }) - - setTimeout(() => { setState({ type: 'done' }); }, hadError ? 5000 : 3000) + if (hadError) { + setState({ type: 'done', error: errAcc }) + } + else { + setState({ type: 'justfinished' }) + setTimeout(() => { setState({ type: 'done' }); }, 3000) + } } return <> @@ -531,11 +534,10 @@ const OneClickSwitchButton = () => { {state.type === 'done' ? 'Transfer my Settings' : state.type === 'loading' ? 'Transferring...' : state.type === 'justfinished' ? 'Success!' - : state.type === 'justerrored' ? `There was Error` - : null + : null } - {state.type === 'justerrored' && state.error} + {state.type === 'done' && state.error ? : null} } @@ -549,7 +551,7 @@ const GeneralTab = () => {

One-Click Switch

-

{`Transfer your settings from VS Code to Void in one click!`}

+

{`Transfer your settings from VS Code to Void in one click.`}

diff --git a/src/vs/workbench/contrib/void/browser/sidebarActions.ts b/src/vs/workbench/contrib/void/browser/sidebarActions.ts index d276f1d2..6dcaa6a9 100644 --- a/src/vs/workbench/contrib/void/browser/sidebarActions.ts +++ b/src/vs/workbench/contrib/void/browser/sidebarActions.ts @@ -20,8 +20,13 @@ import { 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 { VOID_OPEN_SETTINGS_ACTION_ID } from './voidSettingsPane.js'; +import { VOID_TOGGLE_SETTINGS_ACTION_ID } from './voidSettingsPane.js'; import { VOID_CTRL_L_ACTION_ID } from './actionIDs.js'; +import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../common/contributions.js'; +import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js'; +import { Disposable } from '../../../../base/common/lifecycle.js'; +import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js'; +import { URI } from '../../../../base/common/uri.js'; // ---------- Register commands and keybindings ---------- @@ -63,7 +68,7 @@ const getContentInRange = (model: ITextModel, range: IRange | null) => { // Action: when press ctrl+L, show the sidebar chat and add to the selection registerAction2(class extends Action2 { constructor() { - super({ id: VOID_CTRL_L_ACTION_ID, title: 'Void: Show Sidebar', keybinding: { primary: KeyMod.CtrlCmd | KeyCode.KeyL, weight: KeybindingWeight.BuiltinExtension } }); + super({ id: VOID_CTRL_L_ACTION_ID, title: 'Void: Add to Sidebar', keybinding: { primary: KeyMod.CtrlCmd | KeyCode.KeyL, weight: KeybindingWeight.BuiltinExtension } }); } async run(accessor: ServicesAccessor): Promise { @@ -187,6 +192,57 @@ registerAction2(class extends Action2 { } async run(accessor: ServicesAccessor): Promise { const commandService = accessor.get(ICommandService) - commandService.executeCommand(VOID_OPEN_SETTINGS_ACTION_ID) + commandService.executeCommand(VOID_TOGGLE_SETTINGS_ACTION_ID) } }) + + + + +export class TabSwitchListener extends Disposable { + + constructor( + onSwitchTab: (uri: URI) => void, + @ICodeEditorService private readonly _editorService: ICodeEditorService, + ) { + super() + + // when editor switches tabs (models) + const addTabSwitchListeners = (editor: ICodeEditor) => { + this._register(editor.onDidChangeModel(e => { + if (e.newModelUrl) + onSwitchTab(e.newModelUrl) + })) + } + + const initializeEditor = (editor: ICodeEditor) => { + addTabSwitchListeners(editor) + } + + // initialize current editors + any new editors + for (let editor of this._editorService.listCodeEditors()) initializeEditor(editor) + this._register(this._editorService.onCodeEditorAdd(editor => { initializeEditor(editor) })) + } +} + + +class TabSwitchContribution implements IWorkbenchContribution { + static readonly ID = 'workbench.contrib.void.tabswitch' + + constructor( + @IInstantiationService private readonly instantiationService: IInstantiationService, + @ICommandService private readonly commandService: ICommandService, + ) { + const onSwitchTab = () => { + this.commandService.executeCommand(VOID_CTRL_L_ACTION_ID) + } + this.instantiationService.createInstance(TabSwitchListener, onSwitchTab) + + // run on current tab if it exists + this.commandService.executeCommand(VOID_CTRL_L_ACTION_ID) + + + } +} + +registerWorkbenchContribution2(TabSwitchContribution.ID, TabSwitchContribution, WorkbenchPhase.AfterRestored); diff --git a/src/vs/workbench/contrib/void/browser/voidSettingsPane.ts b/src/vs/workbench/contrib/void/browser/voidSettingsPane.ts index fe747ae3..34b7b902 100644 --- a/src/vs/workbench/contrib/void/browser/voidSettingsPane.ts +++ b/src/vs/workbench/contrib/void/browser/voidSettingsPane.ts @@ -117,14 +117,13 @@ Registry.as(EditorExtensions.EditorPane).registerEditorPane ); -export const VOID_OPEN_SETTINGS_ACTION_ID = 'workbench.action.openVoidSettings' // register the gear on the top right +export const VOID_TOGGLE_SETTINGS_ACTION_ID = 'workbench.action.toggleVoidSettings' registerAction2(class extends Action2 { constructor() { super({ - id: VOID_OPEN_SETTINGS_ACTION_ID, - title: nls.localize2('voidSettings', "Void: Settings"), - f1: true, + id: VOID_TOGGLE_SETTINGS_ACTION_ID, + title: nls.localize2('voidSettings', "Void: Toggle Settings"), icon: Codicon.settingsGear, menu: [ { @@ -159,11 +158,35 @@ registerAction2(class extends Action2 { }) + +export const VOID_OPEN_SETTINGS_ACTION_ID = 'workbench.action.openVoidSettings' +registerAction2(class extends Action2 { + constructor() { + super({ + id: VOID_OPEN_SETTINGS_ACTION_ID, + title: nls.localize2('voidSettings', "Void: Open Settings"), + f1: true, + icon: Codicon.settingsGear, + }); + } + async run(accessor: ServicesAccessor): Promise { + const editorService = accessor.get(IEditorService); + const instantiationService = accessor.get(IInstantiationService); + + const input = instantiationService.createInstance(VoidSettingsInput); + await editorService.openEditor(input); + } +}) + + + + + // add to settings gear on bottom left MenuRegistry.appendMenuItem(MenuId.GlobalActivity, { group: '0_command', command: { - id: VOID_OPEN_SETTINGS_ACTION_ID, + id: VOID_TOGGLE_SETTINGS_ACTION_ID, title: nls.localize('voidSettings', "Void Settings") }, order: 1