CEDIT: minor fixes, refactoring

git-svn-id: svn://kolibrios.org@9210 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2021-10-03 17:44:42 +00:00
parent 683ccfc78f
commit 5410543f49
9 changed files with 568 additions and 545 deletions

Binary file not shown.

View File

@ -28,10 +28,10 @@ IMPORT
RW, Ini, EB := EditBox, Icons, Tabs, Timer;
CONST
header = "CEdit (28-sep-2021)";
HEADER = "CEdit (03-oct-2021)";
ShellFilter = "";
EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";
EditFilter = "SH|INC|TXT|ASM|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";
fontWidth = K.fontWidth;
fontHeight = K.fontHeight;
@ -51,14 +51,14 @@ CONST
btnYes = 40;
btnNo = 41;
btnFindNext = 60;
btnReplace = 61;
btnReplaceAll = 62;
btnGoto = 63;
btnCloseSearch = 64;
btnHideSearch = 65;
btnFindNext = 42;
btnReplace = 43;
btnReplaceAll = 44;
btnGoto = 45;
btnCloseSearch = 46;
btnHideSearch = 47;
mainMenuBtn = 70;
mainMenuBtn = 60;
btnHeight = 25;
btnWidth = 75;
@ -184,10 +184,10 @@ VAR
switch, closing: BOOLEAN;
leftButton: BOOLEAN;
hScroll, vScroll: Scroll.tScroll;
LEFT: INTEGER;
FindEdit, ReplaceEdit, GotoEdit: EB.tEditBox;
hScroll, vScroll: Scroll.tScroll;
CS, WH, BKW: CheckBox.tCheckBox;
new_searchText, searchText, replaceText, gotoText: T.tString;
@ -226,14 +226,7 @@ END WritePos;
PROCEDURE EditBox_Focus (edit: EB.tEditBox): BOOLEAN;
VAR
res: BOOLEAN;
BEGIN
res := FALSE;
IF edit # NIL THEN
res := 1 IN edit.flags
END
RETURN res
RETURN 1 IN edit.flags
END EditBox_Focus;
@ -249,7 +242,7 @@ BEGIN
END resetTimer;
PROCEDURE EditBox_SetFocus (edit: EB.tEditBox; value: BOOLEAN);
PROCEDURE EditBox_SetFocus (VAR edit: EB.tEditBox; value: BOOLEAN);
BEGIN
IF value THEN
INCL(edit.flags, 1)
@ -262,7 +255,7 @@ BEGIN
END EditBox_SetFocus;
PROCEDURE SetFocus (edit: EB.tEditBox; value: BOOLEAN);
PROCEDURE SetFocus (VAR edit: EB.tEditBox; value: BOOLEAN);
BEGIN
EditBox_SetFocus(FindEdit, FALSE);
EditBox_SetFocus(ReplaceEdit, FALSE);
@ -413,17 +406,21 @@ PROCEDURE DrawState (text: T.tText; width, height: INTEGER);
VAR
y: INTEGER;
s: ARRAY 24 OF WCHAR;
header: RW.tFileName;
BEGIN
y := (btnHeight - fontHeight) DIV 2 + btnTop;
s := "";
U.append(s, RW.eolNames[text.eol]);
U.append(s, 20X);
U.append(s, 20X + 20X);
U.append(s, E.names[text.enc]);
K.DrawRect(width - LEN(s)*fontWidth, y, LEN(s)*fontWidth, fontHeight, K.winColor);
K.DrawText(width - LENGTH(s)*fontWidth, y, K.textColor, s);
header := HEADER;
IF text.fileName # "" THEN
U.append8(header, " - ");
U.append8(header, text.fileName)
END;
K.SetCaption(header);
K.DrawRect(LEFT + 16*fontWidth, TOP + canvas.height + scrollWidth, width - (LEFT + 16*fontWidth), BOTTOM - scrollWidth + 1, K.winColor);
y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2;
K.DrawRect(LEFT + 16*fontWidth, TOP + canvas.height + scrollWidth, width - LEFT - 24*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
K.DrawText866(LEFT + 16*fontWidth, y, K.textColor, text.fileName);
K.DrawText(width - (LENGTH(s) + 10)*fontWidth, y, K.textColor, s);
WriteModified(width - 8*fontWidth, y)
END DrawState;
@ -576,7 +573,7 @@ VAR
BEGIN
K.BeginDraw;
K.CreateWindow(30 + K.GetTickCount() MOD 128, 30 + K.GetTickCount() MOD 128, winWidth, winHeight, K.winColor, 73H, 0, 0, header);
K.CreateWindow(30 + K.GetTickCount() MOD 128, 30 + K.GetTickCount() MOD 128, winWidth, winHeight, K.winColor, 73H, 0, 0, "");
IF (text # NIL) & ~K.RolledUp() THEN
IF confirm THEN
resetTimer
@ -698,16 +695,7 @@ BEGIN
U.getFileName(text.fileName, OD.FileName, U.SLASH);
IF OD.FileName = "" THEN
OD.FileName := "NewFile.";
CASE text.lang OF
|Languages.langText: ext := "txt"
|Languages.langC: ext := "c"
|Languages.langFasm: ext := "asm"
|Languages.langIni: ext := "ini"
|Languages.langJSON: ext := "json"
|Languages.langLua: ext := "lua"
|Languages.langOberon: ext := "ob07"
|Languages.langPascal: ext := "pas"
END;
Languages.getExt(text.lang, ext);
U.append8(OD.FileName, ext)
END;
OpenFile(fileName, EditFilter);
@ -923,26 +911,11 @@ BEGIN
END open;
PROCEDURE createEdit (left, top: INTEGER): EB.tEditBox;
VAR
edit, EditBox0: EB.tEditBox;
BEGIN
NEW(EditBox0);
EditBox0.text := K.malloc(EDITBOX_MAXCHARS + 2);
ASSERT(EditBox0.text # 0);
edit := EB.create(left, top, EditBox_Width, EDITBOX_MAXCHARS, EditBox0);
edit.flags := {1, 14};
edit.text_color := 30000000H;
EditBox_SetFocus(edit, FALSE)
RETURN edit
END createEdit;
PROCEDURE createSearchForm;
BEGIN
FindEdit := createEdit(searchLeft, TOP + 20);
ReplaceEdit := createEdit(searchLeft, TOP + 20 + 55);
GotoEdit := createEdit(searchLeft, TOP + 20 + 330);
EB.create(searchLeft, TOP + 20, EditBox_Width, EDITBOX_MAXCHARS, FindEdit);
EB.create(searchLeft, TOP + 20 + 55, EditBox_Width, EDITBOX_MAXCHARS, ReplaceEdit);
EB.create(searchLeft, TOP + 20 + 330, EditBox_Width, EDITBOX_MAXCHARS, GotoEdit);
INCL(GotoEdit.flags, 15);
CheckBox.create("backward", BKW);
CheckBox.create("match case", CS);
@ -1041,8 +1014,12 @@ END CloseMenu;
PROCEDURE MenuItemClick (menu: Menu.tMenu; id: INTEGER);
VAR
msg: ARRAY 2 OF INTEGER;
BEGIN
K.SendIPC(mainTID, id)
msg[0] := id;
msg[1] := 8;
K.SendIPC(mainTID, msg)
END MenuItemClick;
@ -1940,9 +1917,10 @@ CONST
VAR
msState: SET;
scroll, x, y, scrollX, scrollY: INTEGER;
pos1, pos2: T.tPoint;
PROCEDURE EditBox (eb: EB.tEditBox);
PROCEDURE EditBox (VAR eb: EB.tEditBox);
VAR
focus: BOOLEAN;
BEGIN
@ -1969,10 +1947,14 @@ BEGIN
END;
IF leftButton THEN
IF K.GetTickCount() - time >= DELAY THEN
T.getPos(text, pos1.Y, pos1.X);
mouse(x, y);
T.mouse(text, x, y);
T.getPos(text, pos2.Y, pos2.X);
IF (pos1.X # pos2.X) OR (pos1.Y # pos2.Y) THEN
repaint
END
END
END;
Scroll.mouse(hScroll);

View File

@ -28,7 +28,7 @@ CONST
TYPE
tEditBox* = POINTER TO RECORD
tEditBox* = RECORD
width*,
left*,
top*,
@ -39,7 +39,7 @@ TYPE
text_color*,
max: INTEGER;
text*: INTEGER;
mouse_variable: tEditBox;
mouse_variable: INTEGER;
flags*: SET;
size,
@ -110,28 +110,21 @@ BEGIN
END setValue;
PROCEDURE create* (tlx, tly, width, max_chars: INTEGER; editbox_interlock: tEditBox): tEditBox;
VAR
new_textbox: tEditBox;
PROCEDURE create* (tlx, tly, width, max_chars: INTEGER; VAR editbox: tEditBox);
BEGIN
NEW(new_textbox);
new_textbox.width := width;
new_textbox.left := tlx;
new_textbox.top := tly;
new_textbox.color := 0FFFFFFH;
new_textbox.shift_color := 06A9480H;
new_textbox.focus_border_color := 0;
new_textbox.blur_border_color := 06A9480H;
new_textbox.text_color := 0;
new_textbox.max := max_chars;
new_textbox.text := KOSAPI.malloc(max_chars + 2);
ASSERT(new_textbox.text # 0);
new_textbox.mouse_variable := editbox_interlock;
new_textbox.flags := {}
RETURN new_textbox
editbox.width := width;
editbox.left := tlx;
editbox.top := tly;
editbox.color := 0FFFFFFH;
editbox.shift_color := 06A9480H;
editbox.focus_border_color := 0;
editbox.blur_border_color := 06A9480H;
editbox.text_color := 30000000H;
editbox.max := max_chars;
editbox.text := KOSAPI.malloc(max_chars + 2);
ASSERT(editbox.text # 0);
editbox.mouse_variable := 0;
editbox.flags := {14}
END create;

View File

@ -46,7 +46,7 @@ END GetName;
PROCEDURE CreateWindow* (x, y, w, h, color, style, hcolor, hstyle: INTEGER; htext: ARRAY OF CHAR);
BEGIN
KOSAPI.sysfunc6(0, x * 65536 + w, y * 65536 + h, color + LSL(style, 24), hcolor + LSL(hstyle, 24), SYSTEM.ADR(htext[0]))
KOSAPI.sysfunc6(0, x*65536 + w, y*65536 + h, color + LSL(style, 24), hcolor + LSL(hstyle, 24), SYSTEM.ADR(htext[0]))
END CreateWindow;
@ -142,25 +142,25 @@ END SetWinSize;
PROCEDURE DrawText* (x, y, color: INTEGER; text: ARRAY OF WCHAR);
BEGIN
KOSAPI.sysfunc6(4, x * 65536 + y, color + LSL(0A0H, 24), SYSTEM.ADR(text[0]), 0, 0)
KOSAPI.sysfunc6(4, x*65536 + y, color + LSL(0A0H, 24), SYSTEM.ADR(text[0]), 0, 0)
END DrawText;
PROCEDURE DrawText69* (x, y, color: INTEGER; text: ARRAY OF CHAR);
BEGIN
KOSAPI.sysfunc6(4, x * 65536 + y, color + LSL(080H, 24), SYSTEM.ADR(text[0]), 0, 0)
KOSAPI.sysfunc6(4, x*65536 + y, color + LSL(080H, 24), SYSTEM.ADR(text[0]), 0, 0)
END DrawText69;
PROCEDURE DrawText866* (x, y, color: INTEGER; text: ARRAY OF CHAR);
BEGIN
KOSAPI.sysfunc6(4, x * 65536 + y, color + LSL(0D0H, 24), SYSTEM.ADR(text[0]), 0, winColor)
KOSAPI.sysfunc6(4, x*65536 + y, color + LSL(0D0H, 24), SYSTEM.ADR(text[0]), 0, winColor)
END DrawText866;
PROCEDURE DrawText866bk* (x, y, color, bkColor: INTEGER; text: ARRAY OF CHAR);
BEGIN
KOSAPI.sysfunc6(4, x * 65536 + y, color + LSL(0D0H, 24), SYSTEM.ADR(text[0]), 0, bkColor)
KOSAPI.sysfunc6(4, x*65536 + y, color + LSL(0D0H, 24), SYSTEM.ADR(text[0]), 0, bkColor)
END DrawText866bk;
@ -233,7 +233,14 @@ END ExitID;
PROCEDURE CreateThread* (proc: INTEGER; stack: ARRAY OF INTEGER): INTEGER;
RETURN KOSAPI.sysfunc4(51, 1, proc, SYSTEM.ADR(stack[LEN(stack) - 2]))
VAR
tid: INTEGER;
BEGIN
tid := KOSAPI.sysfunc4(51, 1, proc, SYSTEM.ADR(stack[LEN(stack) - 2]));
IF tid = -1 THEN
tid := 0
END
RETURN tid
END CreateThread;
@ -323,18 +330,12 @@ BEGIN
END SetIPC;
PROCEDURE SendIPC* (tid, msg: INTEGER);
PROCEDURE SendIPC* (tid: INTEGER; msg: ARRAY OF INTEGER);
BEGIN
KOSAPI.sysfunc5(60, 2, tid, SYSTEM.ADR(msg), SYSTEM.SIZE(INTEGER))
KOSAPI.sysfunc5(60, 2, tid, SYSTEM.ADR(msg[0]), SYSTEM.SIZE(INTEGER)*LEN(msg))
END SendIPC;
PROCEDURE PutPixel* (x, y, color: INTEGER);
BEGIN
KOSAPI.sysfunc4(1, x, y, color)
END PutPixel;
PROCEDURE GetSystemColors*;
VAR
buf: ARRAY 10 OF INTEGER;
@ -384,4 +385,10 @@ BEGIN
END mouse;
PROCEDURE SetCaption* (text: ARRAY OF CHAR);
BEGIN
KOSAPI.sysfunc4(71, 2, SYSTEM.ADR(text[0]), 0)
END SetCaption;
END KolibriOS.

View File

@ -19,7 +19,7 @@
MODULE Languages;
IMPORT Lines;
IMPORT Lines, Utils;
CONST
@ -49,6 +49,8 @@ VAR
currentLang: INTEGER;
fileExt: ARRAY 11 OF RECORD ext: ARRAY 8 OF CHAR; lang: INTEGER END;
PROCEDURE isCS* (lang: INTEGER): BOOLEAN;
RETURN lang IN csLang
@ -395,6 +397,36 @@ BEGIN
END setCurLang;
PROCEDURE getLang* (ext: ARRAY OF CHAR): INTEGER;
VAR
i: INTEGER;
BEGIN
i := 0;
WHILE (i < LEN(fileExt)) & (fileExt[i].ext # ext) DO
INC(i)
END;
IF i < LEN(fileExt) THEN
i := fileExt[i].lang
ELSE
i := langText
END
RETURN i
END getLang;
PROCEDURE getExt* (lang: INTEGER; VAR ext: ARRAY OF CHAR);
VAR
i: INTEGER;
BEGIN
i := 0;
WHILE fileExt[i].lang # lang DO
INC(i)
END;
COPY(fileExt[i].ext, ext);
Utils.lowcase(ext)
END getExt;
PROCEDURE init* (getStr: procGetStr);
BEGIN
currentLang := langText;
@ -406,6 +438,18 @@ BEGIN
loadKW(KW[langIni], Delim[langIni], getStr, "lang_Ini");
loadKW(KW[langFasm], Delim[langFasm], getStr, "lang_Fasm");
loadKW(KW[langJSON], Delim[langJSON], getStr, "lang_JSON");
fileExt[ 0].ext := "OB07"; fileExt[ 0].lang := langOberon;
fileExt[ 1].ext := "C"; fileExt[ 1].lang := langC;
fileExt[ 2].ext := "H"; fileExt[ 2].lang := langC;
fileExt[ 3].ext := "CPP"; fileExt[ 3].lang := langC;
fileExt[ 4].ext := "PAS"; fileExt[ 4].lang := langPascal;
fileExt[ 5].ext := "PP"; fileExt[ 5].lang := langPascal;
fileExt[ 6].ext := "ASM"; fileExt[ 6].lang := langFasm;
fileExt[ 7].ext := "LUA"; fileExt[ 7].lang := langLua;
fileExt[ 8].ext := "INI"; fileExt[ 8].lang := langIni;
fileExt[ 9].ext := "JSON"; fileExt[ 9].lang := langJSON;
fileExt[10].ext := "TXT"; fileExt[10].lang := langText;
END init;

View File

@ -46,8 +46,8 @@ CONST
TYPE
tPoint = RECORD
X, Y: INTEGER
tPoint* = RECORD
X*, Y*: INTEGER
END;
pPoint = POINTER TO tPoint;
@ -67,22 +67,20 @@ TYPE
scroll: tPoint;
CurX: INTEGER;
modified*: BOOLEAN;
edition*: tGuard;
comments, numbers*, guard,
search, cs, whole: BOOLEAN;
curLine: tLine;
fileName*: RW.tFileName;
lang*: INTEGER;
enc*: INTEGER;
eol*: INTEGER;
enc*, eol*: INTEGER;
table: Search.IdxTable;
foundList: List.tList;
idxData: Search.tBuffer;
foundSel: INTEGER;
searchText: tString;
chLog*: ChangeLog.tLog;
maxLength*: INTEGER
maxLength*: INTEGER;
fileName*: RW.tFileName
END;
tProcedure = PROCEDURE;
@ -104,34 +102,6 @@ VAR
charWidth, charHeight: INTEGER;
PROCEDURE setName* (text: tText; name: RW.tFileName);
VAR
ext: RW.tFileName;
BEGIN
text.fileName := name;
U.getFileName(text.fileName, ext, ".");
U.upcase(ext);
IF ext = "OB07" THEN
text.lang := Lang.langOberon
ELSIF (ext = "C") OR (ext = "H") OR (ext = "CPP") THEN
text.lang := Lang.langC
ELSIF (ext = "PAS") OR (ext = "PP") THEN
text.lang := Lang.langPascal
ELSIF ext = "ASM" THEN
text.lang := Lang.langFasm
ELSIF ext = "LUA" THEN
text.lang := Lang.langLua
ELSIF ext = "INI" THEN
text.lang := Lang.langIni
ELSIF ext = "JSON" THEN
text.lang := Lang.langJSON
ELSE
text.lang := Lang.langText
END;
Lang.setCurLang(text.lang)
END setName;
PROCEDURE setLang* (text: tText; lang: INTEGER);
BEGIN
text.lang := lang;
@ -140,6 +110,17 @@ BEGIN
END setLang;
PROCEDURE setName* (text: tText; name: RW.tFileName);
VAR
ext: RW.tFileName;
BEGIN
text.fileName := name;
U.getFileName(name, ext, ".");
U.upcase(ext);
setLang(text, Lang.getLang(ext))
END setName;
PROCEDURE getPos* (text: tText; VAR x, y: INTEGER);
BEGIN
x := text.cursor.X + 1;
@ -518,7 +499,7 @@ BEGIN
ELSE
cond := 0
END
END;
END
ELSIF lang = Lang.langOberon THEN
@ -2089,7 +2070,7 @@ BEGIN
line := getLine(text, n);
firstLine := line;
cnt := 0;
WHILE (line # NIL) & (cnt <= textsize.Y) DO
WHILE (line # NIL) & (cnt < textsize.Y) DO
backColor := colors.back;
IF (line = text.curLine) & ~selected(text) THEN
G.SetColor(canvas, colors.curline);
@ -2122,7 +2103,7 @@ BEGIN
line := firstLine;
SetColor(colors.numtext, colors.numback);
y := padding.top + inter DIV 2;
n := MIN(text.scroll.Y + textsize.Y + 1, text.count);
n := MIN(text.scroll.Y + textsize.Y, text.count);
FOR i := text.scroll.Y + 1 TO n DO
IF text.numbers THEN
IF (i MOD 10 = 0) OR (i - 1 = text.cursor.Y) OR line.label THEN
@ -2147,7 +2128,7 @@ BEGIN
cnt := 0;
line := firstLine;
lastLine := line;
WHILE (line # NIL) & (cnt <= textsize.Y) DO
WHILE (line # NIL) & (cnt < textsize.Y) DO
lastLine := line;
NextLine(line);
INC(cnt)

View File

@ -50,7 +50,7 @@ BEGIN
IF enabled THEN
DEC(cnt, step);
IF cnt <= 0 THEN
KOSAPI.sysfunc5(60, 2, mainTID, SYSTEM.ADR(msg[0]), msg[1]);
K.SendIPC(mainTID, msg);
cnt := time
END
END

View File

@ -200,7 +200,7 @@ BEGIN
IF cap8(s[i]) THEN
END;
DEC(i)
END;
END
END upcase;
@ -240,6 +240,20 @@ BEGIN
END low;
PROCEDURE lowcase* (VAR s: ARRAY OF CHAR);
VAR
i: INTEGER;
BEGIN
i := LENGTH(s) - 1;
WHILE i >= 0 DO
IF ("A" <= s[i]) & (s[i] <= "Z") THEN
s[i] := CHR(ORD(s[i]) + 32)
END;
DEC(i)
END
END lowcase;
PROCEDURE str2int* (s: ARRAY OF WCHAR; VAR val: INTEGER): BOOLEAN;
VAR
i, temp: INTEGER;
@ -262,8 +276,7 @@ BEGIN
IF isDigit(s[i]) THEN
REPEAT
temp := temp * 10;
temp := temp + (ORD(s[i]) - ORD("0"));
temp := temp*10 + ORD(s[i]) - ORD("0");
INC(i)
UNTIL ~isDigit(s[i]);
IF neg THEN

View File

@ -296,7 +296,6 @@ PROCEDURE MouseMove (VAR scroll: tScroll; x, y: INTEGER);
VAR
c: INTEGER;
BEGIN
IF scroll.Slider # -1 THEN
IF scroll.vertical THEN
c := y - scroll.top
ELSE
@ -304,13 +303,16 @@ BEGIN
END;
setPos(scroll, scroll.pos0 + c - scroll.Slider);
paint(scroll)
END
END MouseMove;
PROCEDURE SendIPC;
VAR
msg: ARRAY 2 OF INTEGER;
BEGIN
K.SendIPC(K.ThreadID(), ScrollIPC)
msg[0] := ScrollIPC;
msg[1] := 8;
K.SendIPC(K.ThreadID(), msg)
END SendIPC;
@ -342,7 +344,6 @@ PROCEDURE MouseDown (VAR scroll: tScroll; x, y: INTEGER);
VAR
c, size: INTEGER;
BEGIN
IF ~scroll.mouse THEN
DEC(x, scroll.left);
DEC(y, scroll.top);
scroll.mouse := TRUE;
@ -370,7 +371,6 @@ BEGIN
paint(scroll)
END
END
END
END MouseDown;
@ -381,8 +381,11 @@ VAR
BEGIN
K.mouse(msState, x, y);
IF 0 IN msState THEN
MouseDown(scroll, x, y);
IF ~scroll.mouse THEN
MouseDown(scroll, x, y)
ELSIF scroll.Slider # -1 THEN
MouseMove(scroll, x, y)
END
ELSIF scroll.mouse THEN
MouseUp(scroll);
paint(scroll)