Implement editor cut/copy/paste

This commit is contained in:
akkana%netscape.com 1999-03-10 22:46:15 +00:00
Родитель a9ecaae39b
Коммит 57638ea34c
7 изменённых файлов: 181 добавлений и 9 удалений

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

@ -40,6 +40,7 @@
#include "nsIAtom.h"
#include "nsVoidArray.h"
#include "nsICaret.h"
#include "nsISelectionMgr.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
@ -779,17 +780,71 @@ NS_IMETHODIMP nsEditor::SelectAll()
NS_IMETHODIMP nsEditor::Cut()
{
return NS_ERROR_NOT_IMPLEMENTED;
printf("nsEditor::Cut\n");
nsresult res = Copy();
if (NS_SUCCEEDED(res))
res = DeleteSelection(eLTR);
return res;
}
NS_IMETHODIMP nsEditor::Copy()
{
return NS_ERROR_NOT_IMPLEMENTED;
printf("nsEditor::Copy\n");
// Get the nsSelectionMgr:
// XXX BWEEP BWEEP TEMPORARY!
// The selection mgr needs to be a service.
// See http://bugzilla.mozilla.org/show_bug.cgi?id=3509.
// In the meantime, so I'm not blocked on writing the rest of the code,
// nsSelectionMgr uses the egregious hack of a global variable:
#define EXTERNAL_SELECTION_MGR 1
#ifdef EXTERNAL_SELECTION_MGR
extern nsISelectionMgr* theSelectionMgr;
nsISelectionMgr* selectionMgr = theSelectionMgr;
#else /* EXTERNAL_SELECTION_MGR */
nsISelectionMgr* selectionMgr = 0;
#endif /* EXTERNAL_SELECTION_MGR */
if (!selectionMgr)
{
printf("Can't get selection mgr!\n");
return NS_ERROR_FAILURE;
}
//NS_ADD_REF(theSelectionMgr);
return mPresShell->DoCopy(selectionMgr);
}
NS_IMETHODIMP nsEditor::Paste()
{
return NS_ERROR_NOT_IMPLEMENTED;
printf("nsEditor::Paste\n");
// Get the nsSelectionMgr:
// XXX BWEEP BWEEP TEMPORARY!
// The selection mgr needs to be a service.
// See http://bugzilla.mozilla.org/show_bug.cgi?id=3509.
// In the meantime, so I'm not blocked on writing the rest of the code,
// nsSelectionMgr uses the egregious hack of a global variable:
#ifdef EXTERNAL_SELECTION_MGR
extern nsISelectionMgr* theSelectionMgr;
nsISelectionMgr* selectionMgr = theSelectionMgr;
#else /* EXTERNAL_SELECTION_MGR */
nsISelectionMgr* selectionMgr = 0;
#endif /* EXTERNAL_SELECTION_MGR */
if (!selectionMgr)
{
printf("Can't get selection mgr!\n");
return NS_ERROR_FAILURE;
}
//NS_ADD_REF(theSelectionMgr);
nsString stuffToPaste;
// Now we have the selection mgr. Get its contents as text (for now):
selectionMgr->PasteTextBlocking(&stuffToPaste);
printf("Trying to insert '%s'\n", stuffToPaste.ToNewCString());
// Now let InsertText handle the hard stuff:
return InsertText(stuffToPaste);
}
nsString & nsIEditor::GetTextNodeTag()

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

@ -215,6 +215,37 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
}
break;
// XXX: hard-coded cut
case nsIDOMEvent::VK_X:
if (PR_TRUE==ctrlKey)
{
aProcessed=PR_TRUE;
if (mEditor)
mEditor->Cut();
}
break;
// XXX: hard-coded copy
case nsIDOMEvent::VK_C:
if (PR_TRUE==ctrlKey)
{
aProcessed=PR_TRUE;
if (mEditor)
mEditor->Copy();
}
break;
// XXX: hard-coded paste
case nsIDOMEvent::VK_V:
if (PR_TRUE==ctrlKey)
{
printf("control-v\n");
aProcessed=PR_TRUE;
if (mEditor)
mEditor->Paste();
}
break;
// XXX: hard-coded undo
case nsIDOMEvent::VK_Z:
if (PR_TRUE==ctrlKey)

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

