135877 - convert ab dirtree to use xul tree builder, fix dnd feedback, also 130310, 132362. r/sr=sspitzer

This commit is contained in:
shliang%netscape.com 2003-02-28 03:55:49 +00:00
Родитель a1caf941e3
Коммит ccc117cfc1
8 изменённых файлов: 182 добавлений и 203 удалений

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

@ -323,9 +323,7 @@ function AbDelete()
function AbNewCard(abListItem)
{
var selectedAB = GetSelectedAddressBookDirID(abListItem);
goNewCardDialog(selectedAB);
goNewCardDialog(GetSelectedDirectory());
}
// NOTE, will return -1 if more than one card selected, or no cards selected.
@ -367,10 +365,10 @@ function AbEditCard(card)
return;
if (card.isMailList) {
goEditListDialog(gAbView.URI, card, card.mailListURI, UpdateCardView);
goEditListDialog(GetSelectedDirectory(), card, card.mailListURI, UpdateCardView);
}
else {
goEditCardDialog(gAbView.URI, card, UpdateCardView);
goEditCardDialog(GetSelectedDirectory(), card, UpdateCardView);
}
}
@ -443,8 +441,8 @@ function GetSelectedAddressesFromDirTree()
var addresses = "";
if (dirTree.currentIndex >= 0) {
var selected = dirTree.contentView.getItemAtIndex(dirTree.currentIndex);
var mailingListUri = selected.id;
var selectedResource = dirTree.builderView.getResourceAtIndex(dirTree.currentIndex);
var mailingListUri = selectedResource.Value;
var directory = GetDirectoryFromURI(mailingListUri);
if (directory.isMailList) {
var listCardsCount = directory.addressLists.Count();
@ -568,17 +566,11 @@ function GetSelectedAbCards()
function SelectFirstAddressBook()
{
// this can fail if the dirTree box is collapsed at startup
// and only the results pane (and card view pane) are showing
try {
dirTree.treeBoxObject.selection.select(0);
dirTree.view.selection.select(0);
ChangeDirectoryByURI(GetSelectedDirectory());
}
catch (ex) {
ChangeDirectoryByURI(kPersonalAddressbookURI);
gAbResultsTree.focus();
}
}
function SelectFirstCard()
{
@ -658,6 +650,9 @@ function SetAbView(uri, sortColumn, sortDirection)
var boxObject = GetAbResultsBoxObject();
boxObject.view = gAbView.QueryInterface(Components.interfaces.nsITreeView);
UpdateSortIndicators(sortColumn, sortDirection);
return actualSortColumn;
}
@ -666,6 +661,8 @@ function GetAbView()
return gAbView;
}
// this will return the complete search uri if a quick search is currently being
// done. to get the uri of the directory only, use GetSelectedDirectory().
function GetAbViewURI()
{
if (gAbView)
@ -679,12 +676,11 @@ function ChangeDirectoryByURI(uri)
if (!uri)
uri = kPersonalAddressbookURI;
if (gAbView && gAbView.URI == uri)
if (gAbView && GetAbViewURI() == uri)
return;
var dataNode = document.getElementById(uri);
var sortColumn = dataNode ? dataNode.getAttribute("sortColumn") : kDefaultSortColumn;
var sortDirection = dataNode ? dataNode.getAttribute("sortDirection") : kDefaultAscending;
var sortColumn = gAbResultsTree.getAttribute("sortCol");
var sortDirection = document.getElementById(sortColumn).getAttribute("sortDirection");
var actualSortColumn = SetAbView(uri, sortColumn, sortDirection);
@ -703,25 +699,13 @@ function ChangeDirectoryByURI(uri)
function AbSortAscending()
{
var sortColumn = kDefaultSortColumn;
if (gAbView) {
var node = document.getElementById(gAbView.URI);
sortColumn = node.getAttribute("sortColumn");
}
var sortColumn = gAbResultsTree.getAttribute("sortCol");
SortAndUpdateIndicators(sortColumn, kDefaultAscending);
}
function AbSortDescending()
{
var sortColumn = kDefaultSortColumn;
if (gAbView) {
var node = document.getElementById(gAbView.URI);
sortColumn = node.getAttribute("sortColumn");
}
var sortColumn = gAbResultsTree.getAttribute("sortCol");
SortAndUpdateIndicators(sortColumn, kDefaultDescending);
}
@ -746,19 +730,6 @@ function SortAndUpdateIndicators(sortColumn, sortDirection)
if (gAbView)
gAbView.sortBy(sortColumn, sortDirection);
SaveSortSetting(sortColumn, sortDirection);
}
function SaveSortSetting(column, direction)
{
if ((dirTree || abList) && gAbView) {
var node = document.getElementById(gAbView.URI);
if (node) {
node.setAttribute("sortColumn", column);
node.setAttribute("sortDirection", direction);
}
}
}
function UpdateSortIndicators(colID, sortDirection)
@ -769,6 +740,7 @@ function UpdateSortIndicators(colID, sortDirection)
sortedColumn = document.getElementById(colID);
if (sortedColumn) {
sortedColumn.setAttribute("sortDirection",sortDirection);
gAbResultsTree.setAttribute("sortCol", colID);
}
}
@ -790,37 +762,7 @@ function InvalidateResultsPane()
function AbNewList(abListItem)
{
var selectedAB = GetSelectedAddressBookDirID(abListItem);
goNewListDialog(selectedAB);
}
function GetSelectedAddressBookDirID(abListItem)
{
var selectedAB;
// this can fail if the dirTree box is collapsed at startup
// and only the results pane (and card view pane) are showing
try {
var abDirEntries = document.getElementById(abListItem);
if (abDirEntries && abDirEntries.localName == "tree" && abDirEntries.currentIndex >= 0) {
var selected = abDirEntries.contentView.getItemAtIndex(abDirEntries.currentIndex);
selectedAB = selected.id;
}
// request could be coming from the context menu of addressbook panel in sidebar
// addressbook dirs are listed as menu item. So, get the selected item id.
if (!selectedAB && abDirEntries && abDirEntries.localName == "menulist" && abDirEntries.selectedItem)
selectedAB = abDirEntries.selectedItem.getAttribute("id");
// if we do not have a selected ab still, use personal addressbook
if (!selectedAB)
selectedAB = kPersonalAddressbookURI;
}
catch (ex) {
selectedAB = kPersonalAddressbookURI;
}
return selectedAB;
goNewListDialog(GetSelectedDirectory());
}
function goNewListDialog(selectedAB)
@ -938,17 +880,13 @@ function DirPaneHasFocus()
function GetSelectedDirectory()
{
// this can fail if the dirTree box is collapsed at startup
// and only the results pane (and card view pane) are showing
try {
if (abList)
return abList.selectedItem.id;
else {
if (dirTree.currentIndex < 0)
return null;
var selected = dirTree.contentView.getItemAtIndex(dirTree.currentIndex);
return selected.id;
}
catch (ex) {
return kPersonalAddressbookURI;
var selected = dirTree.builderView.getResourceAtIndex(dirTree.currentIndex)
return selected.Value;
}
}

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

@ -36,13 +36,12 @@ Contributors:
<!-- FIX ME - remove document.commandDispatcher.updateCommands() when tree selection calls this automatically -->
<tree id="dirTree" class="abDirectory plain" seltype="single"
datasources="rdf:addressdirectory" ref="moz-abdirectory://"
flags="dont-build-content"
hidecolumnpicker="true"
onselect="DirPaneSelectionChange(); document.commandDispatcher.updateCommands('addrbook-select');"
onclick="DirPaneClick(event);"
ondblclick="DirPaneDoubleClick(event);"
onblur="goOnEvent(this,'blur')"
ondragover="nsDragAndDrop.dragOver(event, abDirTreeObserver);"
ondragdrop="nsDragAndDrop.drop(event, abDirTreeObserver);">
onblur="goOnEvent(this,'blur')">
<treecols>
<treecol id="DirCol" flex="1" primary="true" label="&dirTreeHeader.label;"/>
@ -51,7 +50,7 @@ Contributors:
<template>
<rule>
<conditions>
<content uri="?container"/>
<treeitem uri="?container"/>
<member container="?container" child="?member"/>
</conditions>

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

@ -65,33 +65,71 @@ var abResultsPaneObserver = {
}
};
var dragService = Components.classes["@mozilla.org/widget/dragservice;1"].getService().QueryInterface(Components.interfaces.nsIDragService);
var abDirTreeObserver = {
onDragStart: function (aEvent, aXferData, aDragAction)
canDropOn: function(index)
{
var targetResource = dirTree.builderView.getResourceAtIndex(index);
var targetURI = targetResource.Value;
var srcURI = GetSelectedDirectory();
if (targetURI == srcURI)
return false;
// determine if we dragging from a mailing list on a directory x to the parent (directory x).
// if so, don't allow the drop
var result = srcURI.split(targetURI);
if (result != srcURI)
return false;
// check if we can write to the target directory
// LDAP is readonly
var targetDirectory = GetDirectoryFromURI(targetURI);
if (!targetDirectory.isMailList &&
(!(targetDirectory.operations & targetDirectory.opWrite)))
return false;
return true;
},
canDropBeforeAfter: function(index, before)
{
},
onDrop: function (aEvent, aXferData, aDragSession)
onDrop: function(row, orientation)
{
var xferData = aXferData.data.split("\n");
var row = {}, col = {}, obj = {};
dirTree.treeBoxObject.getCellAt(aEvent.clientX, aEvent.clientY, row, col, obj);
if (row.value >= dirTree.view.rowCount || row.value < 0) return;
var dragSession = dragService.getCurrentSession();
if (!dragSession)
return false;
var item = dirTree.contentView.getItemAtIndex(row.value);
var targetURI = item.id;
var directory = GetDirectoryFromURI(targetURI);
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
trans.addDataFlavor("moz/abcard");
var abView = GetAbView();
for (var i = 0; i < dragSession.numDropItems; i++) {
dragSession.getData(trans, i);
var dataObj = new Object();
var flavor = new Object();
var len = new Object();
trans.getAnyTransferData(flavor, dataObj, len);
if (dataObj)
dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsString);
else
continue;
var rows = xferData[0].split(",");
var transData = dataObj.data.split("\n");
var rows = transData[0].split(",");
var numrows = rows.length;
var srcURI = GetAbViewURI();
if (srcURI == targetURI) {
// should not be here
return;
}
var targetResource = dirTree.builderView.getResourceAtIndex(row);
var targetURI = targetResource.Value;
var srcURI = GetSelectedDirectory();
if (srcURI == targetURI)
return; // should not be here
var result;
var needToCopyCard = true;
@ -119,60 +157,53 @@ var abDirTreeObserver = {
needToCopyCard = false;
}
var abView = GetAbView();
var directory = GetDirectoryFromURI(targetURI);
for (var i=0;i<numrows;i++) {
var card = abView.getCardFromRow(rows[i]);
directory.dropCard(card, needToCopyCard);
}
var statusText = document.getElementById("statusText");
// XXX get this approved, move it to a string bundle
statusText.setAttribute("label", i + " Card(s) Copied");
var cardsCopiedText = gAddressBookBundle.getFormattedString("cardsCopied", [i]);
statusText.setAttribute("label", cardsCopiedText);
}
},
onDragExit: function (aEvent, aDragSession)
onToggleOpenState: function()
{
},
onDragOver: function (aEvent, aFlavour, aDragSession)
onCycleHeader: function(colID, elt)
{
aDragSession.canDrop = false;
if (aEvent.target.localName != "treechildren")
return false;
},
var row = {}, col = {}, obj = {};
dirTree.treeBoxObject.getCellAt(aEvent.clientX, aEvent.clientY, row, col, obj);
if (row.value >= dirTree.view.rowCount || row.value < 0)
return false;
onCycleCell: function(row, colID)
{
},
var item = dirTree.contentView.getItemAtIndex(row.value);
var targetURI = item.id;
var srcURI = GetAbViewURI();
// you can't drop a card onto the directory it comes from
if (targetURI == srcURI)
return false;
// determine if we dragging from a mailing list on a directory x to the parent (directory x).
// if so, don't allow the drop
var result = srcURI.split(targetURI);
if (result != srcURI)
return false;
// check if we can write to the target directory
// LDAP is readonly
var targetDirectory = GetDirectoryFromURI(targetURI);
if (!targetDirectory.isMailList &&
(!(targetDirectory.operations & targetDirectory.opWrite)))
return false
aDragSession.canDrop = true;
return true;
onSelectionChanged: function()
{
},
getSupportedFlavours: function ()
isEditable: function(row, colID)
{
},
onSetCellText: function(row, colID, value)
{
},
onPerformAction: function(action)
{
},
onPerformActionOnRow: function(action, row)
{
},
onPerformActionOnCell: function(action, row, colID)
{
var flavourSet = new FlavourSet();
flavourSet.appendFlavour("moz/abcard");
return flavourSet;
}
};
}

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

