forked from gphilippot/purebasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiffWindow.pb
2167 lines (1791 loc) · 75 KB
/
DiffWindow.pb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;--------------------------------------------------------------------------------------------
; Copyright (c) Fantaisie Software. All rights reserved.
; Dual licensed under the GPL and Fantaisie Software licenses.
; See LICENSE and LICENSE-FANTAISIE in the project root for license information.
;--------------------------------------------------------------------------------------------
; Diff tools for the PB IDE
;
;- Globals
; Define this to true if the ScintillaGadget supports the following defined messages
; to have a margin with text in it (needs a more recent scintilla version)
; If supported, we can show line numbers (with gaps) in the diff output which is very nice
;
#SCINTILLA_TEXT_MARGIN = #True
; Represents one line in a file to diff
; Used for the markers in the scintilla gadget
;
Enumeration
#DIFF_Empty ; for empty lines when changes are made in other file
#DIFF_Equal
#DIFF_Added
#DIFF_Removed
#DIFF_Changed
#DIFF_StateCount
EndEnumeration
#DIFF_ChangeMarker = #DIFF_StateCount * 2
; future modes may be added here if we have a backup system etc
;
Enumeration
#DIFF_FileToFile
#DIFF_SourceToFile
EndEnumeration
Structure DiffLine
Hash.l ; currently a CRC32, can be something else too (does not include newline)
Length.l ; length in bytes, including newline sequence
*Start ; line start address (in diff buffer)
EndStructure
; Represents a block of common lines
;
Structure DiffBlock
Length.l
StartFileA.l
StartFileB.l
EndStructure
; Represents a block of styled characters for the final diff document
Structure DiffStyleBlock
*Start
Length.l
Lines.l
Style.l
EndStructure
; represents a file entry in directory diff
Structure DiffFile
Name$ ; may differ if FS is case insensitive, but we use only one name for display anyway
Style.l
DateA.l ; last modified
DateB.l
EndStructure
; information about the two files to diff
;
Global Dim DiffA.DiffLine(0), Dim DiffB.DiffLine(0) ; content (freed after diff creation)
Global DiffA_Lines, DiffB_Lines ; # of lines
Global DiffA_Utf8, DiffB_Utf8 ; is utf8 bom present
Global *DiffA_Buffer, *DiffB_Buffer ; memory buffer containing original files (stays allocated until diff is closed)
Global NewList StyleA.DiffStyleBlock() ; resulting diff blocks (stays allocated until diff is closed)
Global NewList StyleB.DiffStyleBlock()
Global DiffA_Title$, DiffB_Title$
Global DiffA_File$, DiffB_File$
Global *DiffSource.SourceFile, DiffMode
; for directory diff
;
Global DiffDirectoryMode ; 0=files only, 1=directory+files, 2=directory only
Global DiffA_Base$, DiffB_Base$, DiffPattern$
Global NewList DiffFiles.DiffFile()
; For the scroll sync
Global DiffScrollX, DiffScrollY, DiffZoom
; For styling
Global DiffStyleGadget, DiffStyleBase, DiffSwapped
Global DiffOpenPattern ; not stored in prefs
Declare UpdateDiffGadget(IsLeft, List Style.DiffStyleBlock(), SetText)
Declare UpdateDiffFileList()
;- Diff window
; Show/hide the progress gadgets and take other appropriate actions
;
Procedure ShowDiffProgress(ShowProgress)
If ShowProgress
State = 0
Else
State = 1
EndIf
HideGadget(#GADGET_Diff_Busy, State)
If DiffDirectoryMode = 0
HideGadget(#GADGET_Diff_Splitter, 1-State)
Else
HideGadget(#GADGET_Diff_FileTitle, 1-State)
If DiffDirectoryMode = 1
HideGadget(#GADGET_Diff_Splitter2, 1-State)
Else
HideGadget(#GADGET_Diff_Files, 1-State)
EndIf
EndIf
EndProcedure
Procedure ResizeDiffSplitterContent() ; triggered on a splitter move
text = Max(GetRequiredHeight(#GADGET_Diff_Title1), 18)
w = GadgetWidth(#GADGET_Diff_Container1)
h = GadgetHeight(#GADGET_Diff_Container1)
ResizeGadget(#GADGET_Diff_Title1, 0, 0, w, text)
ResizeGadget(#GADGET_Diff_File1, 0, text+2, w, h-text-2)
w = GadgetWidth(#GADGET_Diff_Container2)
h = GadgetHeight(#GADGET_Diff_Container2)
ResizeGadget(#GADGET_Diff_Title2, 0, 0, w, text)
ResizeGadget(#GADGET_Diff_File2, 0, text+2, w, h-text-2)
EndProcedure
Procedure UpdateDiffToolbar()
; open tool, swap, refresh, up/down is always on
If DiffDirectoryMode < 2 ; files visible
FileState = 0
Else
FileState = 1
EndIf
DisableToolBarButton(#TOOLBAR_Diff, #MENU_Diff_Open1, FileState)
DisableToolBarButton(#TOOLBAR_Diff, #MENU_Diff_Open2, FileState)
DisableToolBarButton(#TOOLBAR_Diff, #MENU_Diff_Colors, FileState)
DisableToolBarButton(#TOOLBAR_Diff, #MENU_Diff_Vertical, FileState)
If DiffDirectoryMode > 0 ; directory visible
If DiffDirectoryMode = 2
DisableToolBarButton(#TOOLBAR_Diff, #MENU_Diff_HideFiles, 1)
Else
DisableToolBarButton(#TOOLBAR_Diff, #MENU_Diff_HideFiles, 0)
EndIf
Else
DisableToolBarButton(#TOOLBAR_Diff, #MENU_Diff_HideFiles, 1)
EndIf
EndProcedure
Procedure SwitchDirectoryMode(TargetMode)
; adjust the splitters as needed
;
If DiffDirectoryMode <> TargetMode
; required for the creation of the temp gadgets (when switching splitter content)
UseGadgetList(WindowID(#WINDOW_Diff))
Select DiffDirectoryMode
Case 0 ; files only
; need to create the required gadgets now
;
CompilerIf #CompileWindows
TextGadget(#GADGET_Diff_FileTitle, 0, 0, 0, 0, "")
CompilerElse
TextGadget(#GADGET_Diff_FileTitle, 0, 0, 0, 0, "", #PB_Text_Border)
CompilerEndIf
ListIconGadget(#GADGET_Diff_Files, 0, 0, 0, 0, Language("Diff","Filename"), 250, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(#GADGET_Diff_Files, 1, Language("Diff","State"), 100)
AddGadgetColumn(#GADGET_Diff_Files, 2, Language("Diff","Date1"), 130)
AddGadgetColumn(#GADGET_Diff_Files, 3, Language("Diff","Date2"), 130)
If TargetMode = 1
SplitterGadget(#GADGET_Diff_Splitter2, 0, 0, 0, 0, #GADGET_Diff_Files, #GADGET_Diff_Splitter)
SetGadgetAttribute(#GADGET_Diff_Splitter2, #PB_Splitter_FirstMinimumSize, 80)
SetGadgetAttribute(#GADGET_Diff_Splitter2, #PB_Splitter_SecondMinimumSize, 80)
Else
HideGadget(#GADGET_Diff_Splitter, 1)
EndIf
Case 1 ; files and directory
; need to put dummy gadgets in the splitter so it can then be freed without freeing the old content
;
If TargetMode = 0
SetGadgetAttribute(#GADGET_Diff_Splitter2, #PB_Splitter_SecondGadget, TextGadget(#PB_Any,0,0,0,0,""))
FreeGadget(#GADGET_Diff_Splitter2) ; frees the splitter and the listicon
FreeGadget(#GADGET_Diff_FileTitle)
Else
SetGadgetAttribute(#GADGET_Diff_Splitter2, #PB_Splitter_FirstGadget, TextGadget(#PB_Any,0,0,0,0,""))
SetGadgetAttribute(#GADGET_Diff_Splitter2, #PB_Splitter_SecondGadget, TextGadget(#PB_Any,0,0,0,0,""))
FreeGadget(#GADGET_Diff_Splitter2) ; frees only the splitter
HideGadget(#GADGET_Diff_Splitter, 1) ; this one is just hidden, never freed
EndIf
Case 2 ; directory only
HideGadget(#GADGET_Diff_Splitter, 0)
If TargetMode = 0
FreeGadget(#GADGET_Diff_FileTitle)
FreeGadget(#GADGET_Diff_Files)
Else
UseGadgetList(WindowID(#WINDOW_Diff))
SplitterGadget(#GADGET_Diff_Splitter2, 0, 0, 0, 0, #GADGET_Diff_Files, #GADGET_Diff_Splitter)
SetGadgetAttribute(#GADGET_Diff_Splitter2, #PB_Splitter_FirstMinimumSize, 80)
SetGadgetAttribute(#GADGET_Diff_Splitter2, #PB_Splitter_SecondMinimumSize, 80)
EndIf
EndSelect
EndIf
DiffDirectoryMode = TargetMode
; Update toolbar accordingly
UpdateDiffToolbar()
; resize
DiffWindowEvents(#PB_Event_SizeWindow)
ResizeDiffSplitterContent()
EndProcedure
Procedure ShowNextDifference(Gadget, Forward, IsFirst)
If Gadget = #GADGET_Diff_Files Or DiffDirectoryMode = 2 ; use it if only directories are visible too
; directory mode
index = GetGadgetState(#GADGET_Diff_Files)
If index = -1 Or IsFirst
index = 0
ElseIf Forward
index + 1
Else
index - 1
EndIf
If SelectElement(DiffFiles(), index)
Repeat
If DiffFiles()\Style <> #DIFF_Equal
SetGadgetState(#GADGET_Diff_Files, ListIndex(DiffFiles())) ; mark this
Break
ElseIf Forward
Result = NextElement(DiffFiles())
Else
Result = PreviousElement(DiffFiles())
EndIf
Until Result = 0
EndIf
SetActiveGadget(#GADGET_Diff_Files)
Else
; always fallback to File1 if none of the files is selected
If Gadget <> #GADGET_Diff_File2
Gadget = #GADGET_Diff_File1
Other = #GADGET_Diff_File2
Else
Other = #GADGET_Diff_File1
EndIf
If IsFirst
line = ScintillaSendMessage(Gadget, #SCI_MARKERNEXT, 0, 1 << #DIFF_ChangeMarker)
Else
line = ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, ScintillaSendMessage(Gadget, #SCI_GETCURRENTPOS))
If Forward
line = ScintillaSendMessage(Gadget, #SCI_MARKERNEXT, line+1, 1 << #DIFF_ChangeMarker)
Else
line = ScintillaSendMessage(Gadget, #SCI_MARKERPREVIOUS, line-1, 1 << #DIFF_ChangeMarker)
EndIf
EndIf
If line <> -1
ScintillaSendMessage(Gadget, #SCI_LINESCROLL, -99999, -99999)
ScintillaSendMessage(Gadget, #SCI_LINESCROLL, 0, line-3)
ScintillaSendMessage(Gadget, #SCI_GOTOLINE, line, 0)
; scroll the other to the same place
ScintillaSendMessage(Other, #SCI_LINESCROLL, -99999, -99999)
ScintillaSendMessage(Other, #SCI_LINESCROLL, 0, line-3)
ScintillaSendMessage(Other, #SCI_GOTOLINE, line, 0)
EndIf
SetActiveGadget(Gadget)
EndIf
EndProcedure
Procedure DiffWindowEvents(EventID)
If EventID = #PB_Event_Gadget
Select EventGadget()
Case #GADGET_Diff_Splitter, #GADGET_Diff_Splitter
ResizeDiffSplitterContent()
Case #GADGET_Diff_Files
If DiffDirectoryMode > 0 And EventType() = #PB_EventType_LeftDoubleClick
index = GetGadgetState(#GADGET_Diff_Files)
If index <> -1 And SelectElement(DiffFiles(), index)
If DiffFiles()\Style = #DIFF_Changed Or DiffFiles()\Style = #DIFF_Equal ; cannot compare against added/removed files
DiffFileToFile(DiffA_Base$+DiffFiles()\Name$, DiffB_Base$+DiffFiles()\Name$, #False, 1)
EndIf
EndIf
Else
UpdateDiffToolbar() ; update on selection changes
EndIf
EndSelect
ElseIf EventID = #PB_Event_Menu
EventMenu = EventMenu()
Select EventMenu
Case #MENU_Diff_Open1, #MENU_Diff_Open2
If EventMenu = #MENU_Diff_Open1
If DiffSwapped = 0
First = #True
Else
First = #False
EndIf
Else
If DiffSwapped = 0
First = #False
Else
First = #True
EndIf
EndIf
Select DiffMode
Case #DIFF_FileToFile
If First
LoadSourceFile(DiffA_File$)
Else
LoadSourceFile(DiffB_File$)
EndIf
Case #DIFF_SourceToFile ; A is a *Source, B is a file
If First
ChangeCurrentElement(FileList(), *DiffSource)
ChangeActiveSourceCode()
Else
LoadSourceFile(DiffB_File$)
EndIf
EndSelect
Case #MENU_Diff_Refresh
If DiffDirectoryMode > 0
DiffDirectories(DiffA_Base$, DiffB_Base$, DiffPattern$, DiffSwapped, DiffDirectoryMode)
EndIf
If DiffDirectoryMode < 2
Select DiffMode
Case #DIFF_FileToFile
DiffFileToFile(DiffA_File$, DiffB_File$, DiffSwapped, DiffDirectoryMode)
Case #DIFF_SourceToFile
DiffSourceToFile(*DiffSource, DiffB_File$, DiffSwapped)
EndSelect
EndIf
Case #MENU_Diff_Colors
If DiffDirectoryMode < 2
If DiffShowColors
DiffShowColors = 0
Else
DiffShowColors = 1
EndIf
SetToolBarButtonState(#TOOLBAR_Diff, #MENU_Diff_Colors, DiffShowColors)
; update the gadget colors
UpdateDiffGadget(#True, StyleA(), #False)
UpdateDiffGadget(#False, StyleB(), #False)
EndIf
Case #MENU_Diff_Swap
If DiffSwapped = 0
DiffSwapped = 1
Else
DiffSwapped = 0
EndIf
SetToolBarButtonState(#TOOLBAR_Diff, #MENU_Diff_Swap, DiffSwapped)
If DiffDirectoryMode > 0
; just update the view
UpdateDiffFileList()
EndIf
If DiffDirectoryMode < 2
; swapping the files produces the identical diff output, just
; with inserts and deletes reversed, so no need to recalculate it all
;
If DiffSwapped = 0
SetGadgetText(#GADGET_Diff_Title1, DiffA_Title$) ; set original titles
SetGadgetText(#GADGET_Diff_Title2, DiffB_Title$)
Else
SetGadgetText(#GADGET_Diff_Title1, DiffB_Title$) ; swap the titles
SetGadgetText(#GADGET_Diff_Title2, DiffA_Title$)
EndIf
; now update the coloring+text, this takes care of the rest
UpdateDiffGadget(#True, StyleA(), #True)
UpdateDiffGadget(#False, StyleB(), #True)
; mark the first difference again
ShowNextDifference(#GADGET_Diff_File1, #True, #True)
EndIf
Case #MENU_Diff_Vertical
If DiffDirectoryMode < 2
If DiffVertical
DiffVertical = 0
Else
DiffVertical = 1
EndIf
Width = WindowWidth(#WINDOW_Diff)
Height = WindowHeight(#WINDOW_Diff)
; required for the creation of the temp gadgets (when switching splitter content)
UseGadgetList(WindowID(#WINDOW_Diff))
If DiffDirectoryMode = 1
; must get the splitter out of the outer splitter first. use a dummy for the replacement
dummy = TextGadget(#PB_Any, 0, 0, 0, 0, "")
SetGadgetAttribute(#GADGET_Diff_Splitter2, #PB_Splitter_SecondGadget, dummy)
EndIf
; remove the old splitter from the window, replace the content first with dummy gadgets
SetGadgetAttribute(#GADGET_Diff_Splitter, #PB_Splitter_FirstGadget, TextGadget(#PB_Any, 0, 0, 0, 0, ""))
SetGadgetAttribute(#GADGET_Diff_Splitter, #PB_Splitter_SecondGadget, TextGadget(#PB_Any, 0, 0, 0, 0, ""))
FreeGadget(#GADGET_Diff_Splitter)
UseGadgetList(WindowID(#WINDOW_Diff))
If DiffVertical
SplitterGadget(#GADGET_Diff_Splitter, 5, 5+ToolbarTopOffset, Width-10, Height-10-ToolbarHeight, #GADGET_Diff_Container1, #GADGET_Diff_Container2)
Else
SplitterGadget(#GADGET_Diff_Splitter, 5, 5+ToolbarTopOffset, Width-10, Height-10-ToolbarHeight, #GADGET_Diff_Container1, #GADGET_Diff_Container2, #PB_Splitter_Vertical)
EndIf
If DiffDirectoryMode = 1
; put it back into the other splitter (and delete the dummy)
SetGadgetAttribute(#GADGET_Diff_Splitter2, #PB_Splitter_SecondGadget, #GADGET_Diff_Splitter)
FreeGadget(dummy)
EndIf
SetToolBarButtonState(#TOOLBAR_Diff, #MENU_Diff_Vertical, DiffVertical)
ResizeDiffSplitterContent()
EndIf
Case #MENU_Diff_ShowTool
OpenDiffDialogWindow()
Case #MENU_Diff_ShowFiles
; this is a shortcut, so check that it only works in the files list
If DiffDirectoryMode > 0 And GetActiveGadget() = #GADGET_Diff_Files
; same action as for the listicon event
index = GetGadgetState(#GADGET_Diff_Files)
If index <> -1 And SelectElement(DiffFiles(), index)
If DiffFiles()\Style = #DIFF_Changed Or DiffFiles()\Style = #DIFF_Equal ; cannot compare against added/removed files
DiffFileToFile(DiffA_Base$+DiffFiles()\Name$, DiffB_Base$+DiffFiles()\Name$, #False, 1)
EndIf
EndIf
EndIf
Case #MENU_Diff_HideFiles
If DiffDirectoryMode = 1
SwitchDirectoryMode(2)
UpdateDiffToolbar()
EndIf
Case #MENU_Diff_Up
ShowNextDifference(GetActiveGadget(), #False, #False)
Case #MENU_Diff_Down
ShowNextDifference(GetActiveGadget(), #True, #False)
EndSelect
ElseIf EventID = #PB_Event_SizeWindow
Width = WindowWidth(#WINDOW_Diff)
Height = WindowHeight(#WINDOW_Diff)
If DiffDirectoryMode = 0
; only the file splitter
ResizeGadget(#GADGET_Diff_Splitter, 5, 5+ToolbarTopOffset, Width-10, Height-10-ToolbarHeight)
Else
h = Max(GetRequiredHeight(#GADGET_Diff_FileTitle), 30)
ResizeGadget(#GADGET_Diff_FileTitle, 5,5+ToolbarTopOffset, Width-10, h)
If DiffDirectoryMode = 1
; the directory splitter is the main
ResizeGadget(#GADGET_Diff_Splitter2, 5, 7+ToolbarTopOffset+h, Width-10, Height-12-ToolbarHeight-h)
Else
; only the directory view
ResizeGadget(#GADGET_Diff_Files, 5, 7+ToolbarTopOffset+h, Width-10, Height-12-ToolbarHeight-h)
EndIf
EndIf
GetRequiredSize(#GADGET_Diff_Busy, @BusyW, @BusyH)
ResizeGadget(#GADGET_Diff_Busy, (Width-BusyW)/2, ToolbarTopOffset + (Height-ToolBarHeight-BusyH) / 2, BusyW, BusyH)
ElseIf EventID = #PB_Event_CloseWindow
If MemorizeWindow And IsWindowMinimized(#WINDOW_Diff) = 0
DiffWindowPosition\IsMaximized = IsWindowMaximized(#WINDOW_Diff)
If DiffWindowPosition\IsMaximized = 0
DiffWindowPosition\x = WindowX(#WINDOW_Diff)
DiffWindowPosition\y = WindowY(#WINDOW_Diff)
DiffWindowPosition\Width = WindowWidth (#WINDOW_Diff)
DiffWindowPosition\Height = WindowHeight(#WINDOW_Diff)
EndIf
EndIf
CloseWindow(#WINDOW_Diff)
; free the no longer needed data
;
If *DiffA_Buffer
FreeMemory(*DiffA_Buffer)
EndIf
If *DiffB_Buffer
FreeMemory(*DiffB_Buffer)
EndIf
*DiffA_Buffer = 0
*DiffB_Buffer = 0
ClearList(StyleA())
ClearList(StyleB())
EndIf
EndProcedure
ProcedureDLL DiffScintillaCallback(Gadget, *scinotify.SCNotification)
Select *scinotify\nmhdr\code
; There is no separate (cross-platform) notification on scrolling events,
; so use the paint message and check the scrolling position to update the
; second gadget
;
Case #SCN_PAINTED
If Gadget = #GADGET_Diff_File1
OtherGadget = #GADGET_Diff_File2
Else
OtherGadget = #GADGET_Diff_File1
EndIf
Zoom = ScintillaSendMessage(Gadget, #SCI_GETZOOM)
If Zoom <> DiffZoom
DiffZoom = Zoom
ScintillaSendMessage(OtherGadget, #SCI_SETZOOM, DiffZoom)
EndIf
X = ScintillaSendMessage(Gadget, #SCI_GETXOFFSET)
If X <> DiffScrollX
DiffScrollX = X
ScintillaSendMessage(OtherGadget, #SCI_SETXOFFSET, DiffScrollX)
EndIf
; Note: this counts visible lines, not document lines
; this needs to be adjusted if some kind of folding is allowed
Y = ScintillaSendMessage(Gadget, #SCI_GETFIRSTVISIBLELINE)
If Y <> DiffScrollY
DiffScrollY = Y
; #SCI_SETFIRSTVISIBLELINE is not supported in our scintilla version, so emulate it
ScintillaSendMessage(OtherGadget, #SCI_LINESCROLL, 0, DiffScrollY - ScintillaSendMessage(OtherGadget, #SCI_GETFIRSTVISIBLELINE))
EndIf
EndSelect
EndProcedure
Procedure OpenDiffWindow()
;
; This is not a DialogManager created Window, because of the toolbar etc
;
If IsWindow(#WINDOW_Diff) = 0
Flags = #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_Invisible
If DiffWindowPosition\x = -1 And DiffWindowPosition\y = -1
Flags | #PB_Window_ScreenCentered
EndIf
If OpenWindow(#WINDOW_Diff, DiffWindowPosition\x, DiffWindowPosition\y, DiffWindowPosition\Width, DiffWindowPosition\Height, Language("Diff", "Title"), Flags, WindowID(#WINDOW_Main))
WindowBounds(#WINDOW_Diff, 200, 200, #PB_Ignore, #PB_Ignore)
If CreateToolBar(#TOOLBAR_Diff, WindowID(#WINDOW_Diff))
ToolBarImageButton(#MENU_Diff_ShowTool, ImageID(#IMAGE_Diff_ShowTool))
ToolBarImageButton(#MENU_Diff_Open1, ImageID(#IMAGE_Diff_Open1))
ToolBarImageButton(#MENU_Diff_Open2, ImageID(#IMAGE_Diff_Open2))
ToolBarSeparator()
ToolBarImageButton(#MENU_Diff_Colors, ImageID(#IMAGE_Diff_Colors), #PB_ToolBar_Toggle)
ToolBarImageButton(#MENU_Diff_Vertical, ImageID(#IMAGE_Diff_Vertical), #PB_ToolBar_Toggle)
ToolBarImageButton(#MENU_Diff_HideFiles, ImageID(#IMAGE_Diff_HideFiles))
ToolBarSeparator()
ToolBarImageButton(#MENU_Diff_Swap, ImageID(#IMAGE_Diff_Swap))
ToolBarImageButton(#MENU_Diff_Refresh, ImageID(#IMAGE_Diff_Refresh))
ToolBarSeparator()
ToolBarImageButton(#MENU_Diff_Up, ImageID(#IMAGE_Diff_Up))
ToolBarImageButton(#MENU_Diff_Down, ImageID(#IMAGE_Diff_Down))
ToolBarToolTip(#TOOLBAR_Diff, #MENU_Diff_Open1, Language("Diff","Open1"))
ToolBarToolTip(#TOOLBAR_Diff, #MENU_Diff_Open2, Language("Diff","Open2"))
ToolBarToolTip(#TOOLBAR_Diff, #MENU_Diff_Refresh, Language("Diff","Refresh"))
ToolBarToolTip(#TOOLBAR_Diff, #MENU_Diff_Swap, Language("Diff","Swap"))
ToolBarToolTip(#TOOLBAR_Diff, #MENU_Diff_Colors, Language("Diff","Colors"))
ToolBarToolTip(#TOOLBAR_Diff, #MENU_Diff_Vertical, Language("Diff","Vertical"))
ToolBarToolTip(#TOOLBAR_Diff, #MENU_Diff_ShowTool, Language("Diff","ShowTool"))
ToolBarToolTip(#TOOLBAR_Diff, #MENU_Diff_HideFiles, Language("Diff","HideFiles"))
ToolBarToolTip(#TOOLBAR_Diff, #MENU_Diff_Up, Language("Diff","Up"))
ToolBarToolTip(#TOOLBAR_Diff, #MENU_Diff_Down, Language("Diff","Down"))
SetToolBarButtonState(#TOOLBAR_Diff, #MENU_Diff_Colors, DiffShowColors)
SetToolBarButtonState(#TOOLBAR_Diff, #MENU_Diff_Vertical, DiffVertical)
EndIf
; this one has no icon, only a shortcut (enter)
AddKeyboardShortcut(#WINDOW_Diff, #PB_Shortcut_Return, #MENU_Diff_ShowFiles)
TextGadget(#GADGET_Diff_Busy, 0, 0, 0, 0, Language("Diff","Busy"))
HideGadget(#GADGET_Diff_Busy, 1)
; the default state is the File only mode, where there is no gadget for filename and files
DiffDirectoryMode = 0
UpdateDiffToolbar()
; Note: The TextGadget with border looks quite ugly in this context on modern Windows version as it has
; the old style "client edge" border. It looks better without any borders at all here
;
ContainerGadget(#GADGET_Diff_Container1, 0, 0, 0, 0, #PB_Container_BorderLess)
CompilerIf #CompileWindows
TextGadget(#GADGET_Diff_Title1, 0, 0, 0, 0, "")
CompilerElse
TextGadget(#GADGET_Diff_Title1, 0, 0, 0, 0, "", #PB_Text_Border)
CompilerEndIf
ScintillaGadget(#GADGET_Diff_File1, 0, 0, 0, 0, @DiffScintillaCallback())
CloseGadgetList()
ContainerGadget(#GADGET_Diff_Container2, 0, 0, 0, 0, #PB_Container_BorderLess)
CompilerIf #CompileWindows
TextGadget(#GADGET_Diff_Title2, 0, 0, 0, 0, "")
CompilerElse
TextGadget(#GADGET_Diff_Title2, 0, 0, 0, 0, "", #PB_Text_Border)
CompilerEndIf
ScintillaGadget(#GADGET_Diff_File2, 0, 0, 0, 0, @DiffScintillaCallback())
CloseGadgetList()
; this variable is reversed from the splitter flag: vertical splitter = horizontal tiling
If DiffVertical
SplitterGadget(#GADGET_Diff_Splitter, 5, 5+ToolbarTopOffset, DiffWindowPosition\Width-10, DiffWindowPosition\Height-10-ToolbarHeight, #GADGET_Diff_Container1, #GADGET_Diff_Container2)
Else
SplitterGadget(#GADGET_Diff_Splitter, 5, 5+ToolbarTopOffset, DiffWindowPosition\Width-10, DiffWindowPosition\Height-10-ToolbarHeight, #GADGET_Diff_Container1, #GADGET_Diff_Container2, #PB_Splitter_Vertical)
EndIf
SetGadgetAttribute(#GADGET_Diff_Splitter, #PB_Splitter_FirstMinimumSize, 80)
SetGadgetAttribute(#GADGET_Diff_Splitter, #PB_Splitter_SecondMinimumSize, 80)
DiffScrollX = 0
DiffScrollY = 0
DiffZoom = ScintillaSendMessage(#GADGET_Diff_File1, #SCI_GETZOOM)
For Gadget = #GADGET_Diff_File1 To #GADGET_Diff_File2
ScintillaSendMessage(Gadget, #SCI_CLEARCMDKEY, #SCK_TAB) ; to enable the window shortcuts
ScintillaSendMessage(Gadget, #SCI_CLEARCMDKEY, #SCK_RETURN)
ApplyWordChars(Gadget)
ScintillaSendMessage(Gadget, #SCI_SETCARETLINEVISIBLE, 0, 0)
; margin for line numbers, this is hidden in UpdateDiffGadget() if it is disabled
; we cannot use the normal line numbers as we have gaps where stuff is inserted in another file
CompilerIf #SCINTILLA_TEXT_MARGIN
ScintillaSendMessage(Gadget, #SCI_SETMARGINTYPEN, 1, #SC_MARGIN_RTEXT)
ScintillaSendMessage(Gadget, #SCI_SETMARGINMASKN, 1, 0)
ScintillaSendMessage(Gadget, #SCI_SETMARGINSENSITIVEN, 1, 0)
CompilerEndIf
; margin for the markers
ScintillaSendMessage(Gadget, #SCI_SETMARGINTYPEN, 2, #SC_MARGIN_SYMBOL)
ScintillaSendMessage(Gadget, #SCI_SETMARGINMASKN, 2, ~#SC_MASK_FOLDERS)
ScintillaSendMessage(Gadget, #SCI_SETMARGINSENSITIVEN, 2, 0)
For i = 0 To #DIFF_StateCount-1
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, i, #SC_MARK_BACKGROUND)
Next i
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #DIFF_StateCount+#DIFF_Empty, #SC_MARK_EMPTY)
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #DIFF_StateCount+#DIFF_Equal, #SC_MARK_EMPTY)
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #DIFF_StateCount+#DIFF_Added, #SC_MARK_PLUS)
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #DIFF_StateCount+#DIFF_Removed, #SC_MARK_MINUS)
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #DIFF_StateCount+#DIFF_Changed, #SC_MARK_SHORTARROW)
; for knowing where the next change starts
ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #DIFF_ChangeMarker, #SC_MARK_EMPTY)
Next Gadget
EnsureWindowOnDesktop(#WINDOW_Diff)
If DiffWindowPosition\IsMaximized
ShowWindowMaximized(#WINDOW_Diff)
Else
HideWindow(#WINDOW_Diff, 0)
EndIf
DiffWindowEvents(#PB_Event_SizeWindow)
ResizeDiffSplitterContent()
EndIf
Else
SetWindowForeground(#WINDOW_Diff)
EndIf
EndProcedure
Procedure DiffHighlightCallback(*StringStart.BYTE, Length, *Color, IsBold, TextChanged)
ScintillaSendMessage(DiffStyleGadget, #SCI_SETSTYLING, Length, *Color)
EndProcedure
; Update the coloring in the gadget and optionally set the text
;
Procedure UpdateDiffGadget(IsLeft, List Style.DiffStyleBlock(), SetText)
If IsLeft
If DiffSwapped = 0
Gadget = #GADGET_Diff_File1
Else
Gadget = #GADGET_Diff_File2
EndIf
Else
If DiffSwapped = 0
Gadget = #GADGET_Diff_File2
Else
Gadget = #GADGET_Diff_File1
EndIf
EndIf
; Gtk2 'Pango' need an "!" before the font name (else it will use GDK font)
;
ScintillaSendMessage(Gadget, #SCI_STYLERESETDEFAULT, 0, 0)
CompilerIf #CompileLinuxGtk2
FontName$ = "!"+EditorFontName$
ScintillaSendMessage(Gadget, #SCI_STYLESETFONT, #STYLE_DEFAULT, ToAscii(FontName$))
CompilerElse
ScintillaSendMessage(Gadget, #SCI_STYLESETFONT, #STYLE_DEFAULT, ToAscii(EditorFontName$))
CompilerEndIf
ScintillaSendMessage(Gadget, #SCI_STYLESETSIZE, #STYLE_DEFAULT, EditorFontSize)
If EditorFontStyle & #PB_Font_Bold
ScintillaSendMessage(Gadget, #SCI_STYLESETBOLD, #STYLE_DEFAULT, 1)
Else
ScintillaSendMessage(Gadget, #SCI_STYLESETBOLD, #STYLE_DEFAULT, 0)
EndIf
If EditorFontStyle & #PB_Font_Italic
ScintillaSendMessage(Gadget, #SCI_STYLESETITALIC, #STYLE_DEFAULT, 1)
Else
ScintillaSendMessage(Gadget, #SCI_STYLESETITALIC, #STYLE_DEFAULT, 0)
EndIf
ScintillaSendMessage(Gadget, #SCI_STYLESETEOLFILLED, #STYLE_DEFAULT, #True)
; background markers
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #DIFF_Empty, $C0C0C0)
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #DIFF_Equal, $FFFFFF)
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #DIFF_Added, $90EE90)
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #DIFF_Removed, $507FFF)
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #DIFF_Changed, $80FFFF)
; symbol markers
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #DIFF_StateCount+#DIFF_Empty, $C0C0C0)
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #DIFF_StateCount+#DIFF_Equal, $FFFFFF)
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #DIFF_StateCount+#DIFF_Added, $90EE90)
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #DIFF_StateCount+#DIFF_Removed, $507FFF)
ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #DIFF_StateCount+#DIFF_Changed, $80FFFF)
If DiffShowColors
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_DEFAULT, Colors(#COLOR_GlobalBackground)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLECLEARALL, 0, 0) ; to make the background & font change effective!
If EnableKeywordBolding
; Gtk2 'Pango' need an "!" before the font name (else it will use GDK font)
;
CompilerIf #CompileLinuxGtk2
FontName$ = "!"+EditorBoldFontName$
ScintillaSendMessage(Gadget, #SCI_STYLESETFONT, 2, ToAscii(FontName$))
ScintillaSendMessage(Gadget, #SCI_STYLESETFONT, 14, ToAscii(FontName$))
CompilerElse
ScintillaSendMessage(Gadget, #SCI_STYLESETFONT, 2, ToAscii(EditorBoldFontName$))
ScintillaSendMessage(Gadget, #SCI_STYLESETFONT, 14, ToAscii(EditorBoldFontName$))
CompilerEndIf
ScintillaSendMessage(Gadget, #SCI_STYLESETSIZE, #STYLE_DEFAULT, EditorFontSize)
ScintillaSendMessage(Gadget, #SCI_STYLESETBOLD, 2, 1) ; Bold (no effect on linux, but maybe on windows later)
ScintillaSendMessage(Gadget, #SCI_STYLESETBOLD, 14, 1)
If EditorFontStyle & #PB_Font_Italic
ScintillaSendMessage(Gadget, #SCI_STYLESETITALIC, 2, 1)
ScintillaSendMessage(Gadget, #SCI_STYLESETITALIC, 14, 1)
EndIf
EndIf
For i = 0 To #DIFF_StateCount-1
ScintillaSendMessage(Gadget, #SCI_MARKERSETFORE, #DIFF_StateCount+i, Colors(#COLOR_NormalText)\DisplayValue)
Next i
; applies to all margins
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_LINENUMBER, Colors(#COLOR_LineNumber)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_LINENUMBER, Colors(#COLOR_LineNumberBack)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 1, Colors(#COLOR_NormalText)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 2, Colors(#COLOR_BasicKeyword)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 3, Colors(#COLOR_Comment)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 4, Colors(#COLOR_Constant)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 5, Colors(#COLOR_String)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 6, Colors(#COLOR_PureKeyword)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 7, Colors(#COLOR_ASMKeyword)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 8, Colors(#COLOR_Operator)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 9, Colors(#COLOR_Structure)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 10, Colors(#COLOR_Number)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 11, Colors(#COLOR_Pointer)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 12, Colors(#COLOR_Separator)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 13, Colors(#COLOR_Label)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, 14, Colors(#COLOR_CustomKeyword)\DisplayValue)
CompilerIf #CompileWindows
If Colors(#COLOR_Selection)\DisplayValue = -1 ; special accessibility scheme
ScintillaSendMessage(Gadget, #SCI_SETSELBACK, 1, GetSysColor_(#COLOR_HIGHLIGHT))
Else
ScintillaSendMessage(Gadget, #SCI_SETSELBACK, 1, Colors(#COLOR_Selection)\DisplayValue)
EndIf
If Colors(#COLOR_SelectionFront)\DisplayValue = -1
ScintillaSendMessage(Gadget, #SCI_SETSELFORE, 1, GetSysColor_(#COLOR_HIGHLIGHTTEXT))
Else
ScintillaSendMessage(Gadget, #SCI_SETSELFORE, 1, Colors(#COLOR_SelectionFront)\DisplayValue)
EndIf
CompilerElse
ScintillaSendMessage(Gadget, #SCI_SETSELBACK, 1, Colors(#COLOR_Selection)\DisplayValue)
ScintillaSendMessage(Gadget, #SCI_SETSELFORE, 1, Colors(#COLOR_SelectionFront)\DisplayValue)
CompilerEndIf
ScintillaSendMessage(Gadget, #SCI_SETCARETFORE, Colors(#COLOR_Cursor)\DisplayValue, 0)
Else
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_DEFAULT, $FFFFFF)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_DEFAULT, $000000)
ScintillaSendMessage(Gadget, #SCI_STYLECLEARALL, 0, 0) ; to make the background & font change effective!
For i = 0 To #DIFF_StateCount-1
ScintillaSendMessage(Gadget, #SCI_MARKERSETFORE, #DIFF_StateCount+i, $000000)
Next i
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_LINENUMBER, $000000)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_LINENUMBER, $FFFFFF)
CompilerIf #CompileWindows
ScintillaSendMessage(Gadget, #SCI_SETSELBACK, 1, GetSysColor_(#COLOR_HIGHLIGHT))
ScintillaSendMessage(Gadget, #SCI_SETSELFORE, 1, GetSysColor_(#COLOR_HIGHLIGHTTEXT))
CompilerElse
ScintillaSendMessage(Gadget, #SCI_SETSELBACK, 1, $C0C0C0)
ScintillaSendMessage(Gadget, #SCI_SETSELFORE, 1, $000000)
CompilerEndIf
ScintillaSendMessage(Gadget, #SCI_SETCARETFORE, $000000)
EndIf
ScintillaSendMessage(Gadget, #SCI_SETTABWIDTH, TabLength)
ScintillaSendMessage(Gadget, #SCI_SETUSETABS, RealTab)
ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 2, ScintillaSendMessage(Gadget, #SCI_TEXTHEIGHT, 1, 0))
CompilerIf #SCINTILLA_TEXT_MARGIN
Lines = Max(Max(DiffA_Lines, DiffB_Lines), 10) ; use the same margin width on both files
Lines$ = "_" + RSet("9", Len(Str(Lines)), "9")
ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 1, ScintillaSendMessage(Gadget, #SCI_TEXTWIDTH, #STYLE_LINENUMBER, ToAscii(Lines$)))
CompilerElse
; hide this margin
ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 1, 0)
CompilerEndIf
; We need to build the full buffer for the coloring update and to set the text
;
Length = 1 ; for null byte
ForEach Style()
Length + Style()\Length
Next Style()
If SetText
ScintillaSendMessage(Gadget, #SCI_SETREADONLY, 0) ; so it can be modified now
EndIf
*Buffer = AllocateMemory(Length)
If *Buffer
*Pointer = *Buffer
ForEach Style()
If Style()\Start = #Null ; indicates that we need to add empty lines
For i = 1 To Style()\Length / #NewLineLength
PokeAscii(*Pointer, #NewLine)
*Pointer + #NewLineLength
Next i
Else
CopyMemory(Style()\Start, *Pointer, Style()\Length)
*Pointer + Style()\Length
EndIf
Next Style()
If SetText
; adjust the utf8 mode as well (in case a swap took place)
;
If IsLeft
Utf8 = DiffA_Utf8
Else
Utf8 = DiffB_Utf8
EndIf
If Utf8
ScintillaSendMessage(Gadget, #SCI_SETCODEPAGE, #SC_CP_UTF8)
Else
ScintillaSendMessage(Gadget, #SCI_SETCODEPAGE, 0)
EndIf
; set the new text
ScintillaSendMessage(Gadget, #SCI_SETTEXT, 0, *Buffer)
; the line numbers also only need updating when the text changed
CompilerIf #SCINTILLA_TEXT_MARGIN
ScintillaSendMessage(Gadget, #SCI_MARGINTEXTCLEARALL)
CompilerEndIf
; apply the markers for the diff background (only needed on text changes)
; also apply the line number text (if supported)
;
ScintillaSendMessage(Gadget, #SCI_MARKERDELETEALL, -1)
Line = 0
DisplayLine = 1
PreviousStyle = #DIFF_Equal
ForEach Style()
; mark the beginning of each change block
; note: a block with #DIFF_Empty is not a new change when it immediately follows a block of #DIFF_Changed
; because then it is just an extension of that block to match the length in the other file
;
If Style()\Style <> #DIFF_Equal And (Not (Style()\Style = #DIFF_Empty And PreviousStyle = #DIFF_Changed))
ScintillaSendMessage(Gadget, #SCI_MARKERADD, Line, #DIFF_ChangeMarker)
EndIf
If DiffSwapped And Style()\Style = #DIFF_Added
Style = #DIFF_Removed
ElseIf DiffSwapped And Style()\Style = #DIFF_Removed
Style = #DIFF_Added
Else
Style = Style()\Style
EndIf
For i = 1 To Style()\Lines
If Style <> #DIFF_Equal ; keep normal background for equal parts
; the swapped display is exactly the same as the normal one, only
; insers and deletes are reversed, so we can do a swap without changing the underlying data
ScintillaSendMessage(Gadget, #SCI_MARKERADD, Line, Style) ; background
ScintillaSendMessage(Gadget, #SCI_MARKERADD, Line, #DIFF_StateCount+Style) ; symbol
EndIf
CompilerIf #SCINTILLA_TEXT_MARGIN
If Style <> #DIFF_Empty
Text$ = Str(DisplayLine)
ScintillaSendMessage(Gadget, #SCI_MARGINSETTEXT, Line, @Text$)
ScintillaSendMessage(Gadget, #SCI_MARGINSETSTYLE, Line, #STYLE_LINENUMBER)
DisplayLine + 1
EndIf
CompilerEndIf
Line + 1
Next i
PreviousStyle = Style()\Style
Next Style()
EndIf
; apply the styling
;
DiffStyleGadget = Gadget
ScintillaSendMessage(Gadget, #SCI_STARTSTYLING, 0, $1F)
If DiffShowColors
HighlightingEngine(*Buffer, Length-1, 0, @DiffHighlightCallback(), 0)