@ -40,6 +40,7 @@
#include "nsIAtom.h"
#include "nsVoidArray.h"
#include "nsICaret.h"
#include "nsISelectionMgr.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
@ -779,17 +780,71 @@ NS_IMETHODIMP nsEditor::SelectAll()
NS_IMETHODIMP nsEditor::Cut()
{
return NS_ERROR_NOT_IMPLEMENTED;
printf("nsEditor::Cut\n");
nsresult res = Copy();
if (NS_SUCCEEDED(res))
res = DeleteSelection(eLTR);
return res;
}
NS_IMETHODIMP nsEditor::Copy()
{
return NS_ERROR_NOT_IMPLEMENTED;
printf("nsEditor::Copy\n");
// Get the nsSelectionMgr:
// XXX BWEEP BWEEP TEMPORARY!
// The selection mgr needs to be a service.
// See http://bugzilla.mozilla.org/show_bug.cgi?id=3509.
// In the meantime, so I'm not blocked on writing the rest of the code,
// nsSelectionMgr uses the egregious hack of a global variable:
#define EXTERNAL_SELECTION_MGR 1
#ifdef EXTERNAL_SELECTION_MGR
extern nsISelectionMgr* theSelectionMgr;
nsISelectionMgr* selectionMgr = theSelectionMgr;
#else /* EXTERNAL_SELECTION_MGR */
nsISelectionMgr* selectionMgr = 0;
#endif /* EXTERNAL_SELECTION_MGR */
if (!selectionMgr)
{
printf("Can't get selection mgr!\n");
return NS_ERROR_FAILURE;
}
//NS_ADD_REF(theSelectionMgr);
return mPresShell->DoCopy(selectionMgr);
}
NS_IMETHODIMP nsEditor::Paste()
{
return NS_ERROR_NOT_IMPLEMENTED;
printf("nsEditor::Paste\n");
// Get the nsSelectionMgr:
// XXX BWEEP BWEEP TEMPORARY!
// The selection mgr needs to be a service.
// See http://bugzilla.mozilla.org/show_bug.cgi?id=3509.
// In the meantime, so I'm not blocked on writing the rest of the code,
// nsSelectionMgr uses the egregious hack of a global variable:
#ifdef EXTERNAL_SELECTION_MGR
extern nsISelectionMgr* theSelectionMgr;
nsISelectionMgr* selectionMgr = theSelectionMgr;
#else /* EXTERNAL_SELECTION_MGR */
nsISelectionMgr* selectionMgr = 0;
#endif /* EXTERNAL_SELECTION_MGR */
if (!selectionMgr)
{
printf("Can't get selection mgr!\n");
return NS_ERROR_FAILURE;
}
//NS_ADD_REF(theSelectionMgr);
nsString stuffToPaste;
// Now we have the selection mgr. Get its contents as text (for now):
selectionMgr->PasteTextBlocking(&stuffToPaste);
printf("Trying to insert '%s'\n", stuffToPaste.ToNewCString());
// Now let InsertText handle the hard stuff:
return InsertText(stuffToPaste);
}
nsString & nsIEditor::GetTextNodeTag()

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

@ -215,6 +215,37 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
}
break;
// XXX: hard-coded cut
case nsIDOMEvent::VK_X:
if (PR_TRUE==ctrlKey)
{
aProcessed=PR_TRUE;
if (mEditor)
mEditor->Cut();
}
break;
// XXX: hard-coded copy
case nsIDOMEvent::VK_C:
if (PR_TRUE==ctrlKey)
{
aProcessed=PR_TRUE;
if (mEditor)
mEditor->Copy();
}
break;
// XXX: hard-coded paste
case nsIDOMEvent::VK_V:
if (PR_TRUE==ctrlKey)
{
printf("control-v\n");
aProcessed=PR_TRUE;
if (mEditor)
mEditor->Paste();
}
break;
// XXX: hard-coded undo
case nsIDOMEvent::VK_Z:
if (PR_TRUE==ctrlKey)

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

@ -73,7 +73,7 @@
// XXX BWEEP BWEEP This is ONLY TEMPORARY until the service manager
// has a way of registering instances
// (see http://bugzilla.mozilla.org/show_bug.cgi?id=3509 ).
static nsISelectionMgr* theSelectionMgr = 0;
nsISelectionMgr* theSelectionMgr = 0;
// BWEEP BWEEP
//

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

@ -30,7 +30,7 @@ NS_IMPL_RELEASE(nsSelectionMgr)
// XXX BWEEP BWEEP This is ONLY TEMPORARY until the service manager
// has a way of registering instances
// (see http://bugzilla.mozilla.org/show_bug.cgi?id=3509 ).
static nsISelectionMgr* theSelectionMgr = 0;
nsISelectionMgr* theSelectionMgr = 0;
// BWEEP BWEEP
nsSelectionMgr::nsSelectionMgr()

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

@ -25,7 +25,7 @@
// XXX BWEEP BWEEP This is ONLY TEMPORARY until the service manager
// has a way of registering instances
// (see http://bugzilla.mozilla.org/show_bug.cgi?id=3509 ).
static nsISelectionMgr* theSelectionMgr = 0;
nsISelectionMgr* theSelectionMgr = 0;
// BWEEP BWEEP
/**