Subversion Repositories Kolibri OS

Rev

Rev 9668 | Rev 9674 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9668 Rev 9671
Line 64... Line 64...
64
    tText* = POINTER TO RECORD (List.tList)
64
    tText* = POINTER TO RECORD (List.tList)
65
        cursor, select, select2: pPoint;
65
        cursor, select, select2: pPoint;
66
        scroll: tPoint;
66
        scroll: tPoint;
67
        CurX: INTEGER;
67
        CurX: INTEGER;
68
        smallChange: INTEGER;
68
        smallChange: INTEGER;
69
        modified*, smallMove: BOOLEAN;
69
        modified*, smallMove,
70
        edition*: tGuard;
-
 
71
        comments, numbers*, guard,
70
        comments, guard,
72
        search, cs, whole: BOOLEAN;
71
        search, cs, whole: BOOLEAN;
-
 
72
        edition*: tGuard;
73
        curLine: tLine;
73
        curLine: tLine;
74
        lang*: INTEGER;
74
        lang*: INTEGER;
75
        enc, eol: INTEGER;
75
        enc, eol: INTEGER;
76
        table: Search.IdxTable;
76
        table: Search.IdxTable;
77
        foundList: List.tList;
77
        foundList: List.tList;
Line 89... Line 89...
89
VAR
89
VAR
Line 90... Line 90...
90
 
90
 
91
    pdelete: PROCEDURE (text: tText);
91
    pdelete: PROCEDURE (text: tText);
Line 92... Line 92...
92
    ShowCursor: PROCEDURE;
92
    ShowCursor: PROCEDURE;
93
 
93
 
94
    colors*: RECORD
94
    colors: RECORD
95
                text, back, seltext, selback, modified, saved, curline, numtext, numback: INTEGER;
95
                text, back, seltext, selback, modified, saved, curline, numtext, numback: INTEGER;
96
                comment, string, escape, num, delim, key1, key2, key3: INTEGER
96
                comment, string, escape, num, delim, key1, key2, key3: INTEGER
97
             END;
97
             END;
98
    canvas: G.tCanvas;
98
    canvas: G.tCanvas;
99
    drawCursor: BOOLEAN;
99
    drawCursor: BOOLEAN;
100
    padding: RECORD left, top: INTEGER END;
100
    padding: RECORD left, top: INTEGER END;
-
 
101
    size, textsize: tPoint;
Line 101... Line 102...
101
    size, textsize: tPoint;
102
    charWidth, charHeight: INTEGER;
102
    charWidth, charHeight: INTEGER;
103
    autoIndents*, lineNumbers*, autoBrackets*, trimSpace*: BOOLEAN;
103
 
104
 
Line 149... Line 150...
149
    rigth := size.X - 1;
150
    rigth := size.X - 1;
150
    bottom := top + size.Y - 1;
151
    bottom := top + size.Y - 1;
151
END getTextRect;
152
END getTextRect;
Line 152... Line 153...
152
 
153
 
153
 
154
 
154
PROCEDURE toggleNumbers* (text: tText);
155
PROCEDURE toggleNumbers*;
155
BEGIN
156
BEGIN
Line -... Line 157...
-
 
157
    lineNumbers := ~lineNumbers
-
 
158
END toggleNumbers;
-
 
159
 
-
 
160
 
-
 
161
PROCEDURE toggleIndents*;
-
 
162
BEGIN
-
 
163
    autoIndents := ~autoIndents
-
 
164
END toggleIndents;
-
 
165
 
-
 
166
 
-
 
167
PROCEDURE toggleBrackets*;
-
 
168
BEGIN
-
 
169
    autoBrackets := ~autoBrackets
-
 
170
END toggleBrackets;
-
 
171
 
-
 
172
 
-
 
173
PROCEDURE toggleTrimSpace*;
-
 
174
BEGIN
156
    text.numbers := ~text.numbers
175
    trimSpace := ~trimSpace
157
END toggleNumbers;
176
END toggleTrimSpace;
158
 
177
 
159
 
178
 
Line 1144... Line 1163...
1144
        resetSelect(text);
1163
        resetSelect(text);
1145
        curLine := text.curLine;
1164
        curLine := text.curLine;
1146
        IF text.cursor.X > 0 THEN
1165
        IF text.cursor.X > 0 THEN
1147
        	INC(text.smallChange);
1166
        	INC(text.smallChange);
1148
            i := text.cursor.X;
1167
            i := text.cursor.X;
-
 
1168
            IF autoIndents THEN
1149
            n := leadingSpaces(curLine);
1169
	            n := leadingSpaces(curLine)
-
 
1170
            ELSE
-
 
1171
    	        n := 0
-
 
1172
            END;
1150
            modify(text);
1173
            modify(text);
1151
            IF n < i THEN
1174
            IF n < i THEN
1152
                move(text, -1);
1175
                move(text, -1);
1153
                delete(text)
