Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 488582

Summary: File client should dispatch "changed" event when files change.
Product: [ECD] Orion Reporter: libing wang <libingw>
Component: ClientAssignee: libing wang <libingw>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Michael_Rennie, Silenio_Quarti
Version: 11.0   
Target Milestone: 12.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 487279, 488980    

Description libing wang CLA 2016-02-26 12:30:08 EST
When fixing bug 488396, we realized that any silent changes on a file without opening it in the editor will affect the AST caching. But in general, it may affect other things in the future.
The fix of bug 488396 was a specific solution for the "replace selected" feature. Once we fix this bug as a generic solution, we will refactor the fix of bug 488396 to the generic solution.

We may need a generic event like below:

type: "fileChanged"
modified: [],
added:[]
deleted[]
Comment 1 libing wang CLA 2016-02-26 12:31:37 EST
We will have to fix this shortly.
Comment 2 Silenio Quarti CLA 2016-02-29 09:43:10 EST
*** Bug 481606 has been marked as a duplicate of this bug. ***
Comment 3 libing wang CLA 2016-03-10 11:14:53 EST
I have a fix in my work space for bug 488980. 
I am sending an event on fileClient.write and listen to it from inputManager.
Comment 4 libing wang CLA 2016-03-18 15:56:55 EDT
Patch:

diff --git a/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js b/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js
index 0188e99..2c5735a 100644
--- a/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js
+++ b/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js
@@ -500,7 +500,11 @@
 		 * @return {Deferred} A deferred for chaining events after the write completes with new metadata object
 		 */		
 		write: function(writeLocation, contents, args) {
-			return _doServiceCall(this._getService(writeLocation), "write", arguments); //$NON-NLS-1$
+			//return _doServiceCall(this._getService(writeLocation), "write", arguments); //$NON-NLS-1$
+			return _doServiceCall(this._getService(writeLocation), "write", arguments).then(function(result){ //$NON-NLS-0$
+				this.dispatchEvent({ type: "Changed", modified: [writeLocation]}); //$NON-NLS-0$
+				return result;
+			}.bind(this));
 		},
 
 		/**
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/inputManager.js b/bundles/org.eclipse.orion.client.ui/web/orion/inputManager.js
index e673fb1..4540e18 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/inputManager.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/inputManager.js
@@ -134,6 +134,21 @@
 		this.contentTypeRegistry = options.contentTypeRegistry;
 		this.selection = options.selection;
 		this._input = this._title = "";
+		this.fileClient.addEventListener("Changed", function(evt) { //$NON-NLS-0$
+			if (this._fileMetadata && this._fileMetadata._saving) {
+				return;
+			}
+			if(evt && evt.modified) {
+				var metadata = this.getFileMetadata();
+				if(metadata && metadata.Location) {
+					if(evt.modified.some(function(loc){
+						return metadata.Location === loc;
+					})) {
+						this.load();
+					}
+				}
+			}
+		}.bind(this));
 	}
 	objects.mixin(InputManager.prototype, /** @lends orion.editor.InputManager.prototype */ {
 		/**
Comment 6 libing wang CLA 2016-04-15 14:44:21 EDT
last commit:
http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=84d0548120fbb3609de40cec073783fdd1883aa4

We do not want to send out event from fileClient.createProject API because the  {parent, newValue} object require from the UI side can not be obtained directly from the fileClient.

Neither do we want to send out event from fileClient.remoteImport API for hte same reason.
Comment 7 libing wang CLA 2016-04-18 17:13:14 EDT
Added one more fix to dispatch "Changed" event on copied property on fileClinet.remoteImport.
http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=e24154d4d3946eb11b63a7d327b3062224e7182b
Comment 8 libing wang CLA 2016-04-18 17:15:33 EDT
One more commit to fix the issue:
When create a folder under the root of work space, fileClient.createProject API is called. As currently we do not send out "Changed" event on project creation yet, the UI is not reflecting it.

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=b93ea3996bcb8efdfd57c7ff91d561133146df90.
Comment 9 libing wang CLA 2016-04-18 17:27:24 EDT
So far fileClient.createProject is hte only API that is not sending out "Changed" event because the UI side is relying on much more information to refresh the work space and select the project.
I've opened Bug 491942 to fix it.
Comment 10 libing wang CLA 2016-04-19 16:17:49 EDT
Remove the old "fileContentChanged" event and dispatch muultiple file modified change event.

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=651df6c32b0c600550b2ae1132bb09ddf61e68d6