Skip to content

Commit

Permalink
#1587 A global command to configure language specific settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jan 23, 2017
1 parent 8d5e9b5 commit 375f32d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { DefaultPreferencesEditorInput, PreferencesEditor, PreferencesEditorInput } from 'vs/workbench/parts/preferences/browser/preferencesEditor';
import { OpenSettingsAction, OpenGlobalSettingsAction, OpenGlobalKeybindingsAction, OpenWorkspaceSettingsAction } from 'vs/workbench/parts/preferences/browser/preferencesActions';
import { OpenSettingsAction, OpenGlobalSettingsAction, OpenGlobalKeybindingsAction, OpenWorkspaceSettingsAction, ConfigureLanguageBasedSettingsAction } from 'vs/workbench/parts/preferences/browser/preferencesActions';
import { IPreferencesService, CONTEXT_DEFAULT_SETTINGS_EDITOR, DEFAULT_EDITOR_COMMAND_COLLAPSE_ALL } from 'vs/workbench/parts/preferences/common/preferences';
import { PreferencesService } from 'vs/workbench/parts/preferences/browser/preferencesService';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
Expand Down Expand Up @@ -135,6 +135,7 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(OpenSettingsAction, Op
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenGlobalSettingsAction, OpenGlobalSettingsAction.ID, OpenGlobalSettingsAction.LABEL), 'Preferences: Open User Settings', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenWorkspaceSettingsAction, OpenWorkspaceSettingsAction.ID, OpenWorkspaceSettingsAction.LABEL), 'Preferences: Open Workspace Settings', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenGlobalKeybindingsAction, OpenGlobalKeybindingsAction.ID, OpenGlobalKeybindingsAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_S) }), 'Preferences: Open Keyboard Shortcuts', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(ConfigureLanguageBasedSettingsAction, ConfigureLanguageBasedSettingsAction.ID, ConfigureLanguageBasedSettingsAction.LABEL), 'Preferences: Configure langugage specific settings', category);

MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
Expand Down
51 changes: 51 additions & 0 deletions src/vs/workbench/parts/preferences/browser/preferencesActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import { TPromise } from 'vs/base/common/winjs.base';
import * as nls from 'vs/nls';
import URI from 'vs/base/common/uri';
import { Action } from 'vs/base/common/actions';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IQuickOpenService, IPickOpenEntry, IFilePickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences';

export class OpenSettingsAction extends Action {
Expand Down Expand Up @@ -79,4 +82,52 @@ export class OpenWorkspaceSettingsAction extends Action {
public run(event?: any): TPromise<any> {
return this.preferencesService.openWorkspaceSettings();
}
}

export class ConfigureLanguageBasedSettingsAction extends Action {

public static ID = 'workbench.action.configureLanguageBasedSettings';
public static LABEL = nls.localize('configureLanguageBasedSettings', "Configure language specific settings...");

constructor(
id: string,
label: string,
@IModeService private modeService: IModeService,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IPreferencesService private preferencesService: IPreferencesService
) {
super(id, label);
}

public run(): TPromise<any> {
const languages = this.modeService.getRegisteredLanguageNames();
const picks: IPickOpenEntry[] = languages.sort().map((lang, index) => {
let description: string = nls.localize('languageDescriptionConfigured', "({0})", this.modeService.getModeIdForLanguageName(lang.toLowerCase()));
// construct a fake resource to be able to show nice icons if any
let fakeResource: URI;
const extensions = this.modeService.getExtensions(lang);
if (extensions && extensions.length) {
fakeResource = URI.file(extensions[0]);
} else {
const filenames = this.modeService.getFilenames(lang);
if (filenames && filenames.length) {
fakeResource = URI.file(filenames[0]);
}
}
return <IFilePickOpenEntry>{
label: lang,
resource: fakeResource,
description
};
});

return this.quickOpenService.pick(picks, { placeHolder: nls.localize('pickLanguage', "Select Language") })
.then(pick => {
if (pick) {
return this.modeService.getOrCreateModeByLanguageName(pick.label)
.then(mode => this.preferencesService.configureSettingsForLanguage(mode.getLanguageIdentifier().language));
}
});

}
}

0 comments on commit 375f32d

Please sign in to comment.