From 22653e21a239afa8f29cf2c93afe28d21246e7ba Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 9 Jul 2014 12:26:33 +0200 Subject: Propagate file action changes to the file lists Whenever an app needs to register an event late, it does that on the original file actions object. Since the file actions that the file list work on is a merged list, not the original one, the registration event needs to be propagated there as well. --- apps/files/js/app.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'apps/files/js/app.js') diff --git a/apps/files/js/app.js b/apps/files/js/app.js index 45b6b6a0e16..6f5206fcdb6 100644 --- a/apps/files/js/app.js +++ b/apps/files/js/app.js @@ -32,9 +32,11 @@ // regular actions fileActions.merge(OCA.Files.fileActions); - // in case apps would decide to register file actions later, - // replace the global object with this one - OCA.Files.fileActions = fileActions; + this._onActionsUpdated = _.bind(this._onActionsUpdated, this); + OCA.Files.fileActions.on('setDefault.app-files', this._onActionsUpdated); + OCA.Files.fileActions.on('registerAction.app-files', this._onActionsUpdated); + window.FileActions.on('setDefault.app-files', this._onActionsUpdated); + window.FileActions.on('registerAction.app-files', this._onActionsUpdated); this.files = OCA.Files.Files; @@ -59,6 +61,32 @@ this._onPopState(OC.Util.History.parseUrlQuery()); }, + /** + * Destroy the app + */ + destroy: function() { + this.navigation = null; + this.fileList.destroy(); + this.fileList = null; + this.files = null; + OCA.Files.fileActions.off('setDefault.app-files', this._onActionsUpdated); + OCA.Files.fileActions.off('registerAction.app-files', this._onActionsUpdated); + window.FileActions.off('setDefault.app-files', this._onActionsUpdated); + window.FileActions.off('registerAction.app-files', this._onActionsUpdated); + }, + + _onActionsUpdated: function(ev, newAction) { + // forward new action to the file list + if (ev.action) { + this.fileList.fileActions.registerAction(ev.action); + } else if (ev.defaultAction) { + this.fileList.fileActions.setDefault( + ev.defaultAction.mime, + ev.defaultAction.name + ); + } + }, + /** * Returns the container of the currently visible app. * -- cgit v1.2.3