| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 showEntries: function(entries) | 62 showEntries: function(entries) |
| 63 { | 63 { |
| 64 const indexes = WebInspector.DirectoryContentView.columnIndexes; | 64 const indexes = WebInspector.DirectoryContentView.columnIndexes; |
| 65 this.rootNode().removeChildren(); | 65 this.rootNode().removeChildren(); |
| 66 for (var i = 0; i < entries.length; ++i) | 66 for (var i = 0; i < entries.length; ++i) |
| 67 this.rootNode().appendChild(new WebInspector.DirectoryContentView.No
de(entries[i])); | 67 this.rootNode().appendChild(new WebInspector.DirectoryContentView.No
de(entries[i])); |
| 68 }, | 68 }, |
| 69 | 69 |
| 70 _sort: function() | 70 _sort: function() |
| 71 { | 71 { |
| 72 var column = /** @type {string} */ (this.sortColumnIdentifier()); | 72 var column = this.sortColumnIdentifier(); |
| 73 this.sortNodes(WebInspector.DirectoryContentView.Node.comparator(column,
!this.isSortOrderAscending()), false); | 73 if (!column) |
| 74 return; |
| 75 this.sortNodes(WebInspector.DirectoryContentView.Node.comparator(column)
, !this.isSortOrderAscending()); |
| 74 }, | 76 }, |
| 75 | 77 |
| 76 __proto__: WebInspector.DataGrid.prototype | 78 __proto__: WebInspector.DataGrid.prototype |
| 77 } | 79 } |
| 78 | 80 |
| 79 /** | 81 /** |
| 80 * @constructor | 82 * @constructor |
| 81 * @extends {WebInspector.DataGridNode} | 83 * @extends {WebInspector.DataGridNode} |
| 82 * @param {!WebInspector.FileSystemModel.Entry} entry | 84 * @param {!WebInspector.FileSystemModel.Entry} entry |
| 83 */ | 85 */ |
| 84 WebInspector.DirectoryContentView.Node = function(entry) | 86 WebInspector.DirectoryContentView.Node = function(entry) |
| 85 { | 87 { |
| 86 const indexes = WebInspector.DirectoryContentView.columnIndexes; | 88 const indexes = WebInspector.DirectoryContentView.columnIndexes; |
| 87 var data = {}; | 89 var data = {}; |
| 88 data[indexes.Name] = entry.name; | 90 data[indexes.Name] = entry.name; |
| 89 data[indexes.URL] = entry.url; | 91 data[indexes.URL] = entry.url; |
| 90 data[indexes.Type] = entry.isDirectory ? WebInspector.UIString("Directory")
: entry.mimeType; | 92 data[indexes.Type] = entry.isDirectory ? WebInspector.UIString("Directory")
: entry.mimeType; |
| 91 data[indexes.Size] = ""; | 93 data[indexes.Size] = ""; |
| 92 data[indexes.ModificationTime] = ""; | 94 data[indexes.ModificationTime] = ""; |
| 93 | 95 |
| 94 WebInspector.DataGridNode.call(this, data); | 96 WebInspector.DataGridNode.call(this, data); |
| 95 this._entry = entry; | 97 this._entry = entry; |
| 96 this._metadata = null; | 98 this._metadata = null; |
| 97 | 99 |
| 98 this._entry.requestMetadata(this._metadataReceived.bind(this)); | 100 this._entry.requestMetadata(this._metadataReceived.bind(this)); |
| 99 } | 101 } |
| 100 | 102 |
| 101 /** | 103 /** |
| 102 * @param {string} column | 104 * @param {string} column |
| 103 * @param {boolean} reverse | 105 * @return {function(!WebInspector.DataGridNode, !WebInspector.DataGridNode):num
ber} |
| 104 * @return {function(!WebInspector.DirectoryContentView.Node, !WebInspector.Dire
ctoryContentView.Node):number|undefined} | |
| 105 */ | 106 */ |
| 106 WebInspector.DirectoryContentView.Node.comparator = function(column, reverse) | 107 WebInspector.DirectoryContentView.Node.comparator = function(column) |
| 107 { | 108 { |
| 108 var reverseFactor = reverse ? -1 : 1; | |
| 109 const indexes = WebInspector.DirectoryContentView.columnIndexes; | 109 const indexes = WebInspector.DirectoryContentView.columnIndexes; |
| 110 | 110 |
| 111 switch (column) { | 111 switch (column) { |
| 112 case indexes.Name: | 112 case indexes.Name: |
| 113 case indexes.URL: | 113 case indexes.URL: |
| 114 return function(x, y) | 114 return function(x, y) |
| 115 { | 115 { |
| 116 return isDirectoryCompare(x, y) || nameCompare(x, y); | 116 return isDirectoryCompare(x, y) || nameCompare(x, y); |
| 117 }; | 117 }; |
| 118 case indexes.Type: | 118 case indexes.Type: |
| 119 return function(x, y) | 119 return function(x, y) |
| 120 { | 120 { |
| 121 return isDirectoryCompare(x ,y) || typeCompare(x, y) || nameCompare(
x, y); | 121 return isDirectoryCompare(x ,y) || typeCompare(x, y) || nameCompare(
x, y); |
| 122 }; | 122 }; |
| 123 case indexes.Size: | 123 case indexes.Size: |
| 124 return function(x, y) | 124 return function(x, y) |
| 125 { | 125 { |
| 126 return isDirectoryCompare(x, y) || sizeCompare(x, y) || nameCompare(
x, y); | 126 return isDirectoryCompare(x, y) || sizeCompare(x, y) || nameCompare(
x, y); |
| 127 }; | 127 }; |
| 128 case indexes.ModificationTime: | 128 case indexes.ModificationTime: |
| 129 return function(x, y) | 129 return function(x, y) |
| 130 { | 130 { |
| 131 return isDirectoryCompare(x, y) || modificationTimeCompare(x, y) ||
nameCompare(x, y); | 131 return isDirectoryCompare(x, y) || modificationTimeCompare(x, y) ||
nameCompare(x, y); |
| 132 }; | 132 }; |
| 133 default: |
| 134 return WebInspector.DataGrid.TrivialComparator; |
| 133 } | 135 } |
| 134 | 136 |
| 135 function isDirectoryCompare(x, y) | 137 function isDirectoryCompare(x, y) |
| 136 { | 138 { |
| 137 if (x._entry.isDirectory != y._entry.isDirectory) | 139 if (x._entry.isDirectory != y._entry.isDirectory) |
| 138 return y._entry.isDirectory ? 1 : -1; | 140 return y._entry.isDirectory ? 1 : -1; |
| 139 return 0; | 141 return 0; |
| 140 } | 142 } |
| 141 | 143 |
| 142 function nameCompare(x, y) | 144 function nameCompare(x, y) |
| 143 { | 145 { |
| 144 return reverseFactor * x._entry.name.compareTo(y._entry.name); | 146 return x._entry.name.compareTo(y._entry.name); |
| 145 } | 147 } |
| 146 | 148 |
| 147 function typeCompare(x, y) | 149 function typeCompare(x, y) |
| 148 { | 150 { |
| 149 return reverseFactor * (x._entry.mimeType || "").compareTo(y._entry.mime
Type || ""); | 151 return (x._entry.mimeType || "").compareTo(y._entry.mimeType || ""); |
| 150 } | 152 } |
| 151 | 153 |
| 152 function sizeCompare(x, y) | 154 function sizeCompare(x, y) |
| 153 { | 155 { |
| 154 return reverseFactor * ((x._metadata ? x._metadata.size : 0) - (y._metad
ata ? y._metadata.size : 0)); | 156 return ((x._metadata ? x._metadata.size : 0) - (y._metadata ? y._metadat
a.size : 0)); |
| 155 } | 157 } |
| 156 | 158 |
| 157 function modificationTimeCompare(x, y) | 159 function modificationTimeCompare(x, y) |
| 158 { | 160 { |
| 159 return reverseFactor * ((x._metadata ? x._metadata.modificationTime : 0)
- (y._metadata ? y._metadata.modificationTime : 0)); | 161 return ((x._metadata ? x._metadata.modificationTime : 0) - (y._metadata
? y._metadata.modificationTime : 0)); |
| 160 } | 162 } |
| 161 } | 163 } |
| 162 | 164 |
| 163 WebInspector.DirectoryContentView.Node.prototype = { | 165 WebInspector.DirectoryContentView.Node.prototype = { |
| 164 /** | 166 /** |
| 165 * @param {number} errorCode | 167 * @param {number} errorCode |
| 166 * @param {!FileSystemAgent.Metadata} metadata | 168 * @param {!FileSystemAgent.Metadata} metadata |
| 167 */ | 169 */ |
| 168 _metadataReceived: function(errorCode, metadata) | 170 _metadataReceived: function(errorCode, metadata) |
| 169 { | 171 { |
| 170 const indexes = WebInspector.DirectoryContentView.columnIndexes; | 172 const indexes = WebInspector.DirectoryContentView.columnIndexes; |
| 171 if (errorCode !== 0) | 173 if (errorCode !== 0) |
| 172 return; | 174 return; |
| 173 | 175 |
| 174 this._metadata = metadata; | 176 this._metadata = metadata; |
| 175 var data = this.data; | 177 var data = this.data; |
| 176 if (this._entry.isDirectory) | 178 if (this._entry.isDirectory) |
| 177 data[indexes.Size] = WebInspector.UIString("-"); | 179 data[indexes.Size] = WebInspector.UIString("-"); |
| 178 else | 180 else |
| 179 data[indexes.Size] = Number.bytesToString(metadata.size); | 181 data[indexes.Size] = Number.bytesToString(metadata.size); |
| 180 data[indexes.ModificationTime] = new Date(metadata.modificationTime).toI
SOString(); | 182 data[indexes.ModificationTime] = new Date(metadata.modificationTime).toI
SOString(); |
| 181 this.data = data; | 183 this.data = data; |
| 182 }, | 184 }, |
| 183 | 185 |
| 184 __proto__: WebInspector.DataGridNode.prototype | 186 __proto__: WebInspector.DataGridNode.prototype |
| 185 } | 187 } |
| OLD | NEW |