2000-02-16 04:33:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "nsCRT.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsString.h"
|
2000-02-16 04:33:03 +03:00
|
|
|
|
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsIEditorMailSupport.h"
|
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsIPresShell.h"
|
2000-04-15 03:38:21 +04:00
|
|
|
#include "nsIClipboard.h"
|
2000-02-16 04:33:03 +03:00
|
|
|
|
|
|
|
#include "nsEditorCommands.h"
|
|
|
|
|
|
|
|
|
2000-05-06 03:20:21 +04:00
|
|
|
nsBaseEditorCommand::nsBaseEditorCommand()
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
2000-05-06 03:20:21 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsBaseEditorCommand, NS_GET_IID(nsIControllerCommand));
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2000-05-02 01:49:52 +04:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsUndoCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_FALSE;
|
|
|
|
if (aEditor)
|
|
|
|
{
|
|
|
|
PRBool isEnabled;
|
2001-04-07 04:45:26 +04:00
|
|
|
return aEditor->CanUndo(&isEnabled, outCmdEnabled);
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsUndoCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
if (aEditor)
|
|
|
|
return aEditor->Undo(1);
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsRedoCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_FALSE;
|
|
|
|
if (aEditor)
|
|
|
|
{
|
|
|
|
PRBool isEnabled;
|
2001-04-07 04:45:26 +04:00
|
|
|
return aEditor->CanRedo(&isEnabled, outCmdEnabled);
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsRedoCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
if (aEditor)
|
|
|
|
return aEditor->Redo(1);
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCutCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_FALSE;
|
|
|
|
if (aEditor)
|
2001-04-07 04:45:26 +04:00
|
|
|
return aEditor->CanCut(outCmdEnabled);
|
2000-02-16 04:33:03 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCutCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
if (aEditor)
|
|
|
|
return aEditor->Cut();
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-16 00:51:25 +03:00
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCutOrDeleteCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled)
|
2001-02-16 00:51:25 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2001-02-16 00:51:25 +03:00
|
|
|
*outCmdEnabled = (editor != nsnull);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCutOrDeleteCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon)
|
2001-02-16 00:51:25 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2001-02-16 00:51:25 +03:00
|
|
|
if (editor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
nsresult rv = editor->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (NS_SUCCEEDED(rv) && selection)
|
|
|
|
{
|
|
|
|
PRBool isCollapsed;
|
|
|
|
rv = selection->GetIsCollapsed(&isCollapsed);
|
|
|
|
if (NS_SUCCEEDED(rv) && isCollapsed)
|
|
|
|
return editor->DeleteSelection(nsIEditor::eNext);
|
|
|
|
}
|
|
|
|
return editor->Cut();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCopyCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_FALSE;
|
|
|
|
if (aEditor)
|
2001-04-07 04:45:26 +04:00
|
|
|
return aEditor->CanCopy(outCmdEnabled);
|
2000-02-16 04:33:03 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCopyCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
if (aEditor)
|
|
|
|
return aEditor->Copy();
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-16 00:51:25 +03:00
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCopyOrDeleteCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled)
|
2001-02-16 00:51:25 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2001-02-16 00:51:25 +03:00
|
|
|
*outCmdEnabled = (editor != nsnull);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCopyOrDeleteCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon)
|
2001-02-16 00:51:25 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2001-02-16 00:51:25 +03:00
|
|
|
if (editor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
nsresult rv = editor->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (NS_SUCCEEDED(rv) && selection)
|
|
|
|
{
|
|
|
|
PRBool isCollapsed;
|
|
|
|
rv = selection->GetIsCollapsed(&isCollapsed);
|
|
|
|
if (NS_SUCCEEDED(rv) && isCollapsed)
|
|
|
|
return editor->DeleteSelection(nsIEditor::eNext);
|
|
|
|
}
|
|
|
|
return editor->Copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsPasteCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_FALSE;
|
|
|
|
if (aEditor)
|
2001-04-07 04:45:26 +04:00
|
|
|
return aEditor->CanPaste(nsIClipboard::kGlobalClipboard, outCmdEnabled);
|
2000-02-16 04:33:03 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsPasteCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
if (!aEditor)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
2001-04-05 03:48:03 +04:00
|
|
|
nsAutoString cmdString(aCommandName);
|
2000-04-18 11:44:58 +04:00
|
|
|
if (cmdString.EqualsWithConversion("cmd_paste"))
|
2000-04-15 03:38:21 +04:00
|
|
|
rv = aEditor->Paste(nsIClipboard::kGlobalClipboard);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_pasteQuote"))
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(aEditor, &rv);
|
|
|
|
if (mailEditor)
|
2000-04-15 03:38:21 +04:00
|
|
|
rv = mailEditor->PasteAsQuotation(nsIClipboard::kGlobalClipboard);
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsDeleteCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_FALSE;
|
|
|
|
// we can delete when we can cut
|
|
|
|
if (!aEditor)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2001-04-05 03:48:03 +04:00
|
|
|
nsAutoString cmdString(aCommandName);
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2000-04-18 11:44:58 +04:00
|
|
|
if (cmdString.EqualsWithConversion("cmd_delete"))
|
2001-04-07 04:45:26 +04:00
|
|
|
rv = aEditor->CanCut(outCmdEnabled);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteCharBackward"))
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_TRUE;
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteCharForward"))
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_TRUE;
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteWordBackward"))
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_TRUE;
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteWordForward"))
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_TRUE;
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteToBeginningOfLine"))
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_TRUE;
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteToEndOfLine"))
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_TRUE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsDeleteCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
if (!aEditor)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-04-05 03:48:03 +04:00
|
|
|
nsAutoString cmdString(aCommandName);
|
2000-02-16 04:33:03 +03:00
|
|
|
|
|
|
|
nsIEditor::EDirection deleteDir = nsIEditor::eNone;
|
|
|
|
|
2000-04-18 11:44:58 +04:00
|
|
|
if (cmdString.EqualsWithConversion("cmd_delete"))
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::ePrevious;
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteCharBackward"))
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::ePrevious;
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteCharForward"))
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::eNext;
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteWordBackward"))
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::ePreviousWord;
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteWordForward"))
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::eNextWord;
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteToBeginningOfLine"))
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::eToBeginningOfLine;
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_deleteToEndOfLine"))
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::eToEndOfLine;
|
|
|
|
|
|
|
|
return aEditor->DeleteSelection(deleteDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsSelectAllCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_FALSE;
|
|
|
|
if (aEditor)
|
|
|
|
*outCmdEnabled = PR_TRUE; // you can always select all
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsSelectAllCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
if (aEditor)
|
|
|
|
return aEditor->SelectAll();
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsSelectionMoveCommands::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
*outCmdEnabled = PR_FALSE;
|
|
|
|
if (!aEditor)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*outCmdEnabled = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-05 03:48:03 +04:00
|
|
|
nsSelectionMoveCommands::DoCommand(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> aEditor = do_QueryInterface(aCommandRefCon);
|
2000-02-16 04:33:03 +03:00
|
|
|
if (!aEditor)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv;
|
2000-04-27 11:37:12 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsISelectionController> selCont;
|
|
|
|
rv = aEditor->GetSelectionController(getter_AddRefs(selCont));
|
|
|
|
if (NS_FAILED(rv) || !selCont)
|
|
|
|
return rv?rv:NS_ERROR_FAILURE;
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2001-04-05 03:48:03 +04:00
|
|
|
nsAutoString cmdString(aCommandName);
|
2000-02-16 04:33:03 +03:00
|
|
|
|
|
|
|
// complete scroll commands
|
2000-04-18 11:44:58 +04:00
|
|
|
if (cmdString.EqualsWithConversion("cmd_scrollTop"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->CompleteScroll(PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_scrollBottom"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->CompleteScroll(PR_TRUE);
|
|
|
|
|
|
|
|
// complete move commands
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_moveTop"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->CompleteMove(PR_FALSE, PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_moveBottom"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->CompleteMove(PR_TRUE, PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectTop"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->CompleteMove(PR_FALSE, PR_TRUE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectBottom"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->CompleteMove(PR_TRUE, PR_TRUE);
|
|
|
|
|
|
|
|
// line move commands
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_lineNext"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->LineMove(PR_TRUE, PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_linePrevious"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->LineMove(PR_FALSE, PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectLineNext"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->LineMove(PR_TRUE, PR_TRUE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectLinePrevious"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->LineMove(PR_FALSE, PR_TRUE);
|
|
|
|
|
|
|
|
// character move commands
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_charPrevious"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->CharacterMove(PR_FALSE, PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_charNext"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->CharacterMove(PR_TRUE, PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectCharPrevious"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->CharacterMove(PR_FALSE, PR_TRUE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectCharNext"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->CharacterMove(PR_TRUE, PR_TRUE);
|
|
|
|
|
|
|
|
// intra line move commands
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_beginLine"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->IntraLineMove(PR_FALSE, PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_endLine"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->IntraLineMove(PR_TRUE, PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectBeginLine"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->IntraLineMove(PR_FALSE, PR_TRUE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectEndLine"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->IntraLineMove(PR_TRUE, PR_TRUE);
|
|
|
|
|
|
|
|
// word move commands
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_wordPrevious"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->WordMove(PR_FALSE, PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_wordNext"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->WordMove(PR_TRUE, PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectWordPrevious"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->WordMove(PR_FALSE, PR_TRUE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectWordNext"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->WordMove(PR_TRUE, PR_TRUE);
|
|
|
|
|
|
|
|
// scroll page commands
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_scrollPageUp"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->ScrollPage(PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_scrollPageDown"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->ScrollPage(PR_TRUE);
|
|
|
|
|
|
|
|
// scroll line commands
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_scrollLineUp"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->ScrollLine(PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_scrollLineDown"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->ScrollLine(PR_TRUE);
|
|
|
|
|
|
|
|
// page move commands
|
2001-02-26 18:37:25 +03:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_movePageUp"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->PageMove(PR_FALSE, PR_FALSE);
|
2001-02-26 18:37:25 +03:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_movePageDown"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->PageMove(PR_TRUE, PR_FALSE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectPageUp"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->PageMove(PR_FALSE, PR_TRUE);
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (cmdString.EqualsWithConversion("cmd_selectPageDown"))
|
2000-02-16 04:33:03 +03:00
|
|
|
return selCont->PageMove(PR_TRUE, PR_TRUE);
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|