Renamed IsWidgetProperty() to IsContainmentProperty(), added RemoveWidgetItem() call and hooked it up in the generic builder.

This commit is contained in:
waterson%netscape.com 1999-03-12 08:13:14 +00:00
Родитель 8eebc1a046
Коммит 9948afecc3
7 изменённых файлов: 350 добавлений и 23 удалений

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

@ -482,7 +482,7 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
// object that is member of the current container element;
// rather, it specifies a "simple" property of the container
// element. Skip it.
if (!IsWidgetProperty(aElement, property))
if (!IsContainmentProperty(aElement, property))
continue;
// Create a second cursor that'll enumerate all of the values
@ -503,7 +503,7 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
nsCOMPtr<nsIRDFResource> valueResource;
if (NS_SUCCEEDED(value->QueryInterface(kIRDFResourceIID, (void**) getter_AddRefs(valueResource)))
&& IsWidgetProperty(aElement, property)) {
&& IsContainmentProperty(aElement, property)) {
/* XXX hack: always append value resource 1st!
due to sort callback implementation */
tempArray->AppendElement(valueResource);
@ -601,9 +601,9 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSubject,
nsCOMPtr<nsIRDFResource> resource;
if (NS_SUCCEEDED(aObject->QueryInterface(kIRDFResourceIID,
(void**) getter_AddRefs(resource)))
&& IsWidgetProperty(element, aPredicate)) {
&& IsContainmentProperty(element, aPredicate)) {
// Okay, the object _is_ a resource, and the predicate is
// a widget property. So this'll be a new item in the widget
// a containment property. So this'll be a new item in the widget
// control.
// But if the contents of aElement _haven't_ yet been
@ -648,9 +648,82 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSubject,
NS_IMETHODIMP
RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSubject,
nsIRDFResource* aPredicate,
nsIRDFNode* aObject)
nsIRDFResource* aPredicate,
nsIRDFNode* aObject)
{
NS_PRECONDITION(mDocument != nsnull, "not initialized");
if (! mDocument)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
nsCOMPtr<nsISupportsArray> elements;
if (NS_FAILED(rv = NS_NewISupportsArray(getter_AddRefs(elements)))) {
NS_ERROR("unable to create new ISupportsArray");
return rv;
}
// Find all the elements in the content model that correspond to
// aSubject: for each, we'll try to build XUL children if
// appropriate.
if (NS_FAILED(rv = mDocument->GetElementsForResource(aSubject, elements))) {
NS_ERROR("unable to retrieve elements from resource");
return rv;
}
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
nsCOMPtr<nsIContent> element( do_QueryInterface(elements->ElementAt(i)) );
// XXX somehow figure out if building XUL kids on this
// particular element makes any sense whatsoever.
// We'll start by making sure that the element at least has
// the same parent has the content model builder's root
if (!IsElementInWidget(element))
continue;
nsCOMPtr<nsIRDFResource> resource;
if (NS_SUCCEEDED(aObject->QueryInterface(kIRDFResourceIID,
(void**) getter_AddRefs(resource)))
&& IsContainmentProperty(element, aPredicate)) {
// Okay, the object _is_ a resource, and the predicate is
// a containment property. So this'll be a new item in the widget
// control.
// But if the contents of aElement _haven't_ yet been
// generated, then just ignore the unassertion: nothing is
// in the content model to remove.
nsAutoString contentsGenerated;
if (NS_FAILED(rv = element->GetAttribute(kNameSpaceID_None,
kItemContentsGeneratedAtom,
contentsGenerated))) {
NS_ERROR("severe problem trying to get attribute");
return rv;
}
if ((rv == NS_CONTENT_ATTR_HAS_VALUE) &&
contentsGenerated.EqualsIgnoreCase("true")) {
// Okay, it's a "live" element, so go ahead and append the new
// child to this node.
if (NS_FAILED(rv = RemoveWidgetItem(element, aPredicate, resource))) {
NS_ERROR("unable to create new widget item");
return rv;
}
}
}
else {
// Either the object of the assertion is not a resource,
// or the object is a resource and the predicate is not a
// tree property. So this won't be a new row in the
// table. See if we can use it to set a cell value on the
// current element.
/* XXX: WHAT THE HECK IS THIS HERE FOR? - Dave
if (NS_FAILED(rv = SetCellValue(element, aPredicate, aObject))) {
NS_ERROR("unable to set cell value");
return rv;
}*/
}
}
return NS_OK;
}
@ -1151,7 +1224,7 @@ RDFGenericBuilderImpl::IsWidgetInsertionRootElement(nsIContent* element)
}
PRBool
RDFGenericBuilderImpl::IsWidgetProperty(nsIContent* aElement, nsIRDFResource* aProperty)
RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResource* aProperty)
{
// XXX is this okay to _always_ treat ordinal properties as tree
// properties? Probably not...

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

@ -482,7 +482,7 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
// object that is member of the current container element;
// rather, it specifies a "simple" property of the container
// element. Skip it.
if (!IsWidgetProperty(aElement, property))
if (!IsContainmentProperty(aElement, property))
continue;
// Create a second cursor that'll enumerate all of the values
@ -503,7 +503,7 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
nsCOMPtr<nsIRDFResource> valueResource;
if (NS_SUCCEEDED(value->QueryInterface(kIRDFResourceIID, (void**) getter_AddRefs(valueResource)))
&& IsWidgetProperty(aElement, property)) {
&& IsContainmentProperty(aElement, property)) {
/* XXX hack: always append value resource 1st!
due to sort callback implementation */
tempArray->AppendElement(valueResource);
@ -601,9 +601,9 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSubject,
nsCOMPtr<nsIRDFResource> resource;
if (NS_SUCCEEDED(aObject->QueryInterface(kIRDFResourceIID,
(void**) getter_AddRefs(resource)))
&& IsWidgetProperty(element, aPredicate)) {
&& IsContainmentProperty(element, aPredicate)) {
// Okay, the object _is_ a resource, and the predicate is
// a widget property. So this'll be a new item in the widget
// a containment property. So this'll be a new item in the widget
// control.
// But if the contents of aElement _haven't_ yet been
@ -648,9 +648,82 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSubject,
NS_IMETHODIMP
RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSubject,
nsIRDFResource* aPredicate,
nsIRDFNode* aObject)
nsIRDFResource* aPredicate,
nsIRDFNode* aObject)
{
NS_PRECONDITION(mDocument != nsnull, "not initialized");
if (! mDocument)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
nsCOMPtr<nsISupportsArray> elements;
if (NS_FAILED(rv = NS_NewISupportsArray(getter_AddRefs(elements)))) {
NS_ERROR("unable to create new ISupportsArray");
return rv;
}
// Find all the elements in the content model that correspond to
// aSubject: for each, we'll try to build XUL children if
// appropriate.
if (NS_FAILED(rv = mDocument->GetElementsForResource(aSubject, elements))) {
NS_ERROR("unable to retrieve elements from resource");
return rv;
}
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
nsCOMPtr<nsIContent> element( do_QueryInterface(elements->ElementAt(i)) );
// XXX somehow figure out if building XUL kids on this
// particular element makes any sense whatsoever.
// We'll start by making sure that the element at least has
// the same parent has the content model builder's root
if (!IsElementInWidget(element))
continue;
nsCOMPtr<nsIRDFResource> resource;
if (NS_SUCCEEDED(aObject->QueryInterface(kIRDFResourceIID,
(void**) getter_AddRefs(resource)))
&& IsContainmentProperty(element, aPredicate)) {
// Okay, the object _is_ a resource, and the predicate is
// a containment property. So this'll be a new item in the widget
// control.
// But if the contents of aElement _haven't_ yet been
// generated, then just ignore the unassertion: nothing is
// in the content model to remove.
nsAutoString contentsGenerated;
if (NS_FAILED(rv = element->GetAttribute(kNameSpaceID_None,
kItemContentsGeneratedAtom,
contentsGenerated))) {
NS_ERROR("severe problem trying to get attribute");
return rv;
}
if ((rv == NS_CONTENT_ATTR_HAS_VALUE) &&
contentsGenerated.EqualsIgnoreCase("true")) {
// Okay, it's a "live" element, so go ahead and append the new
// child to this node.
if (NS_FAILED(rv = RemoveWidgetItem(element, aPredicate, resource))) {
NS_ERROR("unable to create new widget item");
return rv;
}
}
}
else {
// Either the object of the assertion is not a resource,
// or the object is a resource and the predicate is not a
// tree property. So this won't be a new row in the
// table. See if we can use it to set a cell value on the
// current element.
/* XXX: WHAT THE HECK IS THIS HERE FOR? - Dave
if (NS_FAILED(rv = SetCellValue(element, aPredicate, aObject))) {
NS_ERROR("unable to set cell value");
return rv;
}*/
}
}
return NS_OK;
}
@ -1151,7 +1224,7 @@ RDFGenericBuilderImpl::IsWidgetInsertionRootElement(nsIContent* element)
}
PRBool
RDFGenericBuilderImpl::IsWidgetProperty(nsIContent* aElement, nsIRDFResource* aProperty)
RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResource* aProperty)
{
// XXX is this okay to _always_ treat ordinal properties as tree
// properties? Probably not...

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

@ -97,8 +97,13 @@ public:
nsIRDFResource* aValue,
PRInt32 naturalOrderPos) = 0;
virtual nsresult
RemoveWidgetItem(nsIContent* aWidgetElement,
nsIRDFResource* aProperty,
nsIRDFResource* aValue) = 0;
virtual PRBool
IsWidgetProperty(nsIContent* aElement, nsIRDFResource* aProperty);
IsContainmentProperty(nsIContent* aElement, nsIRDFResource* aProperty);
PRBool
IsOpen(nsIContent* aElement);

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

