Skip to content

Commit

Permalink
fix: set default terminal type (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
erha19 authored Jun 20, 2022
1 parent 4679119 commit 4df3b87
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
10 changes: 10 additions & 0 deletions packages/core-browser/src/preferences/preference-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ export class PreferenceServiceImpl implements PreferenceService {
throw new Error(`Unable to write to ${PreferenceScope.getScopeNames(resolvedScope)[0]} Settings.`);
}

public async update(preferenceName: string, value: any, defaultScope = PreferenceScope.User) {
const resolved = this.resolve(preferenceName);
// 默认会跳过 PreferenceScope.Default 作用域值的设置
if (resolved?.scope) {
this.set(preferenceName, value, resolved.scope);
} else {
this.set(preferenceName, value, defaultScope);
}
}

public hasLanguageSpecific(preferenceName: string, language: string, resourceUri?: string): boolean {
return !!this.doResolve(preferenceName, undefined, resourceUri, undefined, language).languageSpecific;
}
Expand Down
11 changes: 10 additions & 1 deletion packages/core-browser/src/preferences/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface PreferenceService extends IDisposable {

/**
* 设置一个配置的值
* @param preferenceName 偏好名称
* @param preferenceName 配置名称
* @param value 设置值
* @param scope 目标scope级别 如 User, Workspace
* @param resourceUri 资源路径
Expand All @@ -60,6 +60,15 @@ export interface PreferenceService extends IDisposable {
overrideIdentifier?: string,
): Promise<void>;

/**
* 设置一个配置值,优先设置最高 Scope 级别的配置
* 如,但设置了工作区配置的情况下,调用该方法将会优先更新工作区配置
* @param preferenceName 配置名称
* @param value 配置值
* @param defaultScope 默认作用域,当查找不到配置值情况下使用该作用域设置配置值
*/
update(preferenceName: string, value: any, defaultScope?: PreferenceScope): Promise<void>;

onPreferenceChanged: Event<PreferenceChange>;

onPreferencesChanged: Event<PreferenceChanges>;
Expand Down
3 changes: 3 additions & 0 deletions packages/terminal-next/__tests__/browser/mock.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ export class MockPreferenceService implements PreferenceService {
resourceUri?: string,
overrideIdentifier?: string,
): Promise<void> {}

async update(preferenceName: string, value: any, defaultScope?: PreferenceScope): Promise<void> {}

onPreferencesChanged() {
return Disposable.NULL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
IPreferenceSettingsService,
ILogger,
IClipboardService,
PreferenceScope,
TerminalSettingsId,
} from '@opensumi/ide-core-browser';

Expand Down Expand Up @@ -75,6 +74,10 @@ export class TerminalCommandContribution implements CommandContribution {
this.terminalController.reconnect();
}

private setDefaultTerminalType(type: string) {
this.preference.update(TerminalSettingsId.Type, type);
}

registerCommands(registry: CommandRegistry) {
// 搜索
registry.registerCommand(
Expand Down Expand Up @@ -207,31 +210,31 @@ export class TerminalCommandContribution implements CommandContribution {

registry.registerCommand(TERMINAL_COMMANDS.SELECT_ZSH, {
execute: async () => {
this.preference.set(TerminalSettingsId.Type, 'zsh', PreferenceScope.User);
this.setDefaultTerminalType('zsh');
},
});

registry.registerCommand(TERMINAL_COMMANDS.SELECT_BASH, {
execute: async () => {
this.preference.set(TerminalSettingsId.Type, 'bash', PreferenceScope.User);
this.setDefaultTerminalType('bash');
},
});

registry.registerCommand(TERMINAL_COMMANDS.SELECT_SH, {
execute: async () => {
this.preference.set(TerminalSettingsId.Type, 'sh', PreferenceScope.User);
this.setDefaultTerminalType('sh');
},
});

registry.registerCommand(TERMINAL_COMMANDS.SELECT_POWERSHELL, {
execute: async () => {
this.preference.set(TerminalSettingsId.Type, 'powershell', PreferenceScope.User);
this.setDefaultTerminalType('powershell');
},
});

registry.registerCommand(TERMINAL_COMMANDS.SELECT_CMD, {
execute: async () => {
this.preference.set(TerminalSettingsId.Type, 'cmd', PreferenceScope.User);
this.setDefaultTerminalType('cmd');
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const group = 'panel_menu';
export const more1 = 'more_1';
export const more1Sub = 'more_1_sub';
export const more2 = 'more_2';
export const DEFAULT_TERMINAL_TYPE_MENU_ID = 'DEFAULT_TERMINAL_TYPE_MENU_ID';

@Domain(MenuContribution)
export class TerminalMenuContribution implements MenuContribution {
Expand Down Expand Up @@ -124,14 +125,14 @@ export class TerminalMenuContribution implements MenuContribution {

menuRegistry.registerMenuItem(commonMenuId, {
label: localize('terminal.menu.selectType'),
submenu: 'tabbar_bottom_select_sub',
submenu: DEFAULT_TERMINAL_TYPE_MENU_ID,
order: 1,
group: more2,
when,
});

if (isWindows) {
menuRegistry.registerMenuItems('tabbar_bottom_select_sub', [
menuRegistry.registerMenuItems(DEFAULT_TERMINAL_TYPE_MENU_ID, [
{
command: TERMINAL_COMMANDS.SELECT_CMD,
order: 1,
Expand All @@ -148,7 +149,7 @@ export class TerminalMenuContribution implements MenuContribution {
},
]);
} else {
menuRegistry.registerMenuItems('tabbar_bottom_select_sub', [
menuRegistry.registerMenuItems(DEFAULT_TERMINAL_TYPE_MENU_ID, [
{
command: TERMINAL_COMMANDS.SELECT_ZSH,
order: 1,
Expand Down

0 comments on commit 4df3b87

Please sign in to comment.