2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsIPlaintextEditor.h"
|
|
|
|
#include "nsIEditorMailSupport.h"
|
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsIClipboard.h"
|
|
|
|
|
|
|
|
#include "nsEditorCommands.h"
|
2010-08-05 11:39:39 -07:00
|
|
|
#include "nsIDocument.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
#define STATE_ENABLED "state_enabled"
|
|
|
|
#define STATE_DATA "state_data"
|
|
|
|
|
|
|
|
|
|
|
|
nsBaseEditorCommand::nsBaseEditorCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsBaseEditorCommand, nsIControllerCommand)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsUndoCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isEnabled, isEditable = false;
|
2011-08-18 08:34:52 -07:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 10:28:03 -07:00
|
|
|
if (isEditable)
|
|
|
|
return editor->CanUndo(&isEnabled, outCmdEnabled);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsUndoCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
return editor->Undo(1);
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsUndoCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsUndoCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canUndo;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,canUndo);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRedoCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isEnabled, isEditable = false;
|
2011-08-18 08:34:52 -07:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 10:28:03 -07:00
|
|
|
if (isEditable)
|
|
|
|
return editor->CanRedo(&isEnabled, outCmdEnabled);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRedoCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
return editor->Redo(1);
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRedoCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRedoCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canUndo;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,canUndo);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClearUndoCommand::IsCommandEnabled(const char * aCommandName,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsISupports *refCon, bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2011-08-17 10:28:03 -07:00
|
|
|
if (editor)
|
|
|
|
return editor->GetIsSelectionEditable(outCmdEnabled);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClearUndoCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
2010-06-17 12:41:16 -07:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
editor->EnableUndo(false); // Turning off undo clears undo/redo stacks.
|
|
|
|
editor->EnableUndo(true); // This re-enables undo/redo.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClearUndoCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, refCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClearUndoCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool enabled;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = IsCommandEnabled(aCommandName, refCon, &enabled);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCutCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
2011-08-17 10:28:03 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isEditable = false;
|
2011-08-18 08:34:52 -07:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 10:28:03 -07:00
|
|
|
if (isEditable)
|
|
|
|
return editor->CanCut(outCmdEnabled);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCutCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
return editor->Cut();
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCutCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCutCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canUndo;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,canUndo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCutOrDeleteCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-08-17 10:28:03 -07:00
|
|
|
if (editor)
|
|
|
|
return editor->GetIsSelectionEditable(outCmdEnabled);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCutOrDeleteCommand::DoCommand(const char *aCommandName,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
nsresult rv = editor->GetSelection(getter_AddRefs(selection));
|
2012-05-18 01:29:39 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && selection && selection->Collapsed()) {
|
2012-05-18 04:32:20 -07:00
|
|
|
return editor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return editor->Cut();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCutOrDeleteCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCutOrDeleteCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canUndo;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,canUndo);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCopyCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
2011-12-30 09:42:04 -08:00
|
|
|
return editor->CanCopy(outCmdEnabled);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCopyCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
return editor->Copy();
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCopyCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCopyCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canUndo;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,canUndo);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCopyOrDeleteCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-08-17 10:28:03 -07:00
|
|
|
if (editor)
|
|
|
|
return editor->GetIsSelectionEditable(outCmdEnabled);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCopyOrDeleteCommand::DoCommand(const char *aCommandName,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
nsresult rv = editor->GetSelection(getter_AddRefs(selection));
|
2012-05-18 01:29:39 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && selection && selection->Collapsed()) {
|
2012-05-18 04:32:20 -07:00
|
|
|
return editor->DeleteSelection(nsIEditor::eNextWord, nsIEditor::eStrip);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return editor->Copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCopyOrDeleteCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCopyOrDeleteCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canUndo;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,canUndo);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteCommand::IsCommandEnabled(const char *aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
2011-08-17 10:28:03 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isEditable = false;
|
2011-08-18 08:34:52 -07:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 10:28:03 -07:00
|
|
|
if (isEditable)
|
|
|
|
return editor->CanPaste(nsIClipboard::kGlobalClipboard, outCmdEnabled);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return editor->Paste(nsIClipboard::kGlobalClipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canUndo;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,canUndo);
|
|
|
|
}
|
|
|
|
|
2010-01-10 17:45:45 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteTransferableCommand::IsCommandEnabled(const char *aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2010-01-10 17:45:45 -08:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
2011-08-17 10:28:03 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isEditable = false;
|
2011-08-18 08:34:52 -07:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 10:28:03 -07:00
|
|
|
if (isEditable)
|
|
|
|
return editor->CanPasteTransferable(nsnull, outCmdEnabled);
|
|
|
|
}
|
2010-01-10 17:45:45 -08:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2010-01-10 17:45:45 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteTransferableCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteTransferableCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2010-01-10 17:45:45 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
aParams->GetISupportsValue("transferable", getter_AddRefs(supports));
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(supports, NS_ERROR_FAILURE);
|
2010-01-10 17:45:45 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsITransferable> trans = do_QueryInterface(supports);
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE);
|
2010-01-10 17:45:45 -08:00
|
|
|
|
|
|
|
return editor->PasteTransferable(trans);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteTransferableCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2010-01-10 17:45:45 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsITransferable> trans;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
aParams->GetISupportsValue("transferable", getter_AddRefs(supports));
|
|
|
|
if (supports) {
|
|
|
|
trans = do_QueryInterface(supports);
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE);
|
2010-01-10 17:45:45 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canPaste;
|
2010-01-10 17:45:45 -08:00
|
|
|
nsresult rv = editor->CanPasteTransferable(trans, &canPaste);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canPaste);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSwitchTextDirectionCommand::IsCommandEnabled(const char *aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-08-17 10:28:03 -07:00
|
|
|
if (editor)
|
|
|
|
return editor->GetIsSelectionEditable(outCmdEnabled);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSwitchTextDirectionCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return editor->SwitchTextDirection();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSwitchTextDirectionCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSwitchTextDirectionCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canSwitchTextDirection = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canSwitchTextDirection);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canSwitchTextDirection);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDeleteCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2011-08-17 10:28:03 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// we can delete when we can cut
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(editor, NS_OK);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isEditable = false;
|
2011-08-18 08:34:52 -07:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 10:28:03 -07:00
|
|
|
|
|
|
|
if (!isEditable)
|
|
|
|
return NS_OK;
|
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_delete"))
|
2007-03-22 10:30:00 -07:00
|
|
|
return editor->CanCut(outCmdEnabled);
|
2012-05-22 02:37:17 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_forwardDelete"))
|
|
|
|
return editor->CanCut(outCmdEnabled);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_deleteCharBackward"))
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_deleteCharForward"))
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_deleteWordBackward"))
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_deleteWordForward"))
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_deleteToBeginningOfLine"))
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_deleteToEndOfLine"))
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDeleteCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIEditor::EDirection deleteDir = nsIEditor::eNone;
|
|
|
|
|
|
|
|
if (!nsCRT::strcmp("cmd_delete",aCommandName))
|
|
|
|
deleteDir = nsIEditor::ePrevious;
|
2012-05-22 02:37:17 -07:00
|
|
|
else if (!nsCRT::strcmp("cmd_forwardDelete", aCommandName))
|
|
|
|
deleteDir = nsIEditor::eNext;
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp("cmd_deleteCharBackward",aCommandName))
|
|
|
|
deleteDir = nsIEditor::ePrevious;
|
|
|
|
else if (!nsCRT::strcmp("cmd_deleteCharForward",aCommandName))
|
|
|
|
deleteDir = nsIEditor::eNext;
|
|
|
|
else if (!nsCRT::strcmp("cmd_deleteWordBackward",aCommandName))
|
|
|
|
deleteDir = nsIEditor::ePreviousWord;
|
|
|
|
else if (!nsCRT::strcmp("cmd_deleteWordForward",aCommandName))
|
|
|
|
deleteDir = nsIEditor::eNextWord;
|
|
|
|
else if (!nsCRT::strcmp("cmd_deleteToBeginningOfLine",aCommandName))
|
|
|
|
deleteDir = nsIEditor::eToBeginningOfLine;
|
|
|
|
else if (!nsCRT::strcmp("cmd_deleteToEndOfLine",aCommandName))
|
|
|
|
deleteDir = nsIEditor::eToEndOfLine;
|
|
|
|
|
2012-05-10 07:54:33 -07:00
|
|
|
return editor->DeleteSelection(deleteDir, nsIEditor::eStrip);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDeleteCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDeleteCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canUndo;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,canUndo);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectAllCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
|
2011-09-23 14:44:53 -07:00
|
|
|
nsresult rv = NS_OK;
|
2010-11-16 12:45:49 -08:00
|
|
|
// You can always select all, unless the selection is editable,
|
|
|
|
// and the editable region is empty!
|
|
|
|
*outCmdEnabled = true;
|
2011-12-30 09:42:04 -08:00
|
|
|
bool docIsEmpty;
|
2010-11-16 12:45:49 -08:00
|
|
|
|
2011-09-23 14:44:53 -07:00
|
|
|
// you can select all if there is an editor which is non-empty
|
2011-09-22 15:09:44 -07:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-09-23 14:44:53 -07:00
|
|
|
if (editor) {
|
2011-12-30 09:42:04 -08:00
|
|
|
rv = editor->GetDocumentIsEmpty(&docIsEmpty);
|
2011-09-23 14:44:53 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-12-30 09:42:04 -08:00
|
|
|
*outCmdEnabled = !docIsEmpty;
|
2010-11-16 12:45:49 -08:00
|
|
|
}
|
2011-09-23 14:44:53 -07:00
|
|
|
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectAllCommand::DoCommand(const char *aCommandName,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
return editor->SelectAll();
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectAllCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectAllCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canUndo;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,canUndo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionMoveCommands::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *aCommandRefCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-08-17 10:28:03 -07:00
|
|
|
if (editor)
|
|
|
|
return editor->GetIsSelectionEditable(outCmdEnabled);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionMoveCommands::DoCommand(const char *aCommandName,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-05 11:39:39 -07:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
editor->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
|
|
|
if (doc) {
|
|
|
|
// Most of the commands below (possibly all of them) need layout to
|
|
|
|
// be up to date.
|
|
|
|
doc->FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsISelectionController> selCont;
|
|
|
|
nsresult rv = editor->GetSelectionController(getter_AddRefs(selCont));
|
2010-06-17 13:44:35 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(selCont, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// complete scroll commands
|
|
|
|
if (!nsCRT::strcmp(aCommandName,"cmd_scrollTop"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->CompleteScroll(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_scrollBottom"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->CompleteScroll(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// complete move commands
|
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_moveTop"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->CompleteMove(false, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_moveBottom"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->CompleteMove(true, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectTop"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->CompleteMove(false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectBottom"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->CompleteMove(true, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// line move commands
|
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_lineNext"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->LineMove(true, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_linePrevious"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->LineMove(false, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectLineNext"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->LineMove(true, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectLinePrevious"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->LineMove(false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// character move commands
|
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_charPrevious"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->CharacterMove(false, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_charNext"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->CharacterMove(true, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectCharPrevious"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->CharacterMove(false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectCharNext"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->CharacterMove(true, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// intra line move commands
|
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_beginLine"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->IntraLineMove(false, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_endLine"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->IntraLineMove(true, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectBeginLine"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->IntraLineMove(false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectEndLine"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->IntraLineMove(true, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// word move commands
|
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_wordPrevious"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->WordMove(false, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_wordNext"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->WordMove(true, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectWordPrevious"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->WordMove(false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectWordNext"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->WordMove(true, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// scroll page commands
|
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_scrollPageUp"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->ScrollPage(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_scrollPageDown"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->ScrollPage(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// scroll line commands
|
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_scrollLineUp"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->ScrollLine(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_scrollLineDown"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->ScrollLine(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// page move commands
|
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_movePageUp"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->PageMove(false, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_movePageDown"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->PageMove(true, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectPageUp"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->PageMove(false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!nsCRT::strcmp(aCommandName,"cmd_selectPageDown"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return selCont->PageMove(true, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionMoveCommands::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionMoveCommands::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *aCommandRefCon)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canUndo;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED,canUndo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInsertPlaintextCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (editor)
|
2011-08-17 10:28:03 -07:00
|
|
|
return editor->GetIsSelectionEditable(outCmdEnabled);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInsertPlaintextCommand::DoCommand(const char *aCommandName,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInsertPlaintextCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPlaintextEditor> editor = do_QueryInterface(refCon);
|
2010-06-17 13:40:48 -07:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Get text to insert from command params
|
|
|
|
nsAutoString text;
|
|
|
|
nsresult rv = aParams->GetStringValue(STATE_DATA, text);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!text.IsEmpty())
|
|
|
|
return editor->InsertText(text);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInsertPlaintextCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteQuotationCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *refCon,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outCmdEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(refCon);
|
|
|
|
if (editor && mailEditor) {
|
|
|
|
PRUint32 flags;
|
|
|
|
editor->GetFlags(&flags);
|
|
|
|
if (!(flags & nsIPlaintextEditor::eEditorSingleLineMask))
|
|
|
|
return editor->CanPaste(nsIClipboard::kGlobalClipboard, outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*outCmdEnabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteQuotationCommand::DoCommand(const char *aCommandName,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(refCon);
|
|
|
|
if (mailEditor)
|
|
|
|
return mailEditor->PasteAsQuotation(nsIClipboard::kGlobalClipboard);
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteQuotationCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(refCon);
|
|
|
|
if (mailEditor)
|
|
|
|
return mailEditor->PasteAsQuotation(nsIClipboard::kGlobalClipboard);
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPasteQuotationCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams,
|
|
|
|
nsISupports *refCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
|
|
if (editor)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool enabled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
editor->CanPaste(nsIClipboard::kGlobalClipboard, &enabled);
|
|
|
|
aParams->SetBooleanValue(STATE_ENABLED, enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|