25779: Add/improve alternate windows cut/copy/paste key bindings: r=brade sr=sfraser.

68747: Remove redundant code in nsHTMLEditor. sr=sfraser.
This commit is contained in:
akkana%netscape.com 2001-02-15 21:51:25 +00:00
Родитель 4cad25cc57
Коммит 109f0be87c
15 изменённых файлов: 143 добавлений и 231 удалений

Просмотреть файл

@ -52,9 +52,9 @@ CPPSRCS = \
nsEditorUtils.cpp \
nsEditProperty.cpp \
nsHTMLEditUtils.cpp \
nsPlaintextDataTransfer.cpp \
nsPlaintextEditor.cpp \
nsSelectionState.cpp \
nsPlaintextDataTransfer.cpp \
nsPlaintextEditor.cpp \
nsSelectionState.cpp \
nsStyleSheetTxns.cpp \
nsTextEditRules.cpp \
PlaceholderTxn.cpp \

Просмотреть файл

@ -176,7 +176,7 @@ NS_IMETHODIMP PlaceholderTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransact
// efficiency hack: no need to remember selection here, as we haven't yet
// finished the inital batch and we know we will be told when the batch ends.
// we can remeber the selection then.
if (gNoisy) { printf("Placeholder txn assimilated %p\n", aTransaction); }
if (gNoisy) { printf("Placeholder txn assimilated %p\n", (void*)aTransaction); }
}
else
{ // merge typing or IME or deletion transactions if the selection matches

Просмотреть файл

@ -118,6 +118,37 @@ nsCutCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
}
NS_IMETHODIMP
nsCutOrDeleteCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
*outCmdEnabled = (editor != nsnull);
return NS_OK;
}
NS_IMETHODIMP
nsCutOrDeleteCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
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;
}
NS_IMETHODIMP
nsCopyCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
{
@ -141,6 +172,37 @@ nsCopyCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
}
NS_IMETHODIMP
nsCopyOrDeleteCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
*outCmdEnabled = (editor != nsnull);
return NS_OK;
}
NS_IMETHODIMP
nsCopyOrDeleteCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
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;
}
NS_IMETHODIMP
nsPasteCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
{

Просмотреть файл

@ -60,7 +60,9 @@ NS_DECL_EDITOR_COMMAND(nsUndoCommand)
NS_DECL_EDITOR_COMMAND(nsRedoCommand)
NS_DECL_EDITOR_COMMAND(nsCutCommand)
NS_DECL_EDITOR_COMMAND(nsCutOrDeleteCommand)
NS_DECL_EDITOR_COMMAND(nsCopyCommand)
NS_DECL_EDITOR_COMMAND(nsCopyOrDeleteCommand)
NS_DECL_EDITOR_COMMAND(nsPasteCommand)
NS_DECL_EDITOR_COMMAND(nsDeleteCommand)
NS_DECL_EDITOR_COMMAND(nsSelectAllCommand)

Просмотреть файл

@ -132,7 +132,9 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager
NS_REGISTER_ONE_COMMAND(nsRedoCommand, "cmd_redo");
NS_REGISTER_ONE_COMMAND(nsCutCommand, "cmd_cut");
NS_REGISTER_ONE_COMMAND(nsCutOrDeleteCommand, "cmd_cutOrDelete");
NS_REGISTER_ONE_COMMAND(nsCopyCommand, "cmd_copy");
NS_REGISTER_ONE_COMMAND(nsCopyOrDeleteCommand, "cmd_copyOrDelete");
NS_REGISTER_ONE_COMMAND(nsSelectAllCommand, "cmd_selectAll");
NS_REGISTER_ONE_COMMAND(nsPasteCommand, "cmd_paste");

Просмотреть файл

@ -620,7 +620,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
nsAutoTxnsConserveSelection dontSpazMySelection(this);
nsAutoString flavor, stuffToPaste;
flavor.AssignWithConversion( bestFlavor ); // just so we can use flavor.Equals()
#ifdef DEBUG_akkana
#ifdef DEBUG_clipboard
printf("Got flavor [%s]\n", bestFlavor);
#endif
if (flavor.EqualsWithConversion(kHTMLMime))
@ -1289,7 +1289,7 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsPlaintextQuotation(PRInt32 aSelectionType)
#endif
return rv;
}
#ifdef DEBUG_akkana
#ifdef DEBUG_clipboard
printf("Got flavor [%s]\n", flav);
#endif
nsAutoString flavor; flavor.AssignWithConversion(flav);

