NS_IMETHODIMP DeleteCommand::IsCommandEnabled(const char* aCommandName, nsISupports* aCommandRefCon, bool* aIsEnabled) { if (NS_WARN_IF(!aIsEnabled)) { return NS_ERROR_INVALID_ARG; } *aIsEnabled = false; nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); if (!editor) { return NS_OK; } TextEditor* textEditor = editor->AsTextEditor(); MOZ_ASSERT(textEditor); // We can generally delete whenever the selection is editable. However, // cmd_delete doesn't make sense if the selection is collapsed because it's // directionless, which is the same condition under which we can't cut. *aIsEnabled = textEditor->IsSelectionEditable(); if (!nsCRT::strcmp("cmd_delete", aCommandName) && *aIsEnabled) { nsresult rv = textEditor->CanDelete(aIsEnabled); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } } return NS_OK; }
NS_IMETHODIMP SelectionMoveCommands::IsCommandEnabled(const char* aCommandName, nsISupports* aCommandRefCon, bool* aIsEnabled) { NS_ENSURE_ARG_POINTER(aIsEnabled); nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); if (!editor) { *aIsEnabled = false; return NS_OK; } TextEditor* textEditor = editor->AsTextEditor(); MOZ_ASSERT(textEditor); *aIsEnabled = textEditor->IsSelectionEditable(); return NS_OK; }
NS_IMETHODIMP InsertPlaintextCommand::IsCommandEnabled(const char* aCommandName, nsISupports* aCommandRefCon, bool* aIsEnabled) { if (NS_WARN_IF(!aIsEnabled)) { return NS_ERROR_INVALID_ARG; } nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); if (NS_WARN_IF(!editor)) { *aIsEnabled = false; return NS_ERROR_FAILURE; } TextEditor* textEditor = editor->AsTextEditor(); MOZ_ASSERT(textEditor); *aIsEnabled = textEditor->IsSelectionEditable(); return NS_OK; }
NS_IMETHODIMP PasteCommand::IsCommandEnabled(const char* aCommandName, nsISupports* aCommandRefCon, bool* aIsEnabled) { if (NS_WARN_IF(!aIsEnabled)) { return NS_ERROR_INVALID_ARG; } *aIsEnabled = false; nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); if (!editor) { return NS_OK; } TextEditor* textEditor = editor->AsTextEditor(); MOZ_ASSERT(textEditor); if (!textEditor->IsSelectionEditable()) { return NS_OK; } return textEditor->CanPaste(nsIClipboard::kGlobalClipboard, aIsEnabled); }