"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutputChannel = exports.OutputChannelManager = void 0;
var inversify_1 = require("inversify");
var promise_util_1 = require("@theia/core/lib/common/promise-util");
var output_uri_1 = require("@theia/output/lib/common/output-uri");
var output_channel_1 = require("@theia/output/lib/common/output-channel");
var OutputChannelManager = /** @class */ (function (_super) {
    __extends(OutputChannelManager, _super);
    function OutputChannelManager() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    OutputChannelManager.prototype.getChannel = function (name) {
        var existing = this.channels.get(name);
        if (existing) {
            return existing;
        }
        // We have to register the resource first, because `textModelService#createModelReference` will require it
        // right after creating the monaco.editor.ITextModel.
        // All `append` and `appendLine` will be deferred until the underlying text-model instantiation.
        var resource = this.resources.get(name);
        if (!resource) {
            var uri = output_uri_1.OutputUri.create(name);
            var editorModelRef_1 = new promise_util_1.Deferred();
            resource = this.createResource({ uri: uri, editorModelRef: editorModelRef_1 });
            this.resources.set(name, resource);
            this.textModelService.createModelReference(uri).then(function (ref) { return editorModelRef_1.resolve(ref); });
        }
        var channel = new OutputChannel(resource, this.preferences);
        this.channels.set(name, channel);
        this.toDisposeOnChannelDeletion.set(name, this.registerListeners(channel));
        this.channelAddedEmitter.fire(channel);
        if (!this.selectedChannel) {
            this.selectedChannel = channel;
        }
        return channel;
    };
    OutputChannelManager = __decorate([
        inversify_1.injectable()
    ], OutputChannelManager);
    return OutputChannelManager;
}(output_channel_1.OutputChannelManager));
exports.OutputChannelManager = OutputChannelManager;
var OutputChannel = /** @class */ (function (_super) {
    __extends(OutputChannel, _super);
    function OutputChannel() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    OutputChannel.prototype.dispose = function () {
        _super.prototype.dispose.call(this);
        if (this.disposed) {
            var textModifyQueue = this.textModifyQueue;
            textModifyQueue.pause();
            textModifyQueue.clear();
        }
    };
    return OutputChannel;
}(output_channel_1.OutputChannel));
exports.OutputChannel = OutputChannel;
//# sourceMappingURL=output-channel.js.map