undo off by default, Emacs-style undo added
svn: r1719
This commit is contained in:
parent
f695e16a52
commit
e422152bc4
|
@ -79,7 +79,8 @@
|
|||
(inherit get-max-width set-max-width get-admin
|
||||
get-keymap get-style-list
|
||||
set-modified set-filename
|
||||
get-file put-file)
|
||||
get-file put-file
|
||||
get-max-undo-history)
|
||||
(define canvases null)
|
||||
(define active-canvas #f)
|
||||
(define auto-set-wrap? #f)
|
||||
|
@ -360,6 +361,7 @@
|
|||
[else text%]))])
|
||||
(send e set-keymap (get-keymap))
|
||||
(send e set-style-list (get-style-list))
|
||||
(send e set-max-undo-history (get-max-undo-history))
|
||||
e))))])
|
||||
|
||||
(apply super-make-object args)))
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
;; The REPL buffer class
|
||||
(define esq:text%
|
||||
(class100 text% ()
|
||||
(inherit insert last-position get-text erase change-style clear-undos)
|
||||
(inherit insert last-position get-text erase change-style clear-undos set-max-undo-history)
|
||||
(rename [super-on-char on-char])
|
||||
(private-field [prompt-pos 0] [locked? #f])
|
||||
(augment
|
||||
|
@ -62,7 +62,8 @@
|
|||
(send (make-object wx:style-delta% 'change-italic) set-delta-foreground "RED")
|
||||
s e)))
|
||||
(insert "The current input port always returns eof.") (insert #\newline)
|
||||
(new-prompt))))
|
||||
(new-prompt)
|
||||
(set-max-undo-history 'forever))))
|
||||
|
||||
;; GUI creation
|
||||
(define frame (make-object (class100 frame% args
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
(define text-field-text%
|
||||
(class100 text% (cb ret-cb control set-cb-mgrs!)
|
||||
(rename [super-on-char on-char])
|
||||
(inherit get-text last-position)
|
||||
(inherit get-text last-position set-max-undo-history)
|
||||
(private-field
|
||||
[return-cb ret-cb])
|
||||
(private-field
|
||||
|
@ -60,7 +60,8 @@
|
|||
(lambda () (set! block-callback (sub1 block-callback)))))
|
||||
(lambda ()
|
||||
(set! block-callback 0)))
|
||||
(super-init))))
|
||||
(super-init)
|
||||
(set-max-undo-history 'forever))))
|
||||
|
||||
(define wx-text-editor-canvas%
|
||||
(class100* wx-editor-canvas% (wx-text-editor-canvas<%>) (mred proxy control parent style)
|
||||
|
|
|
@ -605,7 +605,7 @@
|
|||
|
||||
(make-fixed-width c message-editor #t return-bitmap)
|
||||
(send message-editor set-paste-text-only #t)
|
||||
(send message-editor set-max-undo-history 5000) ;; Many undos!
|
||||
(send message-editor set-max-undo-history 'forever)
|
||||
(send c set-editor message-editor)
|
||||
|
||||
(activate-spelling message-editor)
|
||||
|
|
|
@ -155,6 +155,7 @@
|
|||
;;;;;; Undo tests
|
||||
|
||||
(define e (make-object text%))
|
||||
(send e set-max-undo-history 1024)
|
||||
|
||||
(stv e insert "Hello")
|
||||
(st #t e is-modified?)
|
||||
|
@ -173,9 +174,10 @@
|
|||
(stv e redo)
|
||||
(st #f e is-modified?)
|
||||
(stv e undo)
|
||||
(st "" e get-text)
|
||||
(stv e set-modified #f)
|
||||
(st #f e is-modified?)
|
||||
(stv e redo)
|
||||
(stv e redo) ; somehow cancel's redo action to set modified to #f...
|
||||
(st #t e is-modified?)
|
||||
(st "Hello" e get-text)
|
||||
(define undone? #f)
|
||||
|
@ -435,5 +437,43 @@
|
|||
|
||||
;; ----------------------------------------
|
||||
|
||||
;; More undo tests, checking mainly that internal undo array grows
|
||||
;; correctly
|
||||
|
||||
(define (test-undos local-undo?)
|
||||
|
||||
(define e (new text%))
|
||||
|
||||
(send e insert (make-string 1024 #\x))
|
||||
|
||||
(send e set-max-undo-history 10240)
|
||||
(send e set-position 0)
|
||||
|
||||
(let loop ([n 1024])
|
||||
(unless (zero? n)
|
||||
(send e set-position (add1 (send e get-start-position)))
|
||||
(send e delete)
|
||||
(send e insert #\y)
|
||||
(when local-undo?
|
||||
(send e undo)
|
||||
(send e redo))
|
||||
(loop (sub1 n))))
|
||||
|
||||
(st (make-string 1024 #\y) e get-text 0 'eof)
|
||||
|
||||
(let loop ([n 1023])
|
||||
(unless (zero? n)
|
||||
(send e undo)
|
||||
(send e undo)
|
||||
(loop (sub1 n))))
|
||||
|
||||
(st (string-append "y" (make-string 1023 #\x) )
|
||||
e get-text 0 'eof))
|
||||
|
||||
(test-undos #f)
|
||||
(test-undos #t)
|
||||
|
||||
;; ----------------------------------------
|
||||
|
||||
(report-errs)
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
|
||||
Version 300.3
|
||||
Default max undo history for an editor<%> is 0; use
|
||||
set-max-undo-history to enable undo
|
||||
Added |MrEd:emacsUndo| low-level preference
|
||||
|
||||
Version 300.1
|
||||
Disabled menu-item shortcuts stay effective (to just beep)
|
||||
|
||||
|
|
|
@ -87,6 +87,34 @@ void wxChangeRecord::DropSetUnmodified(void)
|
|||
{
|
||||
}
|
||||
|
||||
Bool wxChangeRecord::IsComposite()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxChangeRecordId *wxChangeRecord::GetId()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int wxChangeRecord::GetParity()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
wxChangeRecord *wxChangeRecord::Inverse()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxChangeRecord::GetName()
|
||||
{
|
||||
return "???";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
wxSchemeModifyRecord::wxSchemeModifyRecord(void *proc)
|
||||
{
|
||||
p = proc;
|
||||
|
@ -99,6 +127,14 @@ Bool wxSchemeModifyRecord::Undo(wxMediaBuffer *)
|
|||
return wxsSchemeUndo(p);
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxSchemeModifyRecord::GetName()
|
||||
{
|
||||
return "scheme-modify";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
wxUnmodifyRecord::wxUnmodifyRecord(void)
|
||||
{
|
||||
ok = 1;
|
||||
|
@ -116,6 +152,14 @@ void wxUnmodifyRecord::DropSetUnmodified(void)
|
|||
ok = 0;
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxUnmodifyRecord::GetName()
|
||||
{
|
||||
return "unmodify";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
wxInsertRecord::wxInsertRecord(long position, long length, Bool cont, long ss, long es)
|
||||
{
|
||||
start = position;
|
||||
|
@ -137,6 +181,13 @@ Bool wxInsertRecord::Undo(wxMediaBuffer *buffer)
|
|||
return continued;
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxInsertRecord::GetName()
|
||||
{
|
||||
return "insert";
|
||||
}
|
||||
#endif
|
||||
|
||||
wxInsertSnipRecord::wxInsertSnipRecord(wxSnip *thesnip, Bool cont)
|
||||
{
|
||||
snip = thesnip;
|
||||
|
@ -155,6 +206,13 @@ Bool wxInsertSnipRecord::Undo(wxMediaBuffer *buffer)
|
|||
return continued;
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxInsertSnipRecord::GetName()
|
||||
{
|
||||
return "insert-snip";
|
||||
}
|
||||
#endif
|
||||
|
||||
class DeleteSnipItem /* : public wxObject --- uncomment to GC */
|
||||
{
|
||||
public:
|
||||
|
@ -237,6 +295,13 @@ Bool wxDeleteSnipRecord::Undo(wxMediaBuffer *buffer)
|
|||
return continued;
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxDeleteSnipRecord::GetName()
|
||||
{
|
||||
return "delete-snip";
|
||||
}
|
||||
#endif
|
||||
|
||||
wxDeleteRecord::wxDeleteRecord(long startpos, long endpos, Bool cont, long ss, long es)
|
||||
{
|
||||
continued = cont;
|
||||
|
@ -322,6 +387,13 @@ Bool wxDeleteRecord::Undo(wxMediaBuffer *buffer)
|
|||
return continued;
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxDeleteRecord::GetName()
|
||||
{
|
||||
return "delete";
|
||||
}
|
||||
#endif
|
||||
|
||||
class StyleChange /* : public wxObject */
|
||||
{
|
||||
public:
|
||||
|
@ -390,6 +462,13 @@ Bool wxStyleChangeRecord::Undo(wxMediaBuffer *buffer)
|
|||
return continued;
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxStyleChangeRecord::GetName()
|
||||
{
|
||||
return "style-change";
|
||||
}
|
||||
#endif
|
||||
|
||||
class StyleChangeSnip /* : public wxObject */
|
||||
{
|
||||
public:
|
||||
|
@ -451,6 +530,13 @@ Bool wxStyleChangeSnipRecord::Undo(wxMediaBuffer *buffer)
|
|||
return continued;
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxStyleChangeSnipRecord::GetName()
|
||||
{
|
||||
return "style-change-snip";
|
||||
}
|
||||
#endif
|
||||
|
||||
wxMoveSnipRecord::wxMoveSnipRecord(wxSnip *s, double fx, double fy,
|
||||
Bool d, Bool cont)
|
||||
{
|
||||
|
@ -475,6 +561,13 @@ Bool wxMoveSnipRecord::Undo(wxMediaBuffer *buffer)
|
|||
return continued;
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxMoveSnipRecord::GetName()
|
||||
{
|
||||
return "move-snip";
|
||||
}
|
||||
#endif
|
||||
|
||||
wxResizeSnipRecord::wxResizeSnipRecord(wxSnip *s, double fx, double fy,
|
||||
Bool cont)
|
||||
{
|
||||
|
@ -495,3 +588,166 @@ Bool wxResizeSnipRecord::Undo(wxMediaBuffer *buffer)
|
|||
return continued;
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxResizeSnipRecord::GetName()
|
||||
{
|
||||
return "resize-snip";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
wxCompositeRecord::wxCompositeRecord(int _cnt, wxChangeRecordId *_id, int _parity)
|
||||
{
|
||||
cnt = _cnt;
|
||||
seq = new wxChangeRecord*[cnt];
|
||||
id = _id;
|
||||
parity = _parity;
|
||||
if (!id) {
|
||||
id = new wxChangeRecordId;
|
||||
}
|
||||
if (parity)
|
||||
id->positive = this;
|
||||
else
|
||||
id->negative = this;
|
||||
}
|
||||
|
||||
wxCompositeRecord::~wxCompositeRecord()
|
||||
{
|
||||
int i = cnt;
|
||||
wxChangeRecord *cr;
|
||||
while (i--) {
|
||||
cr = seq[i];
|
||||
DELETE_OBJ cr;
|
||||
}
|
||||
cnt = 0;
|
||||
seq = NULL;
|
||||
if (id) {
|
||||
if (parity)
|
||||
id->positive = NULL;
|
||||
else
|
||||
id->negative = NULL;
|
||||
id = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Bool wxCompositeRecord::Undo(wxMediaBuffer *media)
|
||||
{
|
||||
int i = cnt;
|
||||
wxChangeRecord *cr;
|
||||
while (i--) {
|
||||
cr = seq[i];
|
||||
cr->Undo(media);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void wxCompositeRecord::DropSetUnmodified()
|
||||
{
|
||||
int i = cnt;
|
||||
wxChangeRecord *cr;
|
||||
while (i--) {
|
||||
cr = seq[i];
|
||||
cr->DropSetUnmodified();
|
||||
}
|
||||
}
|
||||
|
||||
void wxCompositeRecord::AddUndo(int pos, wxChangeRecord *c)
|
||||
{
|
||||
seq[pos] = c;
|
||||
}
|
||||
|
||||
Bool wxCompositeRecord::IsComposite()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxChangeRecordId *wxCompositeRecord::GetId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
int wxCompositeRecord::GetParity()
|
||||
{
|
||||
return parity;
|
||||
}
|
||||
|
||||
wxChangeRecord *wxCompositeRecord::Inverse()
|
||||
{
|
||||
return new wxInverseRecord(id, !parity);
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxCompositeRecord::GetName()
|
||||
{
|
||||
if (cnt == 1) {
|
||||
wxChangeRecord *cr;
|
||||
cr = seq[0];
|
||||
return cr->GetName();
|
||||
} else
|
||||
return "composite";
|
||||
}
|
||||
#endif
|
||||
|
||||
wxInverseRecord::wxInverseRecord(wxChangeRecordId *_id, int _parity)
|
||||
{
|
||||
id = _id;
|
||||
parity = _parity;
|
||||
}
|
||||
|
||||
wxInverseRecord::~wxInverseRecord()
|
||||
{
|
||||
/* Avoid double-frees by not doing anything */
|
||||
}
|
||||
|
||||
wxChangeRecord *wxInverseRecord::Get()
|
||||
{
|
||||
if (parity)
|
||||
return id->positive;
|
||||
else
|
||||
return id->negative;
|
||||
}
|
||||
|
||||
Bool wxInverseRecord::Undo(wxMediaBuffer *media)
|
||||
{
|
||||
wxChangeRecord *c;
|
||||
c = Get();
|
||||
return c->Undo(media);
|
||||
}
|
||||
|
||||
void wxInverseRecord::DropSetUnmodified()
|
||||
{
|
||||
wxChangeRecord *c;
|
||||
c = Get();
|
||||
if (c)
|
||||
c->DropSetUnmodified();
|
||||
}
|
||||
|
||||
wxChangeRecordId *wxInverseRecord::GetId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
int wxInverseRecord::GetParity()
|
||||
{
|
||||
return parity;
|
||||
}
|
||||
|
||||
wxChangeRecord *wxInverseRecord::Inverse()
|
||||
{
|
||||
wxChangeRecord *c;
|
||||
c = Get();
|
||||
return c->Inverse();
|
||||
}
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *wxInverseRecord::GetName()
|
||||
{
|
||||
wxChangeRecord *c;
|
||||
c = Get();
|
||||
if (c)
|
||||
return c->GetName();
|
||||
else
|
||||
return "inverse";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
|
||||
class wxcgList;
|
||||
|
||||
#define CGREC_DEBUG 0
|
||||
|
||||
class wxChangeRecordId;
|
||||
|
||||
class wxChangeRecord
|
||||
{
|
||||
public:
|
||||
|
@ -8,6 +12,13 @@ class wxChangeRecord
|
|||
virtual ~wxChangeRecord();
|
||||
virtual Bool Undo(wxMediaBuffer *media);
|
||||
virtual void DropSetUnmodified(void);
|
||||
virtual Bool IsComposite();
|
||||
virtual wxChangeRecordId *GetId();
|
||||
virtual int GetParity();
|
||||
virtual wxChangeRecord *Inverse();
|
||||
#if CGREC_DEBUG
|
||||
virtual char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxSchemeModifyRecord : public wxChangeRecord
|
||||
|
@ -16,6 +27,9 @@ class wxSchemeModifyRecord : public wxChangeRecord
|
|||
public:
|
||||
wxSchemeModifyRecord(void *p);
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxUnmodifyRecord : public wxChangeRecord
|
||||
|
@ -25,6 +39,9 @@ class wxUnmodifyRecord : public wxChangeRecord
|
|||
wxUnmodifyRecord(void);
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
void DropSetUnmodified(void);
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxInsertRecord : public wxChangeRecord
|
||||
|
@ -33,11 +50,12 @@ class wxInsertRecord : public wxChangeRecord
|
|||
long start, end;
|
||||
long startsel, endsel;
|
||||
Bool continued;
|
||||
|
||||
public:
|
||||
wxInsertRecord(long position, long length, Bool cont, long startsel, long endsel);
|
||||
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxInsertSnipRecord : public wxChangeRecord
|
||||
|
@ -45,11 +63,12 @@ class wxInsertSnipRecord : public wxChangeRecord
|
|||
private:
|
||||
wxSnip *snip;
|
||||
Bool continued;
|
||||
|
||||
public:
|
||||
wxInsertSnipRecord(wxSnip *s, Bool cont);
|
||||
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxDeleteRecord : public wxChangeRecord
|
||||
|
@ -70,6 +89,10 @@ class wxDeleteRecord : public wxChangeRecord
|
|||
void AddClickback(wxClickback *);
|
||||
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxDeleteSnipRecord : public wxChangeRecord
|
||||
|
@ -87,6 +110,10 @@ class wxDeleteSnipRecord : public wxChangeRecord
|
|||
void InsertSnip(wxSnip *, wxSnip *, double, double);
|
||||
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxStyleChangeRecord : public wxChangeRecord
|
||||
|
@ -103,6 +130,10 @@ class wxStyleChangeRecord : public wxChangeRecord
|
|||
|
||||
void AddStyleChange(long start, long end, wxStyle *style);
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxStyleChangeSnipRecord : public wxChangeRecord
|
||||
|
@ -117,6 +148,10 @@ class wxStyleChangeSnipRecord : public wxChangeRecord
|
|||
|
||||
void AddStyleChange(wxSnip *, wxStyle *style);
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxMoveSnipRecord : public wxChangeRecord
|
||||
|
@ -129,6 +164,9 @@ class wxMoveSnipRecord : public wxChangeRecord
|
|||
public:
|
||||
wxMoveSnipRecord(wxSnip *snip, double x, double y, Bool delta, Bool cont);
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxResizeSnipRecord : public wxChangeRecord
|
||||
|
@ -140,5 +178,51 @@ class wxResizeSnipRecord : public wxChangeRecord
|
|||
public:
|
||||
wxResizeSnipRecord(wxSnip *snip, double x, double y, Bool cont);
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxChangeRecordId {
|
||||
public:
|
||||
wxChangeRecord *positive, *negative;
|
||||
};
|
||||
|
||||
class wxCompositeRecord : public wxChangeRecord
|
||||
{
|
||||
int cnt;
|
||||
int parity;
|
||||
wxChangeRecordId *id;
|
||||
wxChangeRecord **seq;
|
||||
public:
|
||||
wxCompositeRecord(int cnt, wxChangeRecordId *, int parity);
|
||||
~wxCompositeRecord();
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
void DropSetUnmodified(void);
|
||||
void AddUndo(int pos, wxChangeRecord *c);
|
||||
Bool IsComposite();
|
||||
wxChangeRecordId *GetId();
|
||||
int GetParity();
|
||||
wxChangeRecord *Inverse();
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
||||
class wxInverseRecord : public wxChangeRecord
|
||||
{
|
||||
int parity;
|
||||
wxChangeRecordId *id;
|
||||
wxChangeRecord *Get();
|
||||
public:
|
||||
wxInverseRecord(wxChangeRecordId *, int parity);
|
||||
~wxInverseRecord();
|
||||
Bool Undo(wxMediaBuffer *media);
|
||||
void DropSetUnmodified(void);
|
||||
wxChangeRecordId *GetId();
|
||||
int GetParity();
|
||||
wxChangeRecord *Inverse();
|
||||
#if CGREC_DEBUG
|
||||
char *GetName();
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -49,8 +49,6 @@
|
|||
#include <string.h>
|
||||
#include "scheme.h"
|
||||
|
||||
#define NUM_MAX_UNDOS 256
|
||||
|
||||
#define DELETE_CLIP_LIST_CONTENT 0
|
||||
|
||||
#if ALLOW_X_STYLE_SELECTION
|
||||
|
@ -107,6 +105,9 @@ extern Scheme_Object *objscheme_bundle_wxMediaBuffer(wxMediaBuffer*);
|
|||
|
||||
/******************************************************************/
|
||||
|
||||
static int emacs_style_undo = -1;
|
||||
extern int wxGetBoolPreference(const char *name, int *res);
|
||||
|
||||
#ifndef EACH_BUFFER_OWN_OFFSCREEN
|
||||
static int bcounter = 0;
|
||||
#endif
|
||||
|
@ -114,8 +115,6 @@ static int bcounter = 0;
|
|||
wxMediaBuffer::wxMediaBuffer()
|
||||
: wxObject(WXGC_NO_CLEANUP)
|
||||
{
|
||||
wxChangeRecord **crpa;
|
||||
|
||||
map = new wxKeymap();
|
||||
// AddBufferFunctions(map);
|
||||
|
||||
|
@ -127,13 +126,13 @@ wxMediaBuffer::wxMediaBuffer()
|
|||
filename = NULL;
|
||||
|
||||
undomode = redomode = interceptmode = FALSE;
|
||||
maxUndos = NUM_MAX_UNDOS;
|
||||
crpa = MALLOC_CRP(maxUndos);
|
||||
changes = crpa;
|
||||
changes_start = changes_end = 0;
|
||||
crpa = MALLOC_CRP(maxUndos);
|
||||
redochanges = crpa;
|
||||
redochanges_start = redochanges_end = 0;
|
||||
maxUndos = 0;
|
||||
|
||||
if (emacs_style_undo == -1) {
|
||||
if (!wxGetBoolPreference("emacsUndo", &emacs_style_undo)) {
|
||||
emacs_style_undo = 0;
|
||||
}
|
||||
}
|
||||
|
||||
customCursor = NULL;
|
||||
|
||||
|
@ -1467,7 +1466,7 @@ void wxMediaBuffer::Undo(void)
|
|||
if (!undomode && !redomode) {
|
||||
undomode = TRUE;
|
||||
|
||||
PerformUndos(changes, FALSE);
|
||||
PerformUndos(FALSE);
|
||||
|
||||
undomode = FALSE;
|
||||
}
|
||||
|
@ -1478,7 +1477,7 @@ void wxMediaBuffer::Redo(void)
|
|||
if (!undomode && !redomode) {
|
||||
redomode = TRUE;
|
||||
|
||||
PerformUndos(redochanges, TRUE);
|
||||
PerformUndos(TRUE);
|
||||
|
||||
redomode = FALSE;
|
||||
}
|
||||
|
@ -1486,12 +1485,11 @@ void wxMediaBuffer::Redo(void)
|
|||
|
||||
#define delete_cgrec(x) DELETE_OBJ (x)
|
||||
|
||||
static void wxmeClearUndos(wxChangeRecord **changes, int start, int end,
|
||||
int maxUndos)
|
||||
static void wxmeClearUndos(wxChangeRecord **changes, int start, int end, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = start; i != end; i = (i + 1) % maxUndos) {
|
||||
for (i = start; i != end; i = (i + 1) % size) {
|
||||
delete_cgrec(changes[i]);
|
||||
changes[i] = NULL;
|
||||
}
|
||||
|
@ -1502,14 +1500,32 @@ void wxMediaBuffer::AddUndo(wxChangeRecord *rec)
|
|||
if (interceptmode)
|
||||
intercepted->Append((wxObject *)rec);
|
||||
else if (undomode)
|
||||
AppendUndo(rec, redochanges, TRUE);
|
||||
AppendUndo(rec, TRUE);
|
||||
else if (!noundomode) {
|
||||
if (!redomode) {
|
||||
wxmeClearUndos(redochanges, redochanges_start,
|
||||
redochanges_end, maxUndos);
|
||||
redochanges_start = redochanges_end = 0;
|
||||
if (emacs_style_undo) {
|
||||
if (redochanges_start != redochanges_end) {
|
||||
int e = redochanges_end;
|
||||
wxChangeRecord *cr;
|
||||
while (redochanges_start != e) {
|
||||
e = (e - 1 + redochanges_size) % redochanges_size;
|
||||
cr = redochanges[e];
|
||||
AppendUndo(cr->Inverse(), FALSE);
|
||||
}
|
||||
while (redochanges_start != redochanges_end) {
|
||||
AppendUndo(redochanges[redochanges_start], FALSE);
|
||||
redochanges[redochanges_start] = NULL;
|
||||
redochanges_start = (redochanges_start + 1) % redochanges_size;
|
||||
}
|
||||
redochanges_start = 0;
|
||||
redochanges_end = 0;
|
||||
}
|
||||
} else {
|
||||
wxmeClearUndos(redochanges, redochanges_start, redochanges_end, redochanges_size);
|
||||
redochanges_start = redochanges_end = 0;
|
||||
}
|
||||
}
|
||||
AppendUndo(rec, changes, FALSE);
|
||||
AppendUndo(rec, FALSE);
|
||||
} else
|
||||
delete_cgrec(rec);
|
||||
}
|
||||
|
@ -1521,59 +1537,102 @@ void wxMediaBuffer::AddSchemeUndo(void *proc)
|
|||
AddUndo(modrec);
|
||||
}
|
||||
|
||||
void wxMediaBuffer::AppendUndo(wxChangeRecord *rec, wxChangeRecord **changes,
|
||||
Bool redos)
|
||||
void wxMediaBuffer::AppendUndo(wxChangeRecord *rec, Bool redos)
|
||||
{
|
||||
if (maxUndos) {
|
||||
int start, end;
|
||||
wxChangeRecord **c;
|
||||
int start, end, size;
|
||||
|
||||
if (redos) {
|
||||
start = redochanges_start;
|
||||
end = redochanges_end;
|
||||
size = redochanges_size;
|
||||
c = redochanges;
|
||||
} else {
|
||||
start = changes_start;
|
||||
end = changes_end;
|
||||
size = changes_size;
|
||||
c = changes;
|
||||
}
|
||||
|
||||
changes[end] = rec;
|
||||
end = (end + 1) % maxUndos;
|
||||
if (!size) {
|
||||
size = 128; /* Initial undo size */
|
||||
if (size > maxUndos)
|
||||
size = maxUndos;
|
||||
c = MALLOC_CRP(size);
|
||||
}
|
||||
|
||||
c[end] = rec;
|
||||
end = (end + 1) % size;
|
||||
if (end == start) {
|
||||
delete_cgrec(changes[start]);
|
||||
changes[start] = NULL;
|
||||
start = (start + 1) % maxUndos;
|
||||
if ((size < maxUndos) || emacs_style_undo) {
|
||||
/* Make more room */
|
||||
int s, i, j;
|
||||
wxChangeRecord **naya;
|
||||
s = (size * 2);
|
||||
if (s > maxUndos)
|
||||
s = maxUndos;
|
||||
|
||||
naya = MALLOC_CRP(s);
|
||||
for (j = 0, i = start;
|
||||
(j < size);
|
||||
j++, i = (i + 1) % size) {
|
||||
naya[j] = c[i];
|
||||
}
|
||||
size = s;
|
||||
c = naya;
|
||||
start = 0;
|
||||
end = j;
|
||||
} else {
|
||||
/* No room to grow, so drop an undo record */
|
||||
delete_cgrec(c[start]);
|
||||
c[start] = NULL;
|
||||
start = (start + 1) % size;
|
||||
}
|
||||
}
|
||||
|
||||
if (redos) {
|
||||
redochanges_start = start;
|
||||
redochanges_end = end;
|
||||
redochanges_size = size;
|
||||
redochanges = c;
|
||||
} else {
|
||||
changes_start = start;
|
||||
changes_end = end;
|
||||
changes_size = size;
|
||||
changes = c;
|
||||
}
|
||||
} else
|
||||
delete_cgrec(rec);
|
||||
}
|
||||
|
||||
void wxMediaBuffer::PerformUndos(wxChangeRecord **changes, Bool redos)
|
||||
void wxMediaBuffer::PerformUndos(Bool redos)
|
||||
{
|
||||
wxChangeRecord **c;
|
||||
wxChangeRecord *rec;
|
||||
wxChangeRecordId *id = NULL;
|
||||
int parity = 0;
|
||||
Bool cont;
|
||||
int start, end;
|
||||
int start, end, size;
|
||||
|
||||
BeginEditSequence();
|
||||
|
||||
if (redos) {
|
||||
start = redochanges_start;
|
||||
end = redochanges_end;
|
||||
size = redochanges_size;
|
||||
c = redochanges;
|
||||
} else {
|
||||
start = changes_start;
|
||||
end = changes_end;
|
||||
size = changes_size;
|
||||
c = changes;
|
||||
}
|
||||
|
||||
while (start != end) {
|
||||
end = (end - 1 + maxUndos) % maxUndos;
|
||||
rec = changes[end];
|
||||
changes[end] = NULL;
|
||||
end = (end - 1 + size) % size;
|
||||
rec = c[end];
|
||||
c[end] = NULL;
|
||||
|
||||
if (redos) {
|
||||
redochanges_start = start;
|
||||
|
@ -1583,13 +1642,55 @@ void wxMediaBuffer::PerformUndos(wxChangeRecord **changes, Bool redos)
|
|||
changes_end = end;
|
||||
}
|
||||
|
||||
if (emacs_style_undo) {
|
||||
id = rec->GetId();
|
||||
parity = rec->GetParity();
|
||||
}
|
||||
|
||||
cont = rec->Undo(this);
|
||||
delete_cgrec(rec);
|
||||
|
||||
if (!cont)
|
||||
break;
|
||||
}
|
||||
|
||||
EndEditSequence();
|
||||
|
||||
if (emacs_style_undo && !redos) {
|
||||
/* Combine all new steps into one undo record, and
|
||||
set/generate id */
|
||||
start = redochanges_start;
|
||||
end = redochanges_end;
|
||||
size = redochanges_size;
|
||||
c = redochanges;
|
||||
|
||||
if (start != end) {
|
||||
wxChangeRecord *cr;
|
||||
int e, cnt = 0;
|
||||
for (e = end; start != e; ) {
|
||||
e = (e - 1 + size) % size;
|
||||
cr = c[e];
|
||||
if (cr->IsComposite())
|
||||
break;
|
||||
else
|
||||
cnt++;
|
||||
}
|
||||
|
||||
if (cnt > 0) {
|
||||
wxCompositeRecord *cu;
|
||||
int i;
|
||||
cu = new wxCompositeRecord(cnt, id, !parity);
|
||||
for (i = 0; i < cnt; i++) {
|
||||
e = (end - cnt + i + size) % size;
|
||||
cu->AddUndo(i, c[e]);
|
||||
c[e] = NULL;
|
||||
}
|
||||
e = (end - cnt + size) % size;
|
||||
c[e] = cu;
|
||||
end = (e + 1) % size;
|
||||
redochanges_end = end;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxMediaBuffer::PerformUndoList(wxList *changes)
|
||||
|
@ -1612,46 +1713,31 @@ void wxMediaBuffer::PerformUndoList(wxList *changes)
|
|||
}
|
||||
|
||||
void wxMediaBuffer::ClearUndos()
|
||||
{
|
||||
wxmeClearUndos(changes, changes_start, changes_end, maxUndos);
|
||||
{
|
||||
wxmeClearUndos(changes, changes_start, changes_end, changes_size);
|
||||
changes_start = changes_end = 0;
|
||||
wxmeClearUndos(redochanges, redochanges_start, redochanges_end, maxUndos);
|
||||
wxmeClearUndos(redochanges, redochanges_start, redochanges_end, redochanges_size);
|
||||
redochanges_start = redochanges_end = 0;
|
||||
}
|
||||
|
||||
void wxMediaBuffer::SetMaxUndoHistory(int v)
|
||||
{
|
||||
wxChangeRecord **naya;
|
||||
int i, j;
|
||||
if (v < 0)
|
||||
v = 0xfffFFFF;
|
||||
|
||||
if (undomode || redomode || (v == maxUndos))
|
||||
return;
|
||||
|
||||
naya = MALLOC_CRP(v);
|
||||
for (j = 0, i = changes_start;
|
||||
(i != changes_end) && (j < v);
|
||||
j++, i = (i + 1) % maxUndos) {
|
||||
naya[j] = changes[i];
|
||||
if (!v) {
|
||||
ClearUndos();
|
||||
changes = NULL;
|
||||
redochanges = NULL;
|
||||
changes_size = 0;
|
||||
redochanges_size = 0;
|
||||
}
|
||||
for (; i != changes_end; i = (i + 1) % maxUndos) {
|
||||
delete_cgrec(changes[i]);
|
||||
}
|
||||
changes = naya;
|
||||
changes_start = 0;
|
||||
changes_end = v ? (j % v) : 0;
|
||||
|
||||
naya = MALLOC_CRP(v);
|
||||
for (j = 0, i = redochanges_start;
|
||||
(i != redochanges_end) && (j < v);
|
||||
j++, i = (i + 1) % maxUndos) {
|
||||
naya[j] = redochanges[i];
|
||||
}
|
||||
for (; i != redochanges_end; i = (i + 1) % maxUndos) {
|
||||
delete_cgrec(redochanges[i]);
|
||||
}
|
||||
redochanges = naya;
|
||||
redochanges_start = 0;
|
||||
redochanges_end = v ? (j % v) : v;
|
||||
/* Should we bother downsizing if maxUndos gets smaller but stays
|
||||
non-0? */
|
||||
|
||||
maxUndos = v;
|
||||
}
|
||||
|
@ -2369,13 +2455,13 @@ void wxMediaBuffer::SetModified(Bool mod)
|
|||
num_parts_modified = 0;
|
||||
for (i = changes_end; i != changes_start; ) {
|
||||
wxChangeRecord *cr;
|
||||
i = (i - 1 + maxUndos) % maxUndos;
|
||||
i = (i - 1 + changes_size) % changes_size;
|
||||
cr = changes[i];
|
||||
cr->DropSetUnmodified();
|
||||
}
|
||||
for (i = redochanges_end; i != redochanges_start; ) {
|
||||
wxChangeRecord *cr;
|
||||
i = (i - 1 + maxUndos) % maxUndos;
|
||||
i = (i - 1 + redochanges_size) % redochanges_size;
|
||||
cr = redochanges[i];
|
||||
cr->DropSetUnmodified();
|
||||
}
|
||||
|
|
|
@ -97,9 +97,10 @@ class wxMediaBuffer : public wxObject
|
|||
int maxUndos;
|
||||
|
||||
wxChangeRecord **changes;
|
||||
int changes_start, changes_end;
|
||||
int changes_start, changes_end, changes_size;
|
||||
wxChangeRecord **redochanges;
|
||||
int redochanges_start, redochanges_end;
|
||||
int redochanges_start, redochanges_end, redochanges_size;
|
||||
wxChangeRecord **savedchanges; /* for Emacs-style undo */
|
||||
wxList *intercepted;
|
||||
|
||||
wxCursor *customCursor;
|
||||
|
@ -124,9 +125,9 @@ class wxMediaBuffer : public wxObject
|
|||
virtual void InsertPasteSnip(wxSnip *snip, wxBufferData *) = 0;
|
||||
virtual void InsertPasteString(wxchar *str) = 0;
|
||||
|
||||
void PerformUndos(wxChangeRecord **, Bool redos);
|
||||
void PerformUndos(Bool redos);
|
||||
void PerformUndoList(wxList *);
|
||||
void AppendUndo(wxChangeRecord *, wxChangeRecord **, Bool redo);
|
||||
void AppendUndo(wxChangeRecord *, Bool redo);
|
||||
|
||||
Bool DoOwnCaret(Bool ownit);
|
||||
Bool DoSetCaretOwner(wxSnip *, int);
|
||||
|
|
|
@ -1258,13 +1258,13 @@ static Scheme_Object *os_wxMediaBufferSetMaxUndoHistory(int n, Scheme_Object *p
|
|||
WXS_USE_ARGUMENT(n) WXS_USE_ARGUMENT(p)
|
||||
REMEMBER_VAR_STACK();
|
||||
objscheme_check_valid(os_wxMediaBuffer_class, "set-max-undo-history in editor<%>", n, p);
|
||||
int x0;
|
||||
long x0;
|
||||
|
||||
SETUP_VAR_STACK_REMEMBERED(1);
|
||||
VAR_STACK_PUSH(0, p);
|
||||
|
||||
|
||||
x0 = WITH_VAR_STACK(objscheme_unbundle_integer_in(p[POFFSET+0], 0, 100000, "set-max-undo-history in editor<%>"));
|
||||
x0 = WITH_VAR_STACK(objscheme_unbundle_nonnegative_symbol_integer(p[POFFSET+0], "forever", "set-max-undo-history in editor<%>"));
|
||||
|
||||
|
||||
WITH_VAR_STACK(((wxMediaBuffer *)((Scheme_Class_Object *)p[0])->primdata)->SetMaxUndoHistory(x0));
|
||||
|
|
|
@ -144,7 +144,7 @@ static void NoInsertFile(wxMediaBuffer *)
|
|||
|
||||
@ "add-undo" : void AddSchemeUndo(UNKNOWN_OBJ//ubUndoer////push); : : /CHECKUNDOER
|
||||
|
||||
@ "set-max-undo-history" : void SetMaxUndoHistory(rint[0|100000]);
|
||||
@ "set-max-undo-history" : void SetMaxUndoHistory(nnls[forever]);
|
||||
@ "get-max-undo-history" : int GetMaxUndoHistory();
|
||||
|
||||
@ "do-edit-operation" : void DoEdit(SYM[editOp],bool=TRUE,ExactLong=0);
|
||||
|
|
|
@ -724,6 +724,7 @@ scheme_init_port_fun(Scheme_Env *env)
|
|||
void scheme_init_port_fun_config(void)
|
||||
{
|
||||
scheme_set_root_param(MZCONFIG_LOAD_DIRECTORY, scheme_false);
|
||||
scheme_set_root_param(MZCONFIG_WRITE_DIRECTORY, scheme_false);
|
||||
scheme_set_root_param(MZCONFIG_USE_COMPILED_KIND,
|
||||
scheme_make_immutable_pair(scheme_make_path("compiled"),
|
||||
scheme_null));
|
||||
|
|
Loading…
Reference in New Issue
Block a user