Commit abbc2c53 authored by timothy@apple.com's avatar timothy@apple.com
Browse files

Alphabetically sort scripts in the Script's panel file popup menu.

        https://bugs.webkit.org/show_bug.cgi?id=23395

        Reviewed by Timothy Hatcher.

        * inspector/front-end/ScriptsPanel.js:
        (WebInspector.ScriptsPanel.prototype._addScriptToFilesMenu):
        * inspector/front-end/utilities.js:
        (insertionIndexForObjectInListSortedByFunction):
        (indexOfObjectInListSortedByFunction):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@41335 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e7ecc958
2009-03-01 Ross Boucher <rboucher@gmail.com>
Alphabetically sort scripts in the Script's panel file popup menu.
https://bugs.webkit.org/show_bug.cgi?id=23395
Reviewed by Timothy Hatcher.
* inspector/front-end/ScriptsPanel.js:
(WebInspector.ScriptsPanel.prototype._addScriptToFilesMenu):
* inspector/front-end/utilities.js:
(insertionIndexForObjectInListSortedByFunction):
(indexOfObjectInListSortedByFunction):
2009-03-01 Yael Aharon <yael.aharon@nokia.com>
 
Pass securityOrigin->host() instead of securityOrigin->domain() to WebInspector
......@@ -569,11 +569,29 @@ WebInspector.ScriptsPanel.prototype = {
var select = this.filesSelectElement;
// FIXME: Append in some meaningful order.
var option = document.createElement("option");
option.representedObject = (script.resource || script);
option.text = (script.sourceURL ? WebInspector.displayNameForURL(script.sourceURL) : WebInspector.UIString("(program)"));
select.appendChild(option);
var insertionIndex = -1;
if (select.childNodes) {
insertionIndex = insertionIndexForObjectInListSortedByFunction(option, select.childNodes, function(a, b) {
a = a.text.toLowerCase();
b = b.text.toLowerCase();
if (a < b)
return -1;
else if (a > b)
return 1;
return 0;
});
}
if (insertionIndex < 0)
select.appendChild(option);
else
select.insertBefore(option, select.childNodes.item(insertionIndex));
script.filesSelectOption = option;
......
......@@ -937,6 +937,40 @@ Array.prototype.remove = function(value, onlyFirst)
}
}
function insertionIndexForObjectInListSortedByFunction(anObject, aList, aFunction)
{
// indexOf returns (-lowerBound - 1). Taking (-result - 1) works out to lowerBound.
return (-indexOfObjectInListSortedByFunction(anObject, aList, aFunction) - 1);
}
function indexOfObjectInListSortedByFunction(anObject, aList, aFunction)
{
var first = 0;
var last = aList.length - 1;
var floor = Math.floor;
var mid, c;
while (first <= last) {
mid = floor((first + last) / 2);
c = aFunction(anObject, aList[mid]);
if (c > 0)
first = mid + 1;
else if (c < 0)
last = mid - 1;
else {
//we return the first occurance of an item in the list.
while (mid > 0 && aFunction(anObject, aList[mid - 1]) === 0)
mid--;
return mid;
}
}
// By returning 1 less than the negative lower search bound, we can reuse this function
// for both indexOf and insertionIndexFor, with some simple arithmetic.
return (-first - 1);
}
String.sprintf = function(format)
{
return String.vsprintf(format, Array.prototype.slice.call(arguments, 1));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment