Title: [121748] trunk
Revision
121748
Author
[email protected]
Date
2012-07-03 02:17:23 -0700 (Tue, 03 Jul 2012)

Log Message

Web Inspector: Make DirectoryContentView sortable
https://bugs.webkit.org/show_bug.cgi?id=90361

Patch by Taiju Tsuiki <[email protected]> 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:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (121747 => 121748)


--- trunk/LayoutTests/ChangeLog	2012-07-03 08:58:49 UTC (rev 121747)
+++ trunk/LayoutTests/ChangeLog	2012-07-03 09:17:23 UTC (rev 121748)
@@ -1,3 +1,12 @@
+2012-07-03  Taiju Tsuiki  <[email protected]>
+
+        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  <[email protected]>
 
         [Chromium] Rebaseline: fast/box-sizing/box-sizing.html

Modified: trunk/LayoutTests/http/tests/inspector/filesystem/get-metadata-expected.txt (121747 => 121748)


--- trunk/LayoutTests/http/tests/inspector/filesystem/get-metadata-expected.txt	2012-07-03 08:58:49 UTC (rev 121747)
+++ trunk/LayoutTests/http/tests/inspector/filesystem/get-metadata-expected.txt	2012-07-03 09:17:23 UTC (rev 121748)
@@ -7,5 +7,5 @@
 errorCode: 0
 metadata:
   modificationTime: (exists)
-  size: (null)
+  size: 0
 

Modified: trunk/Source/WebCore/ChangeLog (121747 => 121748)


--- trunk/Source/WebCore/ChangeLog	2012-07-03 08:58:49 UTC (rev 121747)
+++ trunk/Source/WebCore/ChangeLog	2012-07-03 09:17:23 UTC (rev 121748)
@@ -1,3 +1,24 @@
+2012-07-03  Taiju Tsuiki  <[email protected]>
+
+        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  <[email protected]>
 
         Web Inspector: WebInspector.TextViewer should be renamed WebInspector.TextEditor

Modified: trunk/Source/WebCore/inspector/Inspector.json (121747 => 121748)


--- trunk/Source/WebCore/inspector/Inspector.json	2012-07-03 08:58:49 UTC (rev 121747)
+++ trunk/Source/WebCore/inspector/Inspector.json	2012-07-03 09:17:23 UTC (rev 121748)
@@ -1427,7 +1427,7 @@
                 "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."
             }

Modified: trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp (121747 => 121748)


--- trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp	2012-07-03 08:58:49 UTC (rev 121747)
+++ trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp	2012-07-03 09:17:23 UTC (rev 121748)
@@ -399,9 +399,7 @@
 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;
 }

Modified: trunk/Source/WebCore/inspector/front-end/DirectoryContentView.js (121747 => 121748)


--- trunk/Source/WebCore/inspector/front-end/DirectoryContentView.js	2012-07-03 08:58:49 UTC (rev 121747)
+++ trunk/Source/WebCore/inspector/front-end/DirectoryContentView.js	2012-07-03 09:17:23 UTC (rev 121748)
@@ -38,21 +38,28 @@
     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 @@
         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 @@
     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 @@
 
         this._metadata = metadata;
         var 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 = ""
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to