Fix 233473: History doesn't sort properly.

This commit is contained in:
blakeross%telocity.com 2004-02-09 05:04:33 +00:00
Родитель b5015a424d
Коммит 0061b8bf8d
3 изменённых файлов: 79 добавлений и 79 удалений

Просмотреть файл

@ -27,7 +27,6 @@
<page id="history-panel" orient="vertical"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="HistoryCommonInit();"
onunload="onUnload();"
elementtofocus="historyTree">
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
@ -91,7 +90,7 @@
</toolbarbutton>
</hbox>
<tree id="historyTree" flex="1" class="plain"
context="historyContextMenu" persist="ref"
context="historyContextMenu"
datasources="rdf:history" ref="NC:HistoryByDate" flags="dont-build-content"
onkeypress="if (event.keyCode == 13) OpenURL(event.shiftKey || event.metaKey);"
onselect="this.treeBoxObject.view.selectionChanged();
@ -106,7 +105,7 @@
<treeitem uri="rdf:*" rdf:type="rdf:http://www.w3.org/1999/02/22-rdf-syntax-ns#type">
<treerow>
<treecell label="rdf:http://home.netscape.com/NC-rdf#Name"
dayindex="rdf:http://home.netscape.com/NC-rdf#DayFolderIndex"
sortName="rdf:http://home.netscape.com/NC-rdf#Name?sort=true"
visitcount="rdf:http://home.netscape.com/NC-rdf#VisitCount"
date="rdf:http://home.netscape.com/NC-rdf#Date"/>
</treerow>
@ -117,7 +116,7 @@
<treecols id="historyTreeCols">
<treecol flex="1" id="Name" persist="sortActive sortDirection"
hideheader="true" primary="true"
sort="rdf:http://home.netscape.com/NC-rdf#DayFolderIndex"
sort="rdf:http://home.netscape.com/NC-rdf#Name?sort=true"
sortActive="true"/>
</treecols>
</tree>

Просмотреть файл

@ -59,8 +59,12 @@ function HistoryCommonInit()
document.getElementById("bydayandsite").setAttribute("checked", "true");
else
document.getElementById("byday").setAttribute("checked", "true");
// XXXBlake we should persist the last search value
// If it's empty, this will do the right thing and just group by the old grouping.
searchHistory(gSearchBox.value);
gHistoryTree.focus();
SortInNewDirection(find_sort_direction(find_sort_column()));
gHistoryTree.treeBoxObject.view.selection.select(0);
}
@ -150,10 +154,8 @@ function OpenURL(aWhere, event)
function SortBy(sortKey)
{
// XXXBlake Welcome to the end of the world of Lame.
// You can go no further. You are standing on the edge -- teetering, even.
// Look on the bright side: you can rest assured that no code you see in the future
// will even come close to the lameness of the code below.
// We set the sortDirection to the one before we actually want it to be in the
// cycle list, since cycleHeader cycles it forward before doing the sort.
var sortDirection;
switch(sortKey) {
@ -162,17 +164,13 @@ function SortBy(sortKey)
sortDirection = "ascending";
break;
case "name":
sortKey = "rdf:http://home.netscape.com/NC-rdf#Name";
sortKey = "rdf:http://home.netscape.com/NC-rdf#Name?sort=true";
sortDirection = "natural";
break;
case "lastvisited":
sortKey = "rdf:http://home.netscape.com/NC-rdf#Date";
sortDirection = "ascending";
break;
case "day":
sortKey = "rdf:http://home.netscape.com/NC-rdf#DayFolderIndex";
sortDirection = "natural";
break;
default:
return;
}
@ -182,37 +180,55 @@ function SortBy(sortKey)
gHistoryTree.treeBoxObject.view.cycleHeader(sortKey, col);
}
function IsFindResource(uri)
{
return (uri.substr(0, 5) == "find:");
}
function GroupBy(groupingType)
{
var isFind = IsFindResource(groupingType);
if (!isFind) {
gHistoryGrouping = groupingType;
switch(groupingType) {
case "none":
gHistoryTree.setAttribute("ref", "NC:HistoryRoot");
break;
case "site":
// xxx for now
gHistoryTree.setAttribute("ref", "NC:HistoryRoot");
SortBy("name");
break;
case "dayandsite":
gHistoryTree.setAttribute("ref", "NC:HistoryByDateAndSite");
SortBy("dayandsite");
break;
case "visited":
gHistoryTree.setAttribute("ref", "NC:HistoryRoot");
SortBy("visited");
break;
case "lastvisited":
gHistoryTree.setAttribute("ref", "NC:HistoryRoot");
SortBy("lastvisited");
break;
case "day":
default:
gHistoryTree.setAttribute("ref", "NC:HistoryByDate");
SortBy("day");
break;
}
gSearchBox.value = "";
}
switch(groupingType) {
case "site":
gHistoryTree.setAttribute("ref", "NC:HistoryRoot");
break;
case "dayandsite":
gHistoryTree.setAttribute("ref", "NC:HistoryByDateAndSite");
break;
case "visited":
gHistoryTree.setAttribute("ref", "NC:HistoryRoot");
break;
case "lastvisited":
gHistoryTree.setAttribute("ref", "NC:HistoryRoot");
break;
case "day":
gHistoryTree.setAttribute("ref", "NC:HistoryByDate");
break;
default:
gHistoryTree.setAttribute("ref", groupingType);
}
Sort(isFind? gHistoryGrouping : groupingType);
}
function Sort(groupingType)
{
switch(groupingType) {
case "site":
case "dayandsite":
case "day":
SortBy("name");
break;
case "lastvisited":
SortBy("lastvisited");
break;
case "visited":
SortBy("visited");
break;
}
}
function historyAddBookmarks()
@ -293,14 +309,11 @@ function buildContextMenu()
function searchHistory(aInput)
{
if (!aInput)
if (aInput == "") {
GroupBy(gHistoryGrouping);
else
gHistoryTree.setAttribute("ref",
"find:datasource=history&match=Name&method=contains&text=" + encodeURIComponent(aInput));
return;
}
GroupBy("find:datasource=history&match=Name&method=contains&text=" + encodeURIComponent(aInput));
}
function onUnload()
{
return;
}