@ -91,6 +91,11 @@ public:
nsIRDFResource* aProperty,
nsIRDFResource* aValue, PRInt32 aNaturalOrderPos);
nsresult
RemoveWidgetItem(nsIContent* aMenuItemElement,
nsIRDFResource* aProperty,
nsIRDFResource* aValue);
nsresult
GetRootWidgetAtom(nsIAtom** aResult) {
NS_ADDREF(kMenuAtom);
@ -291,3 +296,13 @@ RDFMenuBuilderImpl::AddWidgetItem(nsIContent* aElement,
return NS_OK;
}
nsresult
RDFMenuBuilderImpl::RemoveWidgetItem(nsIContent* aMenuItemElement,
nsIRDFResource* aProperty,
nsIRDFResource* aValue)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -92,6 +92,11 @@ public:
nsIRDFResource* aProperty,
nsIRDFResource* aValue, PRInt32 aNaturalOrderPos);
nsresult
RemoveWidgetItem(nsIContent* aTreeItemElement,
nsIRDFResource* aProperty,
nsIRDFResource* aValue);
nsresult
GetRootWidgetAtom(nsIAtom** aResult) {
NS_ADDREF(kToolbarAtom);
@ -294,3 +299,14 @@ RDFToolbarBuilderImpl::AddWidgetItem(nsIContent* aElement,
return NS_OK;
}
nsresult
RDFToolbarBuilderImpl::RemoveWidgetItem(nsIContent* aToolbarItemElement,
nsIRDFResource* aProperty,
nsIRDFResource* aValue)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -127,6 +127,11 @@ public:
nsIRDFResource* aProperty,
nsIRDFResource* aValue, PRInt32 aNaturalOrderPos);
nsresult
RemoveWidgetItem(nsIContent* aTreeItemElement,
nsIRDFResource* aProperty,
nsIRDFResource* aValue);
nsresult
EnsureCell(nsIContent* aTreeItemElement, PRInt32 aIndex, nsIContent** aCellElement);
@ -400,7 +405,7 @@ RDFTreeBuilderImpl::AddWidgetItem(nsIContent* aElement,
}
// Ignore properties that are used to indicate "tree-ness"
if (IsWidgetProperty(aElement, property))
if (IsContainmentProperty(aElement, property))
continue;
PRInt32 nameSpaceID;
@ -464,6 +469,73 @@ RDFTreeBuilderImpl::AddWidgetItem(nsIContent* aElement,
}
nsresult
RDFTreeBuilderImpl::RemoveWidgetItem(nsIContent* aTreeItemElement,
nsIRDFResource* aProperty,
nsIRDFResource* aValue)
{
nsresult rv;
nsCOMPtr<nsIContent> treechildren;
if (NS_FAILED(rv = FindChildByTag(aTreeItemElement,
kNameSpaceID_XUL,
kTreeChildrenAtom,
getter_AddRefs(treechildren)))) {
// XXX make this a warning
NS_ERROR("attempt to remove child from an element with no treechildren");
return NS_OK;
}
PRInt32 count;
if (NS_FAILED(rv = treechildren->ChildCount(count)))
return rv;
for (PRInt32 i = 0; i < count; ++i) {
nsCOMPtr<nsIContent> kid;
if (NS_FAILED(rv = treechildren->ChildAt(i, *getter_AddRefs(kid))))
return rv; // XXX fatal
// Make sure it's a <xul:treeitem>
PRInt32 nameSpaceID;
if (NS_FAILED(rv = kid->GetNameSpaceID(nameSpaceID)))
return rv; // XXX fatal
if (nameSpaceID != kNameSpaceID_XUL)
continue; // wrong namespace
nsCOMPtr<nsIAtom> tag;
if (NS_FAILED(rv = kid->GetTag(*getter_AddRefs(tag))))
return rv; // XXX fatal
if (tag.get() != kTreeItemAtom)
continue; // wrong tag
// Now get the resource ID from the RDF:ID attribute. We do it
// via the content model, because you're never sure who
// might've added this stuff in...
nsCOMPtr<nsIRDFResource> resource;
if (NS_FAILED(rv = GetElementResource(kid, getter_AddRefs(resource)))) {
NS_ERROR("severe error retrieving resource");
return rv;
}
if (resource.get() != aValue)
continue; // not the resource we want
// Fount it! Now kill it.
treechildren->RemoveChildAt(i, PR_TRUE);
return NS_OK;
}
// XXX make this a warning
NS_ERROR("unable to find child to remove");
return NS_OK;
}
nsresult
RDFTreeBuilderImpl::EnsureCell(nsIContent* aTreeItemElement,
PRInt32 aIndex,

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

@ -482,7 +482,7 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
// object that is member of the current container element;
// rather, it specifies a "simple" property of the container
// element. Skip it.
if (!IsWidgetProperty(aElement, property))
if (!IsContainmentProperty(aElement, property))
continue;
// Create a second cursor that'll enumerate all of the values
@ -503,7 +503,7 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
nsCOMPtr<nsIRDFResource> valueResource;
if (NS_SUCCEEDED(value->QueryInterface(kIRDFResourceIID, (void**) getter_AddRefs(valueResource)))
&& IsWidgetProperty(aElement, property)) {
&& IsContainmentProperty(aElement, property)) {
/* XXX hack: always append value resource 1st!
due to sort callback implementation */
tempArray->AppendElement(valueResource);
@ -601,9 +601,9 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSubject,
nsCOMPtr<nsIRDFResource> resource;
if (NS_SUCCEEDED(aObject->QueryInterface(kIRDFResourceIID,
(void**) getter_AddRefs(resource)))
&& IsWidgetProperty(element, aPredicate)) {
&& IsContainmentProperty(element, aPredicate)) {
// Okay, the object _is_ a resource, and the predicate is
// a widget property. So this'll be a new item in the widget
// a containment property. So this'll be a new item in the widget
// control.
// But if the contents of aElement _haven't_ yet been
@ -648,9 +648,82 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSubject,
NS_IMETHODIMP
RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSubject,
nsIRDFResource* aPredicate,
nsIRDFNode* aObject)
nsIRDFResource* aPredicate,
nsIRDFNode* aObject)
{
NS_PRECONDITION(mDocument != nsnull, "not initialized");
if (! mDocument)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
nsCOMPtr<nsISupportsArray> elements;
if (NS_FAILED(rv = NS_NewISupportsArray(getter_AddRefs(elements)))) {
NS_ERROR("unable to create new ISupportsArray");
return rv;
}
// Find all the elements in the content model that correspond to
// aSubject: for each, we'll try to build XUL children if
// appropriate.
if (NS_FAILED(rv = mDocument->GetElementsForResource(aSubject, elements))) {
NS_ERROR("unable to retrieve elements from resource");
return rv;
}
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
nsCOMPtr<nsIContent> element( do_QueryInterface(elements->ElementAt(i)) );
// XXX somehow figure out if building XUL kids on this
// particular element makes any sense whatsoever.
// We'll start by making sure that the element at least has
// the same parent has the content model builder's root
if (!IsElementInWidget(element))
continue;
nsCOMPtr<nsIRDFResource> resource;
if (NS_SUCCEEDED(aObject->QueryInterface(kIRDFResourceIID,
(void**) getter_AddRefs(resource)))
&& IsContainmentProperty(element, aPredicate)) {
// Okay, the object _is_ a resource, and the predicate is
// a containment property. So this'll be a new item in the widget
// control.
// But if the contents of aElement _haven't_ yet been
// generated, then just ignore the unassertion: nothing is
// in the content model to remove.
nsAutoString contentsGenerated;
if (NS_FAILED(rv = element->GetAttribute(kNameSpaceID_None,
kItemContentsGeneratedAtom,
contentsGenerated))) {
NS_ERROR("severe problem trying to get attribute");
return rv;
}
if ((rv == NS_CONTENT_ATTR_HAS_VALUE) &&
contentsGenerated.EqualsIgnoreCase("true")) {
// Okay, it's a "live" element, so go ahead and append the new
// child to this node.
if (NS_FAILED(rv = RemoveWidgetItem(element, aPredicate, resource))) {
NS_ERROR("unable to create new widget item");
return rv;
}
}
}
else {
// Either the object of the assertion is not a resource,
// or the object is a resource and the predicate is not a
// tree property. So this won't be a new row in the
// table. See if we can use it to set a cell value on the
// current element.
/* XXX: WHAT THE HECK IS THIS HERE FOR? - Dave
if (NS_FAILED(rv = SetCellValue(element, aPredicate, aObject))) {
NS_ERROR("unable to set cell value");
return rv;
}*/
}
}
return NS_OK;
}
@ -1151,7 +1224,7 @@ RDFGenericBuilderImpl::IsWidgetInsertionRootElement(nsIContent* element)
}
PRBool
RDFGenericBuilderImpl::IsWidgetProperty(nsIContent* aElement, nsIRDFResource* aProperty)
RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResource* aProperty)
{
// XXX is this okay to _always_ treat ordinal properties as tree
// properties? Probably not...