CEDIT: new version by akron1

git-svn-id: svn://kolibrios.org@9073 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2021-07-21 16:13:29 +00:00
parent f195324958
commit f73a566b8b
11 changed files with 696 additions and 520 deletions

Binary file not shown.

View File

@ -7,7 +7,7 @@
ctrl+L преобразовать буквы A..Z слева от курсора в a..z ctrl+L преобразовать буквы A..Z слева от курсора в a..z
ctrl+U преобразовать буквы a..z слева от курсора в A..Z ctrl+U преобразовать буквы a..z слева от курсора в A..Z
ctrl+F показать панель поиска ctrl+F показать панель поиска
Esc скрыть панель поиска Esc закрыть панель поиска
F3 найти следующий F3 найти следующий
shift+F3 найти предыдущий shift+F3 найти предыдущий
ctrl+Z отменить ctrl+Z отменить

File diff suppressed because it is too large Load Diff

View File

@ -27,7 +27,7 @@ TYPE
END; END;
tBoolItem = POINTER TO RECORD (List.tItem) tBoolItem = POINTER TO RECORD (List.tItem)
adr: INTEGER; val: BOOLEAN adr: INTEGER; val: BOOLEAN; save: BOOLEAN
END; END;
(* (*
tUntypedPtr = POINTER TO RECORD (List.tItem) tUntypedPtr = POINTER TO RECORD (List.tItem)
@ -39,7 +39,7 @@ TYPE
END; END;
*) *)
tGuard* = POINTER TO RECORD (List.tItem) tGuard* = POINTER TO RECORD (List.tItem)
saved*: BOOLEAN
END; END;
tLog* = POINTER TO RECORD tLog* = POINTER TO RECORD
@ -123,6 +123,21 @@ BEGIN
END clear; END clear;
PROCEDURE save* (guard: tGuard);
VAR
item: List.tItem;
BEGIN
item := CL.Log.first;
WHILE item # NIL DO
IF item IS tGuard THEN
item(tGuard).saved := FALSE
END;
item := item.next
END;
guard.saved := TRUE
END save;
PROCEDURE changeWord (adrV, adrX: INTEGER); PROCEDURE changeWord (adrV, adrX: INTEGER);
VAR VAR
item: tIntItem; item: tIntItem;
@ -144,6 +159,7 @@ BEGIN
NEW(item); NEW(item);
item.adr := SYSTEM.ADR(v); item.adr := SYSTEM.ADR(v);
item.val := x; item.val := x;
item.save := FALSE;
IF ~CL.isLast THEN IF ~CL.isLast THEN
clear(CL.guard) clear(CL.guard)
END; END;
@ -151,6 +167,81 @@ BEGIN
END changeBool; END changeBool;
PROCEDURE delSaved*;
VAR
boolItem: tBoolItem;
cur: List.tItem;
del: BOOLEAN;
BEGIN
cur := CL.guard.next;
WHILE cur # NIL DO
IF cur IS tBoolItem THEN
boolItem := cur(tBoolItem);
del := boolItem.save
ELSE
del := FALSE
END;
cur := cur.next;
IF del THEN
List.delete(CL.Log, boolItem);
DISPOSE(boolItem)
END
END
END delSaved;
PROCEDURE delCurSaved*;
VAR
boolItem: tBoolItem;
cur: List.tItem;
del: BOOLEAN;
BEGIN
cur := CL.guard.prev;
WHILE (cur # NIL) & ~(cur IS tGuard) DO
IF cur IS tBoolItem THEN
boolItem := cur(tBoolItem);
del := boolItem.save
ELSE
del := FALSE
END;
cur := cur.prev;
IF del THEN
SYSTEM.PUT(boolItem.adr, ~boolItem.val);
List.delete(CL.Log, boolItem);
DISPOSE(boolItem)
END
END
END delCurSaved;
PROCEDURE changeBool2 (VAR v: BOOLEAN; x: BOOLEAN);
VAR
item, boolItem: tBoolItem;
cur: List.tItem;
del: BOOLEAN;
BEGIN
NEW(item);
item.adr := SYSTEM.ADR(v);
item.val := x;
item.save := TRUE;
cur := CL.guard.prev;
WHILE cur # NIL DO
IF cur IS tBoolItem THEN
boolItem := cur(tBoolItem);
del := boolItem.save & (boolItem.adr = SYSTEM.ADR(v)) & (boolItem.val = x)
ELSE
del := FALSE
END;
cur := cur.prev;
IF del THEN
List.delete(CL.Log, boolItem);
DISPOSE(boolItem)
END
END;
List.insert(CL.Log, CL.guard.prev, item)
END changeBool2;
PROCEDURE changeInt (VAR v: INTEGER; x: INTEGER); PROCEDURE changeInt (VAR v: INTEGER; x: INTEGER);
BEGIN BEGIN
changeWord(SYSTEM.ADR(v), SYSTEM.ADR(x)) changeWord(SYSTEM.ADR(v), SYSTEM.ADR(x))
@ -205,5 +296,5 @@ END create;
BEGIN BEGIN
List.init(changeInt, changePtr); List.init(changeInt, changePtr);
Lines.init(changeInt, changePtr, changeBool(*, typedPtr, untypedPtr*)) Lines.init(changeInt, changePtr, changeBool, changeBool2(*, typedPtr, untypedPtr*))
END ChangeLog. END ChangeLog.

View File

@ -118,11 +118,8 @@ END appends;
PROCEDURE eol* (buffer: tBuffer); PROCEDURE eol* (buffer: tBuffer);
VAR
s: ARRAY 2 OF WCHAR;
BEGIN BEGIN
s[0] := 0DX; s[1] := 0AX; appends(buffer, 0DX + 0AX, 0, 1)
appends(buffer, s, 0, 1)
END eol; END eol;

View File

@ -29,6 +29,7 @@ TYPE
VAR VAR
cpW1251*, cp866*: CP; cpW1251*, cp866*: CP;
names*: ARRAY 4, 16 OF WCHAR;
UNI*: ARRAY 65536, 2 OF INTEGER; UNI*: ARRAY 65536, 2 OF INTEGER;
@ -121,6 +122,10 @@ END setUNI;
BEGIN BEGIN
names[CP866] := "CP866";
names[W1251] := "Windows-1251";
names[UTF8] := "UTF-8";
names[UTF8BOM] := "UTF-8-BOM";
InitW1251(cpW1251); InitW1251(cpW1251);
InitCP866(cp866); InitCP866(cp866);
setUNI setUNI

View File

@ -265,6 +265,36 @@ BEGIN
END Create; END Create;
PROCEDURE Copy* (From, To: ARRAY OF CHAR): BOOLEAN;
VAR
buf, size: INTEGER;
outFile: FS;
res: BOOLEAN;
BEGIN
res := FALSE;
size := FileSize(From);
IF size > 0 THEN
buf := Load(From, size)
ELSE
buf := -1;
size := 0
END;
IF buf # 0 THEN
outFile := Create(To);
IF outFile # NIL THEN
IF size # 0 THEN
res := Write(outFile, buf, size) = size
END;
Close(outFile)
END;
IF size # 0 THEN
buf := KOSAPI.free(buf)
END
END
RETURN res
END Copy;
PROCEDURE DirExists* (FName: ARRAY OF CHAR): BOOLEAN; PROCEDURE DirExists* (FName: ARRAY OF CHAR): BOOLEAN;
VAR VAR
fd: rFD; fd: rFD;

View File

@ -27,7 +27,7 @@ CONST
langNone* = 0; langC* = 1; langOberon* = 2; langPascal* = 3; langNone* = 0; langC* = 1; langOberon* = 2; langPascal* = 3;
langFasm* = 4; langLua* = 5; langIni* = 6; langFasm* = 4; langLua* = 5; langIni* = 6;
csLang = {langNone, langC, langOberon, langLua, langIni}; csLang = {langC, langOberon, langLua, langIni};
TYPE TYPE

View File

@ -46,7 +46,7 @@ TYPE
VAR VAR
_movInt: PmovInt; _movInt: PmovInt;
_movBool: PmovBool; _movBool, _movBool2: PmovBool;
_movPtr: PmovPtr; _movPtr: PmovPtr;
(* _typedPtr: PTypedPtr; (* _typedPtr: PTypedPtr;
_untypedPtr: PUntypedPtr;*) _untypedPtr: PUntypedPtr;*)
@ -66,6 +66,12 @@ BEGIN
END movBool; END movBool;
PROCEDURE movBool2 (VAR v: BOOLEAN; x: BOOLEAN);
BEGIN
_movBool2(v, x)
END movBool2;
PROCEDURE movPtr (VAR v: List.tItem; x: List.tItem); PROCEDURE movPtr (VAR v: List.tItem; x: List.tItem);
BEGIN BEGIN
_movPtr(v, x) _movPtr(v, x)
@ -174,8 +180,8 @@ END modify;
PROCEDURE save* (line: tLine); PROCEDURE save* (line: tLine);
BEGIN BEGIN
IF ~line.temp THEN IF ~line.temp THEN
movBool(line.saved, TRUE); movBool2(line.saved, TRUE);
movBool(line.modified, FALSE) movBool2(line.modified, FALSE)
END; END;
line.modified := FALSE; line.modified := FALSE;
line.saved := TRUE line.saved := TRUE
@ -416,11 +422,12 @@ BEGIN
END chCase; END chCase;
PROCEDURE init* (movInt: PmovInt; movPtr: PmovPtr; movBool: PmovBool(*; typedPtr: PTypedPtr; untypedPtr: PUntypedPtr*)); PROCEDURE init* (movInt: PmovInt; movPtr: PmovPtr; movBool, movBool2: PmovBool(*; typedPtr: PTypedPtr; untypedPtr: PUntypedPtr*));
BEGIN BEGIN
_movInt := movInt; _movInt := movInt;
_movPtr := movPtr; _movPtr := movPtr;
_movBool := movBool; _movBool := movBool;
_movBool2 := movBool2;
(* _typedPtr := typedPtr; (* _typedPtr := typedPtr;
_untypedPtr := untypedPtr;*) _untypedPtr := untypedPtr;*)
END init; END init;

View File

@ -71,7 +71,7 @@ BEGIN
END; END;
K.DrawLine(x, y2, x, y, K.borderColor); K.DrawLine(x, y2, x, y, K.borderColor);
K.DrawText866bk(x + K.fontWidth, y + (height - K.fontHeight) DIV 2, K.textColor, color, s); K.DrawText866bk(x + K.fontWidth, y + (height - K.fontHeight) DIV 2, K.textColor, color, s);
K.CreateButton(id + ORD({30}) + btnID, x, y - 1, width, height - 1, color, ""); K.CreateButton(id + ORD({30}) + btnID, x + 1, y - 1, width - 1, height - 1, color, "");
END drawTab; END drawTab;

View File

@ -27,7 +27,7 @@ IMPORT
E := Encodings, E := Encodings,
CB := Clipboard, CB := Clipboard,
K := KolibriOS, K := KolibriOS,
ChangeLog, ChangeLog, File,
Lang := Languages; Lang := Languages;
@ -37,8 +37,6 @@ CONST
TAB = RW.TAB_SIZE; TAB = RW.TAB_SIZE;
lenEOL = CB.lenEOL; lenEOL = CB.lenEOL;
SHIFT* = 0; CTRL* = 1;
mark_width = 2; mark_width = 2;
pad_left = mark_width + 3; pad_left = mark_width + 3;
pad_top = 0; pad_top = 0;
@ -1187,20 +1185,19 @@ END scroll;
PROCEDURE save* (text: tText; name: RW.tFileName; enc, nl: INTEGER): BOOLEAN; PROCEDURE save* (text: tText; name: RW.tFileName; enc, nl: INTEGER): BOOLEAN;
CONST
tempFile = "/tmp0/1/cedit~.tmp";
VAR VAR
line: tLine; line: tLine;
file: RW.tOutput; file: RW.tOutput;
res: BOOLEAN; res: BOOLEAN;
Len: INTEGER; Len: INTEGER;
(* item: List.tItem;*)
BEGIN BEGIN
ChangeLog.setGuard(text.edition);
res := TRUE; res := TRUE;
file := RW.create(name, enc, nl); file := RW.create(tempFile, enc, nl);
IF file # NIL THEN IF file # NIL THEN
(* IF ChangeLog.Log.last IS ChangeLog.tGuard THEN ChangeLog.delSaved;
item := List.pop(ChangeLog.Log);
DISPOSE(item)
END;*)
line := text.first(tLine); line := text.first(tLine);
WHILE (line # NIL) & res DO WHILE (line # NIL) & res DO
Len := Lines.trimLength(line); Len := Lines.trimLength(line);
@ -1219,14 +1216,21 @@ BEGIN
END; END;
IF ~RW.close(file) THEN IF ~RW.close(file) THEN
res := FALSE res := FALSE
END;
IF res THEN
text.modified := FALSE
END END
ELSE ELSE
res := FALSE res := FALSE
END; END;
text.guard := TRUE IF res THEN
res := File.Copy(tempFile, name);
IF res THEN
text.modified := FALSE;
ChangeLog.save(text.edition);
IF File.Delete(tempFile) THEN END
END
END;
IF ~res THEN
ChangeLog.delCurSaved
END
RETURN res RETURN res
END save; END save;
@ -1262,8 +1266,7 @@ BEGIN
IF item # NIL THEN IF item # NIL THEN
guard := item(tGuard); guard := item(tGuard);
text.edition := guard; text.edition := guard
text.modified := TRUE
END; END;
item := ChangeLog.CL.Log.first; item := ChangeLog.CL.Log.first;
@ -1272,7 +1275,8 @@ BEGIN
item := item.next item := item.next
END; END;
redoGuard(text, guard); redoGuard(text, guard);
ChangeLog.setGuard(guard) ChangeLog.setGuard(guard);
text.modified := ~guard.saved
END undo; END undo;
@ -1291,7 +1295,8 @@ BEGIN
guard := item(tGuard); guard := item(tGuard);
redoGuard(text, guard) redoGuard(text, guard)
END; END;
ChangeLog.setGuard(guard) ChangeLog.setGuard(guard);
text.modified := ~guard.saved
END redo; END redo;
@ -1432,19 +1437,42 @@ PROCEDURE gotoLabel* (text: tText; frw: BOOLEAN);
VAR VAR
line: tLine; line: tLine;
n: INTEGER; n: INTEGER;
PROCEDURE search (VAR line: tLine; VAR n: INTEGER; frw: BOOLEAN);
BEGIN
IF frw THEN
WHILE (line # NIL) & ~line.label DO
NextLine(line);
INC(n)
END
ELSE
WHILE (line # NIL) & ~line.label DO
PrevLine(line);
DEC(n)
END
END
END search;
BEGIN BEGIN
n := text.cursor.Y; n := text.cursor.Y;
line := text.curLine; line := text.curLine;
IF frw THEN IF frw THEN
REPEAT NextLine(line);
line := line.next(tLine);
INC(n) INC(n)
UNTIL (line = NIL) OR line.label
ELSE ELSE
REPEAT PrevLine(line);
line := line.prev(tLine);
DEC(n) DEC(n)
UNTIL (line = NIL) OR line.label END;
search(line, n, frw);
IF line = NIL THEN
IF frw THEN
n := 0;
line := text.first(tLine)
ELSE
n := text.count - 1;
line := text.last(tLine)
END;
search(line, n, frw)
END; END;
IF line # NIL THEN IF line # NIL THEN
IF goto(text, n + 1) THEN END IF goto(text, n + 1) THEN END
@ -1615,9 +1643,9 @@ BEGIN
END wordSel; END wordSel;
PROCEDURE key* (text: tText; code: INTEGER; shift: SET); PROCEDURE key* (text: tText; code: INTEGER; shift, ctrl: BOOLEAN);
BEGIN BEGIN
IF SHIFT IN shift THEN IF shift THEN
setSelect(text) setSelect(text)
ELSE ELSE
IF (33 <= code) & (code <= 40) THEN IF (33 <= code) & (code <= 40) THEN
@ -1627,27 +1655,27 @@ BEGIN
CASE code OF CASE code OF
|33: |33:
IF CTRL IN shift THEN IF ctrl THEN
UpDown(text, text.scroll.Y - text.cursor.Y) UpDown(text, text.scroll.Y - text.cursor.Y)
ELSE ELSE
text.scroll.Y := MAX(text.scroll.Y - textsize.Y, 0); text.scroll.Y := MAX(text.scroll.Y - textsize.Y, 0);
UpDown(text, -textsize.Y) UpDown(text, -textsize.Y)
END END
|34: |34:
IF CTRL IN shift THEN IF ctrl THEN
UpDown(text, MIN(text.scroll.Y + textsize.Y - 1, text.count - 1) - text.cursor.Y) UpDown(text, MIN(text.scroll.Y + textsize.Y - 1, text.count - 1) - text.cursor.Y)
ELSE ELSE
text.scroll.Y := MIN(text.scroll.Y + textsize.Y, text.count - 1); text.scroll.Y := MIN(text.scroll.Y + textsize.Y, text.count - 1);
UpDown(text, textsize.Y) UpDown(text, textsize.Y)
END END
|35: |35:
IF CTRL IN shift THEN IF ctrl THEN
SetPos(text, text.last(tLine).length, text.count - 1) SetPos(text, text.last(tLine).length, text.count - 1)
ELSE ELSE
SetPos(text, text.curLine.length, text.cursor.Y) SetPos(text, text.curLine.length, text.cursor.Y)
END END
|36: |36:
IF CTRL IN shift THEN IF ctrl THEN
SetPos(text, 0, 0) SetPos(text, 0, 0)
ELSE ELSE
SetPos(text, 0, text.cursor.Y) SetPos(text, 0, text.cursor.Y)
@ -1659,7 +1687,7 @@ BEGIN
SetPos(text, text.cursor.X - 1, text.cursor.Y) SetPos(text, text.cursor.X - 1, text.cursor.Y)
END END
|38: |38:
IF CTRL IN shift THEN IF ctrl THEN
upLine(text) upLine(text)
ELSE ELSE
UpDown(text, -1) UpDown(text, -1)
@ -1671,49 +1699,49 @@ BEGIN
SetPos(text, text.cursor.X + 1, text.cursor.Y) SetPos(text, text.cursor.X + 1, text.cursor.Y)
END END
|40: |40:
IF CTRL IN shift THEN IF ctrl THEN
downLine(text) downLine(text)
ELSE ELSE
UpDown(text, 1) UpDown(text, 1)
END END
|46: |46:
IF CTRL IN shift THEN IF ctrl THEN
delLine(text) delLine(text)
ELSE ELSE
delete(text); ShowCursor; drawCursor := TRUE delete(text); ShowCursor; drawCursor := TRUE
END END
|ORD("C"): |ORD("C"):
IF CTRL IN shift THEN IF ctrl THEN
IF selected(text) THEN IF selected(text) THEN
copy(text) copy(text)
END END
END END
|ORD("X"): |ORD("X"):
IF CTRL IN shift THEN IF ctrl THEN
IF selected(text) THEN IF selected(text) THEN
copy(text); copy(text);
delSelect(text) delSelect(text)
END END
END END
|ORD("V"): |ORD("V"):
IF CTRL IN shift THEN IF ctrl THEN
IF CB.available() THEN IF CB.available() THEN
paste(text) paste(text)
END END
END END
|ORD("A"): |ORD("A"):
IF CTRL IN shift THEN IF ctrl THEN
text.select2.X := 0; text.select2.X := 0;
text.select2.Y := 0; text.select2.Y := 0;
text.select := text.select2; text.select := text.select2;
SetPos(text, text.last(tLine).length, text.count - 1) SetPos(text, text.last(tLine).length, text.count - 1)
END END
|ORD("L"), ORD("U"): |ORD("L"), ORD("U"):
IF CTRL IN shift THEN IF ctrl THEN
changeCase(text, code = ORD("U")) changeCase(text, code = ORD("U"))
END END
|ORD("D"): |ORD("D"):
IF CTRL IN shift THEN IF ctrl THEN
dupLine(text) dupLine(text)
END END
ELSE ELSE
@ -1842,8 +1870,9 @@ BEGIN
IF text.guard THEN IF text.guard THEN
NEW(guard); NEW(guard);
List.append(ChangeLog.CL.Log, guard); List.append(ChangeLog.CL.Log, guard);
guard.saved := ChangeLog.isFirstGuard(guard);
text.edition := guard; text.edition := guard;
text.guard := FALSE; text.guard := FALSE
ELSE ELSE
guard := text.edition guard := text.edition
END; END;