зеркало из https://github.com/mozilla/pjs.git
Paving the way for the implementation of expanding/collapsing folders.
This commit is contained in:
Родитель
ee06af94c2
Коммит
9e6d9c33ac
|
@ -97,17 +97,11 @@ void nsHTDataModel::AddNodesToArray(nsIContent* pContent, PRUint32 indentLevel)
|
|||
}
|
||||
else mRootNode = pDataItem;
|
||||
|
||||
nsHTItem* pItem = NS_STATIC_CAST(nsHTItem*, pDataItem->GetImplData());
|
||||
|
||||
nsIContent* pChildrenNode = nsHTDataModel::FindChildWithName(pItem->GetContentNode(), "children");
|
||||
if (pChildrenNode)
|
||||
if (pContent == mContentRoot || pDataItem->IsExpanded())
|
||||
{
|
||||
// If the node is OPEN, then its children need to be added to the visibility array.
|
||||
nsString attrValue;
|
||||
nsresult result = pContent->GetAttribute("open", attrValue);
|
||||
attrValue.ToLowerCase();
|
||||
if ((pContent == mContentRoot) || (result == NS_CONTENT_ATTR_NO_VALUE ||
|
||||
(result == NS_CONTENT_ATTR_HAS_VALUE && attrValue=="true")))
|
||||
nsHTItem* pItem = NS_STATIC_CAST(nsHTItem*, pDataItem->GetImplData());
|
||||
nsIContent* pChildrenNode = nsHTDataModel::FindChildWithName(pItem->GetContentNode(), "children");
|
||||
if (pChildrenNode)
|
||||
{
|
||||
PRInt32 numChildren = 0;
|
||||
pChildrenNode->ChildCount(numChildren);
|
||||
|
|
|
@ -37,7 +37,23 @@ nsHTItem::~nsHTItem()
|
|||
|
||||
PRBool nsHTItem::IsExpandedDelegate() const
|
||||
{
|
||||
return PR_FALSE;
|
||||
nsString attrValue;
|
||||
nsresult result = mContentNode->GetAttribute("open", attrValue);
|
||||
attrValue.ToLowerCase();
|
||||
return (result == NS_CONTENT_ATTR_NO_VALUE ||
|
||||
(result == NS_CONTENT_ATTR_HAS_VALUE && attrValue=="true"));
|
||||
}
|
||||
|
||||
void nsHTItem::ToggleOpenStateDelegate()
|
||||
{
|
||||
nsString attrValue;
|
||||
// Need to set the attribute's value.
|
||||
if (IsExpandedDelegate())
|
||||
attrValue = "false";
|
||||
else attrValue = "true";
|
||||
|
||||
// Set it and wait for the callback.
|
||||
mContentNode->SetAttribute("open", attrValue, PR_TRUE);
|
||||
}
|
||||
|
||||
PRUint32 nsHTItem::GetIndentationLevelDelegate() const
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
virtual ~nsHTItem();
|
||||
|
||||
virtual PRBool IsExpandedDelegate() const;
|
||||
virtual void ToggleOpenStateDelegate();
|
||||
|
||||
virtual PRUint32 GetIndentationLevelDelegate() const;
|
||||
virtual void SetIndentationLevelDelegate(PRUint32 n);
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ public:
|
|||
// All functions inherited from HierarchicalDataItem are delegated to
|
||||
// the concrete implementation.
|
||||
virtual PRBool IsExpanded() const { return IsExpandedDelegate(); };
|
||||
virtual void ToggleOpenState() { ToggleOpenStateDelegate(); };
|
||||
virtual PRUint32 GetIndentationLevel() const { return GetIndentationLevelDelegate(); };
|
||||
virtual void SetIndentationLevel(PRUint32 n) { SetIndentationLevelDelegate(n); };
|
||||
// End of delegated functions
|
||||
|
|
|
@ -35,7 +35,8 @@ public:
|
|||
virtual ~nsHierarchicalDataItem() {};
|
||||
|
||||
virtual PRBool IsExpanded() const = 0;
|
||||
|
||||
virtual void ToggleOpenState() = 0;
|
||||
|
||||
virtual PRUint32 GetIndentationLevel() const = 0;
|
||||
virtual void SetIndentationLevel(PRUint32 n) = 0;
|
||||
|
||||
|
|
|
@ -309,13 +309,17 @@ void nsTreeView::HandleMouseUp(nsGUIEvent* aEvent)
|
|||
nsHitLocation type;
|
||||
DetermineHitLocation(mCachedMovePoint, row, column, type);
|
||||
|
||||
// If the user boinked the trigger, then we need to open or close the node.
|
||||
// If the user clicked the trigger, then we need to open or close the node.
|
||||
if (type == eTriggerHit)
|
||||
{
|
||||
nsHierarchicalDataItem* pItem = mDataModel->GetNthItem(row);
|
||||
pItem->ToggleOpenState();
|
||||
}
|
||||
else if (type == eContentHit)
|
||||
{
|
||||
// The user boinked content (a text or icon). Select it.
|
||||
// The user clicked on content (a text or icon). Select it.
|
||||
nsHierarchicalDataItem* pItem = mDataModel->GetNthItem(row);
|
||||
//pDataModel->SetSelection(pItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче