Web Inspector: Make DirectoryContentView sortable
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jul 2012 09:17:23 +0000 (09:17 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jul 2012 09:17:23 +0000 (09:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90361

Patch by Taiju Tsuiki <tzik@chromium.org> on 2012-07-03
Reviewed by Vsevolod Vlasov.

Source/WebCore:

* inspector/Inspector.json:
* inspector/InspectorFileSystemAgent.cpp:
(WebCore):
* inspector/front-end/DirectoryContentView.js:
(WebInspector.DirectoryContentView):
(WebInspector.DirectoryContentView.prototype.showEntries):
(WebInspector.DirectoryContentView.prototype._sort):
(WebInspector.DirectoryContentView.Node.comparator.isDirectoryCompare):
(WebInspector.DirectoryContentView.Node.comparator.nameCompare):
(WebInspector.DirectoryContentView.Node.comparator.typeCompare):
(WebInspector.DirectoryContentView.Node.comparator.sizeCompare):
(WebInspector.DirectoryContentView.Node.comparator):
(WebInspector.DirectoryContentView.Node.prototype._metadataReceived):

LayoutTests:

* http/tests/inspector/filesystem/get-metadata-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@121748 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/filesystem/get-metadata-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/inspector/Inspector.json
Source/WebCore/inspector/InspectorFileSystemAgent.cpp
Source/WebCore/inspector/front-end/DirectoryContentView.js

index 59ecece..0ac4257 100644 (file)
@@ -1,3 +1,12 @@
+2012-07-03  Taiju Tsuiki  <tzik@chromium.org>
+
+        Web Inspector: Make DirectoryContentView sortable
+        https://bugs.webkit.org/show_bug.cgi?id=90361
+
+        Reviewed by Vsevolod Vlasov.
+
+        * http/tests/inspector/filesystem/get-metadata-expected.txt:
+
 2012-07-03  Yoshifumi Inoue  <yosin@chromium.org>
 
         [Chromium] Rebaseline: fast/box-sizing/box-sizing.html
index 0ca699a..73e6222 100644 (file)
@@ -1,3 +1,24 @@
+2012-07-03  Taiju Tsuiki  <tzik@chromium.org>
+
+        Web Inspector: Make DirectoryContentView sortable
+        https://bugs.webkit.org/show_bug.cgi?id=90361
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/Inspector.json:
+        * inspector/InspectorFileSystemAgent.cpp:
+        (WebCore):
+        * inspector/front-end/DirectoryContentView.js:
+        (WebInspector.DirectoryContentView):
+        (WebInspector.DirectoryContentView.prototype.showEntries):
+        (WebInspector.DirectoryContentView.prototype._sort):
+        (WebInspector.DirectoryContentView.Node.comparator.isDirectoryCompare):
+        (WebInspector.DirectoryContentView.Node.comparator.nameCompare):
+        (WebInspector.DirectoryContentView.Node.comparator.typeCompare):
+        (WebInspector.DirectoryContentView.Node.comparator.sizeCompare):
+        (WebInspector.DirectoryContentView.Node.comparator):
+        (WebInspector.DirectoryContentView.Node.prototype._metadataReceived):
+
 2012-07-03  Jan Keromnes  <janx@linux.com>
 
         Web Inspector: WebInspector.TextViewer should be renamed WebInspector.TextEditor
index 3711cf3..59797ab 100644 (file)
                 "type": "object",
                 "properties": [
                     { "name": "modificationTime", "type": "number", "description": "Modification time." },
-                    { "name": "size", "type": "number", "optional": true, "description": "File size. This field is available only for a file." }
+                    { "name": "size", "type": "number", "description": "File size. This field is always zero for directories." }
                 ],
                 "description": "Represents metadata of a file or entry."
             }
index dffef09..8901174 100644 (file)
@@ -399,9 +399,7 @@ bool GetMetadataTask::didGetEntry(Entry* entry)
 bool GetMetadataTask::didGetMetadata(Metadata* metadata)
 {
     using TypeBuilder::FileSystem::Metadata;
-    RefPtr<Metadata> result = Metadata::create().setModificationTime(metadata->modificationTime());
-    if (!m_isDirectory)
-        result->setSize(metadata->size());
+    RefPtr<Metadata> result = Metadata::create().setModificationTime(metadata->modificationTime()).setSize(metadata->size());
     reportResult(static_cast<FileError::ErrorCode>(0), result);
     return true;
 }
index f98f0ac..21ced25 100644 (file)
@@ -38,21 +38,28 @@ WebInspector.DirectoryContentView = function()
     var columns = {};
     columns[indexes.Name] = {};
     columns[indexes.Name].title = WebInspector.UIString("Name");
+    columns[indexes.Name].sort = "ascending";
+    columns[indexes.Name].sortable = true;
     columns[indexes.Name].width = "20%";
     columns[indexes.URL] = {};
     columns[indexes.URL].title = WebInspector.UIString("URL");
+    columns[indexes.URL].sortable = true;
     columns[indexes.URL].width = "20%";
     columns[indexes.Type] = {};
     columns[indexes.Type].title = WebInspector.UIString("Type");
+    columns[indexes.Type].sortable = true;
     columns[indexes.Type].width = "15%";
     columns[indexes.Size] = {};
     columns[indexes.Size].title = WebInspector.UIString("Size");
+    columns[indexes.Size].sortable = true;
     columns[indexes.Size].width = "10%";
     columns[indexes.ModificationTime] = {};
     columns[indexes.ModificationTime].title = WebInspector.UIString("Modification Time");
+    columns[indexes.ModificationTime].sortable = true;
     columns[indexes.ModificationTime].width = "25%";
 
     WebInspector.DataGrid.call(this, columns);
+    this.addEventListener("sorting changed", this._sort, this);
 }
 
 WebInspector.DirectoryContentView.columnIndexes = {
@@ -73,6 +80,12 @@ WebInspector.DirectoryContentView.prototype = {
         this.rootNode().removeChildren();
         for (var i = 0; i < entries.length; ++i)
             this.rootNode().appendChild(new WebInspector.DirectoryContentView.Node(entries[i]));
+    },
+
+    _sort: function()
+    {
+        var column = /** @type {string} */ this.sortColumnIdentifier;
+        this.sortNodes(WebInspector.DirectoryContentView.Node.comparator(column, this.sortOrder === "descending"), false);
     }
 }
 
