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 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * | 10 * |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 this._rootNode = new WebInspector.NavigatorRootTreeNode(this); | 55 this._rootNode = new WebInspector.NavigatorRootTreeNode(this); |
56 this._rootNode.populate(); | 56 this._rootNode.populate(); |
57 | 57 |
58 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod
el.EventTypes.InspectedURLChanged, this._inspectedURLChanged, this); | 58 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod
el.EventTypes.InspectedURLChanged, this._inspectedURLChanged, this); |
59 } | 59 } |
60 | 60 |
61 WebInspector.NavigatorView.Events = { | 61 WebInspector.NavigatorView.Events = { |
62 ItemSelected: "ItemSelected", | 62 ItemSelected: "ItemSelected", |
63 ItemSearchStarted: "ItemSearchStarted", | 63 ItemSearchStarted: "ItemSearchStarted", |
64 FileRenamed: "FileRenamed" | 64 ItemRenamingRequested: "ItemRenamingRequested" |
65 } | 65 } |
66 | 66 |
67 WebInspector.NavigatorView.iconClassForType = function(type) | 67 WebInspector.NavigatorView.iconClassForType = function(type) |
68 { | 68 { |
69 if (type === WebInspector.NavigatorTreeOutline.Types.Domain) | 69 if (type === WebInspector.NavigatorTreeOutline.Types.Domain) |
70 return "navigator-domain-tree-item"; | 70 return "navigator-domain-tree-item"; |
71 if (type === WebInspector.NavigatorTreeOutline.Types.FileSystem) | 71 if (type === WebInspector.NavigatorTreeOutline.Types.FileSystem) |
72 return "navigator-folder-tree-item"; | 72 return "navigator-folder-tree-item"; |
73 return "navigator-folder-tree-item"; | 73 return "navigator-folder-tree-item"; |
74 } | 74 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 node = parentNode; | 245 node = parentNode; |
246 while (node) { | 246 while (node) { |
247 parentNode = node.parent; | 247 parentNode = node.parent; |
248 if (!parentNode || !node.isEmpty()) | 248 if (!parentNode || !node.isEmpty()) |
249 break; | 249 break; |
250 parentNode.removeChild(node); | 250 parentNode.removeChild(node); |
251 node = parentNode; | 251 node = parentNode; |
252 } | 252 } |
253 }, | 253 }, |
254 | 254 |
255 _fileRenamed: function(uiSourceCode, newTitle) | |
256 { | |
257 var data = { uiSourceCode: uiSourceCode, name: newTitle }; | |
258 this.dispatchEventToListeners(WebInspector.NavigatorView.Events.FileRena
med, data); | |
259 }, | |
260 | |
261 /** | 255 /** |
262 * @param {WebInspector.UISourceCode} uiSourceCode | 256 * @param {WebInspector.UISourceCode} uiSourceCode |
263 */ | 257 */ |
264 handleRename: function(uiSourceCode, callback) | 258 requestRename: function(uiSourceCode) |
265 { | 259 { |
| 260 this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.ItemR
enamingRequested, uiSourceCode); |
266 }, | 261 }, |
267 | 262 |
268 /** | 263 /** |
269 * @param {WebInspector.UISourceCode} uiSourceCode | 264 * @param {WebInspector.UISourceCode} uiSourceCode |
270 * @param {function(boolean)=} callback | 265 * @param {function(boolean)=} callback |
271 */ | 266 */ |
272 rename: function(uiSourceCode, callback) | 267 rename: function(uiSourceCode, callback) |
273 { | 268 { |
274 var uri = uiSourceCode.uri(); | 269 var node = this._uiSourceCodeNodes[uiSourceCode.uri()]; |
275 var node = this._uiSourceCodeNodes[uri]; | |
276 if (!node) | 270 if (!node) |
277 return null; | 271 return null; |
278 /** | 272 node.rename(callback); |
279 * @param {boolean} renameCommitted | 273 }, |
280 */ | |
281 function callbackWrapper(renameCommitted) | |
282 { | |
283 if (renameCommitted) { | |
284 delete this._uiSourceCodeNodes[uri]; | |
285 this._uiSourceCodeNodes[uiSourceCode.uri()] = node; | |
286 } | |
287 | 274 |
288 if (callback) | 275 /** |
289 callback(renameCommitted); | 276 * @param {WebInspector.UISourceCode} uiSourceCode |
290 } | 277 * @param {string} oldURI |
291 node.rename(callbackWrapper.bind(this)); | 278 */ |
| 279 _titleChanged: function(uiSourceCode, oldURI) |
| 280 { |
| 281 var node = this._uiSourceCodeNodes[oldURI]; |
| 282 delete this._uiSourceCodeNodes[oldURI]; |
| 283 this._uiSourceCodeNodes[uiSourceCode.uri()] = node; |
292 }, | 284 }, |
293 | 285 |
294 reset: function() | 286 reset: function() |
295 { | 287 { |
296 for (var uri in this._uiSourceCodeNodes) | 288 for (var uri in this._uiSourceCodeNodes) |
297 this._uiSourceCodeNodes[uri].dispose(); | 289 this._uiSourceCodeNodes[uri].dispose(); |
298 | 290 |
299 this._scriptsTree.removeChildren(); | 291 this._scriptsTree.removeChildren(); |
300 this._uiSourceCodeNodes = {}; | 292 this._uiSourceCodeNodes = {}; |
301 this._rootNode.reset(); | 293 this._rootNode.reset(); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 * @param {string} mimeType | 554 * @param {string} mimeType |
563 */ | 555 */ |
564 function callback(content, contentEncoded, mimeType) | 556 function callback(content, contentEncoded, mimeType) |
565 { | 557 { |
566 this._warmedUpContent = content; | 558 this._warmedUpContent = content; |
567 } | 559 } |
568 }, | 560 }, |
569 | 561 |
570 _shouldRenameOnMouseDown: function() | 562 _shouldRenameOnMouseDown: function() |
571 { | 563 { |
| 564 if (!this._uiSourceCode.canRename()) |
| 565 return false; |
572 var isSelected = this === this.treeOutline.selectedTreeElement; | 566 var isSelected = this === this.treeOutline.selectedTreeElement; |
573 var isFocused = this.treeOutline.childrenListElement.isSelfOrAncestor(do
cument.activeElement); | 567 var isFocused = this.treeOutline.childrenListElement.isSelfOrAncestor(do
cument.activeElement); |
574 return isSelected && isFocused && !WebInspector.isBeingEdited(this.treeO
utline.element); | 568 return isSelected && isFocused && !WebInspector.isBeingEdited(this.treeO
utline.element); |
575 }, | 569 }, |
576 | 570 |
577 selectOnMouseDown: function(event) | 571 selectOnMouseDown: function(event) |
578 { | 572 { |
579 if (event.which !== 1 || !this._shouldRenameOnMouseDown()) { | 573 if (event.which !== 1 || !this._shouldRenameOnMouseDown()) { |
580 TreeElement.prototype.selectOnMouseDown.call(this, event); | 574 TreeElement.prototype.selectOnMouseDown.call(this, event); |
581 return; | 575 return; |
582 } | 576 } |
583 setTimeout(rename.bind(this), 300); | 577 setTimeout(rename.bind(this), 300); |
584 | 578 |
585 function rename() | 579 function rename() |
586 { | 580 { |
587 if (this._shouldRenameOnMouseDown()) | 581 if (this._shouldRenameOnMouseDown()) |
588 this._navigatorView.handleRename(this._uiSourceCode); | 582 this._navigatorView.requestRename(this._uiSourceCode); |
589 } | 583 } |
590 }, | 584 }, |
591 | 585 |
592 _ondragstart: function(event) | 586 _ondragstart: function(event) |
593 { | 587 { |
594 event.dataTransfer.setData("text/plain", this._warmedUpContent); | 588 event.dataTransfer.setData("text/plain", this._warmedUpContent); |
595 event.dataTransfer.effectAllowed = "copy"; | 589 event.dataTransfer.effectAllowed = "copy"; |
596 return true; | 590 return true; |
597 }, | 591 }, |
598 | 592 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 if (!this._treeElement) | 836 if (!this._treeElement) |
843 return; | 837 return; |
844 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
TitleChanged, this._titleChanged, this); | 838 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
TitleChanged, this._titleChanged, this); |
845 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyChanged, this._workingCopyChanged, this); | 839 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyChanged, this._workingCopyChanged, this); |
846 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyCommitted, this._workingCopyCommitted, this); | 840 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyCommitted, this._workingCopyCommitted, this); |
847 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
FormattedChanged, this._formattedChanged, this); | 841 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.
FormattedChanged, this._formattedChanged, this); |
848 }, | 842 }, |
849 | 843 |
850 _titleChanged: function(event) | 844 _titleChanged: function(event) |
851 { | 845 { |
| 846 var oldURI = /** @type {string} */ (event.data); |
| 847 this._navigatorView._titleChanged(this._uiSourceCode, oldURI); |
852 this.updateTitle(); | 848 this.updateTitle(); |
853 }, | 849 }, |
854 | 850 |
855 _workingCopyChanged: function(event) | 851 _workingCopyChanged: function(event) |
856 { | 852 { |
857 this.updateTitle(); | 853 this.updateTitle(); |
858 }, | 854 }, |
859 | 855 |
860 _workingCopyCommitted: function(event) | 856 _workingCopyCommitted: function(event) |
861 { | 857 { |
(...skipping 24 matching lines...) Expand all Loading... |
886 { | 882 { |
887 if (!this._treeElement) | 883 if (!this._treeElement) |
888 return; | 884 return; |
889 | 885 |
890 // Tree outline should be marked as edited as well as the tree element t
o prevent search from starting. | 886 // Tree outline should be marked as edited as well as the tree element t
o prevent search from starting. |
891 var treeOutlineElement = this._treeElement.treeOutline.element; | 887 var treeOutlineElement = this._treeElement.treeOutline.element; |
892 WebInspector.markBeingEdited(treeOutlineElement, true); | 888 WebInspector.markBeingEdited(treeOutlineElement, true); |
893 | 889 |
894 function commitHandler(element, newTitle, oldTitle) | 890 function commitHandler(element, newTitle, oldTitle) |
895 { | 891 { |
896 if (newTitle && newTitle !== oldTitle) | 892 if (newTitle !== oldTitle) { |
897 this._navigatorView._fileRenamed(this._uiSourceCode, newTitle); | 893 this._treeElement.titleText = newTitle; |
| 894 this._uiSourceCode.rename(newTitle, renameCallback.bind(this)); |
| 895 return; |
| 896 } |
898 afterEditing.call(this, true); | 897 afterEditing.call(this, true); |
899 } | 898 } |
900 | 899 |
| 900 function renameCallback(success) |
| 901 { |
| 902 if (!success) { |
| 903 WebInspector.markBeingEdited(treeOutlineElement, false); |
| 904 this.updateTitle(); |
| 905 this.rename(callback); |
| 906 return; |
| 907 } |
| 908 afterEditing.call(this, true); |
| 909 } |
| 910 |
901 function cancelHandler() | 911 function cancelHandler() |
902 { | 912 { |
903 afterEditing.call(this, false); | 913 afterEditing.call(this, false); |
904 } | 914 } |
905 | 915 |
906 /** | 916 /** |
907 * @param {boolean} committed | 917 * @param {boolean} committed |
908 */ | 918 */ |
909 function afterEditing(committed) | 919 function afterEditing(committed) |
910 { | 920 { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 | 1066 |
1057 willRemoveChild: function(node) | 1067 willRemoveChild: function(node) |
1058 { | 1068 { |
1059 if (node._isMerged || !this.isPopulated()) | 1069 if (node._isMerged || !this.isPopulated()) |
1060 return; | 1070 return; |
1061 this._treeElement.removeChild(node._treeElement); | 1071 this._treeElement.removeChild(node._treeElement); |
1062 }, | 1072 }, |
1063 | 1073 |
1064 __proto__: WebInspector.NavigatorTreeNode.prototype | 1074 __proto__: WebInspector.NavigatorTreeNode.prototype |
1065 } | 1075 } |
OLD | NEW |