From 5712b3621326f102e8e0e20319be990e2b3bed7d Mon Sep 17 00:00:00 2001 From: Shim Heungwoon Date: Wed, 23 Sep 2015 18:22:25 +0900 Subject: [PATCH] [BUGFIX] Reloading file updated from another ide --- .../plugins/editors/DataSourceHandler.js | 36 +++++++++++++- common/src/webida/plugins/editors/plugin.js | 48 ++----------------- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/common/src/webida/plugins/editors/DataSourceHandler.js b/common/src/webida/plugins/editors/DataSourceHandler.js index 224124a3..23b0ba2c 100644 --- a/common/src/webida/plugins/editors/DataSourceHandler.js +++ b/common/src/webida/plugins/editors/DataSourceHandler.js @@ -77,9 +77,12 @@ define([ * @private */ _subscribe: function() { - //open + //on deleted this.subscribed.push(topic.subscribe('workspace.nodes.deleting', this._onNodesDeleted.bind(this))); this.subscribed.push(topic.subscribe('fs.cache.node.deleted', this._checkCase.bind(this))); + + //on content changed + this.subscribed.push(topic.subscribe('data-source/content-change', this._onContentChange.bind(this))); }, /** @@ -210,6 +213,14 @@ define([ } }, + // ************* On Content Changed ************* // + + _onContentChange: function(dataSourceId) { + var dsRegistry = workbench.getDataSourceRegistry(); + var dataSource = dsRegistry.getDataSourceById(dataSourceId); + _askReload(dataSource); + }, + /** * @private */ @@ -238,5 +249,28 @@ define([ }); } + function _askReload(dataSource) { + var dataSourceId = dataSource.getId(); + var persistence = dataSource.getPersistence(); + require(['popup-dialog'], function(PopupDialog) { + // @formatter:off + PopupDialog.yesno({ + title: "Reload '" + persistence.getName() + "'?", + message: "'" + persistence.getPath() + "' has been changed. " + + 'Reload the editor(s) for the resource?', + type: 'warning' + }).then(function() { + var page = workbench.getCurrentPage(); + var registry = page.getPartRegistry(); + var parts = registry.getPartsByDataSource(dataSource); + parts.forEach(function(part) { + part.resetModel(); + }); + }, function() { + }); + // @formatter:on + }); + } + return DataSourceHandler; }); diff --git a/common/src/webida/plugins/editors/plugin.js b/common/src/webida/plugins/editors/plugin.js index badd6f61..17139e97 100644 --- a/common/src/webida/plugins/editors/plugin.js +++ b/common/src/webida/plugins/editors/plugin.js @@ -24,12 +24,9 @@ define([ 'dojo/topic', 'external/lodash/lodash.min', - 'external/URIjs/src/URI', 'webida-lib/app', - 'webida-lib/util/path', 'webida-lib/util/arrays/BubblingArray', 'webida-lib/util/logger/logger-client', - 'webida-lib/util/notify', 'webida-lib/plugin-manager-0.1', 'webida-lib/plugins/workbench/plugin', 'webida-lib/plugins/workbench/ui/CompatibleTabPartContainer', @@ -37,23 +34,17 @@ define([ 'webida-lib/plugins/workbench/ui/LayoutPane', 'webida-lib/plugins/workbench/ui/PartContainer', 'webida-lib/plugins/workbench/ui/Workbench', - 'webida-lib/widgets/views/view', 'webida-lib/widgets/views/viewmanager', 'webida-lib/widgets/views/viewFocusController', - 'external/async/dist/async.min', 'plugins/webida.notification/notification-message', - 'plugins/webida.workspace.model.file/FileDataSource', //TODO : temp for 7.21 './DataSourceHandler', './LifecycleManager' ], function ( topic, _, - URI, ide, - pathUtil, BubblingArray, Logger, - notify, pm, workbench, CompatibleTabPartContainer, @@ -61,12 +52,9 @@ define([ LayoutPane, PartContainer, Workbench, - View, vm, ViewFocusController, - async, toastr, - FileDataSource, DataSourceHandler, LifecycleManager ) { @@ -90,6 +78,7 @@ define([ }); topic.subscribe('fs.cache.file.invalidated', function(fsURL, path) { + logger.info('fs.cache.file.invalidated arrived'); var file = editors.getFile(path); if (file) { if (file === editors.currentFile) { @@ -102,14 +91,7 @@ define([ topic.subscribe('fs.cache.file.set', function(fsUrl, target, reason) { if (reason === 'refreshed') { - var file = editors.getFile(target); - if (file) { - if (file === editors.currentFile) { - _.defer(askAndReload.bind(null, file)); - } else { - file.toAskAndReload = true; - } - } + topic.publish('data-source/content-change', target); } }); @@ -121,7 +103,7 @@ define([ //Compatibility topic.subscribe('current-part-changed', function(oldPart, newPart) { - console.log('current-part-changed'); + logger.info('current-part-changed arrived'); if (oldPart !== newPart) { @@ -141,7 +123,7 @@ define([ key: 'E' }); - /////////////////////// TODO refactor + //------------ TODO refactor --------------- var file = newPart.getDataSource().getPersistence(); @@ -156,10 +138,6 @@ define([ fsCache.refreshFileContents(file.path); } - if (file.toAskAndReload) { - file.toAskAndReload = false; - _.defer(askAndReload.bind(null, file)); - } topic.publish('editors.selected', file.path, file); } } else { @@ -175,24 +153,6 @@ define([ var fsCache = ide.getFSCache(); var asked = []; - function askAndReload(file) { - require(['popup-dialog'], function(PopupDialog) { - if (asked.indexOf(file) === -1) { - console.assert(asked.length === 0, 'assertion fail: only one file is asked to reload at any point of time'); - asked.push(file); - PopupDialog.yesno({ - title: 'Reload File', - message: file.path + '

' + 'File \'' + file.name + '\' has changed.
' + 'Do you want to reload?', - type: 'warning' - }).then(function() { - asked.pop(); - topic.publish('editor/open', file.getPersistenceId()); - }, function() { - asked.pop(); - }); - } - }); - } /** @module editors */ var editors = {