| 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 |
| 266 */ |
| 267 _pushCheckContentUpdatedCallback: function(callback) |
| 268 { |
| 269 if (!this._checkContentUpdatedCallbacks) |
| 270 this._checkContentUpdatedCallbacks = []; |
| 271 this._checkContentUpdatedCallbacks.push(callback); |
| 272 }, |
| 273 |
| 274 _terminateContentCheck: function() |
| 275 { |
| 276 delete this._checkingContent; |
| 277 if (this._checkContentUpdatedCallbacks) { |
| 278 this._checkContentUpdatedCallbacks.forEach(function(callback) { call
back(); }); |
| 279 delete this._checkContentUpdatedCallbacks; |
| 280 } |
| 281 }, |
| 282 |
| 283 /** |
| 265 * @param {function()=} callback | 284 * @param {function()=} callback |
| 266 */ | 285 */ |
| 267 checkContentUpdated: function(callback) | 286 checkContentUpdated: function(callback) |
| 268 { | 287 { |
| 269 if (!this._project.canSetFileContent()) | 288 callback = callback || function() {}; |
| 289 if (!this._project.canSetFileContent()) { |
| 290 callback(); |
| 270 return; | 291 return; |
| 271 if (this._checkingContent) | 292 } |
| 293 this._pushCheckContentUpdatedCallback(callback); |
| 294 |
| 295 if (this._checkingContent) { |
| 272 return; | 296 return; |
| 297 } |
| 273 this._checkingContent = true; | 298 this._checkingContent = true; |
| 274 this._project.requestFileContent(this, contentLoaded.bind(this)); | 299 this._project.requestFileContent(this, contentLoaded.bind(this)); |
| 275 | 300 |
| 276 /** | 301 /** |
| 277 * @param {?string} updatedContent | 302 * @param {?string} updatedContent |
| 278 * @this {WebInspector.UISourceCode} | 303 * @this {WebInspector.UISourceCode} |
| 279 */ | 304 */ |
| 280 function contentLoaded(updatedContent) | 305 function contentLoaded(updatedContent) |
| 281 { | 306 { |
| 282 if (updatedContent === null) { | 307 if (updatedContent === null) { |
| 283 var workingCopy = this.workingCopy(); | 308 var workingCopy = this.workingCopy(); |
| 284 this._commitContent("", false); | 309 this._commitContent("", false); |
| 285 this.setWorkingCopy(workingCopy); | 310 this.setWorkingCopy(workingCopy); |
| 286 delete this._checkingContent; | 311 this._terminateContentCheck(); |
| 287 if (callback) | |
| 288 callback(); | |
| 289 return; | 312 return; |
| 290 } | 313 } |
| 291 if (typeof this._lastAcceptedContent === "string" && this._lastAccep
tedContent === updatedContent) { | 314 if (typeof this._lastAcceptedContent === "string" && this._lastAccep
tedContent === updatedContent) { |
| 292 delete this._checkingContent; | 315 this._terminateContentCheck(); |
| 293 if (callback) | |
| 294 callback(); | |
| 295 return; | 316 return; |
| 296 } | 317 } |
| 297 if (this._content === updatedContent) { | 318 if (this._content === updatedContent) { |
| 298 delete this._lastAcceptedContent; | 319 delete this._lastAcceptedContent; |
| 299 delete this._checkingContent; | 320 this._terminateContentCheck(); |
| 300 if (callback) | |
| 301 callback(); | |
| 302 return; | 321 return; |
| 303 } | 322 } |
| 304 | 323 |
| 305 if (!this.isDirty()) { | 324 if (!this.isDirty()) { |
| 306 this._commitContent(updatedContent, false); | 325 this._commitContent(updatedContent, false); |
| 307 delete this._checkingContent; | 326 this._terminateContentCheck(); |
| 308 if (callback) | |
| 309 callback(); | |
| 310 return; | 327 return; |
| 311 } | 328 } |
| 312 | 329 |
| 313 var shouldUpdate = window.confirm(WebInspector.UIString("This file w
as changed externally. Would you like to reload it?")); | 330 var shouldUpdate = window.confirm(WebInspector.UIString("This file w
as changed externally. Would you like to reload it?")); |
| 314 if (shouldUpdate) | 331 if (shouldUpdate) |
| 315 this._commitContent(updatedContent, false); | 332 this._commitContent(updatedContent, false); |
| 316 else | 333 else |
| 317 this._lastAcceptedContent = updatedContent; | 334 this._lastAcceptedContent = updatedContent; |
| 318 delete this._checkingContent; | 335 this._terminateContentCheck(); |
| 319 if (callback) | |
| 320 callback(); | |
| 321 } | 336 } |
| 322 }, | 337 }, |
| 323 | 338 |
| 324 /** | 339 /** |
| 325 * @param {function(?string)} callback | 340 * @param {function(?string)} callback |
| 326 */ | 341 */ |
| 327 requestOriginalContent: function(callback) | 342 requestOriginalContent: function(callback) |
| 328 { | 343 { |
| 329 this._project.requestFileContent(this, callback); | 344 this._project.requestFileContent(this, callback); |
| 330 }, | 345 }, |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 function persist() | 993 function persist() |
| 979 { | 994 { |
| 980 window.localStorage[key] = this._content; | 995 window.localStorage[key] = this._content; |
| 981 window.localStorage["revision-history"] = JSON.stringify(registry); | 996 window.localStorage["revision-history"] = JSON.stringify(registry); |
| 982 } | 997 } |
| 983 | 998 |
| 984 // Schedule async storage. | 999 // Schedule async storage. |
| 985 setTimeout(persist.bind(this), 0); | 1000 setTimeout(persist.bind(this), 0); |
| 986 } | 1001 } |
| 987 } | 1002 } |
| OLD | NEW |