Changed GetEnabledCommands to GetAllCommands/IsCommandEnabled.

This commit is contained in:
warren%netscape.com 1999-03-12 21:28:34 +00:00
Родитель e0b6ac944f
Коммит 5ab052576e
11 изменённых файлов: 231 добавлений и 126 удалений

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

@ -637,68 +637,70 @@ NS_IMETHODIMP nsMSGFolderDataSource::Flush()
}
NS_IMETHODIMP
nsMSGFolderDataSource::GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult)
nsMSGFolderDataSource::GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands)
{
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIEnumerator> commands;
PRBool haveFolderCmds = PR_FALSE;
PRBool haveMessageCmds = PR_FALSE;
nsresult rv;
PRUint32 cnt = aSources->Count();
for (PRUint32 i = 0; i < cnt; i++) {
nsISupports* source = (*aSources)[i];
nsIMsgFolder* folder;
nsIMessage* message;
nsIMsgFolder* folder;
nsIMessage* message;
nsISupportsArray* cmds = nsnull;
nsISupportsArray* cmds;
if (NS_SUCCEEDED(source->QueryInterface(nsIMsgFolder::GetIID(), (void**)&folder))) {
NS_RELEASE(folder); // release now that we know it's a folder
if (!haveFolderCmds) {
rv = NS_NewISupportsArray(&cmds);
if (NS_FAILED(rv)) return rv;
cmds->AppendElement(kNC_Delete);
haveFolderCmds = PR_TRUE;
}
}
else if (NS_SUCCEEDED(source->QueryInterface(nsIMessage::GetIID(), (void**)&message))) {
NS_RELEASE(message); // release now that we know it's a message
if (!haveMessageCmds) {
rv = NS_NewISupportsArray(&cmds);
if (NS_FAILED(rv)) return rv;
cmds->AppendElement(kNC_Delete);
cmds->AppendElement(kNC_Reply);
cmds->AppendElement(kNC_Forward);
haveMessageCmds = PR_TRUE;
}
}
if (cmds) {
nsIEnumerator* cmdEnum;
rv = cmds->Enumerate(&cmdEnum);
if (NS_FAILED(rv)) return rv;
if (commands == nsnull)
commands = dont_QueryInterface(cmdEnum);
else {
nsIEnumerator* unionCmds;
rv = NS_NewUnionEnumerator(commands, cmdEnum, &unionCmds);
if (NS_FAILED(rv)) return rv;
commands = dont_QueryInterface(unionCmds);
}
}
if (NS_SUCCEEDED(source->QueryInterface(nsIMsgFolder::GetIID(), (void**)&folder))) {
NS_RELEASE(folder); // release now that we know it's a folder
rv = NS_NewISupportsArray(&cmds);
if (NS_FAILED(rv)) return rv;
cmds->AppendElement(kNC_Delete);
}
else if (NS_SUCCEEDED(source->QueryInterface(nsIMessage::GetIID(), (void**)&message))) {
NS_RELEASE(message); // release now that we know it's a message
rv = NS_NewISupportsArray(&cmds);
if (NS_FAILED(rv)) return rv;
cmds->AppendElement(kNC_Delete);
cmds->AppendElement(kNC_Reply);
cmds->AppendElement(kNC_Forward);
}
*aResult = commands;
return rv;
if (cmds != nsnull)
return cmds->Enumerate(commands);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsMSGFolderDataSource::DoCommand(nsISupportsArray* aSources,
nsMSGFolderDataSource::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
nsIMsgFolder* folder;
nsIMessage* message;
PRUint32 cnt = aSources->Count();
for (PRUint32 i = 0; i < cnt; i++) {
nsCOMPtr<nsISupports> source = dont_QueryInterface((*aSources)[i]);
if (NS_SUCCEEDED(source->QueryInterface(nsIMsgFolder::GetIID(), (void**)&folder))) {
NS_RELEASE(folder); // release now that we know it's a folder
// we don't care about the arguments -- folder commands are always enabled
if (!(peq(aCommand, kNC_Delete)))
return NS_COMFALSE;
}
else if (NS_SUCCEEDED(source->QueryInterface(nsIMessage::GetIID(), (void**)&message))) {
NS_RELEASE(message); // release now that we know it's a message
// we don't care about the arguments -- message commands are always enabled
if (!(peq(aCommand, kNC_Delete) ||
peq(aCommand, kNC_Reply) ||
peq(aCommand, kNC_Forward)))
return NS_COMFALSE;
}
}
return NS_OK; // succeeded for all sources
}
NS_IMETHODIMP
nsMSGFolderDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments)
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
nsresult rv = NS_OK;
@ -721,8 +723,7 @@ nsMSGFolderDataSource::DoCommand(nsISupportsArray* aSources,
if (peq(aCommand, kNC_Delete)) {
nsIMsgFolder *folder;
if(rv = NS_SUCCEEDED(GetFolderFromMessage(message, &folder)))
{
if (rv = NS_SUCCEEDED(GetFolderFromMessage(message, &folder))) {
rv = folder->DeleteMessage(message);
}
}

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

@ -97,13 +97,16 @@ public:
NS_IMETHOD Flush();
NS_IMETHOD GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult);
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands);
NS_IMETHOD DoCommand(nsISupportsArray* aSources,
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments);
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
NS_IMETHOD OnItemAdded(nsIFolder *parentFolder, nsISupports *item);

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

@ -189,22 +189,31 @@ public:
NS_IMETHOD Flush(void) = 0;
/**
* Returns the intersection of enabled commands for the set of targets
* specified.
* Returns the set of all commands defined for a given source.
*
* @return NS_OK unless a catastrophic error occurs. If the method
* returns NS_OK, you may assume that labels points to a valid (but
* possible empty) nsIRDFCursor object.
*/
NS_IMETHOD GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult) = 0;
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands) = 0;
/**
* Perform the specified command on the resource.
* Returns whether a given command is enabled for a set of sources.
*
* XXX We will probably need to make this interface much more intricate
* to handle arbitrary arguments and selection sets.
* @return NS_OK if command is enabled for all sources
* @return NS_COMFALSE if command is not enabled for any source
*/
NS_IMETHOD DoCommand(nsISupportsArray* aSources,
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments) = 0;
/**
* Perform the specified command on set of sources.
*/
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments) = 0;
nsISupportsArray/*<nsIRDFResource>*/* aArguments) = 0;
};
#endif /* nsIRDFDataSource_h__ */

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

