On the road to making the bookmarks menu work properly.

This commit is contained in:
hyatt%netscape.com 1999-03-13 00:08:25 +00:00
Родитель df2a860b7a
Коммит d3c5cc49f3
7 изменённых файлов: 115 добавлений и 12 удалений

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

@ -1371,6 +1371,29 @@ RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResourc
return PR_FALSE;
}
PRBool
RDFGenericBuilderImpl::IsContainer(nsIContent* aElement, nsIRDFResource* aResource)
{
PRBool result = PR_FALSE;
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
if (NS_FAILED(mDB->ArcLabelsOut(aResource, getter_AddRefs(arcs)))) {
NS_ERROR("unable to get arcs out");
return result;
}
while (NS_SUCCEEDED(arcs->Advance())) {
nsCOMPtr<nsIRDFResource> property;
if (NS_FAILED(arcs->GetPredicate(getter_AddRefs(property)))) {
NS_ERROR("unable to get cursor value");
return result;
}
// Ignore properties that are used to indicate "tree-ness"
if (IsContainmentProperty(aElement, property))
return PR_TRUE;
}
return result;
}
PRBool
RDFGenericBuilderImpl::IsOpen(nsIContent* aElement)

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

@ -1371,6 +1371,29 @@ RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResourc
return PR_FALSE;
}
PRBool
RDFGenericBuilderImpl::IsContainer(nsIContent* aElement, nsIRDFResource* aResource)
{
PRBool result = PR_FALSE;
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
if (NS_FAILED(mDB->ArcLabelsOut(aResource, getter_AddRefs(arcs)))) {
NS_ERROR("unable to get arcs out");
return result;
}
while (NS_SUCCEEDED(arcs->Advance())) {
nsCOMPtr<nsIRDFResource> property;
if (NS_FAILED(arcs->GetPredicate(getter_AddRefs(property)))) {
NS_ERROR("unable to get cursor value");
return result;
}
// Ignore properties that are used to indicate "tree-ness"
if (IsContainmentProperty(aElement, property))
return PR_TRUE;
}
return result;
}
PRBool
RDFGenericBuilderImpl::IsOpen(nsIContent* aElement)

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

@ -105,6 +105,9 @@ public:
virtual PRBool
IsContainmentProperty(nsIContent* aElement, nsIRDFResource* aProperty);
PRBool
IsContainer(nsIContent* aParentElement, nsIRDFResource* aTargetResource);
PRBool
IsOpen(nsIContent* aElement);

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

@ -209,15 +209,32 @@ RDFMenuBuilderImpl::AddWidgetItem(nsIContent* aElement,
return NS_ERROR_UNEXPECTED;
}
// Find out if we're a container or not.
PRBool markAsContainer = IsContainer(aElement, aValue);
nsCOMPtr<nsIAtom> itemAtom;
// Figure out what atom to use based on whether or not we're a container
// or leaf
if (markAsContainer)
{
// We're a menu element
GetWidgetFolderAtom(getter_AddRefs(itemAtom));
}
else
{
// We're a menuitem element
GetWidgetItemAtom(getter_AddRefs(itemAtom));
}
// Create the <xul:menuitem> element
nsCOMPtr<nsIContent> menuItem;
if (NS_FAILED(rv = CreateResourceElement(kNameSpaceID_XUL,
kMenuItemAtom,
itemAtom,
aValue,
getter_AddRefs(menuItem))))
return rv;
// Add the <xul:menuitem> to the <xul:menu> element.
// Add the new menu item to the <xul:menu> element.
menuParent->AppendChildTo(menuItem, PR_TRUE);
// Add miscellaneous attributes by iterating _all_ of the
@ -235,8 +252,8 @@ RDFMenuBuilderImpl::AddWidgetItem(nsIContent* aElement,
return rv;
}
// Ignore ordinal properties
if (rdf_IsOrdinalProperty(property))
// Ignore properties that are used to indicate "tree-ness"
if (IsContainmentProperty(aElement, property))
continue;
PRInt32 nameSpaceID;
@ -289,10 +306,15 @@ RDFMenuBuilderImpl::AddWidgetItem(nsIContent* aElement,
return rv;
}
// Finally, mark this as a "container" so that we know to
// recursively generate kids if they're asked for.
if (markAsContainer == PR_TRUE)
{
// Finally, mark this as a "container" so that we know to
// recursively generate kids if they're asked for.
if (NS_FAILED(rv = menuItem->SetAttribute(kNameSpaceID_RDF, kContainerAtom, "true", PR_FALSE)))
return rv;
}
return NS_OK;
}

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

