"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeybindingContributionPoint = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const common_1 = require("../../../common");
const types_1 = require("../../types");
let KeybindingContributionPoint = class KeybindingContributionPoint extends common_1.VSCodeContributePoint {
    contribute() {
        for (const contrib of this.contributesMap) {
            const { extensionId, contributes } = contrib;
            const extension = this.extensionManageService.getExtensionInstanceByExtId(extensionId);
            if (!extension) {
                continue;
            }
            const keybindings = contributes.map((contributedKeyBinding) => this.toKeybinding(contributedKeyBinding, extension.isBuiltin));
            this.addDispose(this.keybindingRegistry.registerKeybindings(keybindings));
        }
    }
    toKeybinding(contributedKeyBinding, isBuiltin) {
        const keybinding = this.toOSKeybinding(contributedKeyBinding);
        const { command, when } = contributedKeyBinding;
        return {
            keybinding,
            command,
            when,
            priority: isBuiltin ? ide_core_browser_1.KeybindingWeight.BuiltinExtension * 100 : ide_core_browser_1.KeybindingWeight.ExternalExtension * 100,
        };
    }
    toOSKeybinding(ContributedKeyBinding) {
        let keybinding;
        const os = ide_core_browser_1.OS.type();
        if (os === ide_core_browser_1.OperatingSystem.Windows && ContributedKeyBinding.win) {
            keybinding = ContributedKeyBinding.win;
        }
        else if (os === ide_core_browser_1.OperatingSystem.Macintosh && ContributedKeyBinding.mac) {
            keybinding = ContributedKeyBinding.mac;
        }
        else if (ContributedKeyBinding.linux) {
            keybinding = ContributedKeyBinding.linux;
        }
        return keybinding || ContributedKeyBinding.key;
    }
};
exports.KeybindingContributionPoint = KeybindingContributionPoint;
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_core_browser_1.KeybindingRegistry),
    tslib_1.__metadata("design:type", Object)
], KeybindingContributionPoint.prototype, "keybindingRegistry", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(types_1.AbstractExtInstanceManagementService),
    tslib_1.__metadata("design:type", types_1.AbstractExtInstanceManagementService)
], KeybindingContributionPoint.prototype, "extensionManageService", void 0);
exports.KeybindingContributionPoint = KeybindingContributionPoint = tslib_1.__decorate([
    (0, di_1.Injectable)(),
    (0, common_1.Contributes)('keybindings'),
    (0, common_1.LifeCycle)(4 /* LifeCyclePhase.Ready */)
], KeybindingContributionPoint);
//# sourceMappingURL=keybindings.js.map