| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 this._name = parsedURL.lastPathComponent; | 49 this._name = parsedURL.lastPathComponent; |
| 50 if (parsedURL.queryParams) | 50 if (parsedURL.queryParams) |
| 51 this._name += '?' + parsedURL.queryParams; | 51 this._name += '?' + parsedURL.queryParams; |
| 52 } else { | 52 } else { |
| 53 this._origin = ''; | 53 this._origin = ''; |
| 54 this._parentURL = ''; | 54 this._parentURL = ''; |
| 55 this._name = url; | 55 this._name = url; |
| 56 } | 56 } |
| 57 | 57 |
| 58 this._contentType = contentType; | 58 this._contentType = contentType; |
| 59 /** @type {?function(?string)} */ | |
| 60 this._requestContentCallback = null; | |
| 61 /** @type {?Promise<?string>} */ | 59 /** @type {?Promise<?string>} */ |
| 62 this._requestContentPromise = null; | 60 this._requestContentPromise = null; |
| 63 /** @type {!Multimap<string, !Workspace.UISourceCode.LineMarker>} */ | 61 /** @type {!Multimap<string, !Workspace.UISourceCode.LineMarker>} */ |
| 64 this._decorations = new Multimap(); | 62 this._decorations = new Multimap(); |
| 65 | 63 |
| 66 /** @type {!Array.<!Workspace.Revision>} */ | 64 /** @type {!Array.<!Workspace.Revision>} */ |
| 67 this.history = []; | 65 this.history = []; |
| 68 | 66 |
| 69 /** @type {!Array<!Workspace.UISourceCode.Message>} */ | 67 /** @type {!Array<!Workspace.UISourceCode.Message>} */ |
| 70 this._messages = []; | 68 this._messages = []; |
| 69 |
| 70 this._contentLoaded = false; |
| 71 /** @type {?string} */ |
| 72 this._content = null; |
| 73 this._forceLoadOnCheckContent = false; |
| 74 this._checkingContent = false; |
| 75 /** @type {?string} */ |
| 76 this._lastAcceptedContent = null; |
| 77 /** @type {?string} */ |
| 78 this._workingCopy = null; |
| 79 /** @type {?function() : string} */ |
| 80 this._workingCopyGetter = null; |
| 71 } | 81 } |
| 72 | 82 |
| 73 /** | 83 /** |
| 74 * @return {!Promise<?Workspace.UISourceCodeMetadata>} | 84 * @return {!Promise<?Workspace.UISourceCodeMetadata>} |
| 75 */ | 85 */ |
| 76 requestMetadata() { | 86 requestMetadata() { |
| 77 return this._project.requestMetadata(this); | 87 return this._project.requestMetadata(this); |
| 78 } | 88 } |
| 79 | 89 |
| 80 /** | 90 /** |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 */ | 213 */ |
| 204 project() { | 214 project() { |
| 205 return this._project; | 215 return this._project; |
| 206 } | 216 } |
| 207 | 217 |
| 208 /** | 218 /** |
| 209 * @override | 219 * @override |
| 210 * @return {!Promise<?string>} | 220 * @return {!Promise<?string>} |
| 211 */ | 221 */ |
| 212 requestContent() { | 222 requestContent() { |
| 213 if (this._content || this._contentLoaded) | 223 if (this._requestContentPromise) |
| 214 return Promise.resolve(this._content); | 224 return this._requestContentPromise; |
| 215 var promise = this._requestContentPromise; | 225 |
| 216 if (!promise) { | 226 if (this._contentLoaded) { |
| 217 promise = new Promise(fulfill => this._requestContentCallback = fulfill); | 227 this._requestContentPromise = Promise.resolve(this._content); |
| 218 this._requestContentPromise = promise; | 228 } else { |
| 219 this._project.requestFileContent(this, this._fireContentAvailable.bind(thi
s)); | 229 var fulfill; |
| 230 this._requestContentPromise = new Promise(x => fulfill = x); |
| 231 this._project.requestFileContent(this, content => { |
| 232 this._contentLoaded = true; |
| 233 this._content = content; |
| 234 fulfill(content); |
| 235 }); |
| 220 } | 236 } |
| 221 return promise; | 237 return this._requestContentPromise; |
| 222 } | 238 } |
| 223 | 239 |
| 224 checkContentUpdated() { | 240 checkContentUpdated() { |
| 225 if (!this._contentLoaded && !this._forceLoadOnCheckContent) | 241 if (!this._contentLoaded && !this._forceLoadOnCheckContent) |
| 226 return; | 242 return; |
| 227 | 243 |
| 228 if (!this._project.canSetFileContent() || this._checkingContent) | 244 if (!this._project.canSetFileContent() || this._checkingContent) |
| 229 return; | 245 return; |
| 230 | 246 |
| 231 this._checkingContent = true; | 247 this._checkingContent = true; |
| 232 this._project.requestFileContent(this, contentLoaded.bind(this)); | 248 this._project.requestFileContent(this, contentLoaded.bind(this)); |
| 233 | 249 |
| 234 /** | 250 /** |
| 235 * @param {?string} updatedContent | 251 * @param {?string} updatedContent |
| 236 * @this {Workspace.UISourceCode} | 252 * @this {Workspace.UISourceCode} |
| 237 */ | 253 */ |
| 238 function contentLoaded(updatedContent) { | 254 function contentLoaded(updatedContent) { |
| 239 this._checkingContent = false; | 255 this._checkingContent = false; |
| 240 if (updatedContent === null) { | 256 if (updatedContent === null) { |
| 241 var workingCopy = this.workingCopy(); | 257 var workingCopy = this.workingCopy(); |
| 242 this._contentCommitted('', false); | 258 this._contentCommitted('', false); |
| 243 this.setWorkingCopy(workingCopy); | 259 this.setWorkingCopy(workingCopy); |
| 244 return; | 260 return; |
| 245 } | 261 } |
| 246 if (typeof this._lastAcceptedContent === 'string' && this._lastAcceptedCon
tent === updatedContent) | 262 if (this._lastAcceptedContent === updatedContent) |
| 247 return; | 263 return; |
| 248 | 264 |
| 249 if (this._content === updatedContent) { | 265 if (this._content === updatedContent) { |
| 250 delete this._lastAcceptedContent; | 266 this._lastAcceptedContent = null; |
| 251 return; | 267 return; |
| 252 } | 268 } |
| 253 | 269 |
| 254 if (!this.isDirty() || this._workingCopy === updatedContent) { | 270 if (!this.isDirty() || this._workingCopy === updatedContent) { |
| 255 this._contentCommitted(updatedContent, false); | 271 this._contentCommitted(updatedContent, false); |
| 256 return; | 272 return; |
| 257 } | 273 } |
| 258 | 274 |
| 259 var shouldUpdate = | 275 var shouldUpdate = |
| 260 window.confirm(Common.UIString('This file was changed externally. Woul
d you like to reload it?')); | 276 window.confirm(Common.UIString('This file was changed externally. Woul
d you like to reload it?')); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 290 Workspace.fileManager.close(this._url); | 306 Workspace.fileManager.close(this._url); |
| 291 } | 307 } |
| 292 this._contentCommitted(content, true); | 308 this._contentCommitted(content, true); |
| 293 } | 309 } |
| 294 | 310 |
| 295 /** | 311 /** |
| 296 * @param {string} content | 312 * @param {string} content |
| 297 * @param {boolean} committedByUser | 313 * @param {boolean} committedByUser |
| 298 */ | 314 */ |
| 299 _contentCommitted(content, committedByUser) { | 315 _contentCommitted(content, committedByUser) { |
| 300 delete this._lastAcceptedContent; | 316 this._lastAcceptedContent = null; |
| 301 this._content = content; | 317 this._content = content; |
| 302 this._contentLoaded = true; | 318 this._contentLoaded = true; |
| 319 this._requestContentPromise = null; |
| 303 | 320 |
| 304 var lastRevision = this.history.length ? this.history[this.history.length -
1] : null; | 321 var lastRevision = this.history.length ? this.history[this.history.length -
1] : null; |
| 305 if (!lastRevision || lastRevision._content !== this._content) { | 322 if (!lastRevision || lastRevision._content !== this._content) { |
| 306 var revision = new Workspace.Revision(this, this._content, new Date()); | 323 var revision = new Workspace.Revision(this, this._content, new Date()); |
| 307 this.history.push(revision); | 324 this.history.push(revision); |
| 308 } | 325 } |
| 309 | 326 |
| 310 this._innerResetWorkingCopy(); | 327 this._innerResetWorkingCopy(); |
| 311 this.dispatchEventToListeners( | 328 this.dispatchEventToListeners( |
| 312 Workspace.UISourceCode.Events.WorkingCopyCommitted, {uiSourceCode: this,
content: content}); | 329 Workspace.UISourceCode.Events.WorkingCopyCommitted, {uiSourceCode: this,
content: content}); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 Host.userMetrics.actionTaken(Host.UserMetrics.Action.RevisionApplied); | 395 Host.userMetrics.actionTaken(Host.UserMetrics.Action.RevisionApplied); |
| 379 this.requestOriginalContent().then(revert.bind(this)); | 396 this.requestOriginalContent().then(revert.bind(this)); |
| 380 } | 397 } |
| 381 | 398 |
| 382 /** | 399 /** |
| 383 * @return {string} | 400 * @return {string} |
| 384 */ | 401 */ |
| 385 workingCopy() { | 402 workingCopy() { |
| 386 if (this._workingCopyGetter) { | 403 if (this._workingCopyGetter) { |
| 387 this._workingCopy = this._workingCopyGetter(); | 404 this._workingCopy = this._workingCopyGetter(); |
| 388 delete this._workingCopyGetter; | 405 this._workingCopyGetter = null; |
| 389 } | 406 } |
| 390 if (this.isDirty()) | 407 if (this.isDirty()) |
| 391 return this._workingCopy; | 408 return /** @type {string} */ (this._workingCopy); |
| 392 return this._content; | 409 return this._content || ''; |
| 393 } | 410 } |
| 394 | 411 |
| 395 resetWorkingCopy() { | 412 resetWorkingCopy() { |
| 396 this._innerResetWorkingCopy(); | 413 this._innerResetWorkingCopy(); |
| 397 this._workingCopyChanged(); | 414 this._workingCopyChanged(); |
| 398 } | 415 } |
| 399 | 416 |
| 400 _innerResetWorkingCopy() { | 417 _innerResetWorkingCopy() { |
| 401 delete this._workingCopy; | 418 this._workingCopy = null; |
| 402 delete this._workingCopyGetter; | 419 this._workingCopyGetter = null; |
| 403 } | 420 } |
| 404 | 421 |
| 405 /** | 422 /** |
| 406 * @param {string} newWorkingCopy | 423 * @param {string} newWorkingCopy |
| 407 */ | 424 */ |
| 408 setWorkingCopy(newWorkingCopy) { | 425 setWorkingCopy(newWorkingCopy) { |
| 409 this._workingCopy = newWorkingCopy; | 426 this._workingCopy = newWorkingCopy; |
| 410 delete this._workingCopyGetter; | 427 this._workingCopyGetter = null; |
| 411 this._workingCopyChanged(); | 428 this._workingCopyChanged(); |
| 412 } | 429 } |
| 413 | 430 |
| 431 /** |
| 432 * @param {function(): string } workingCopyGetter |
| 433 */ |
| 414 setWorkingCopyGetter(workingCopyGetter) { | 434 setWorkingCopyGetter(workingCopyGetter) { |
| 415 this._workingCopyGetter = workingCopyGetter; | 435 this._workingCopyGetter = workingCopyGetter; |
| 416 this._workingCopyChanged(); | 436 this._workingCopyChanged(); |
| 417 } | 437 } |
| 418 | 438 |
| 419 _workingCopyChanged() { | 439 _workingCopyChanged() { |
| 420 this._removeAllMessages(); | 440 this._removeAllMessages(); |
| 421 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang
ed, this); | 441 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang
ed, this); |
| 422 this._project.workspace().dispatchEventToListeners( | 442 this._project.workspace().dispatchEventToListeners( |
| 423 Workspace.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this}); | 443 Workspace.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this}); |
| 424 } | 444 } |
| 425 | 445 |
| 426 removeWorkingCopyGetter() { | 446 removeWorkingCopyGetter() { |
| 427 if (!this._workingCopyGetter) | 447 if (!this._workingCopyGetter) |
| 428 return; | 448 return; |
| 429 this._workingCopy = this._workingCopyGetter(); | 449 this._workingCopy = this._workingCopyGetter(); |
| 430 delete this._workingCopyGetter; | 450 this._workingCopyGetter = null; |
| 431 } | 451 } |
| 432 | 452 |
| 433 commitWorkingCopy() { | 453 commitWorkingCopy() { |
| 434 if (this.isDirty()) | 454 if (this.isDirty()) |
| 435 this._commitContent(this.workingCopy()); | 455 this._commitContent(this.workingCopy()); |
| 436 } | 456 } |
| 437 | 457 |
| 438 /** | 458 /** |
| 439 * @return {boolean} | 459 * @return {boolean} |
| 440 */ | 460 */ |
| 441 isDirty() { | 461 isDirty() { |
| 442 return typeof this._workingCopy !== 'undefined' || typeof this._workingCopyG
etter !== 'undefined'; | 462 return this._workingCopy !== null || this._workingCopyGetter !== null; |
| 443 } | 463 } |
| 444 | 464 |
| 445 /** | 465 /** |
| 446 * @return {string} | 466 * @return {string} |
| 447 */ | 467 */ |
| 448 extension() { | 468 extension() { |
| 449 return Common.ParsedURL.extractExtension(this._name); | 469 return Common.ParsedURL.extractExtension(this._name); |
| 450 } | 470 } |
| 451 | 471 |
| 452 /** | 472 /** |
| (...skipping 22 matching lines...) Expand all Loading... |
| 475 | 495 |
| 476 /** | 496 /** |
| 477 * @param {string} content | 497 * @param {string} content |
| 478 */ | 498 */ |
| 479 function doSearch(content) { | 499 function doSearch(content) { |
| 480 callback(Common.ContentProvider.performSearchInContent(content, query, cas
eSensitive, isRegex)); | 500 callback(Common.ContentProvider.performSearchInContent(content, query, cas
eSensitive, isRegex)); |
| 481 } | 501 } |
| 482 } | 502 } |
| 483 | 503 |
| 484 /** | 504 /** |
| 485 * @param {?string} content | |
| 486 */ | |
| 487 _fireContentAvailable(content) { | |
| 488 this._contentLoaded = true; | |
| 489 this._content = content; | |
| 490 | |
| 491 var callback = this._requestContentCallback; | |
| 492 this._requestContentCallback = null; | |
| 493 this._requestContentPromise = null; | |
| 494 | |
| 495 callback.call(null, content); | |
| 496 } | |
| 497 | |
| 498 /** | |
| 499 * @return {boolean} | 505 * @return {boolean} |
| 500 */ | 506 */ |
| 501 contentLoaded() { | 507 contentLoaded() { |
| 502 return this._contentLoaded; | 508 return this._contentLoaded; |
| 503 } | 509 } |
| 504 | 510 |
| 505 /** | 511 /** |
| 506 * @param {number} lineNumber | 512 * @param {number} lineNumber |
| 507 * @param {number=} columnNumber | 513 * @param {number=} columnNumber |
| 508 * @return {!Workspace.UILocation} | 514 * @return {!Workspace.UILocation} |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 Workspace.UISourceCodeMetadata = class { | 907 Workspace.UISourceCodeMetadata = class { |
| 902 /** | 908 /** |
| 903 * @param {?Date} modificationTime | 909 * @param {?Date} modificationTime |
| 904 * @param {?number} contentSize | 910 * @param {?number} contentSize |
| 905 */ | 911 */ |
| 906 constructor(modificationTime, contentSize) { | 912 constructor(modificationTime, contentSize) { |
| 907 this.modificationTime = modificationTime; | 913 this.modificationTime = modificationTime; |
| 908 this.contentSize = contentSize; | 914 this.contentSize = contentSize; |
| 909 } | 915 } |
| 910 }; | 916 }; |
| OLD | NEW |