Skip to content

Commit

Permalink
[BUGFIX] Reloading file updated from another ide
Browse files Browse the repository at this point in the history
  • Loading branch information
hwshim committed Sep 23, 2015
1 parent f7786e7 commit 5712b36
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 45 deletions.
36 changes: 35 additions & 1 deletion common/src/webida/plugins/editors/DataSourceHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
},

/**
Expand Down Expand Up @@ -210,6 +213,14 @@ define([
}
},

// ************* On Content Changed ************* //

_onContentChange: function(dataSourceId) {
var dsRegistry = workbench.getDataSourceRegistry();
var dataSource = dsRegistry.getDataSourceById(dataSourceId);
_askReload(dataSource);
},

/**
* @private
*/
Expand Down Expand Up @@ -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;
});
48 changes: 4 additions & 44 deletions common/src/webida/plugins/editors/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,37 @@
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',
'webida-lib/plugins/workbench/ui/EditorPart',
'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,
EditorPart,
LayoutPane,
PartContainer,
Workbench,
View,
vm,
ViewFocusController,
async,
toastr,
FileDataSource,
DataSourceHandler,
LifecycleManager
) {
Expand All @@ -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) {
Expand All @@ -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);
}
});

Expand All @@ -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) {

Expand All @@ -141,7 +123,7 @@ define([
key: 'E'
});

/////////////////////// TODO refactor
//------------ TODO refactor ---------------

var file = newPart.getDataSource().getPersistence();

Expand All @@ -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 {
Expand All @@ -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 + '<br><br>' + 'File \'' + file.name + '\' has changed. <br>' + 'Do you want to reload?',
type: 'warning'
}).then(function() {
asked.pop();
topic.publish('editor/open', file.getPersistenceId());
}, function() {
asked.pop();
});
}
});
}

/** @module editors */
var editors = {
Expand Down

0 comments on commit 5712b36

Please sign in to comment.