Indicate which keymap is installed (fixes #21076)

This commit is contained in:
Christof Marti 2017-02-23 14:13:23 -08:00
parent f9d76beb24
commit 95f8b3c880
4 changed files with 69 additions and 14 deletions

View file

@ -7,7 +7,7 @@
import * as arrays from 'vs/base/common/arrays';
import * as nls from 'vs/nls';
import { chain, any } from 'vs/base/common/event';
import Event, { chain, any } from 'vs/base/common/event';
import { onUnexpectedError, canceled } from 'vs/base/common/errors';
import { TPromise } from 'vs/base/common/winjs.base';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
@ -31,7 +31,6 @@ export class KeymapExtensions implements IWorkbenchContribution {
constructor(
@IInstantiationService private instantiationService: IInstantiationService,
@IExtensionManagementService private extensionService: IExtensionManagementService,
@IExtensionEnablementService private extensionEnablementService: IExtensionEnablementService,
@IChoiceService private choiceService: IChoiceService,
@ILifecycleService lifecycleService: ILifecycleService,
@ -39,12 +38,7 @@ export class KeymapExtensions implements IWorkbenchContribution {
) {
this.disposables.push(
lifecycleService.onShutdown(() => this.dispose()),
any(
chain(extensionService.onDidInstallExtension)
.map(e => stripVersion(e.id))
.event,
extensionEnablementService.onEnablementChanged
)((id => {
instantiationService.invokeFunction(onKeymapExtensionChanged)((id => {
this.checkForOtherKeymaps(id)
.then(null, onUnexpectedError);
}))
@ -98,6 +92,17 @@ export class KeymapExtensions implements IWorkbenchContribution {
}
}
export function onKeymapExtensionChanged(accessor: ServicesAccessor): Event<string> {
const extensionService = accessor.get(IExtensionManagementService);
const extensionEnablementService = accessor.get(IExtensionEnablementService);
return any(
chain(extensionService.onDidInstallExtension)
.map(e => stripVersion(e.id))
.event,
extensionEnablementService.onEnablementChanged
);
}
export function getInstalledKeymaps(accessor: ServicesAccessor): TPromise<IKeymapExtension[]> {
const extensionService = accessor.get(IExtensionManagementService);
const extensionEnablementService = accessor.get(IExtensionEnablementService);

View file

@ -56,9 +56,9 @@ export default () => `
<li class="showCommands"><button data-href="command:workbench.action.showCommands"><h3>${escape(localize('welcomePage.showCommands', "Find and run all commands"))}</h3> <span>${escape(localize('welcomePage.showCommandsDescription', "Rapidly access and search commands from the control panel ({0})")).replace('{0}', '<span class="shortcut" data-command="workbench.action.showCommands"></span>')}</span></button></li>
<li class="openGlobalSettings"><button data-href="command:workbench.action.openGlobalSettings"><h3>${escape(localize('welcomePage.configureSettings', "Configure settings"))}</h3> <span>${escape(localize('welcomePage.configureSettingsDescription', "Unlock the full power of VS Code by tweaking the settings"))}</span></button></li>
<li class="showRecommendedKeymapExtensions"><button data-href="command:workbench.extensions.action.showRecommendedKeymapExtensions"><h3>${escape(localize('welcomePage.installKeymapDescription', "Install keyboard shortcuts"))}</h3> <span>${escape(localize('welcomePage.installKeymap', "Install the keyboard shortcuts of {0}, {1}, {2} and {3}"))
.replace('{0}', `<a class="installKeymap" data-keymap-name="${escape(localize('welcomePage.vim', "Vim"))}" data-keymap="vscodevim.vim" href="javascript:void(0)">${escape(localize('welcomePage.vim', "Vim"))}</a>`)
.replace('{1}', `<a class="installKeymap" data-keymap-name="${escape(localize('welcomePage.sublime', "Sublime"))}" data-keymap="ms-vscode.sublime-keybindings" href="javascript:void(0)">${escape(localize('welcomePage.sublime', "Sublime"))}</a>`)
.replace('{2}', `<a class="installKeymap" data-keymap-name="${escape(localize('welcomePage.atom', "Atom"))}" data-keymap="ms-vscode.atom-keybindings" href="javascript:void(0)">${escape(localize('welcomePage.atom', "Atom"))}</a>`)
.replace('{0}', `<a class="installKeymap" data-keymap-name="${escape(localize('welcomePage.vim', "Vim"))}" data-keymap="vscodevim.vim" href="javascript:void(0)">${escape(localize('welcomePage.vim', "Vim"))}</a><span class="currentKeymap" data-keymap="vscodevim.vim">${escape(localize('welcomePage.vimCurrent', "Vim (current)"))}</span>`)
.replace('{1}', `<a class="installKeymap" data-keymap-name="${escape(localize('welcomePage.sublime', "Sublime"))}" data-keymap="ms-vscode.sublime-keybindings" href="javascript:void(0)">${escape(localize('welcomePage.sublime', "Sublime"))}</a><span class="currentKeymap" data-keymap="ms-vscode.sublime-keybindings">${escape(localize('welcomePage.sublimeCurrent', "Sublime (current)"))}</span>`)
.replace('{2}', `<a class="installKeymap" data-keymap-name="${escape(localize('welcomePage.atom', "Atom"))}" data-keymap="ms-vscode.atom-keybindings" href="javascript:void(0)">${escape(localize('welcomePage.atom', "Atom"))}</a><span class="currentKeymap" data-keymap="ms-vscode.atom-keybindings">${escape(localize('welcomePage.atomCurrent', "Atom (current)"))}</span>`)
.replace('{3}', `<a href="command:workbench.extensions.action.showRecommendedKeymapExtensions">${escape(localize('welcomePage.others', "others"))}</a>`)}
</span></button></li>
</ul>

View file

@ -256,6 +256,16 @@
outline-offset: -5px;
}
.monaco-workbench > .part.editor > .content .welcomePage .commands li button .currentKeymap {
display: none;
}
.monaco-workbench > .part.editor > .content .welcomePage .commands li button .installKeymap.installed {
display: none;
}
.monaco-workbench > .part.editor > .content .welcomePage .commands li button .currentKeymap.installed {
display: inline;
}
.monaco-workbench > .part.editor > .content .welcomePageContainer.max-height-685px .title {
display: none;
}

View file

@ -29,9 +29,11 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { Schemas } from 'vs/base/common/network';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { getInstalledKeymaps } from 'vs/workbench/parts/extensions/electron-browser/keymapExtensions';
import { getInstalledKeymaps, IKeymapExtension, onKeymapExtensionChanged } from 'vs/workbench/parts/extensions/electron-browser/keymapExtensions';
import { IExtensionEnablementService, IExtensionManagementService, IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { used } from 'vs/workbench/parts/welcome/page/electron-browser/vs_code_welcome_page';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
used();
@ -98,6 +100,8 @@ const reorderedQuickLinks = [
class WelcomePage {
private disposables: IDisposable[] = [];
constructor(
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IInstantiationService private instantiationService: IInstantiationService,
@ -111,24 +115,27 @@ class WelcomePage {
@IExtensionEnablementService private extensionEnablementService: IExtensionEnablementService,
@IExtensionGalleryService private extensionGalleryService: IExtensionGalleryService,
@IExtensionManagementService private extensionManagementService: IExtensionManagementService,
@ILifecycleService lifecycleService: ILifecycleService,
@ITelemetryService private telemetryService: ITelemetryService
) {
this.disposables.push(lifecycleService.onShutdown(() => this.dispose()));
this.create();
}
private create() {
const recentlyOpened = this.windowService.getRecentlyOpen();
const installedKeymaps = this.instantiationService.invokeFunction(getInstalledKeymaps);
const uri = URI.parse(require.toUrl('./vs_code_welcome_page'))
.with({
scheme: Schemas.walkThrough,
query: JSON.stringify({ moduleId: 'vs/workbench/parts/welcome/page/electron-browser/vs_code_welcome_page' })
});
const input = this.instantiationService.createInstance(WalkThroughInput, localize('welcome.title', "Welcome"), '', uri, telemetryFrom, container => this.onReady(container, recentlyOpened));
const input = this.instantiationService.createInstance(WalkThroughInput, localize('welcome.title', "Welcome"), '', uri, telemetryFrom, container => this.onReady(container, recentlyOpened, installedKeymaps));
this.editorService.openEditor(input, { pinned: true }, Position.ONE)
.then(null, onUnexpectedError);
}
private onReady(container: HTMLElement, recentlyOpened: TPromise<{ files: string[]; folders: string[]; }>): void {
private onReady(container: HTMLElement, recentlyOpened: TPromise<{ files: string[]; folders: string[]; }>, installedKeymaps: TPromise<IKeymapExtension[]>): void {
const enabled = this.configurationService.lookup<boolean>(enabledKey).value;
const showOnStartup = <HTMLInputElement>container.querySelector('#showOnStartup');
if (enabled) {
@ -210,6 +217,14 @@ class WelcomePage {
}
}
});
this.updateInstalledKeymaps(container, installedKeymaps);
this.disposables.push(this.instantiationService.invokeFunction(onKeymapExtensionChanged)(id => {
if (container.querySelector(`.installKeymap[data-keymap="${id}"], .currentKeymap[data-keymap="${id}"]`)) {
const installedKeymaps = this.instantiationService.invokeFunction(getInstalledKeymaps);
this.updateInstalledKeymaps(container, installedKeymaps);
}
}));
}
private installKeymap(keymapName: string, keymapIdentifier: string): void {
@ -299,4 +314,29 @@ class WelcomePage {
this.messageService.show(Severity.Error, err);
});
}
private updateInstalledKeymaps(container: HTMLElement, installedKeymaps: TPromise<IKeymapExtension[]>) {
installedKeymaps.then(extensions => {
const elements = container.querySelectorAll('.installKeymap, .currentKeymap');
for (let i = 0; i < elements.length; i++) {
elements[i].classList.remove('installed');
}
extensions.filter(ext => ext.globallyEnabled)
.map(ext => ext.identifier)
.forEach(id => {
const install = container.querySelector(`.installKeymap[data-keymap="${id}"]`);
if (install) {
install.classList.add('installed');
}
const current = container.querySelector(`.currentKeymap[data-keymap="${id}"]`);
if (current) {
current.classList.add('installed');
}
});
}).then(null, onUnexpectedError);
}
dispose(): void {
this.disposables = dispose(this.disposables);
}
}