@ -132,13 +132,16 @@ public:
NS_IMETHOD Flush();
NS_IMETHOD GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult);
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands);
NS_IMETHOD DoCommand(nsISupportsArray* aSources,
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments);
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
// nsIRDFCompositeDataSource interface
NS_IMETHOD AddDataSource(nsIRDFDataSource* source);
@ -867,6 +870,7 @@ CompositeDataSourceImpl::Flush()
return NS_OK;
}
#if 0
NS_IMETHODIMP
CompositeDataSourceImpl::GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
@ -893,11 +897,53 @@ CompositeDataSourceImpl::GetEnabledCommands(nsISupportsArray* aSources,
*aResult = commands;
return NS_OK;
}
#endif
NS_IMETHODIMP
CompositeDataSourceImpl::DoCommand(nsISupportsArray* aSources,
CompositeDataSourceImpl::GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** result)
{
nsCOMPtr<nsIEnumerator> commands; // union of enabled commands
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
nsIEnumerator* dsCmds;
nsresult rv = ds->GetAllCommands(source, &dsCmds);
if (NS_SUCCEEDED(rv)) {
if (commands == nsnull) {
commands = dont_QueryInterface(dsCmds);
}
else {
nsIEnumerator* unionCmds;
rv = NS_NewUnionEnumerator(commands, dsCmds, &unionCmds);
if (NS_FAILED(rv)) return rv;
NS_RELEASE(dsCmds);
commands = dont_QueryInterface(unionCmds);
}
}
}
*result = commands;
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
nsresult rv;
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
rv = ds->IsCommandEnabled(aSources, aCommand, aArguments);
if (rv == NS_COMFALSE || NS_FAILED(rv)) return rv;
}
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments)
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);

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

