OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 * @unrestricted | 547 * @unrestricted |
548 */ | 548 */ |
549 Snippets.SnippetsProject = class extends Bindings.ContentProviderBasedProject { | 549 Snippets.SnippetsProject = class extends Bindings.ContentProviderBasedProject { |
550 /** | 550 /** |
551 * @param {!Workspace.Workspace} workspace | 551 * @param {!Workspace.Workspace} workspace |
552 * @param {!Snippets.ScriptSnippetModel} model | 552 * @param {!Snippets.ScriptSnippetModel} model |
553 */ | 553 */ |
554 constructor(workspace, model) { | 554 constructor(workspace, model) { |
555 super(workspace, 'snippets:', Workspace.projectTypes.Snippets, '', false /*
isServiceProject */); | 555 super(workspace, 'snippets:', Workspace.projectTypes.Snippets, '', false /*
isServiceProject */); |
556 this._model = model; | 556 this._model = model; |
| 557 /** @type {!WeakMap<!Workspace.UISourceCode, !Promise<?string>>} */ |
| 558 this._originalContent = new WeakMap(); |
557 } | 559 } |
558 | 560 |
559 /** | 561 /** |
560 * @param {string} name | 562 * @param {string} name |
561 * @param {!Common.ContentProvider} contentProvider | 563 * @param {!Common.ContentProvider} contentProvider |
562 * @return {!Workspace.UISourceCode} | 564 * @return {!Workspace.UISourceCode} |
563 */ | 565 */ |
564 addSnippet(name, contentProvider) { | 566 addSnippet(name, contentProvider) { |
565 return this.addContentProvider(name, contentProvider); | 567 return this.addContentProvider(name, contentProvider); |
566 } | 568 } |
567 | 569 |
568 /** | 570 /** |
569 * @override | 571 * @override |
570 * @return {boolean} | 572 * @return {boolean} |
571 */ | 573 */ |
572 canSetFileContent() { | 574 canSetFileContent() { |
573 return true; | 575 return true; |
574 } | 576 } |
| 577 /** |
| 578 * @override |
| 579 * @param {!Workspace.UISourceCode} uiSourceCode |
| 580 * @return {!Promise<?string>} |
| 581 */ |
| 582 requestOriginalFileContent(uiSourceCode) { |
| 583 if (this._originalContent.has(uiSourceCode)) |
| 584 return this._originalContent.get(uiSourceCode); |
| 585 var promise = super.requestOriginalFileContent(uiSourceCode); |
| 586 this._originalContent.set(uiSourceCode, promise); |
| 587 return promise; |
| 588 } |
575 | 589 |
576 /** | 590 /** |
577 * @override | 591 * @override |
578 * @param {!Workspace.UISourceCode} uiSourceCode | 592 * @param {!Workspace.UISourceCode} uiSourceCode |
579 * @param {string} newContent | 593 * @param {string} newContent |
580 * @param {function(?string)} callback | 594 * @param {function()} callback |
581 */ | 595 */ |
582 setFileContent(uiSourceCode, newContent, callback) { | 596 setFileContent(uiSourceCode, newContent, callback) { |
583 this._model._setScriptSnippetContent(uiSourceCode.url(), newContent); | 597 this.requestOriginalFileContent(uiSourceCode).then(() => { |
584 callback(''); | 598 this._model._setScriptSnippetContent(uiSourceCode.url(), newContent); |
| 599 callback(); |
| 600 }); |
585 } | 601 } |
586 | 602 |
587 /** | 603 /** |
588 * @override | 604 * @override |
589 * @return {boolean} | 605 * @return {boolean} |
590 */ | 606 */ |
591 canRename() { | 607 canRename() { |
592 return true; | 608 return true; |
593 } | 609 } |
594 | 610 |
(...skipping 24 matching lines...) Expand all Loading... |
619 */ | 635 */ |
620 deleteFile(url) { | 636 deleteFile(url) { |
621 this._model.deleteScriptSnippet(url); | 637 this._model.deleteScriptSnippet(url); |
622 } | 638 } |
623 }; | 639 }; |
624 | 640 |
625 /** | 641 /** |
626 * @type {!Snippets.ScriptSnippetModel} | 642 * @type {!Snippets.ScriptSnippetModel} |
627 */ | 643 */ |
628 Snippets.scriptSnippetModel = new Snippets.ScriptSnippetModel(Workspace.workspac
e); | 644 Snippets.scriptSnippetModel = new Snippets.ScriptSnippetModel(Workspace.workspac
e); |
OLD | NEW |