Example #1
0
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;
}