Просмотреть файл

@ -2602,110 +2602,7 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList)
#pragma mark -
#endif
NS_IMETHODIMP
nsHTMLEditor::Undo(PRUint32 aCount)
{
ForceCompositionEnd();
nsresult result = NS_OK;
nsAutoRules beginRulesSniffing(this, kOpUndo, nsIEditor::eNone);
nsTextRulesInfo ruleInfo(nsTextEditRules::kUndo);
nsCOMPtr<nsISelection> selection;
GetSelection(getter_AddRefs(selection));
PRBool cancel, handled;
result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (!cancel && NS_SUCCEEDED(result))
{
result = nsEditor::Undo(aCount);
result = mRules->DidDoAction(selection, &ruleInfo, result);
}
return result;
}
NS_IMETHODIMP
nsHTMLEditor::Redo(PRUint32 aCount)
{
nsresult result = NS_OK;
nsAutoRules beginRulesSniffing(this, kOpRedo, nsIEditor::eNone);
nsTextRulesInfo ruleInfo(nsTextEditRules::kRedo);
nsCOMPtr<nsISelection> selection;
GetSelection(getter_AddRefs(selection));
PRBool cancel, handled;
result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (!cancel && NS_SUCCEEDED(result))
{
result = nsEditor::Redo(aCount);
result = mRules->DidDoAction(selection, &ruleInfo, result);
}
return result;
}
NS_IMETHODIMP nsHTMLEditor::Cut()
{
nsCOMPtr<nsISelection> selection;
nsresult res = GetSelection(getter_AddRefs(selection));
if (!NS_SUCCEEDED(res))
return res;
PRBool isCollapsed;
if (NS_SUCCEEDED(selection->GetIsCollapsed(&isCollapsed)) && isCollapsed)
return NS_ERROR_NOT_AVAILABLE;
res = Copy();
if (NS_SUCCEEDED(res))
res = DeleteSelection(eNone);
return res;
}
NS_IMETHODIMP nsHTMLEditor::CanCut(PRBool &aCanCut)
{
aCanCut = PR_FALSE;
nsCOMPtr<nsISelection> selection;
nsresult res = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(res)) return res;
PRBool isCollapsed;
res = selection->GetIsCollapsed(&isCollapsed);
if (NS_FAILED(res)) return res;
aCanCut = !isCollapsed && IsModifiable();
return NS_OK;
}
NS_IMETHODIMP nsHTMLEditor::Copy()
{
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
if (!ps) return NS_ERROR_NOT_INITIALIZED;
return ps->DoCopy();
}
NS_IMETHODIMP nsHTMLEditor::CanCopy(PRBool &aCanCopy)
{
aCanCopy = PR_FALSE;
nsCOMPtr<nsISelection> selection;
nsresult res = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(res)) return res;
PRBool isCollapsed;
res = selection->GetIsCollapsed(&isCollapsed);
if (NS_FAILED(res)) return res;
aCanCopy = !isCollapsed;
return NS_OK;
}
// Undo, Redo, Cut, CanCut, Copy, CanCopy, all inherited from nsPlaintextEditor
static nsresult SetSelectionAroundHeadChildren(nsCOMPtr<nsISelection> aSelection, nsWeakPtr aDocWeak)
{

Просмотреть файл

@ -249,13 +249,6 @@ public:
NS_IMETHOD GetFlags(PRUint32 *aFlags);
NS_IMETHOD SetFlags(PRUint32 aFlags);
NS_IMETHOD Undo(PRUint32 aCount);
NS_IMETHOD Redo(PRUint32 aCount);
NS_IMETHOD Cut();
NS_IMETHOD CanCut(PRBool &aCanCut);
NS_IMETHOD Copy();
NS_IMETHOD CanCopy(PRBool &aCanCopy);
NS_IMETHOD Paste(PRInt32 aSelectionType);
NS_IMETHOD CanPaste(PRInt32 aSelectionType, PRBool &aCanPaste);

Просмотреть файл

@ -176,7 +176,7 @@ NS_IMETHODIMP PlaceholderTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransact
// efficiency hack: no need to remember selection here, as we haven't yet
// finished the inital batch and we know we will be told when the batch ends.
// we can remeber the selection then.
if (gNoisy) { printf("Placeholder txn assimilated %p\n", aTransaction); }
if (gNoisy) { printf("Placeholder txn assimilated %p\n", (void*)aTransaction); }
}
else
{ // merge typing or IME or deletion transactions if the selection matches

Просмотреть файл

@ -118,6 +118,37 @@ nsCutCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
}
NS_IMETHODIMP
nsCutOrDeleteCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
*outCmdEnabled = (editor != nsnull);
return NS_OK;
}
NS_IMETHODIMP
nsCutOrDeleteCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
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;
}
NS_IMETHODIMP
nsCopyCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
{
@ -141,6 +172,37 @@ nsCopyCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
}
NS_IMETHODIMP
nsCopyOrDeleteCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
*outCmdEnabled = (editor != nsnull);
return NS_OK;
}
NS_IMETHODIMP
nsCopyOrDeleteCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
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;
}
NS_IMETHODIMP
nsPasteCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
{

Просмотреть файл

@ -60,7 +60,9 @@ NS_DECL_EDITOR_COMMAND(nsUndoCommand)
NS_DECL_EDITOR_COMMAND(nsRedoCommand)
NS_DECL_EDITOR_COMMAND(nsCutCommand)
NS_DECL_EDITOR_COMMAND(nsCutOrDeleteCommand)
NS_DECL_EDITOR_COMMAND(nsCopyCommand)
NS_DECL_EDITOR_COMMAND(nsCopyOrDeleteCommand)
NS_DECL_EDITOR_COMMAND(nsPasteCommand)
NS_DECL_EDITOR_COMMAND(nsDeleteCommand)
NS_DECL_EDITOR_COMMAND(nsSelectAllCommand)

Просмотреть файл

@ -132,7 +132,9 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager
NS_REGISTER_ONE_COMMAND(nsRedoCommand, "cmd_redo");
NS_REGISTER_ONE_COMMAND(nsCutCommand, "cmd_cut");
NS_REGISTER_ONE_COMMAND(nsCutOrDeleteCommand, "cmd_cutOrDelete");
NS_REGISTER_ONE_COMMAND(nsCopyCommand, "cmd_copy");
NS_REGISTER_ONE_COMMAND(nsCopyOrDeleteCommand, "cmd_copyOrDelete");
NS_REGISTER_ONE_COMMAND(nsSelectAllCommand, "cmd_selectAll");
NS_REGISTER_ONE_COMMAND(nsPasteCommand, "cmd_paste");

Просмотреть файл

@ -620,7 +620,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
nsAutoTxnsConserveSelection dontSpazMySelection(this);
nsAutoString flavor, stuffToPaste;
flavor.AssignWithConversion( bestFlavor ); // just so we can use flavor.Equals()
#ifdef DEBUG_akkana
#ifdef DEBUG_clipboard
printf("Got flavor [%s]\n", bestFlavor);
#endif
if (flavor.EqualsWithConversion(kHTMLMime))
@ -1289,7 +1289,7 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsPlaintextQuotation(PRInt32 aSelectionType)
#endif
return rv;
}
#ifdef DEBUG_akkana
#ifdef DEBUG_clipboard
printf("Got flavor [%s]\n", flav);
#endif
nsAutoString flavor; flavor.AssignWithConversion(flav);