@ -49,18 +49,14 @@ function AbResultsPaneOnClick(event)
var t = event.originalTarget;
if (t.localName == "treecol") {
var sortDirection = kDefaultDescending;
var sortDirection;
var currentDirection = t.getAttribute("sortDirection");
if (gAbView) {
var node = document.getElementById(gAbView.URI);
if (node) {
sortDirection = node.getAttribute("sortDirection");
}
if (sortDirection == kDefaultDescending)
if (currentDirection == kDefaultDescending)
sortDirection = kDefaultAscending;
else
sortDirection = kDefaultDescending;
}
SortAndUpdateIndicators(t.id, sortDirection);
}
else if (t.localName == "treechildren") {

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

@ -51,72 +51,77 @@
<tree id="abResultsTree" flex="1" enableColumnDrag="true" class="plain"
onclick="AbResultsPaneOnClick(event);"
onselect="this.view.selectionChanged();">
onselect="this.view.selectionChanged();"
sortCol="GeneratedName"
persist="sortCol">
<treecols id="abResultsTreeCols">
<!-- these column ids must match up to the mork column names, except for GeneratedName, see nsIAddrDatabase.idl -->
<treecol id="GeneratedName" class="sortDirectionIndicator"
persist="hidden ordinal width" flex="1" label="&GeneratedName.label;" primary="true"/>
persist="hidden ordinal width sortDirection" flex="1"
label="&GeneratedName.label;" primary="true"/>
<splitter class="tree-splitter"/>
<treecol id="PrimaryEmail" class="sortDirectionIndicator"
persist="hidden ordinal width" flex="1" label="&PrimaryEmail.label;"/>
persist="hidden ordinal width sortDirection" flex="1" label="&PrimaryEmail.label;"/>
<splitter class="tree-splitter"/>
<treecol id="_AimScreenName" class="sortDirectionIndicator"
persist="hidden ordinal width" flex="1" label="&ScreenName.label;"/>
<splitter class="tree-splitter"/>
<treecol id="WorkPhone" class="sortDirectionIndicator"
persist="hidden ordinal width" flex="1" label="&WorkPhone.label;"/>
persist="hidden ordinal width sortDirection" flex="1" label="&ScreenName.label;"/>
<splitter class="tree-splitter"/>
<treecol id="Company" class="sortDirectionIndicator"
persist="hidden ordinal width" flex="1" label="&Company.label;"/>
persist="hidden ordinal width sortDirection" flex="1" label="&Company.label;"/>
<splitter class="tree-splitter"/>
<!-- LOCALIZATION NOTE: _PhoneticName may be enabled for Japanese builds. -->
<!--
<treecol id="_PhoneticName" class="sortDirectionIndicator"
persist="hidden ordinal width"
hiddenbydefault="true"
flex="1" label="&_PhoneticName.label;"/>
<splitter class="tree-splitter"/>
-->
<treecol id="NickName" class="sortDirectionIndicator"
persist="hidden ordinal width"
persist="hidden ordinal width sortDirection"
hiddenbydefault="true"
flex="1" label="&NickName.label;"/>
<splitter class="tree-splitter"/>
<treecol id="HomePhone" class="sortDirectionIndicator"
persist="hidden ordinal width"
<treecol id="SecondEmail" class="sortDirectionIndicator"
persist="hidden ordinal width sortDirection"
hiddenbydefault="true"
flex="1" label="&HomePhone.label;"/>
flex="1" label="&SecondEmail.label;"/>
<splitter class="tree-splitter"/>
<treecol id="FaxNumber" class="sortDirectionIndicator"
persist="hidden ordinal width"
<treecol id="Department" class="sortDirectionIndicator"
persist="hidden ordinal width sortDirection"
hiddenbydefault="true"
flex="1" label="&FaxNumber.label;"/>
flex="1" label="&Department.label;"/>
<splitter class="tree-splitter"/>
<treecol id="PagerNumber" class="sortDirectionIndicator"
persist="hidden ordinal width"
<treecol id="JobTitle" class="sortDirectionIndicator"
persist="hidden ordinal width sortDirection"
hiddenbydefault="true"
flex="1" label="&PagerNumber.label;"/>
flex="1" label="&JobTitle.label;"/>
<splitter class="tree-splitter"/>
<treecol id="CellularNumber" class="sortDirectionIndicator"
persist="hidden ordinal width"
persist="hidden ordinal width sortDirection"
hiddenbydefault="true"
flex="1" label="&CellularNumber.label;"/>
<splitter class="tree-splitter"/>
<treecol id="SecondEmail" class="sortDirectionIndicator"
persist="hidden ordinal width"
<treecol id="PagerNumber" class="sortDirectionIndicator"
persist="hidden ordinal width sortDirection"
hiddenbydefault="true"
flex="1" label="&SecondEmail.label;"/>
flex="1" label="&PagerNumber.label;"/>
<splitter class="tree-splitter"/>
<treecol id="JobTitle" class="sortDirectionIndicator"
persist="hidden ordinal width"
<treecol id="FaxNumber" class="sortDirectionIndicator"
persist="hidden ordinal width sortDirection"
hiddenbydefault="true"
flex="1" label="&JobTitle.label;"/>
flex="1" label="&FaxNumber.label;"/>
<splitter class="tree-splitter"/>
<treecol id="Department" class="sortDirectionIndicator"
persist="hidden ordinal width"
<treecol id="HomePhone" class="sortDirectionIndicator"
persist="hidden ordinal width sortDirection"
hiddenbydefault="true"
flex="1" label="&Department.label;"/>
flex="1" label="&HomePhone.label;"/>
<splitter class="tree-splitter"/>
<treecol id="WorkPhone" class="sortDirectionIndicator"
persist="hidden ordinal width sortDirection" flex="1" label="&WorkPhone.label;"/>
<!-- LOCALIZATION NOTE: _PhoneticName may be enabled for Japanese builds. -->
<!--
<treecol id="_PhoneticName" class="sortDirectionIndicator"
persist="hidden ordinal width sortDirection"
hiddenbydefault="true"
flex="1" label="&_PhoneticName.label;"/>
<splitter class="tree-splitter"/>
-->
</treecols>
<treechildren ondraggesture="nsDragAndDrop.startDrag(event, abResultsPaneObserver);"/>
</tree>

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

@ -63,7 +63,9 @@
<vbox id="results_box" flex="1">
<hbox id="panel-bar" class="toolbar" align="center">
<label value="&lookIn.label;"/>
<menulist id="addressbookList" oncommand="DirPaneSelectionChangeMenulist(); AbPanelOnChange(event)" flex="1">
<menulist id="addressbookList"
oncommand="DirPaneSelectionChangeMenulist(); AbPanelOnChange(event)" flex="1"
persist="selectedAB">
<menupopup id="addressbookList-menupopup"
datasources="rdf:addressdirectory"
ref="moz-abdirectory://">
@ -84,18 +86,18 @@
onkeypress="onAbSearchKeyPress(event);"/>
</hbox>
<tree id="abResultsTree" flex="1" context="composeMail" onclick="AbResultsPaneOnClick(event);" class="plain">
<tree id="abResultsTree" flex="1" context="composeMail" onclick="AbResultsPaneOnClick(event);" class="plain"
sortCol="GeneratedName" persist="sortCol">
<treecols>
<!-- these column ids must match up to the mork column names, see nsIAddrDatabase.idl -->
<treecol id="GeneratedName" class="sortDirectionIndicator"
persist="hidden ordinal width" flex="1" label="&GeneratedName.label;" primary="true"/>
persist="hidden ordinal width sortDirection" flex="1" label="&GeneratedName.label;" primary="true"/>
<splitter class="tree-splitter"/>
<treecol id="PrimaryEmail" class="sortDirectionIndicator"
persist="hidden ordinal width"
persist="hidden ordinal width sortDirection"
hiddenbydefault="true"
flex="1" label="&PrimaryEmail.label;"/>
</treecols>
<treechildren/>
</tree>

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

@ -152,7 +152,7 @@ function OnLoadAddressBook()
SetupAbCommandUpdateHandlers();
//workaround - add setTimeout to make sure dynamic overlays get loaded first
setTimeout('SelectFirstAddressBook()',0);
setTimeout('OnLoadDirTree()', 0);
// if the pref is locked disable the menuitem New->LDAP directory
if (gPrefs.prefIsLocked("ldap_2.disable_button_add"))
@ -165,6 +165,13 @@ function OnLoadAddressBook()
addrbookSession.addAddressBookListener(gAddressBookAbListener, Components.interfaces.nsIAbListener.directoryRemoved);
}
function OnLoadDirTree() {
var treeBuilder = dirTree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder);
treeBuilder.addObserver(abDirTreeObserver);
SelectFirstAddressBook();
}
function GetCurrentPrefs()
{
// prefs
@ -321,7 +328,7 @@ function AbPrintCardInternal(doPrintPreview, msgType)
return;
var addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(Components.interfaces.nsIAddressBook);
var uri = GetAbViewURI();
var uri = GetSelectedDirectory();
if (!uri)
return;
@ -375,7 +382,7 @@ function CreatePrintCardUrl(card)
function AbPrintAddressBookInternal(doPrintPreview, msgType)
{
var addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(Components.interfaces.nsIAddressBook);
var uri = GetAbViewURI();
var uri = GetSelectedDirectory();
if (!uri)
return;
@ -467,7 +474,7 @@ function AbDeleteDirectory()
if (parentRow == -1)
parentId = "moz-abdirectory://";
else
parentId = dirTree.contentView.getItemAtIndex(parentRow).id;
parentId = dirTree.builderView.getResourceAtIndex(parentRow).Value;
var parentDir = GetDirectoryFromURI(parentId);
parentArray.AppendElement(parentDir);
@ -536,6 +543,7 @@ function onAdvancedAbSearch()
function onEnterInSearchBar()
{
ClearCardViewPane();
gSearchInput.select();
if (!gQueryURIFormat)
gQueryURIFormat = gPrefs.getComplexValue("mail.addr_book.quicksearchquery.format",
@ -544,9 +552,8 @@ function onEnterInSearchBar()
var searchURI = GetSelectedDirectory();
if (!searchURI) return;
var dataNode = document.getElementById(searchURI);
var sortColumn = dataNode.getAttribute("sortColumn");
var sortDirection = dataNode.getAttribute("sortDirection");
var sortColumn = gAbView.sortColumn;
var sortDirection = gAbView.sortDirection;
/*
XXX todo, handle the case where the LDAP url

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

@ -84,6 +84,7 @@ ldap_2.servers.history.description=Collected Addresses
totalCardStatus=Total Cards in %1$S: %2$S
## LOCALIZATION NOTE (matchesFound): do not localize %S
matchesFound=%S matches found
cardsCopied=%S card(s) copied
# LDAP directory stuff
directoriesListItemNone=None