Просмотреть файл

@ -1555,51 +1555,39 @@ nsGlobalHistory::GetTarget(nsIRDFResource* aSource,
// find URIs are special
if (IsFindResource(aSource)) {
if (aProperty == kNC_Name || aProperty == kNC_NameSort) {
// for sorting, we sort by uri, so just return the URI as a literal
if (aProperty == kNC_NameSort) {
nsCOMPtr<nsIRDFLiteral> uriLiteral;
rv = gRDFService->GetLiteral(NS_ConvertUTF8toUCS2(uri).get(),
getter_AddRefs(uriLiteral));
if (NS_FAILED(rv)) return(rv);
*aTarget = uriLiteral;
NS_ADDREF(*aTarget);
return NS_OK;
}
else
return GetFindUriName(uri, aTarget);
} else if (aProperty == kNC_DayFolderIndex) {
if (aProperty == kNC_Name)
return GetFindUriName(uri, aTarget);
if (aProperty == kNC_NameSort) {
// parse out the 'text' token
nsVoidArray tokenList;
FindUrlToTokenList(uri, tokenList);
nsCOMPtr<nsIRDFInt> intLiteral;
nsCOMPtr<nsIRDFLiteral> literal;
for (PRInt32 i = 0; i < tokenList.Count(); ++i) {
tokenPair* token = NS_STATIC_CAST(tokenPair*, tokenList[i]);
if (!strcmp(token->tokenName, "text")) {
rv = gRDFService->GetIntLiteral(atoi(token->tokenValue),
getter_AddRefs(intLiteral));
break;
if (!strncmp(token->tokenName, "text", token->tokenNameLength)) {
rv = gRDFService->GetLiteral(NS_ConvertUTF8toUCS2(Substring(token->tokenValue, token->tokenValue + token->tokenValueLength)).get(),
getter_AddRefs(literal));
// We don't break out of the loop here because there could be other text tokens in the string.
// The last one is the most specific so wait and see if we've got one...
}
}
FreeTokenList(tokenList);
if (intLiteral && NS_SUCCEEDED(rv)) {
*aTarget = intLiteral;
if (literal && NS_SUCCEEDED(rv)) {
*aTarget = literal;
NS_ADDREF(*aTarget);
return NS_OK;
} else {
*aTarget = nsnull;
return rv;
}
*aTarget = nsnull;
return rv;
}
} else if (aProperty == kNC_DayFolderIndex)
return NS_RDF_NO_VALUE;
}
// ok, we got this far, so we have to retrieve something from
// the row in the database
nsCOMPtr<nsIMdbRow> row;