@ -206,6 +206,8 @@ RDFToolbarBuilderImpl::AddWidgetItem(nsIContent* aElement,
return NS_ERROR_UNEXPECTED;
}
PRBool markAsContainer = IsContainer(aElement, aValue);
// Create the <xul:titledbutton> element
nsCOMPtr<nsIContent> toolbarItem;
if (NS_FAILED(rv = CreateResourceElement(kNameSpaceID_XUL,
@ -232,8 +234,8 @@ RDFToolbarBuilderImpl::AddWidgetItem(nsIContent* aElement,
return rv;
}
// Ignore ordinal properties
if (rdf_IsOrdinalProperty(property))
// Ignore properties that are used to indicate "tree-ness"
if (IsContainmentProperty(aElement, property))
continue;
PRInt32 nameSpaceID;
@ -292,10 +294,15 @@ RDFToolbarBuilderImpl::AddWidgetItem(nsIContent* aElement,
return rv;
}
// Finally, mark this as a "container" so that we know to
// recursively generate kids if they're asked for.
if (markAsContainer == PR_TRUE)
{
// Finally, mark this as a "container" so that we know to
// recursively generate kids if they're asked for.
if (NS_FAILED(rv = toolbarItem->SetAttribute(kNameSpaceID_RDF, kContainerAtom, "true", PR_FALSE)))
return rv;
}
return NS_OK;
}

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

@ -522,6 +522,9 @@ RDFTreeBuilderImpl::AddWidgetItem(nsIContent* aElement,
return NS_ERROR_UNEXPECTED;
}
// Find out if we're a container or not.
PRBool markAsContainer = PR_FALSE;
// Create the <xul:treeitem> element
nsCOMPtr<nsIContent> treeItem;
if (NS_FAILED(rv = CreateResourceElement(kNameSpaceID_XUL,
@ -555,7 +558,6 @@ RDFTreeBuilderImpl::AddWidgetItem(nsIContent* aElement,
return rv;
}
PRBool markAsContainer = PR_FALSE;
while (NS_SUCCEEDED(rv = arcs->Advance())) {
nsCOMPtr<nsIRDFResource> property;
if (NS_FAILED(rv = arcs->GetPredicate(getter_AddRefs(property)))) {
@ -622,7 +624,7 @@ RDFTreeBuilderImpl::AddWidgetItem(nsIContent* aElement,
return rv;
}
if (markAsContainer == PR_TRUE)
if (markAsContainer)
{
// Finally, mark this as a "container" so that we know to
// recursively generate kids if they're asked for.

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

@ -1371,6 +1371,29 @@ RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResourc
return PR_FALSE;
}
PRBool
RDFGenericBuilderImpl::IsContainer(nsIContent* aElement, nsIRDFResource* aResource)
{
PRBool result = PR_FALSE;
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
if (NS_FAILED(mDB->ArcLabelsOut(aResource, getter_AddRefs(arcs)))) {
NS_ERROR("unable to get arcs out");
return result;
}
while (NS_SUCCEEDED(arcs->Advance())) {
nsCOMPtr<nsIRDFResource> property;
if (NS_FAILED(arcs->GetPredicate(getter_AddRefs(property)))) {
NS_ERROR("unable to get cursor value");
return result;
}
// Ignore properties that are used to indicate "tree-ness"
if (IsContainmentProperty(aElement, property))
return PR_TRUE;
}
return result;
}
PRBool
RDFGenericBuilderImpl::IsOpen(nsIContent* aElement)