// Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. define([ 'jquery', 'base/js/namespace', 'base/js/dialog', 'base/js/utils', ], function($, IPython, dialog, utils) { "use strict"; var KernelSelector = function(selector, notebook) { var that = this; this.selector = selector; this.notebook = notebook; this.notebook.set_kernelselector(this); this.events = notebook.events; this.current_selection = null; this.kernelspecs = {}; if (this.selector !== undefined) { this.element = $(selector); this.request_kernelspecs(); } this.bind_events(); // Make the object globally available for user convenience & inspection IPython.kernelselector = this; this._finish_load = null; this.loaded = new Promise(function(resolve, reject) { that._finish_load = resolve; }); Object.seal(this); }; KernelSelector.prototype.request_kernelspecs = function() { var url = utils.url_join_encode(this.notebook.base_url, 'api/kernelspecs'); utils.promising_ajax(url).then($.proxy(this._got_kernelspecs, this)); }; KernelSelector.prototype._got_kernelspecs = function(data) { var that = this; this.kernelspecs = data.kernelspecs; var change_kernel_submenu = $("#menu-change-kernel-submenu"); var new_notebook_submenu = $("#menu-new-notebook-submenu"); var keys = Object.keys(data.kernelspecs).sort(function (a, b) { // sort by display_name var da = data.kernelspecs[a].spec.display_name; var db = data.kernelspecs[b].spec.display_name; if (da === db) { return 0; } else if (da > db) { return 1; } else { return -1; } }); keys.map(function (key) { // Create the Kernel > Change kernel submenu var ks = data.kernelspecs[key]; change_kernel_submenu.append( $("