Просмотреть файл

@ -2602,110 +2602,7 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList)
#pragma mark -
#endif
NS_IMETHODIMP
nsHTMLEditor::Undo(PRUint32 aCount)
{
ForceCompositionEnd();
nsresult result = NS_OK;
nsAutoRules beginRulesSniffing(this, kOpUndo, nsIEditor::eNone);
nsTextRulesInfo ruleInfo(nsTextEditRules::kUndo);
nsCOMPtr<nsISelection> selection;
GetSelection(getter_AddRefs(selection));
PRBool cancel, handled;
result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (!cancel && NS_SUCCEEDED(result))
{
result = nsEditor::Undo(aCount);
result = mRules->DidDoAction(selection, &ruleInfo, result);
}
return result;
}
NS_IMETHODIMP
nsHTMLEditor::Redo(PRUint32 aCount)
{
nsresult result = NS_OK;
nsAutoRules beginRulesSniffing(this, kOpRedo, nsIEditor::eNone);
nsTextRulesInfo ruleInfo(nsTextEditRules::kRedo);
nsCOMPtr<nsISelection> selection;
GetSelection(getter_AddRefs(selection));
PRBool cancel, handled;
result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (!cancel && NS_SUCCEEDED(result))
{
result = nsEditor::Redo(aCount);
result = mRules->DidDoAction(selection, &ruleInfo, result);
}
return result;
}
NS_IMETHODIMP nsHTMLEditor::Cut()
{
nsCOMPtr<nsISelection> selection;
nsresult res = GetSelection(getter_AddRefs(selection));
if (!NS_SUCCEEDED(res))
return res;
PRBool isCollapsed;
if (NS_SUCCEEDED(selection->GetIsCollapsed(&isCollapsed)) && isCollapsed)
return NS_ERROR_NOT_AVAILABLE;
res = Copy();
if (NS_SUCCEEDED(res))
res = DeleteSelection(eNone);
return res;
}
NS_IMETHODIMP nsHTMLEditor::CanCut(PRBool &aCanCut)
{
aCanCut = PR_FALSE;
nsCOMPtr<nsISelection> selection;
nsresult res = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(res)) return res;
PRBool isCollapsed;
res = selection->GetIsCollapsed(&isCollapsed);
if (NS_FAILED(res)) return res;
aCanCut = !isCollapsed && IsModifiable();
return NS_OK;
}
NS_IMETHODIMP nsHTMLEditor::Copy()
{
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
if (!ps) return NS_ERROR_NOT_INITIALIZED;
return ps->DoCopy();
}
NS_IMETHODIMP nsHTMLEditor::CanCopy(PRBool &aCanCopy)
{
aCanCopy = PR_FALSE;
nsCOMPtr<nsISelection> selection;
nsresult res = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(res)) return res;
PRBool isCollapsed;
res = selection->GetIsCollapsed(&isCollapsed);
if (NS_FAILED(res)) return res;
aCanCopy = !isCollapsed;
return NS_OK;
}
// Undo, Redo, Cut, CanCut, Copy, CanCopy, all inherited from nsPlaintextEditor
static nsresult SetSelectionAroundHeadChildren(nsCOMPtr<nsISelection> aSelection, nsWeakPtr aDocWeak)
{

Просмотреть файл

@ -249,13 +249,6 @@ public:
NS_IMETHOD GetFlags(PRUint32 *aFlags);
NS_IMETHOD SetFlags(PRUint32 aFlags);
NS_IMETHOD Undo(PRUint32 aCount);
NS_IMETHOD Redo(PRUint32 aCount);
NS_IMETHOD Cut();
NS_IMETHOD CanCut(PRBool &aCanCut);
NS_IMETHOD Copy();
NS_IMETHOD CanCopy(PRBool &aCanCopy);
NS_IMETHOD Paste(PRInt32 aSelectionType);
NS_IMETHOD CanPaste(PRInt32 aSelectionType, PRBool &aCanPaste);