@ -208,13 +208,16 @@ public:
NS_IMETHOD Flush();
NS_IMETHOD GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult);
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands);
NS_IMETHOD DoCommand(nsISupportsArray* aSources,
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments);
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
// Implemenatation methods
Assertion* GetForwardArcs(nsIRDFResource* u);
@ -1444,18 +1447,26 @@ InMemoryDataSource::Flush()
}
NS_IMETHODIMP
InMemoryDataSource::GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult)
InMemoryDataSource::GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
InMemoryDataSource::DoCommand(nsISupportsArray* aSources,
InMemoryDataSource::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
InMemoryDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments)
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;

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

@ -260,15 +260,20 @@ public:
NS_IMETHOD Flush(void);
NS_IMETHOD GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult) {
return mInner->GetEnabledCommands(aSources, aArguments, aResult);
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands) {
return mInner->GetAllCommands(source, commands);
}
NS_IMETHOD DoCommand(nsISupportsArray* aSources,
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments) {
return mInner->IsCommandEnabled(aSources, aCommand, aArguments);
}
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments) {
nsISupportsArray/*<nsIRDFResource>*/* aArguments) {
// XXX Uh oh, this could cause problems wrt. the "dirty" flag
// if it changes the in-memory store's internal state.
return mInner->DoCommand(aSources, aCommand, aArguments);

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

@ -665,13 +665,16 @@ public:
NS_IMETHOD Flush(void);
NS_IMETHOD GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult);
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands);
NS_IMETHOD DoCommand(nsISupportsArray* aSources,
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments);
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
};
@ -799,9 +802,17 @@ BookmarkDataSourceImpl::Flush(void)
NS_IMETHODIMP
BookmarkDataSourceImpl::GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult)
BookmarkDataSourceImpl::GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
BookmarkDataSourceImpl::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;

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

@ -519,23 +519,27 @@ FileSystemDataSource::Flush()
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FileSystemDataSource::GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult)
FileSystemDataSource::GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FileSystemDataSource::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FileSystemDataSource::DoCommand(nsISupportsArray* aSources,
FileSystemDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments)
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;

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

@ -135,13 +135,16 @@ public:
NS_IMETHOD AddObserver(nsIRDFObserver *n);
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
NS_IMETHOD Flush();
NS_IMETHOD GetEnabledCommands(nsISupportsArray* aTargets,
nsISupportsArray* aArguments,
nsIEnumerator** aResult);
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands);
NS_IMETHOD DoCommand(nsISupportsArray* aTargets,
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments);
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
};

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

@ -206,15 +206,22 @@ public:
return mInner->Flush();
}
NS_IMETHOD GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult) {
return mInner->GetEnabledCommands(aSources, aArguments, aResult);
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands) {
return mInner->GetAllCommands(source, commands);
}
NS_IMETHOD DoCommand(nsISupportsArray* aSources,
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments) {
return mInner->IsCommandEnabled(aSources, aCommand, aArguments);
}
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments) {
nsISupportsArray/*<nsIRDFResource>*/* aArguments) {
// XXX Uh oh, this could cause problems wrt. the "dirty" flag
// if it changes the in-memory store's internal state.
return mInner->DoCommand(aSources, aCommand, aArguments);
}

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

@ -198,15 +198,20 @@ public:
NS_IMETHOD Flush(void);
NS_IMETHOD GetEnabledCommands(nsISupportsArray* aSources,
nsISupportsArray* aArguments,
nsIEnumerator** aResult) {
return mInner->GetEnabledCommands(aSources, aArguments, aResult);
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands) {
return mInner->GetAllCommands(source, commands);
}
NS_IMETHOD DoCommand(nsISupportsArray* aSources,
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments) {
return mInner->IsCommandEnabled(aSources, aCommand, aArguments);
}
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray* aArguments) {
nsISupportsArray/*<nsIRDFResource>*/* aArguments) {
// XXX Uh oh, this could cause problems wrt. the "dirty" flag
// if it changes the in-memory store's internal state.
return mInner->DoCommand(aSources, aCommand, aArguments);