NS_IMETHODIMP SelectAllCommand::IsCommandEnabled(const char* aCommandName, nsISupports* aCommandRefCon, bool* aIsEnabled) { NS_ENSURE_ARG_POINTER(aIsEnabled); nsresult rv = NS_OK; // You can always select all, unless the selection is editable, // and the editable region is empty! *aIsEnabled = true; nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); if (!editor) { return NS_OK; } // You can select all if there is an editor which is non-empty TextEditor* textEditor = editor->AsTextEditor(); MOZ_ASSERT(textEditor); bool isEmpty = false; rv = textEditor->IsEmpty(&isEmpty); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } *aIsEnabled = !isEmpty; return NS_OK; }