OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 return Promise.resolve(this._content); | 215 return Promise.resolve(this._content); |
216 var promise = this._requestContentPromise; | 216 var promise = this._requestContentPromise; |
217 if (!promise) { | 217 if (!promise) { |
218 promise = new Promise(fulfill => this._requestContentCallback = fulfill); | 218 promise = new Promise(fulfill => this._requestContentCallback = fulfill); |
219 this._requestContentPromise = promise; | 219 this._requestContentPromise = promise; |
220 this._project.requestFileContent(this, this._fireContentAvailable.bind(thi
s)); | 220 this._project.requestFileContent(this, this._fireContentAvailable.bind(thi
s)); |
221 } | 221 } |
222 return promise; | 222 return promise; |
223 } | 223 } |
224 | 224 |
225 /** | 225 checkContentUpdated() { |
226 * @param {function()} callback | 226 if (!this._contentLoaded && !this._forceLoadOnCheckContent) |
227 */ | 227 return; |
228 _pushCheckContentUpdatedCallback(callback) { | |
229 if (!this._checkContentUpdatedCallbacks) | |
230 this._checkContentUpdatedCallbacks = []; | |
231 this._checkContentUpdatedCallbacks.push(callback); | |
232 } | |
233 | 228 |
234 _terminateContentCheck() { | 229 if (!this._project.canSetFileContent() || this._checkingContent) |
235 delete this._checkingContent; | |
236 if (this._checkContentUpdatedCallbacks) { | |
237 this._checkContentUpdatedCallbacks.forEach(function(callback) { | |
238 callback(); | |
239 }); | |
240 delete this._checkContentUpdatedCallbacks; | |
241 } | |
242 } | |
243 | |
244 /** | |
245 * @param {boolean=} forceLoad | |
246 * @param {function()=} callback | |
247 */ | |
248 checkContentUpdated(forceLoad, callback) { | |
249 callback = callback || function() {}; | |
250 forceLoad = forceLoad || this._forceLoadOnCheckContent; | |
251 if (!this.contentLoaded() && !forceLoad) { | |
252 callback(); | |
253 return; | |
254 } | |
255 | |
256 if (!this._project.canSetFileContent()) { | |
257 callback(); | |
258 return; | |
259 } | |
260 this._pushCheckContentUpdatedCallback(callback); | |
261 | |
262 if (this._checkingContent) | |
263 return; | 230 return; |
264 | 231 |
265 this._checkingContent = true; | 232 this._checkingContent = true; |
266 this._project.requestFileContent(this, contentLoaded.bind(this)); | 233 this._project.requestFileContent(this, contentLoaded.bind(this)); |
267 | 234 |
268 /** | 235 /** |
269 * @param {?string} updatedContent | 236 * @param {?string} updatedContent |
270 * @this {Workspace.UISourceCode} | 237 * @this {Workspace.UISourceCode} |
271 */ | 238 */ |
272 function contentLoaded(updatedContent) { | 239 function contentLoaded(updatedContent) { |
| 240 this._checkingContent = false; |
273 if (updatedContent === null) { | 241 if (updatedContent === null) { |
274 var workingCopy = this.workingCopy(); | 242 var workingCopy = this.workingCopy(); |
275 this._contentCommitted('', false); | 243 this._contentCommitted('', false); |
276 this.setWorkingCopy(workingCopy); | 244 this.setWorkingCopy(workingCopy); |
277 this._terminateContentCheck(); | |
278 return; | 245 return; |
279 } | 246 } |
280 if (typeof this._lastAcceptedContent === 'string' && this._lastAcceptedCon
tent === updatedContent) { | 247 if (typeof this._lastAcceptedContent === 'string' && this._lastAcceptedCon
tent === updatedContent) |
281 this._terminateContentCheck(); | |
282 return; | 248 return; |
283 } | |
284 | 249 |
285 if (this._content === updatedContent) { | 250 if (this._content === updatedContent) { |
286 delete this._lastAcceptedContent; | 251 delete this._lastAcceptedContent; |
287 this._terminateContentCheck(); | |
288 return; | 252 return; |
289 } | 253 } |
290 | 254 |
291 if (!this.isDirty() || this._workingCopy === updatedContent) { | 255 if (!this.isDirty() || this._workingCopy === updatedContent) { |
292 this._contentCommitted(updatedContent, false); | 256 this._contentCommitted(updatedContent, false); |
293 this._terminateContentCheck(); | |
294 return; | 257 return; |
295 } | 258 } |
296 | 259 |
297 var shouldUpdate = | 260 var shouldUpdate = |
298 window.confirm(Common.UIString('This file was changed externally. Woul
d you like to reload it?')); | 261 window.confirm(Common.UIString('This file was changed externally. Woul
d you like to reload it?')); |
299 if (shouldUpdate) | 262 if (shouldUpdate) |
300 this._contentCommitted(updatedContent, false); | 263 this._contentCommitted(updatedContent, false); |
301 else | 264 else |
302 this._lastAcceptedContent = updatedContent; | 265 this._lastAcceptedContent = updatedContent; |
303 this._terminateContentCheck(); | |
304 } | 266 } |
305 } | 267 } |
306 | 268 |
307 forceLoadOnCheckContent() { | 269 forceLoadOnCheckContent() { |
308 this._forceLoadOnCheckContent = true; | 270 this._forceLoadOnCheckContent = true; |
309 } | 271 } |
310 | 272 |
311 /** | 273 /** |
312 * @return {!Promise<?string>} | 274 * @return {!Promise<?string>} |
313 */ | 275 */ |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 Workspace.UISourceCodeMetadata = class { | 902 Workspace.UISourceCodeMetadata = class { |
941 /** | 903 /** |
942 * @param {?Date} modificationTime | 904 * @param {?Date} modificationTime |
943 * @param {?number} contentSize | 905 * @param {?number} contentSize |
944 */ | 906 */ |
945 constructor(modificationTime, contentSize) { | 907 constructor(modificationTime, contentSize) { |
946 this.modificationTime = modificationTime; | 908 this.modificationTime = modificationTime; |
947 this.contentSize = contentSize; | 909 this.contentSize = contentSize; |
948 } | 910 } |
949 }; | 911 }; |
OLD | NEW |