From 18e706dc0d0508628bbb590a546dae3a840b850f Mon Sep 17 00:00:00 2001 From: "sfraser%netscape.com" Date: Mon, 1 May 2000 01:33:22 +0000 Subject: [PATCH] Add an UpdateCommandState method to the command maanger. --- .../document/public/nsIControllerCommand.idl | 8 +++++ .../src/nsControllerCommandManager.cpp | 34 ++++++++++++++++++- rdf/base/idl/nsIControllerCommand.idl | 8 +++++ .../src/nsControllerCommandManager.cpp | 34 ++++++++++++++++++- 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/content/xul/document/public/nsIControllerCommand.idl b/content/xul/document/public/nsIControllerCommand.idl index 432717d61674..773353b860ae 100644 --- a/content/xul/document/public/nsIControllerCommand.idl +++ b/content/xul/document/public/nsIControllerCommand.idl @@ -131,6 +131,14 @@ interface nsIControllerCommandManager : nsISupports */ boolean isCommandEnabled(in wstring aCommandName, in nsISupports aCommandRefCon); + /** + * Tell the command to udpate its state (if it is a state updating command) + * + * @param aCommandName the name of the command to update + * @param aCommandRefCon the command context data + */ + void updateCommandState(in wstring aCommandName, in nsISupports aCommandRefCon); + /** * Get whether the named command is supported. * diff --git a/content/xul/document/src/nsControllerCommandManager.cpp b/content/xul/document/src/nsControllerCommandManager.cpp index e2645f65ffba..db485e7035bd 100644 --- a/content/xul/document/src/nsControllerCommandManager.cpp +++ b/content/xul/document/src/nsControllerCommandManager.cpp @@ -118,7 +118,39 @@ nsControllerCommandManager::IsCommandEnabled(const PRUnichar *aCommandName, nsIS return commandHandler->IsCommandEnabled(aCommandName, aCommandRefCon, aResult); } -/* boolean supportsCommand (in wstring command); */ + +NS_IMETHODIMP +nsControllerCommandManager::UpdateCommandState(const PRUnichar *aCommandName, nsISupports *aCommandRefCon) +{ + NS_ENSURE_ARG_POINTER(aCommandName); + + // find the command + nsCOMPtr commandHandler; + FindCommandHandler(aCommandName, getter_AddRefs(commandHandler)); + if (!commandHandler) + { +#if DEBUG + nsCAutoString msg("Controller command manager asked to update the state of a command that it does not handle -- "); + msg.AppendWithConversion(aCommandName); + NS_WARNING(msg); +#endif + return NS_OK; // we don't handle this command + } + + nsCOMPtr stateCommand = do_QueryInterface(commandHandler); + if (!stateCommand) + { +#if DEBUG + nsCAutoString msg("Controller command manager asked to update the state of a command that doesn't do state updating -- "); + msg.AppendWithConversion(aCommandName); + NS_WARNING(msg); +#endif + return NS_ERROR_NO_INTERFACE; + } + + return stateCommand->UpdateCommandState(aCommandName, aCommandRefCon); +} + NS_IMETHODIMP nsControllerCommandManager::SupportsCommand(const PRUnichar *aCommandName, nsISupports *aCommandRefCon, PRBool *aResult) { diff --git a/rdf/base/idl/nsIControllerCommand.idl b/rdf/base/idl/nsIControllerCommand.idl index 432717d61674..773353b860ae 100644 --- a/rdf/base/idl/nsIControllerCommand.idl +++ b/rdf/base/idl/nsIControllerCommand.idl @@ -131,6 +131,14 @@ interface nsIControllerCommandManager : nsISupports */ boolean isCommandEnabled(in wstring aCommandName, in nsISupports aCommandRefCon); + /** + * Tell the command to udpate its state (if it is a state updating command) + * + * @param aCommandName the name of the command to update + * @param aCommandRefCon the command context data + */ + void updateCommandState(in wstring aCommandName, in nsISupports aCommandRefCon); + /** * Get whether the named command is supported. * diff --git a/rdf/content/src/nsControllerCommandManager.cpp b/rdf/content/src/nsControllerCommandManager.cpp index e2645f65ffba..db485e7035bd 100644 --- a/rdf/content/src/nsControllerCommandManager.cpp +++ b/rdf/content/src/nsControllerCommandManager.cpp @@ -118,7 +118,39 @@ nsControllerCommandManager::IsCommandEnabled(const PRUnichar *aCommandName, nsIS return commandHandler->IsCommandEnabled(aCommandName, aCommandRefCon, aResult); } -/* boolean supportsCommand (in wstring command); */ + +NS_IMETHODIMP +nsControllerCommandManager::UpdateCommandState(const PRUnichar *aCommandName, nsISupports *aCommandRefCon) +{ + NS_ENSURE_ARG_POINTER(aCommandName); + + // find the command + nsCOMPtr commandHandler; + FindCommandHandler(aCommandName, getter_AddRefs(commandHandler)); + if (!commandHandler) + { +#if DEBUG + nsCAutoString msg("Controller command manager asked to update the state of a command that it does not handle -- "); + msg.AppendWithConversion(aCommandName); + NS_WARNING(msg); +#endif + return NS_OK; // we don't handle this command + } + + nsCOMPtr stateCommand = do_QueryInterface(commandHandler); + if (!stateCommand) + { +#if DEBUG + nsCAutoString msg("Controller command manager asked to update the state of a command that doesn't do state updating -- "); + msg.AppendWithConversion(aCommandName); + NS_WARNING(msg); +#endif + return NS_ERROR_NO_INTERFACE; + } + + return stateCommand->UpdateCommandState(aCommandName, aCommandRefCon); +} + NS_IMETHODIMP nsControllerCommandManager::SupportsCommand(const PRUnichar *aCommandName, nsISupports *aCommandRefCon, PRBool *aResult) {