update cedit by akron1

git-svn-id: svn://kolibrios.org@9050 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2021-07-10 23:39:41 +00:00
parent 7b13d5fb4e
commit e9c913f9db
10 changed files with 603 additions and 137 deletions

View File

@ -77,7 +77,7 @@ icon=98
exec=/kolibrios/utils/thashview exec=/kolibrios/utils/thashview
icon=124 icon=124
[TextEditor] [TextEdit]
exec=/kolibrios/utils/t_edit exec=/kolibrios/utils/t_edit
icon=9 icon=9
next=$CodeEdit next=$CodeEdit

Binary file not shown.

View File

@ -25,10 +25,10 @@ IMPORT
G := Graph, T := Text, E := Encodings, G := Graph, T := Text, E := Encodings,
CB := Clipboard, Languages, CB := Clipboard, Languages,
ChangeLog, Scroll, ChangeLog, Scroll,
RW, Ini, box_lib, Icons; RW, Ini, box_lib, Icons, Tabs;
CONST CONST
header = "CEdit (06-jul-2021)"; header = "CEdit (10-jul-2021)";
ShellFilter = ""; ShellFilter = "";
EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI"; EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI";
@ -80,7 +80,7 @@ CONST
toolbarDelim = 7; toolbarDelim = 7;
iconPad = (toolBtnSize - Icons.SIZE) DIV 2; iconPad = (toolBtnSize - Icons.SIZE) DIV 2;
TOP = btnTop + toolBtnSize + 7; TOP = btnTop + toolBtnSize + 10 + Tabs.tabHeight;
RIGHT = scrollWidth - 2; RIGHT = scrollWidth - 2;
BOTTOM = scrollWidth + 18; BOTTOM = scrollWidth + 18;
@ -115,8 +115,10 @@ CONST
menuOpen = 11; menuOpen = 11;
menuSave = 12; menuSave = 12;
menuSaveAs = 13; menuSaveAs = 13;
menuFolder = 14; menuSaveAll = 14;
menuExit = 15; menuFolder = 15;
menuClose = 16;
menuExit = 17;
menuNumbers = 20; menuNumbers = 20;
menuFontSize = 21; menuFontSize = 21;
@ -146,17 +148,25 @@ CONST
menuPipet = 70; menuPipet = 70;
menuSysFunc = 71; menuSysFunc = 71;
maxTexts = 32;
VAR VAR
canvas: G.tCanvas; canvas: G.tCanvas;
font, font1, font2: G.tFont; font, font1, font2: G.tFont;
tabs: Tabs.tTabs;
text: T.tText; text: T.tText;
texts: ARRAY maxTexts OF T.tText;
textsCount, curText: INTEGER;
winWidth, winHeight: INTEGER; winWidth, winHeight: INTEGER;
shift: SET; shift: SET;
AppPath, runScript, buildScript, debugScript: RW.tFileName; AppPath, runScript, buildScript, debugScript: RW.tFileName;
OD: OpenDlg.Dialog; OD: OpenDlg.Dialog;
confirm, notFound, search, modified: BOOLEAN; confirm, notFound, search, modified: BOOLEAN;
switch: BOOLEAN;
leftButton, VScroll, HScroll: BOOLEAN; leftButton, VScroll, HScroll: BOOLEAN;
vScroll, hScroll: Scroll.tScroll; vScroll, hScroll: Scroll.tScroll;
LEFT: INTEGER; LEFT: INTEGER;
@ -335,6 +345,26 @@ BEGIN
END WriteModified; END WriteModified;
PROCEDURE DrawState (text: T.tText; width, height: INTEGER);
VAR
y: INTEGER;
BEGIN
y := (btnHeight - fontHeight) DIV 2 + btnTop;
K.DrawRect(width - 12*fontWidth, y, 12*fontWidth, fontHeight, K.winColor);
CASE text.enc OF
|E.UTF8: K.DrawText866(width - 5*fontWidth, y, K.textColor, "UTF-8")
|E.UTF8BOM: K.DrawText866(width - 9*fontWidth, y, K.textColor, "UTF-8-BOM")
|E.CP866: K.DrawText866(width - 5*fontWidth, y, K.textColor, "CP866")
|E.W1251: K.DrawText866(width - 12*fontWidth, y, K.textColor, "Windows-1251")
END;
y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2;
K.DrawRect(LEFT + 16*fontWidth, TOP + canvas.height + scrollWidth - 1, width - LEFT - 24*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
K.DrawText866(LEFT + 16*fontWidth, y, K.textColor, text.fileName);
WriteModified(width - 8*fontWidth, y)
END DrawState;
PROCEDURE repaint; PROCEDURE repaint;
VAR VAR
width, height, scrollX, scrollY, y: INTEGER; width, height, scrollX, scrollY, y: INTEGER;
@ -348,8 +378,14 @@ BEGIN
IF ~search THEN IF ~search THEN
T.wordSel(text) T.wordSel(text)
END; END;
T.draw(text);
K.ClientSize(width, height); K.ClientSize(width, height);
IF switch THEN
DrawState(text, width, height);
Tabs.draw(tabs);
IF search & T.search(text, searchText, cs, whole) THEN END;
switch := FALSE
END;
T.draw(text);
y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2; y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2;
K.DrawRect(LEFT, TOP + canvas.height + scrollWidth - 1, 16*fontWidth, BOTTOM - scrollWidth + 1, K.winColor); K.DrawRect(LEFT, TOP + canvas.height + scrollWidth - 1, 16*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
WritePos(y); WritePos(y);
@ -360,7 +396,7 @@ BEGIN
T.getScroll(text, scrollX, scrollY); T.getScroll(text, scrollX, scrollY);
vScroll.value := scrollY; vScroll.maxVal := text.count - 1; vScroll.value := scrollY; vScroll.maxVal := text.count - 1;
hScroll.value := scrollX; hScroll.maxVal := Lines.maxLength; hScroll.value := scrollX; hScroll.maxVal := text.maxLength;
Scroll.draw(vScroll, LEFT + canvas.width - 1, TOP + scrollWidth - 1); Scroll.draw(vScroll, LEFT + canvas.width - 1, TOP + scrollWidth - 1);
Scroll.draw(hScroll, LEFT + scrollWidth, TOP + canvas.height - 1); Scroll.draw(hScroll, LEFT + scrollWidth, TOP + canvas.height - 1);
@ -388,6 +424,7 @@ BEGIN
K.ClientSize(cliWidth, cliHeight); K.ClientSize(cliWidth, cliHeight);
G.destroy(canvas); G.destroy(canvas);
canvas := G.CreateCanvas(cliWidth - (LEFT + RIGHT + 1), cliHeight - (TOP + BOTTOM)); canvas := G.CreateCanvas(cliWidth - (LEFT + RIGHT + 1), cliHeight - (TOP + BOTTOM));
Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, cliWidth - (LEFT + RIGHT + 1), Tabs.tabHeight);
G.SetFont(canvas, font); G.SetFont(canvas, font);
T.setCanvas(canvas); T.setCanvas(canvas);
T.resize(canvas.width, canvas.height); T.resize(canvas.width, canvas.height);
@ -448,7 +485,7 @@ END SearchPanel;
PROCEDURE draw_window; PROCEDURE draw_window;
VAR VAR
width, height, x, y: INTEGER; width, height, x: INTEGER;
PROCEDURE drawToolbarBtn (id, x: INTEGER); PROCEDURE drawToolbarBtn (id, x: INTEGER);
@ -547,21 +584,11 @@ BEGIN
K.PutPixel(LEFT + canvas.width + scrollWidth - 2, TOP, K.winColor); K.PutPixel(LEFT + canvas.width + scrollWidth - 2, TOP, K.winColor);
K.PutPixel(LEFT, TOP + canvas.height + scrollWidth - 2, K.winColor); K.PutPixel(LEFT, TOP + canvas.height + scrollWidth - 2, K.winColor);
y := (btnHeight - fontHeight) DIV 2 + btnTop; DrawState(text, width, height);
CASE text.enc OF
|E.UTF8: K.DrawText866(width - 5*fontWidth, y, K.textColor, "UTF-8")
|E.UTF8BOM: K.DrawText866(width - 9*fontWidth, y, K.textColor, "UTF-8-BOM")
|E.CP866: K.DrawText866(width - 5*fontWidth, y, K.textColor, "CP866")
|E.W1251: K.DrawText866(width - 12*fontWidth, y, K.textColor, "Windows-1251")
END;
IF search THEN IF search THEN
SearchPanel(searchLeft, TOP) SearchPanel(searchLeft, TOP)
END; END;
Tabs.draw(tabs);
y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2;
K.DrawRect(LEFT + 16*fontWidth, TOP + canvas.height + scrollWidth - 1, width - LEFT - 24*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
K.DrawText866(LEFT + 16*fontWidth, y, K.textColor, text.fileName);
WriteModified(width - 8*fontWidth, y);
repaint repaint
END; END;
K.EndDraw K.EndDraw
@ -622,9 +649,20 @@ BEGIN
END error; END error;
PROCEDURE saveAs; PROCEDURE saveError (name: RW.tFileName);
VAR VAR
fileName: RW.tFileName; s: RW.tFileName;
BEGIN
s := "'cedit: error saving file ";
U.append8(s, name);
U.append8(s, "' -E");
error(s)
END saveError;
PROCEDURE saveAs (text: T.tText);
VAR
fileName, name: RW.tFileName;
ext: ARRAY 8 OF CHAR; ext: ARRAY 8 OF CHAR;
BEGIN BEGIN
OD._type := OpenDlg.tsave; OD._type := OpenDlg.tsave;
@ -645,44 +683,86 @@ BEGIN
OpenFile(fileName, EditFilter); OpenFile(fileName, EditFilter);
IF fileName # "" THEN IF fileName # "" THEN
IF T.save(text, fileName, text.enc, RW.EOL_CRLF) THEN IF T.save(text, fileName, text.enc, RW.EOL_CRLF) THEN
T.setName(text, fileName) T.setName(text, fileName);
U.getFileName(fileName, name, U.SLASH);
Tabs.rename(tabs, curText, name)
ELSE ELSE
error("'cedit: error saving file' -E") saveError(fileName)
END END
END END
END saveAs; END saveAs;
PROCEDURE save; PROCEDURE getIdx (text: T.tText): INTEGER;
VAR
i: INTEGER;
BEGIN
i := 0;
WHILE texts[i] # text DO
INC(i)
END
RETURN i
END getIdx;
PROCEDURE Switch (txt: T.tText);
BEGIN
Tabs.switch(tabs, curText);
text := txt;
T.switch(txt);
switch := TRUE
END Switch;
PROCEDURE save (text: T.tText);
BEGIN BEGIN
IF text.modified THEN IF text.modified THEN
IF text.fileName # "" THEN IF text.fileName # "" THEN
IF ~T.save(text, text.fileName, text.enc, RW.EOL_CRLF) THEN IF ~T.save(text, text.fileName, text.enc, RW.EOL_CRLF) THEN
error("'cedit: error saving file' -E") saveError(text.fileName)
END END
ELSE ELSE
saveAs curText := getIdx(text);
Switch(text);
saveAs(text)
END END
END END
END save; END save;
PROCEDURE SelfRun (file: ARRAY OF CHAR); PROCEDURE saveAll;
BEGIN
K.Run(AppPath, file)
END SelfRun;
PROCEDURE open;
VAR VAR
fileName: RW.tFileName; i: INTEGER;
BEGIN BEGIN
OD._type := OpenDlg.topen; i := textsCount - 1;
OpenFile(fileName, EditFilter); WHILE i >= 0 DO
IF fileName # "" THEN IF texts[i].modified THEN
SelfRun(fileName) save(texts[i])
END END;
END open; DEC(i)
END;
END saveAll;
PROCEDURE insert (pos: INTEGER; txt: T.tText);
VAR
i: INTEGER;
name: RW.tFileName;
BEGIN
FOR i := textsCount - 1 TO pos BY -1 DO
texts[i + 1] := texts[i]
END;
texts[pos] := txt;
INC(textsCount);
curText := pos;
IF txt.fileName = "" THEN
name := "new"
ELSE
U.getFileName(txt.fileName, name, U.SLASH)
END;
Tabs.add(tabs, name);
Switch(txt)
END insert;
PROCEDURE Confirm; PROCEDURE Confirm;
@ -707,6 +787,104 @@ BEGIN
END Confirm; END Confirm;
PROCEDURE closeFile (conf: BOOLEAN);
VAR
i: INTEGER;
BEGIN
IF text.modified & conf THEN
Confirm
ELSE
Tabs.delete(tabs, curText);
FOR i := curText + 1 TO textsCount - 1 DO
texts[i - 1] := texts[i]
END;
DEC(textsCount);
IF curText = textsCount THEN
DEC(curText)
END;
IF curText >= 0 THEN
Switch(texts[curText])
ELSE
K.Exit
END;
draw_window
END
END closeFile;
PROCEDURE NewFile;
VAR
nov: T.tText;
BEGIN
IF textsCount < maxTexts THEN
nov := T.New();
T.SetPos(nov, 0, 0);
insert(textsCount, nov)
ELSE
error("'cedit: too many files' -E")
END
END NewFile;
PROCEDURE getFileNum (fileName: RW.tFileName): INTEGER;
VAR
i: INTEGER;
PROCEDURE nameEq (name1, name2: RW.tFileName): BOOLEAN;
VAR
n1, n2: RW.tFileName;
BEGIN
n1 := name1;
n2 := name2;
U.upcase(n1);
U.upcase(n2)
RETURN n1 = n2
END nameEq;
BEGIN
i := 0;
WHILE (i < textsCount) & ~nameEq(texts[i].fileName, fileName) DO
INC(i)
END;
IF i = textsCount THEN
i := -1
END
RETURN i
END getFileNum;
PROCEDURE open;
VAR
fileName: RW.tFileName;
nov: T.tText;
err, n: INTEGER;
BEGIN
IF textsCount < maxTexts THEN
OD._type := OpenDlg.topen;
OpenFile(fileName, EditFilter);
IF fileName # "" THEN
n := getFileNum(fileName);
IF n = -1 THEN
nov := T.open(fileName, err);
IF nov = NIL THEN
error("'cedit: error opening file' -E")
ELSE
insert(textsCount, nov);
T.SetPos(nov, 0, 0)
END
ELSE
curText := n;
Tabs.switch(tabs, n);
Switch(texts[n]);
draw_window
END
END
ELSE
error("'cedit: too many files' -E")
END
END open;
PROCEDURE createEdit (left, top: INTEGER): box_lib.edit_box; PROCEDURE createEdit (left, top: INTEGER): box_lib.edit_box;
VAR VAR
edit, EditBox0: box_lib.edit_box; edit, EditBox0: box_lib.edit_box;
@ -813,11 +991,18 @@ END LeftButtonUp;
PROCEDURE close; PROCEDURE close;
VAR
cont: BOOLEAN;
BEGIN BEGIN
IF text.modified THEN cont := TRUE;
Confirm WHILE (textsCount > 0) & cont DO
ELSE IF text.modified THEN
K.Exit Confirm;
cont := FALSE
ELSE
closeFile(FALSE);
repaint
END
END END
END close; END close;
@ -859,15 +1044,20 @@ BEGIN
|menuSelectAll: T.key(text, ORD("A"), {T.CTRL}) |menuSelectAll: T.key(text, ORD("A"), {T.CTRL})
|menuNew: |menuNew:
SelfRun("") NewFile
|menuOpen: |menuOpen:
open open
|menuSave: |menuSave:
save; save(text);
repaint repaint
|menuSaveAs: |menuSaveAs:
saveAs; saveAs(text);
repaint repaint
|menuSaveAll:
saveAll;
repaint
|menuClose:
closeFile(TRUE)
|menuFolder: |menuFolder:
K.Run("/rd/1/File Managers/Eolite", text.fileName) K.Run("/rd/1/File Managers/Eolite", text.fileName)
|menuExit: |menuExit:
@ -1010,13 +1200,16 @@ VAR
menu: List.tList; menu: List.tList;
BEGIN BEGIN
menu := List.create(NIL); menu := List.create(NIL);
Menu.AddMenuItem(menu, menuNew, "new ctrl-N"); Menu.AddMenuItem(menu, menuNew, "new ctrl-N");
Menu.AddMenuItem(menu, menuOpen, "open ctrl-O"); Menu.AddMenuItem(menu, menuOpen, "open ctrl-O");
Menu.AddMenuItem(menu, menuSave, "save ctrl-S"); Menu.AddMenuItem(menu, menuSave, "save ctrl-S");
Menu.AddMenuItem(menu, menuSaveAs, "save as"); Menu.AddMenuItem(menu, menuSaveAs, "save as");
Menu.AddMenuItem(menu, menuFolder, "folder"); Menu.AddMenuItem(menu, menuSaveAll, "save all");
Menu.AddMenuItem(menu, menuFolder, "folder");
Menu.delimiter(menu); Menu.delimiter(menu);
Menu.AddMenuItem(menu, menuExit, "exit"); Menu.AddMenuItem(menu, menuClose, "close");
Menu.delimiter(menu);
Menu.AddMenuItem(menu, menuExit, "exit");
RETURN Menu.create(menu, MenuItemClick, MenuKeyDown) RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
END CreateMenuFile; END CreateMenuFile;
@ -1155,6 +1348,11 @@ BEGIN
IF menu = menuFile THEN IF menu = menuFile THEN
Menu.setEnabled(menu, menuSave, text.modified); Menu.setEnabled(menu, menuSave, text.modified);
Menu.setEnabled(menu, menuFolder, text.fileName # ""); Menu.setEnabled(menu, menuFolder, text.fileName # "");
i := 0;
WHILE (i < textsCount) & ~texts[i].modified DO
INC(i)
END;
Menu.setEnabled(menu, menuSaveAll, i < textsCount);
INC(x, menuFileX) INC(x, menuFileX)
ELSIF (menu = menuEdit) OR (menu = context) THEN ELSIF (menu = menuEdit) OR (menu = context) THEN
Menu.setEnabled(menu, menuUndo, ~ChangeLog.isFirstGuard(text.edition)); Menu.setEnabled(menu, menuUndo, ~ChangeLog.isFirstGuard(text.edition));
@ -1218,7 +1416,7 @@ END ShowMenu;
PROCEDURE main; PROCEDURE main;
VAR VAR
width, height, x, y, scrollX, scrollY, i: INTEGER; width, height, x, y, scrollX, scrollY, i: INTEGER;
key: INTEGER; key, btn: INTEGER;
msState: SET; msState: SET;
scroll: INTEGER; scroll: INTEGER;
err: INTEGER; err: INTEGER;
@ -1230,6 +1428,9 @@ BEGIN
K.GetSystemColors; K.GetSystemColors;
Icons.get(icons, grayIcons); Icons.get(icons, grayIcons);
modified := FALSE; modified := FALSE;
switch := FALSE;
textsCount := 0;
curText := 0;
mainTID := K.ThreadID(); mainTID := K.ThreadID();
K.SetIPC(IPC); K.SetIPC(IPC);
U.ptr2str(K.GetName(), AppPath); U.ptr2str(K.GetName(), AppPath);
@ -1239,7 +1440,7 @@ BEGIN
resized := FALSE; resized := FALSE;
shift := {}; shift := {};
K.ScreenSize(winWidth, winHeight); K.ScreenSize(winWidth, winHeight);
winWidth := (winWidth * 80) DIV 100 - (128 + 30); winWidth := (winWidth*80) DIV 100 - (128 + 30);
winHeight := winHeight - (128 + 30); winHeight := winHeight - (128 + 30);
winWidth := MAX(winWidth, minWinWidth); winWidth := MAX(winWidth, minWinWidth);
winHeight := MAX(winHeight, minWinHeight); winHeight := MAX(winHeight, minWinHeight);
@ -1247,6 +1448,8 @@ BEGIN
cliHeight := winHeight; cliHeight := winHeight;
LEFT := searchLeft; LEFT := searchLeft;
canvas := G.CreateCanvas(winWidth - (LEFT + RIGHT + 10), winHeight - (TOP + BOTTOM + 4) - K.SkinHeight()); canvas := G.CreateCanvas(winWidth - (LEFT + RIGHT + 10), winHeight - (TOP + BOTTOM + 4) - K.SkinHeight());
tabs := Tabs.create();
Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, canvas.width, Tabs.tabHeight);
font1 := G.CreateFont(1, "", {}); font1 := G.CreateFont(1, "", {});
font2 := G.CreateFont(2, "", {}); font2 := G.CreateFont(2, "", {});
font := font1; font := font1;
@ -1275,6 +1478,7 @@ BEGIN
END END
END; END;
OD := OpenDlg.Create(draw_window, OpenDlg.topen, filePath, ""); OD := OpenDlg.Create(draw_window, OpenDlg.topen, filePath, "");
insert(0, text);
vScroll := Scroll.create(scrollWidth, canvas.height - scrollWidth*2 + 1); vScroll := Scroll.create(scrollWidth, canvas.height - scrollWidth*2 + 1);
hScroll := Scroll.create(canvas.width - scrollWidth*2, scrollWidth); hScroll := Scroll.create(canvas.width - scrollWidth*2, scrollWidth);
@ -1320,9 +1524,9 @@ BEGIN
getKBState; getKBState;
IF confirm THEN IF confirm THEN
IF key DIV 65536 = 28 THEN (* Enter *) IF key DIV 65536 = 28 THEN (* Enter *)
save; save(text);
IF ~text.modified THEN IF ~text.modified THEN
K.Exit closeFile(FALSE)
END; END;
repaint repaint
END; END;
@ -1407,7 +1611,7 @@ BEGIN
open open
|30: key := ORD("A") |30: key := ORD("A")
|31: key := -1; |31: key := -1;
save save(text)
|32: key := ORD("D") |32: key := ORD("D")
|38: key := ORD("L") |38: key := ORD("L")
|44: T.undo(text); |44: T.undo(text);
@ -1416,7 +1620,7 @@ BEGIN
|46: key := ORD("C") |46: key := ORD("C")
|47: key := ORD("V") |47: key := ORD("V")
|49: key := -1; |49: key := -1;
SelfRun("") NewFile
ELSE ELSE
key := -1 key := -1
END END
@ -1431,7 +1635,17 @@ BEGIN
END; END;
repaint repaint
|3: |3:
CASE K.ButtonCode() OF btn := K.ButtonCode();
CASE btn OF
|Tabs.btnID .. Tabs.btnID + maxTexts - 1:
DEC(btn, Tabs.btnID);
curText := btn;
Tabs.switch(tabs, btn);
Switch(texts[btn]);
draw_window
|Tabs.btnID - 1: Tabs.scroll(tabs, -1); switch := TRUE; repaint
|Tabs.btnID - 2: Tabs.scroll(tabs, +1); switch := TRUE; repaint
|0: |0:
|btnFile: |btnFile:
@ -1449,21 +1663,23 @@ BEGIN
|btnTools: |btnTools:
ShowMenu(menuTools) ShowMenu(menuTools)
|btnNo: |btnNo:
K.Exit closeFile(FALSE);
repaint
|btnYes: |btnYes:
save; save(text);
IF ~text.modified THEN IF ~text.modified THEN
K.Exit closeFile(FALSE)
END; END;
repaint repaint
|btnClose: |btnClose:
close close
|btnNew: |btnNew:
SelfRun("") NewFile;
repaint
|btnOpen: |btnOpen:
open open
|btnSave: |btnSave:
save; save(text);
repaint repaint
|btnSearch: |btnSearch:
IF ~search THEN IF ~search THEN

View File

@ -42,11 +42,15 @@ TYPE
END; END;
tLog* = POINTER TO RECORD
Log*: List.tList;
guard: tGuard;
isLast: BOOLEAN
END;
VAR VAR
Log*: List.tList; CL*: tLog;
guard: tGuard;
isLast: BOOLEAN;
PROCEDURE isLastGuard* (guard: tGuard): BOOLEAN; PROCEDURE isLastGuard* (guard: tGuard): BOOLEAN;
@ -55,7 +59,7 @@ VAR
res: BOOLEAN; res: BOOLEAN;
BEGIN BEGIN
IF guard # NIL THEN IF guard # NIL THEN
item := Log.last; item := CL.Log.last;
WHILE ~(item IS tGuard) DO WHILE ~(item IS tGuard) DO
item := item.prev item := item.prev
END; END;
@ -72,7 +76,7 @@ VAR
item: List.tItem; item: List.tItem;
BEGIN BEGIN
ASSERT(guard # NIL); ASSERT(guard # NIL);
item := Log.first; item := CL.Log.first;
WHILE ~(item IS tGuard) DO WHILE ~(item IS tGuard) DO
item := item.next item := item.next
END END
@ -82,8 +86,8 @@ END isFirstGuard;
PROCEDURE setGuard* (_guard: tGuard); PROCEDURE setGuard* (_guard: tGuard);
BEGIN BEGIN
guard := _guard; CL.guard := _guard;
isLast := isLastGuard(_guard) CL.isLast := isLastGuard(_guard)
END setGuard; END setGuard;
@ -102,9 +106,9 @@ VAR
item: List.tItem; item: List.tItem;
(*res: INTEGER;*) (*res: INTEGER;*)
BEGIN BEGIN
isLast := TRUE; CL.isLast := TRUE;
REPEAT REPEAT
item := List.pop(Log); item := List.pop(CL.Log);
IF item # guard THEN IF item # guard THEN
(* (*
IF item IS tUntypedPtr THEN IF item IS tUntypedPtr THEN
@ -115,7 +119,7 @@ BEGIN
DISPOSE(item) DISPOSE(item)
END END
UNTIL item = guard; UNTIL item = guard;
List.append(Log, item) List.append(CL.Log, item)
END clear; END clear;
@ -126,10 +130,10 @@ BEGIN
NEW(item); NEW(item);
item.adr := adrV; item.adr := adrV;
SYSTEM.GET(adrX, item.val); SYSTEM.GET(adrX, item.val);
IF ~isLast THEN IF ~CL.isLast THEN
clear(guard) clear(CL.guard)
END; END;
List.append(Log, item) List.append(CL.Log, item)
END changeWord; END changeWord;
@ -140,10 +144,10 @@ BEGIN
NEW(item); NEW(item);
item.adr := SYSTEM.ADR(v); item.adr := SYSTEM.ADR(v);
item.val := x; item.val := x;
IF ~isLast THEN IF ~CL.isLast THEN
clear(guard) clear(CL.guard)
END; END;
List.append(Log, item) List.append(CL.Log, item)
END changeBool; END changeBool;
@ -179,10 +183,27 @@ BEGIN
END untypedPtr; END untypedPtr;
*) *)
PROCEDURE set* (_CL: tLog);
BEGIN
CL := _CL
END set;
PROCEDURE create* (VAR maxLength: INTEGER): tLog;
VAR
newLog: tLog;
BEGIN
NEW(newLog);
newLog.guard := NIL;
newLog.isLast := TRUE;
newLog.Log := List.create(NIL);
CL := newLog;
Lines.setMaxLength(maxLength)
RETURN newLog
END create;
BEGIN BEGIN
guard := NIL;
isLast := TRUE;
List.init(changeInt, changePtr); List.init(changeInt, changePtr);
Lines.init(changeInt, changePtr, changeBool(*, typedPtr, untypedPtr*)); Lines.init(changeInt, changePtr, changeBool(*, typedPtr, untypedPtr*))
Log := List.create(NIL)
END ChangeLog. END ChangeLog.

View File

@ -23,20 +23,6 @@ IMPORT
KOSAPI, SYSTEM; KOSAPI, SYSTEM;
CONST CONST
(*
winColor* = 0EEEEEEH;
textColor* = 0000000H;
btnColor* = 0CCCCCCH;
btnTextColor* = 0000000H;
toolbarColor* = 0DFDFDFH;
scrollColor* = 0A0A0A0H;
scrollBkColor* = winColor;
borderColor* = 0808080H;
selMenuColor* = 0CCE8FFH;
shadowColor* = 0808080H;
caseColor* = 00000FFH;
disCaseColor* = 0808080H;
*)
fontWidth* = 8; fontWidth* = 8;
fontHeight* = 16; fontHeight* = 16;
@ -44,7 +30,7 @@ VAR
winColor*, textColor*, btnColor*, btnTextColor*, winColor*, textColor*, btnColor*, btnTextColor*,
toolbarColor*, scrollColor*, scrollBkColor*, toolbarColor*, scrollColor*, scrollBkColor*,
borderColor*, selMenuColor*, shadowColor*, borderColor*, shadowColor*,
caseColor*, disCaseColor*: INTEGER; caseColor*, disCaseColor*: INTEGER;
@ -172,6 +158,12 @@ BEGIN
END DrawText866; 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)
END DrawText866bk;
PROCEDURE MousePos* (VAR x, y: INTEGER); PROCEDURE MousePos* (VAR x, y: INTEGER);
VAR VAR
res: INTEGER; res: INTEGER;
@ -343,15 +335,6 @@ PROCEDURE GetSystemColors*;
VAR VAR
buf: ARRAY 10 OF INTEGER; buf: ARRAY 10 OF INTEGER;
BEGIN BEGIN
(* winColor := 0EEEEEEH;
textColor := 0000000H;
btnColor := 0CCCCCCH;
btnTextColor := 0000000H;
scrollColor := 0A0A0A0H;
scrollBkColor := winColor;
borderColor := 0808080H;
*)
selMenuColor := 0CCE8FFH;
toolbarColor := 0DFDFDFH; toolbarColor := 0DFDFDFH;
shadowColor := 0808080H; shadowColor := 0808080H;
caseColor := 00000FFH; caseColor := 00000FFH;

View File

@ -27,6 +27,8 @@ 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};
TYPE TYPE
tLine = Lines.tLine; tLine = Lines.tLine;
@ -43,6 +45,11 @@ VAR
oberonKW, cKW, pascalKW, luaKW, iniKW, fasmKW: ARRAY 3 OF tKeyWords; oberonKW, cKW, pascalKW, luaKW, iniKW, fasmKW: ARRAY 3 OF tKeyWords;
PROCEDURE isCS* (lang: INTEGER): BOOLEAN;
RETURN lang IN csLang
END isCS;
PROCEDURE checkKW (s: ARRAY OF WCHAR; KW: tKeyWords): BOOLEAN; PROCEDURE checkKW (s: ARRAY OF WCHAR; KW: tKeyWords): BOOLEAN;
VAR VAR
i: INTEGER; i: INTEGER;

View File

@ -51,7 +51,7 @@ VAR
(* _typedPtr: PTypedPtr; (* _typedPtr: PTypedPtr;
_untypedPtr: PUntypedPtr;*) _untypedPtr: PUntypedPtr;*)
maxLength*: INTEGER; pMaxLength: INTEGER;
PROCEDURE movInt (VAR v: INTEGER; x: INTEGER); PROCEDURE movInt (VAR v: INTEGER; x: INTEGER);
@ -75,9 +75,12 @@ END movPtr;
PROCEDURE malloc (size: INTEGER): INTEGER; PROCEDURE malloc (size: INTEGER): INTEGER;
VAR VAR
ptr: INTEGER; ptr: INTEGER;
maxLength: INTEGER;
BEGIN BEGIN
ASSERT(pMaxLength # 0);
SYSTEM.GET(pMaxLength, maxLength);
IF size > maxLength THEN IF size > maxLength THEN
maxLength := size SYSTEM.PUT(pMaxLength, size)
END; END;
size := size*WCHAR_SIZE + 4; size := size*WCHAR_SIZE + 4;
INC(size, (-size) MOD 32); INC(size, (-size) MOD 32);
@ -422,6 +425,12 @@ BEGIN
END init; END init;
PROCEDURE setMaxLength* (VAR maxLength: INTEGER);
BEGIN BEGIN
maxLength := 64 pMaxLength := SYSTEM.ADR(maxLength)
END setMaxLength;
BEGIN
pMaxLength := 0
END Lines. END Lines.

View File

@ -176,18 +176,22 @@ BEGIN
movPtr(a.next, b0); movPtr(a.next, b0);
movPtr(b.next, a); movPtr(b.next, a);
movPtr(a.prev, b); movPtr(a.prev, b);
IF (a0 # NIL) & (b0 # NIL) THEN IF a0 # NIL THEN
movPtr(a0.next, b); IF b0 # NIL THEN
movPtr(b0.prev, a); movPtr(a0.next, b);
ELSIF (a0 # NIL) & (b0 = NIL) THEN movPtr(b0.prev, a);
movPtr(a0.next, b); ELSE
movPtr(list.last, a) movPtr(a0.next, b);
ELSIF (a0 = NIL) & (b0 # NIL) THEN movPtr(list.last, a)
movPtr(b0.prev, a); END
movPtr(list.first, b) ELSE
ELSIF (a0 = NIL) & (b0 = NIL) THEN IF b0 # NIL THEN
movPtr(list.first, b); movPtr(b0.prev, a);
movPtr(list.last, a) movPtr(list.first, b)
ELSE
movPtr(list.first, b);
movPtr(list.last, a)
END
END END
END END
END _exchange; END _exchange;

View File

@ -0,0 +1,215 @@
(*
Copyright 2021 Anton Krotov
This file is part of CEdit.
CEdit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CEdit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CEdit. If not, see <http://www.gnu.org/licenses/>.
*)
MODULE Tabs;
IMPORT List, K := KolibriOS, RW;
CONST
btnID* = 100;
tabHeight* = 22;
curTabHeight = 26;
TYPE
tItem = POINTER TO RECORD (List.tItem)
val: RW.tFileName
END;
tTabs* = POINTER TO RECORD
strings: List.tList;
first, current: INTEGER;
width, height: INTEGER;
x, y: INTEGER
END;
PROCEDURE drawTab (t: tTabs; id, x, y, width, height: INTEGER; s: ARRAY OF CHAR);
VAR
x2, y2: INTEGER;
BEGIN
IF id = t.current THEN
INC(height, curTabHeight - tabHeight);
DEC(y, curTabHeight - tabHeight)
END;
x2 := x + width - 1;
y2 := y + height - 1;
K.DrawRect(x, y, width, height, K.winColor);
K.DrawLine(x, y, x2, y, K.borderColor);
K.DrawLine(x2, y, x2, y2, K.borderColor);
K.DrawLine(x2, y2, x, y2, K.borderColor);
K.DrawLine(x, y2, x, y, K.borderColor);
K.DrawText866bk(x + K.fontWidth, y + (height - K.fontHeight) DIV 2, K.textColor, K.winColor, s);
K.CreateButton(id + ORD({30}) + btnID, x, y - 1, width, height - 1, K.winColor, "");
END drawTab;
PROCEDURE tabWidth (tab: tItem): INTEGER;
RETURN (LENGTH(tab.val) + 2)*K.fontWidth
END tabWidth;
PROCEDURE Width (t: tTabs; pos, n: INTEGER): INTEGER;
VAR
res, i: INTEGER;
item: List.tItem;
BEGIN
res := 0;
i := pos;
item := List.getItem(t.strings, i);
WHILE (item # NIL) & (i <= n) DO
INC(res, tabWidth(item(tItem)));
item := item.next;
INC(i)
END
RETURN res
END Width;
PROCEDURE draw* (t: tTabs);
CONST
scrWidth = 10;
VAR
x, y, xmax, n, width: INTEGER;
item: List.tItem;
BEGIN
y := t.y;
x := t.x;
K.DrawRect(x, y - (curTabHeight - tabHeight), t.width + 2*scrWidth, t.height + (curTabHeight - tabHeight), K.winColor);
IF Width(t, 0, t.strings.count - 1) > t.width THEN
INC(x, 2*scrWidth);
K.CreateButton(btnID - 1, t.x, t.y, scrWidth, t.height - 1, K.btnColor, "<");
K.CreateButton(btnID - 2, t.x + scrWidth, t.y, scrWidth, t.height - 1, K.btnColor, ">")
ELSE
t.first := 0
END;
xmax := x + t.width - 1;
n := t.strings.count - 1;
WHILE (n >= 0) & (Width(t, n, t.strings.count - 1) <= t.width) DO
DEC(n)
END;
IF n < 0 THEN
n := 0
ELSE
INC(n)
END;
IF n < t.first THEN
t.first := n
END;
K.DrawRect(x, y, t.width, t.height, K.winColor);
item := List.getItem(t.strings, t.first);
n := t.first;
WHILE (item # NIL) & (x <= xmax) DO
width := tabWidth(item(tItem));
IF x + width - 1 <= xmax THEN
drawTab(t, n, x, y, width, t.height, item(tItem).val)
END;
INC(n);
INC(x, width);
item := item.next
END
END draw;
PROCEDURE add* (t: tTabs; s: ARRAY OF CHAR);
VAR
item: tItem;
BEGIN
NEW(item);
item.val := s;
List.append(t.strings, item);
END add;
PROCEDURE rename* (t: tTabs; n: INTEGER; s: ARRAY OF CHAR);
VAR
item: List.tItem;
BEGIN
item := List.getItem(t.strings, n);
item(tItem).val := s
END rename;
PROCEDURE delete* (t: tTabs; n: INTEGER);
VAR
item: List.tItem;
BEGIN
item := List.getItem(t.strings, n);
List.delete(t.strings, item)
END delete;
PROCEDURE scroll* (t: tTabs; n: INTEGER);
VAR
pos: INTEGER;
BEGIN
pos := t.first + n;
IF pos < 0 THEN
pos := 0
ELSIF pos >= t.strings.count THEN
pos := t.strings.count - 1
END;
t.first := pos
END scroll;
PROCEDURE switch* (t: tTabs; n: INTEGER);
BEGIN
IF (0 <= n) & (n < t.strings.count) THEN
t.current := n;
IF n < t.first THEN
t.first := 0
END;
WHILE Width(t, t.first, n) > t.width DO
INC(t.first)
END
END
END switch;
PROCEDURE setArea* (t: tTabs; x, y, width, height: INTEGER);
BEGIN
t.x := x;
t.y := y;
t.width := width;
t.height := height
END setArea;
PROCEDURE create* (): tTabs;
VAR
res: tTabs;
BEGIN
NEW(res);
res.strings := List.create(NIL);
res.current := 0;
res.first := 0
RETURN res
END create;
END Tabs.

View File

@ -80,7 +80,9 @@ TYPE
foundList: List.tList; foundList: List.tList;
idxData: Search.tBuffer; idxData: Search.tBuffer;
foundSel: INTEGER; foundSel: INTEGER;
searchText: tString searchText: tString;
chLog*: ChangeLog.tLog;
maxLength*: INTEGER
END; END;
tProcedure = PROCEDURE; tProcedure = PROCEDURE;
@ -393,7 +395,7 @@ BEGIN
ELSIF (c = "'") OR (c = '"') THEN ELSIF (c = "'") OR (c = '"') THEN
String(text, line, i, y, backColor) String(text, line, i, y, backColor)
ELSIF (U.isLetter(c) OR (c = "_")) THEN ELSIF (U.isLetter(c) OR (c = "_")) THEN
ident(text, i, i, y, line, backColor, FALSE) ident(text, i, i, y, line, backColor, Lang.isCS(lang))
ELSIF isFASMdelim(c) THEN ELSIF isFASMdelim(c) THEN
PrintLex(text, line, i, i, y, colors.delim, backColor) PrintLex(text, line, i, i, y, colors.delim, backColor)
ELSIF U.isDigit(c) THEN ELSIF U.isDigit(c) THEN
@ -438,7 +440,7 @@ BEGIN
String(text, line, i, y, backColor); String(text, line, i, y, backColor);
cond := 0 cond := 0
ELSIF (U.isLetter(c) OR (c = "_")) THEN ELSIF (U.isLetter(c) OR (c = "_")) THEN
ident(text, i, i - ORD((i > 0) & (getChar(line, i - 1) = "#")), y, line, backColor, TRUE); ident(text, i, i - ORD((i > 0) & (getChar(line, i - 1) = "#")), y, line, backColor, Lang.isCS(lang));
cond := 0 cond := 0
ELSIF U.isDigit(c) THEN ELSIF U.isDigit(c) THEN
k := i; k := i;
@ -557,7 +559,7 @@ BEGIN
PrintLex(text, line, k, i, y, color, backColor); PrintLex(text, line, k, i, y, color, backColor);
cond := 0 cond := 0
ELSIF (depth = 0) & (U.isLetter(c) OR (c = "_")) THEN ELSIF (depth = 0) & (U.isLetter(c) OR (c = "_")) THEN
ident(text, i, i, y, line, backColor, TRUE); ident(text, i, i, y, line, backColor, Lang.isCS(lang));
cond := 0 cond := 0
ELSIF c = "(" THEN ELSIF c = "(" THEN
cond := 1 cond := 1
@ -645,7 +647,7 @@ BEGIN
PrintLex(text, line, k, i, y, colors.num, backColor); PrintLex(text, line, k, i, y, colors.num, backColor);
cond := 0 cond := 0
ELSIF U.isLetter(c) OR (c = "_") THEN ELSIF U.isLetter(c) OR (c = "_") THEN
ident(text, i, i, y, line, backColor, TRUE); ident(text, i, i, y, line, backColor, Lang.isCS(lang));
cond := 0 cond := 0
ELSE ELSE
cond := 0 cond := 0
@ -744,7 +746,7 @@ BEGIN
PrintLex(text, line, k, i, y, colors.num, backColor); PrintLex(text, line, k, i, y, colors.num, backColor);
cond := 0 cond := 0
ELSIF (U.isLetter(c) OR (c = "_")) THEN ELSIF (U.isLetter(c) OR (c = "_")) THEN
ident(text, i, i, y, line, backColor, FALSE); ident(text, i, i, y, line, backColor, Lang.isCS(lang));
cond := 0 cond := 0
ELSE ELSE
cond := 0 cond := 0
@ -786,7 +788,7 @@ BEGIN
DEC(i); DEC(i);
PrintLex(text, line, k, i, y, colors.num, backColor) PrintLex(text, line, k, i, y, colors.num, backColor)
ELSIF (U.isLetter(c) OR (c = "_")) THEN ELSIF (U.isLetter(c) OR (c = "_")) THEN
ident(text, i, i, y, line, backColor, TRUE) ident(text, i, i, y, line, backColor, Lang.isCS(lang))
END END
ELSIF depth = 1 THEN ELSIF depth = 1 THEN
IF c = "]" THEN IF c = "]" THEN
@ -1179,7 +1181,7 @@ PROCEDURE scroll* (text: tText; h, v: INTEGER);
BEGIN BEGIN
INC(text.scroll.X, h); INC(text.scroll.X, h);
INC(text.scroll.Y, v); INC(text.scroll.Y, v);
text.scroll.X := MIN(MAX(text.scroll.X, 0), Lines.maxLength); text.scroll.X := MIN(MAX(text.scroll.X, 0), text.maxLength);
text.scroll.Y := MIN(MAX(text.scroll.Y, 0), text.count - 1) text.scroll.Y := MIN(MAX(text.scroll.Y, 0), text.count - 1)
END scroll; END scroll;
@ -1264,7 +1266,7 @@ BEGIN
text.modified := TRUE text.modified := TRUE
END; END;
item := ChangeLog.Log.first; item := ChangeLog.CL.Log.first;
WHILE item # guard DO WHILE item # guard DO
ChangeLog.redo(item); ChangeLog.redo(item);
item := item.next item := item.next
@ -1579,7 +1581,7 @@ BEGIN
str := "" str := ""
END END
END; END;
IF search(text, str, TRUE, TRUE) THEN END IF search(text, str, Lang.isCS(text.lang), TRUE) THEN END
END wordSel; END wordSel;
@ -1809,7 +1811,7 @@ BEGIN
END; END;
IF text.guard THEN IF text.guard THEN
NEW(guard); NEW(guard);
List.append(ChangeLog.Log, guard); List.append(ChangeLog.CL.Log, guard);
text.edition := guard; text.edition := guard;
text.guard := FALSE; text.guard := FALSE;
ELSE ELSE
@ -1944,11 +1946,20 @@ BEGIN
END draw; END draw;
PROCEDURE switch* (text: tText);
BEGIN
ChangeLog.set(text.chLog);
Lines.setMaxLength(text.maxLength)
END switch;
PROCEDURE create (fileName: RW.tFileName): tText; PROCEDURE create (fileName: RW.tFileName): tText;
VAR VAR
text: tText; text: tText;
BEGIN BEGIN
NEW(text); NEW(text);
text.maxLength := 64;
text.chLog := ChangeLog.create(text.maxLength);
NEW(text.cursor); NEW(text.cursor);
NEW(text.select2); NEW(text.select2);
text.cursor.X := 0; text.cursor.X := 0;