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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 if (this._content || this._contentLoaded) { | 255 if (this._content || this._contentLoaded) { |
256 callback(this._content); | 256 callback(this._content); |
257 return; | 257 return; |
258 } | 258 } |
259 this._requestContentCallbacks.push(callback); | 259 this._requestContentCallbacks.push(callback); |
260 if (this._requestContentCallbacks.length === 1) | 260 if (this._requestContentCallbacks.length === 1) |
261 this._project.requestFileContent(this, this._fireContentAvailable.bi nd(this)); | 261 this._project.requestFileContent(this, this._fireContentAvailable.bi nd(this)); |
262 }, | 262 }, |
263 | 263 |
264 /** | 264 /** |
265 * @param {function()=} callback | 265 * @param {function(boolean)=} callback |
vsevik
2014/03/28 16:18:36
Looks like this parameter is never used, why do yo
apavlov
2014/03/30 13:02:09
Previously, not all paths would invoke the callbac
| |
266 */ | 266 */ |
267 checkContentUpdated: function(callback) | 267 checkContentUpdated: function(callback) |
268 { | 268 { |
269 if (!this._project.canSetFileContent()) | 269 callback = callback || function() {}; |
270 if (this._checkingContent) { | |
vsevik
2014/03/28 16:18:36
Why did you swap the conditionals?
apavlov
2014/03/30 13:02:09
This happened after a few steps of refactoring :)
| |
271 callback(false); | |
270 return; | 272 return; |
271 if (this._checkingContent) | 273 } |
274 if (!this._project.canSetFileContent()) { | |
275 callback(true); | |
272 return; | 276 return; |
277 } | |
273 this._checkingContent = true; | 278 this._checkingContent = true; |
274 this._project.requestFileContent(this, contentLoaded.bind(this)); | 279 this._project.requestFileContent(this, contentLoaded.bind(this)); |
275 | 280 |
276 /** | 281 /** |
277 * @param {?string} updatedContent | 282 * @param {?string} updatedContent |
278 * @this {WebInspector.UISourceCode} | 283 * @this {WebInspector.UISourceCode} |
279 */ | 284 */ |
280 function contentLoaded(updatedContent) | 285 function contentLoaded(updatedContent) |
281 { | 286 { |
282 if (updatedContent === null) { | 287 if (updatedContent === null) { |
283 var workingCopy = this.workingCopy(); | 288 var workingCopy = this.workingCopy(); |
284 this._commitContent("", false); | 289 this._commitContent("", false); |
285 this.setWorkingCopy(workingCopy); | 290 this.setWorkingCopy(workingCopy); |
286 delete this._checkingContent; | 291 delete this._checkingContent; |
287 if (callback) | 292 callback(true); |
288 callback(); | |
289 return; | 293 return; |
290 } | 294 } |
291 if (typeof this._lastAcceptedContent === "string" && this._lastAccep tedContent === updatedContent) { | 295 if (typeof this._lastAcceptedContent === "string" && this._lastAccep tedContent === updatedContent) { |
292 delete this._checkingContent; | 296 delete this._checkingContent; |
293 if (callback) | 297 callback(true); |
294 callback(); | |
295 return; | 298 return; |
296 } | 299 } |
297 if (this._content === updatedContent) { | 300 if (this._content === updatedContent) { |
298 delete this._lastAcceptedContent; | 301 delete this._lastAcceptedContent; |
299 delete this._checkingContent; | 302 delete this._checkingContent; |
300 if (callback) | 303 callback(true); |
301 callback(); | |
302 return; | 304 return; |
303 } | 305 } |
304 | 306 |
305 if (!this.isDirty()) { | 307 if (!this.isDirty()) { |
306 this._commitContent(updatedContent, false); | 308 this._commitContent(updatedContent, false); |
307 delete this._checkingContent; | 309 delete this._checkingContent; |
308 if (callback) | 310 callback(true); |
309 callback(); | |
310 return; | 311 return; |
311 } | 312 } |
312 | 313 |
313 var shouldUpdate = window.confirm(WebInspector.UIString("This file w as changed externally. Would you like to reload it?")); | 314 var shouldUpdate = window.confirm(WebInspector.UIString("This file w as changed externally. Would you like to reload it?")); |
314 if (shouldUpdate) | 315 if (shouldUpdate) |
315 this._commitContent(updatedContent, false); | 316 this._commitContent(updatedContent, false); |
316 else | 317 else |
317 this._lastAcceptedContent = updatedContent; | 318 this._lastAcceptedContent = updatedContent; |
318 delete this._checkingContent; | 319 delete this._checkingContent; |
319 if (callback) | 320 callback(true); |
320 callback(); | |
321 } | 321 } |
322 }, | 322 }, |
323 | 323 |
324 /** | 324 /** |
325 * @param {function(?string)} callback | 325 * @param {function(?string)} callback |
326 */ | 326 */ |
327 requestOriginalContent: function(callback) | 327 requestOriginalContent: function(callback) |
328 { | 328 { |
329 this._project.requestFileContent(this, callback); | 329 this._project.requestFileContent(this, callback); |
330 }, | 330 }, |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
978 function persist() | 978 function persist() |
979 { | 979 { |
980 window.localStorage[key] = this._content; | 980 window.localStorage[key] = this._content; |
981 window.localStorage["revision-history"] = JSON.stringify(registry); | 981 window.localStorage["revision-history"] = JSON.stringify(registry); |
982 } | 982 } |
983 | 983 |
984 // Schedule async storage. | 984 // Schedule async storage. |
985 setTimeout(persist.bind(this), 0); | 985 setTimeout(persist.bind(this), 0); |
986 } | 986 } |
987 } | 987 } |
OLD | NEW |