1176
                delete(text)
1154
            ELSE
1177
            ELSE
Line 1203... Line 1226...
1203
    END;
1226
    END;
1204
    List._insert(text, curLine, newLine);
1227
    List._insert(text, curLine, newLine);
1205
    SetPos(text, 0, text.cursor.Y + 1);
1228
    SetPos(text, 0, text.cursor.Y + 1);
1206
    line := text.curLine.prev(tLine);
1229
    line := text.curLine.prev(tLine);
1207
    n := -1;
1230
    n := -1;
1208
    WHILE (line # NIL) & (n = -1) DO
1231
    WHILE (line # NIL) & (n = -1) & autoIndents DO
1209
        IF (*line.length*)Lines.trimLength(line) # 0 THEN
1232
        IF (*line.length*)Lines.trimLength(line) # 0 THEN
1210
            n := leadingSpaces(line);
1233
            n := leadingSpaces(line);
1211
            line2 := line
1234
            line2 := line
1212
        END;
1235
        END;
1213
        PrevLine(line)
1236
        PrevLine(line)
Line 1333... Line 1356...
1333
    		INC(text.smallChange)
1356
    		INC(text.smallChange)
1334
    	END;
1357
    	END;
1335
        delSelect(text);
1358
        delSelect(text);
1336
        curLine := text.curLine;
1359
        curLine := text.curLine;
1337
        Lines.insert(curLine, text.cursor.X, WCHR(code));
1360
        Lines.insert(curLine, text.cursor.X, WCHR(code));
-
 
1361
        IF autoBrackets THEN
-
 
1362
        	IF code = ORD("(") THEN
-
 
1363
        		code := ORD(")")
-
 
1364
        	ELSIF code = ORD("[") THEN
-
 
1365
        		code := ORD("]")
-
 
1366
        	ELSIF code = ORD("{") THEN
-
 
1367
        		code := ORD("}")
-
 
1368
        	ELSE
-
 
1369
        		code := -1
-
 
1370
        	END;
-
 
1371
        	IF code # -1 THEN
-
 
1372
        		Lines.insert(curLine, text.cursor.X + 1, WCHR(code))
-
 
1373
        	END
-
 
1374
        END;
1338
        Lines.modify(curLine);
1375
        Lines.modify(curLine);
1339
        modify(text);
1376
        modify(text);
1340
        SetPos(text, text.cursor.X + 1, text.cursor.Y)
1377
        SetPos(text, text.cursor.X + 1, text.cursor.Y)
1341
    ELSIF code = 8 THEN
1378
    ELSIF code = 8 THEN
1342
		BkSpace(text)
1379
		BkSpace(text)
Line 1371... Line 1408...
1371
    tempFile = "/tmp0/1/cedit~.tmp";
1408
    tempFile = "/tmp0/1/cedit~.tmp";
1372
VAR
1409
VAR
1373
    line: tLine;
1410
    line: tLine;
1374
    file: RW.tOutput;
1411
    file: RW.tOutput;
1375
    res: BOOLEAN;
1412
    res: BOOLEAN;
-
 
1413
    Len: INTEGER;
1376
BEGIN
1414
BEGIN
1377
    ChangeLog.setGuard(text.edition);
1415
    ChangeLog.setGuard(text.edition);
1378
    file := RW.create(tempFile, text.enc, text.eol);
1416
    file := RW.create(tempFile, text.enc, text.eol);
1379
    IF file # NIL THEN
1417
    IF file # NIL THEN
1380
        ChangeLog.delSaved;
1418
        ChangeLog.delSaved;
1381
        line := text.first(tLine);
1419
        line := text.first(tLine);
1382
        WHILE line # NIL DO
1420
        WHILE line # NIL DO
-
 
1421
        	IF trimSpace THEN
-
 
1422
        		Len := Lines.trimLength(line)
-
 
1423
        	ELSE
-
 
1424
        		Len := line.length
-
 
1425
        	END;
1383
            RW.putString(file, line, Lines.trimLength(line));
1426
            RW.putString(file, line, Len);
1384
            NextLine(line);
1427
            NextLine(line);
1385
            IF line # NIL THEN
1428
            IF line # NIL THEN
1386
                RW.newLine(file)
1429
                RW.newLine(file)
1387
            END
1430
            END
1388
        END;
1431
        END;
Line 2260... Line 2303...
2260
    G.SetColor(canvas, colors.back);
2303
    G.SetColor(canvas, colors.back);
2261
    IF ~text.smallMove THEN
2304
    IF ~text.smallMove THEN
2262
    	G.clear(canvas)
2305
    	G.clear(canvas)
2263
    END;
2306
    END;
2264
    wNum := charWidth;
2307
    wNum := charWidth;
2265
    IF text.numbers THEN
2308
    IF lineNumbers THEN
2266
        numWidth := U.lg10(text.count) + 2;
2309
        numWidth := U.lg10(text.count) + 2;
2267
        xNum := numWidth*wNum - wNum DIV 2;
2310
        xNum := numWidth*wNum - wNum DIV 2;
2268
        setPadding(numWidth*wNum + pad_left, padding.top);
2311
        setPadding(numWidth*wNum + pad_left, padding.top);
2269
    ELSE
2312
    ELSE
2270
        setPadding(pad_left + wNum*2, padding.top)
2313
        setPadding(pad_left + wNum*2, padding.top)
Line 2320... Line 2363...
2320
    line := firstLine;
2363
    line := firstLine;
2321
    SetColor(colors.numtext, colors.numback);
2364
    SetColor(colors.numtext, colors.numback);
2322
    y := padding.top + inter DIV 2;
2365
    y := padding.top + inter DIV 2;
2323
    n := MIN(text.scroll.Y + textsize.Y, text.count);
2366
    n := MIN(text.scroll.Y + textsize.Y, text.count);
2324
    FOR i := text.scroll.Y + 1 TO n DO
2367
    FOR i := text.scroll.Y + 1 TO n DO
2325
        IF text.numbers THEN
2368
        IF lineNumbers THEN
2326
            IF (i MOD 10 = 0) OR (i - 1 = text.cursor.Y) OR line.label THEN
2369
            IF (i MOD 10 = 0) OR (i - 1 = text.cursor.Y) OR line.label THEN
2327
                U.int2str(i, s);
2370
                U.int2str(i, s);
2328
                G.TextOut2(canvas, (numWidth - U.lg10(i) - 1)*wNum - wNum DIV 2, y, s, LENGTH(s))
2371
                G.TextOut2(canvas, (numWidth - U.lg10(i) - 1)*wNum - wNum DIV 2, y, s, LENGTH(s))
2329
            ELSE
2372
            ELSE
2330
                G.SetColor(canvas, colors.numtext);
2373
                G.SetColor(canvas, colors.numtext);
Line 2344... Line 2387...
2344
    IF text.searchText # "" THEN
2387
    IF text.searchText # "" THEN
2345
    	IF text.smallMove THEN
2388
    	IF text.smallMove THEN
2346
    		firstLine := text.curLine;
2389
    		firstLine := text.curLine;
2347
    		lastLine := firstLine
2390
    		lastLine := firstLine
2348
    	ELSE
2391
    	ELSE
2349
    	    lastLine := getLine2(text, text.scroll.Y + textsize.Y - 1)
2392
    	    lastLine := getLine2(text, MIN(text.scroll.Y + textsize.Y, text.count) - 1)
2350
        END;
2393
        END;
2351
        p := text.foundList.first(Search.tPos);
2394
        p := text.foundList.first(Search.tPos);
2352
        WHILE p # NIL DO
2395
        WHILE p # NIL DO
2353
        	y := padding.top + inter DIV 2;
2396
        	y := padding.top + inter DIV 2;
2354
        	IF text.smallMove THEN
2397
        	IF text.smallMove THEN
Line 2424... Line 2467...
2424
    text.smallMove := FALSE;
2467
    text.smallMove := FALSE;
2425
    text.comments := TRUE;
2468
    text.comments := TRUE;
2426
    text.search := TRUE;
2469
    text.search := TRUE;
2427
    text.cs := FALSE;
2470
    text.cs := FALSE;
2428
    text.whole := FALSE;
2471
    text.whole := FALSE;
2429
    text.numbers := TRUE;
-
 
2430
    text.guard := TRUE;
2472
    text.guard := TRUE;
2431
    text.edition := NIL;
2473
    text.edition := NIL;
2432
    text.foundList := List.create(NIL);
2474
    text.foundList := List.create(NIL);
2433
    text.searchText := "";
2475
    text.searchText := "";
2434
    text.foundSel := 0;
2476
    text.foundSel := 0;
Line 2672... Line 2714...
2672
    resetSelect(text)
2714
    resetSelect(text)
2673
    RETURN text
2715
    RETURN text
2674
END New;
2716
END New;
Line 2675... Line 2717...
2675
 
2717
 
2676
 
2718
 
2677
PROCEDURE init* (pShowCursor: tProcedure);
2719
PROCEDURE init* (pShowCursor: tProcedure; _lineNumbers, _autoIndents, _autoBrackets, _trimSpace: BOOLEAN);
2678
BEGIN
2720
BEGIN
2679
    ShowCursor := pShowCursor;
2721
    ShowCursor := pShowCursor;
-
 
2722
    pdelete := delete;
-
 
2723
    drawCursor := TRUE;
-
 
2724
    lineNumbers := _lineNumbers;
-
 
2725
    autoIndents := _autoIndents;
2680
    pdelete := delete;
2726
    autoBrackets := _autoBrackets;
2681
    drawCursor := TRUE;
2727
    trimSpace := _trimSpace;
2682
    padding.left := pad_left;
2728
    padding.left := pad_left;