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
icon=124
[TextEditor]
[TextEdit]
exec=/kolibrios/utils/t_edit
icon=9
next=$CodeEdit

Binary file not shown.

View File

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

View File

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

View File

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

View File

@ -27,6 +27,8 @@ CONST
langNone* = 0; langC* = 1; langOberon* = 2; langPascal* = 3;
langFasm* = 4; langLua* = 5; langIni* = 6;
csLang = {langNone, langC, langOberon, langLua, langIni};
TYPE
tLine = Lines.tLine;
@ -43,6 +45,11 @@ VAR
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;
VAR
i: INTEGER;

View File

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

View File

@ -176,18 +176,22 @@ BEGIN
movPtr(a.next, b0);
movPtr(b.next, a);
movPtr(a.prev, b);
IF (a0 # NIL) & (b0 # NIL) THEN
movPtr(a0.next, b);
movPtr(b0.prev, a);
ELSIF (a0 # NIL) & (b0 = NIL) THEN
movPtr(a0.next, b);
movPtr(list.last, a)
ELSIF (a0 = NIL) & (b0 # NIL) THEN
movPtr(b0.prev, a);
movPtr(list.first, b)
ELSIF (a0 = NIL) & (b0 = NIL) THEN
movPtr(list.first, b);
movPtr(list.last, a)
IF a0 # NIL THEN
IF b0 # NIL THEN
movPtr(a0.next, b);
movPtr(b0.prev, a);
ELSE
movPtr(a0.next, b);
movPtr(list.last, a)
END
ELSE
IF b0 # NIL THEN
movPtr(b0.prev, a);
movPtr(list.first, b)
ELSE
movPtr(list.first, b);
movPtr(list.last, a)
END
END
END
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;
idxData: Search.tBuffer;
foundSel: INTEGER;
searchText: tString
searchText: tString;
chLog*: ChangeLog.tLog;
maxLength*: INTEGER
END;
tProcedure = PROCEDURE;
@ -393,7 +395,7 @@ BEGIN
ELSIF (c = "'") OR (c = '"') THEN
String(text, line, i, y, backColor)
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
PrintLex(text, line, i, i, y, colors.delim, backColor)
ELSIF U.isDigit(c) THEN
@ -438,7 +440,7 @@ BEGIN
String(text, line, i, y, backColor);
cond := 0
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
ELSIF U.isDigit(c) THEN
k := i;
@ -557,7 +559,7 @@ BEGIN
PrintLex(text, line, k, i, y, color, backColor);
cond := 0
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
ELSIF c = "(" THEN
cond := 1
@ -645,7 +647,7 @@ BEGIN
PrintLex(text, line, k, i, y, colors.num, backColor);
cond := 0
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
ELSE
cond := 0
@ -744,7 +746,7 @@ BEGIN
PrintLex(text, line, k, i, y, colors.num, backColor);
cond := 0
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
ELSE
cond := 0
@ -786,7 +788,7 @@ BEGIN
DEC(i);
PrintLex(text, line, k, i, y, colors.num, backColor)
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
ELSIF depth = 1 THEN
IF c = "]" THEN
@ -1179,7 +1181,7 @@ PROCEDURE scroll* (text: tText; h, v: INTEGER);
BEGIN
INC(text.scroll.X, h);
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)
END scroll;
@ -1264,7 +1266,7 @@ BEGIN
text.modified := TRUE
END;
item := ChangeLog.Log.first;
item := ChangeLog.CL.Log.first;
WHILE item # guard DO
ChangeLog.redo(item);
item := item.next
@ -1579,7 +1581,7 @@ BEGIN
str := ""
END
END;
IF search(text, str, TRUE, TRUE) THEN END
IF search(text, str, Lang.isCS(text.lang), TRUE) THEN END
END wordSel;
@ -1809,7 +1811,7 @@ BEGIN
END;
IF text.guard THEN
NEW(guard);
List.append(ChangeLog.Log, guard);
List.append(ChangeLog.CL.Log, guard);
text.edition := guard;
text.guard := FALSE;
ELSE
@ -1944,11 +1946,20 @@ BEGIN
END draw;
PROCEDURE switch* (text: tText);
BEGIN
ChangeLog.set(text.chLog);
Lines.setMaxLength(text.maxLength)
END switch;
PROCEDURE create (fileName: RW.tFileName): tText;
VAR
text: tText;
BEGIN
NEW(text);
text.maxLength := 64;
text.chLog := ChangeLog.create(text.maxLength);
NEW(text.cursor);
NEW(text.select2);
text.cursor.X := 0;