From 79a712bf67e73f8f3c5cce2061a7b911b61f80a5 Mon Sep 17 00:00:00 2001 From: Miguel Castillo Date: Thu, 14 Aug 2014 14:59:40 -0400 Subject: [PATCH 1/5] Adding theme tab in the extension manager dialog --- src/extensibility/ExtensionManagerDialog.js | 1 + src/extensibility/ExtensionManagerView.js | 2 +- .../ExtensionManagerViewModel.js | 85 ++++++++++++++++++- src/htmlContent/extension-manager-dialog.html | 1 + src/nls/root/strings.js | 1 + 5 files changed, 87 insertions(+), 3 deletions(-) diff --git a/src/extensibility/ExtensionManagerDialog.js b/src/extensibility/ExtensionManagerDialog.js index 392863ef334..854593ef92c 100644 --- a/src/extensibility/ExtensionManagerDialog.js +++ b/src/extensibility/ExtensionManagerDialog.js @@ -272,6 +272,7 @@ define(function (require, exports, module) { // Load registry only if the registry URL exists if (context.showRegistry) { models.push(new ExtensionManagerViewModel.RegistryViewModel()); + models.push(new ExtensionManagerViewModel.ThemesViewModel()); } models.push(new ExtensionManagerViewModel.InstalledViewModel()); diff --git a/src/extensibility/ExtensionManagerView.js b/src/extensibility/ExtensionManagerView.js index e92b17db108..40ab53b8f29 100644 --- a/src/extensibility/ExtensionManagerView.js +++ b/src/extensibility/ExtensionManagerView.js @@ -218,7 +218,7 @@ define(function (require, exports, module) { context.isMarkedForRemoval = ExtensionManager.isMarkedForRemoval(info.metadata.name); context.isMarkedForUpdate = ExtensionManager.isMarkedForUpdate(info.metadata.name); - context.showInstallButton = (this.model.source === this.model.SOURCE_REGISTRY) && !context.updateAvailable; + context.showInstallButton = (this.model.source === this.model.SOURCE_REGISTRY || this.model.source === this.model.SOURCE_THEMES) && !context.updateAvailable; context.showUpdateButton = context.updateAvailable && !context.isMarkedForUpdate && !context.isMarkedForRemoval; context.allowInstall = context.isCompatible && !context.isInstalled; diff --git a/src/extensibility/ExtensionManagerViewModel.js b/src/extensibility/ExtensionManagerViewModel.js index d78d55ab94b..03d394aebd0 100644 --- a/src/extensibility/ExtensionManagerViewModel.js +++ b/src/extensibility/ExtensionManagerViewModel.js @@ -68,6 +68,12 @@ define(function (require, exports, module) { */ ExtensionManagerViewModel.prototype.SOURCE_REGISTRY = "registry"; + /** + * @type {string} + * Constant indicating that this model/view should initialize from the main extension registry with only themes. + */ + ExtensionManagerViewModel.prototype.SOURCE_THEMES = "themes"; + /** * @type {string} * Constant indicating that this model/view should initialize from the list of locally installed extensions. @@ -158,7 +164,7 @@ define(function (require, exports, module) { */ ExtensionManagerViewModel.prototype.initialize = function () { var self = this; - + this._initializeFromSourcePromise = this._initializeFromSource().always(function () { self._updateMessage(); }); @@ -326,7 +332,7 @@ define(function (require, exports, module) { // Sort the registry by last published date and store the sorted list of IDs. self.sortedFullSet = registry_utils.sortRegistry(self.extensions, "registryInfo") .filter(function (entry) { - return entry.registryInfo !== undefined; + return entry.registryInfo !== undefined && entry.registryInfo.metadata.theme === undefined; }) .map(function (entry) { return entry.registryInfo.metadata.name; @@ -494,7 +500,82 @@ define(function (require, exports, module) { } return entry; }; + + + /** + * The model for the ExtensionManagerView that is responsible for handling registry-based theme extensions. + * This extends ExtensionManagerViewModel. + * Must be disposed with dispose() when done. + * + * Events: + * - change - triggered when the data for a given extension changes. Second parameter is the extension id. + * - filter - triggered whenever the filtered set changes (including on initialize). + * + * @constructor + */ + function ThemesViewModel() { + ExtensionManagerViewModel.call(this); + + // when registry is downloaded, sort extensions again - those with updates will be before others + this._ready = new $.Deferred(); + + // Gotta wait for the event of when the registry is downloaded in order to process the full set of + // extensions. + $(ExtensionManager).on("registryDownload", function () { + this.extensions = ExtensionManager.extensions; + this.sortedFullSet = registry_utils.sortRegistry(this.extensions, "registryInfo") + .filter(function (entry) { + return entry.installInfo === undefined && entry.registryInfo !== undefined && entry.registryInfo.metadata.theme; + }) + .map(function (entry) { + return entry.registryInfo.metadata.name; + }); + + this._setInitialFilter(); + this._ready.resolve(this.extensions); + }.bind(this)); + } + + + // Inheritance setup + ThemesViewModel.prototype = Object.create(ExtensionManagerViewModel.prototype); + ThemesViewModel.prototype.constructor = ThemesViewModel; + + + /** + * @type {string} + * ThemeViewModels always have a source of SOURCE_THEMES. + */ + ThemesViewModel.prototype.source = ExtensionManagerViewModel.prototype.SOURCE_THEMES; + + + /** + * Initializes the model from the remote extension registry. + * @return {$.Promise} a promise that's resolved with the registry JSON data. + */ + ThemesViewModel.prototype._initializeFromSource = function () { + var self = this; + return self._ready.promise(); + }; + + + /** + * @private + * Finds the theme extension metadata by id. If there is no theme extension matching the given id, + * this returns `null`. + * @param {string} id of the theme extension + * @return {Object?} extension metadata or null if there's no matching extension + */ + ThemesViewModel.prototype._getEntry = function (id) { + var entry = this.extensions[id]; + if (entry) { + return entry.registryInfo; + } + return entry; + }; + exports.RegistryViewModel = RegistryViewModel; + exports.ThemesViewModel = ThemesViewModel; exports.InstalledViewModel = InstalledViewModel; }); diff --git a/src/htmlContent/extension-manager-dialog.html b/src/htmlContent/extension-manager-dialog.html index 805328d1c4f..1b72b176a94 100644 --- a/src/htmlContent/extension-manager-dialog.html +++ b/src/htmlContent/extension-manager-dialog.html @@ -3,6 +3,7 @@