@@ -100,6 +113,67 @@ WebInspector.DirectoryContentView.Node = function(entry)
     this._entry.requestMetadata(this._metadataReceived.bind(this));
 }
 
+/**
+ * @param {string} column
+ * @param {boolean} reverse
+ */
+WebInspector.DirectoryContentView.Node.comparator = function(column, reverse)
+{
+    var reverseFactor = reverse ? -1 : 1;
+    const indexes = WebInspector.DirectoryContentView.columnIndexes;
+
+    switch (column) {
+    case indexes.Name:
+    case indexes.URL:
+        return function(x, y)
+        {
+            return isDirectoryCompare(x, y) || nameCompare(x, y);
+        };
+    case indexes.Type:
+        return function(x, y)
+        {
+            return isDirectoryCompare(x ,y) || typeCompare(x, y) || nameCompare(x, y);
+        };
+    case indexes.Size:
+        return function(x, y)
+        {
+            return isDirectoryCompare(x, y) || sizeCompare(x, y) || nameCompare(x, y);
+        };
+    case indexes.ModificationTime:
+        return function(x, y)
+        {
+            return isDirectoryCompare(x, y) || modificationTimeCompare(x, y) || nameCompare(x, y);
+        };
+    }
+
+    function isDirectoryCompare(x, y)
+    {
+        if (x._entry.isDirectory != y._entry.isDirectory)
+            return y._entry.isDirectory ? 1 : -1;
+        return 0;
+    }
+
+    function nameCompare(x, y)
+    {
+        return reverseFactor * x._entry.name.localeCompare(y._entry.name);
+    }
+
+    function typeCompare(x, y)
+    {
+        return reverseFactor * (x._entry.mimeType || "").localeCompare(y._entry.mimeType || "");
+    }
+
+    function sizeCompare(x, y)
+    {
+        return reverseFactor * ((x._metadata ? x._metadata.size : 0) - (y._metadata ? y._metadata.size : 0));
+    }
+
+    function modificationTimeCompare(x, y)
+    {
+        return reverseFactor * ((x._metadata ? x._metadata.modificationTime : 0) - (y._metadata ? y._metadata.modificationTime : 0));
+    }
+}
+
 WebInspector.DirectoryContentView.Node.prototype = {
     /**
      * @param {number} errorCode
@@ -113,7 +187,9 @@ WebInspector.DirectoryContentView.Node.prototype = {
 
         this._metadata = metadata;
         var data = this.data;
-        if ("size" in metadata)
+        if (this._entry.isDirectory)
+            data[indexes.Size] = WebInspector.UIString("-");
+        else
             data[indexes.Size] = Number.bytesToString(metadata.size);
         data[indexes.ModificationTime] = new Date(metadata.modificationTime).toGMTString();
         this.data = data;