1
1
using System ;
2
2
using System . IO ;
3
3
using System . Threading . Tasks ;
4
-
5
4
using Avalonia . Threading ;
6
-
7
5
using CommunityToolkit . Mvvm . ComponentModel ;
8
6
9
7
namespace SourceGit . ViewModels
@@ -24,7 +22,58 @@ public bool IgnoreWhitespace
24
22
{
25
23
Preferences . Instance . IgnoreWhitespaceChangesInDiff = value ;
26
24
OnPropertyChanged ( ) ;
27
- LoadDiffContent ( ) ;
25
+
26
+ if ( _isTextDiff )
27
+ LoadContent ( ) ;
28
+ }
29
+ }
30
+ }
31
+
32
+ public bool ShowEntireFile
33
+ {
34
+ get => Preferences . Instance . UseFullTextDiff ;
35
+ set
36
+ {
37
+ if ( value != Preferences . Instance . UseFullTextDiff )
38
+ {
39
+ Preferences . Instance . UseFullTextDiff = value ;
40
+ OnPropertyChanged ( ) ;
41
+
42
+ if ( Content is ITextDiffContext ctx )
43
+ {
44
+ ctx . ResetScroll ( ) ;
45
+ LoadContent ( ) ;
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ public bool UseBlockNavigation
52
+ {
53
+ get => Preferences . Instance . UseBlockNavigationInDiffView ;
54
+ set
55
+ {
56
+ if ( value != Preferences . Instance . UseBlockNavigationInDiffView )
57
+ {
58
+ Preferences . Instance . UseBlockNavigationInDiffView = value ;
59
+ OnPropertyChanged ( ) ;
60
+ ( Content as ITextDiffContext ) ? . ResetBlockNavigation ( value ) ;
61
+ }
62
+ }
63
+ }
64
+
65
+ public bool UseSideBySide
66
+ {
67
+ get => Preferences . Instance . UseSideBySideDiff ;
68
+ set
69
+ {
70
+ if ( value != Preferences . Instance . UseSideBySideDiff )
71
+ {
72
+ Preferences . Instance . UseSideBySideDiff = value ;
73
+ OnPropertyChanged ( ) ;
74
+
75
+ if ( Content is ITextDiffContext ctx && ctx . IsSideBySide ( ) != value )
76
+ Content = ctx . SwitchMode ( ) ;
28
77
}
29
78
}
30
79
}
@@ -72,33 +121,49 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
72
121
else
73
122
Title = $ "{ _option . OrgPath } → { _option . Path } ";
74
123
75
- LoadDiffContent ( ) ;
76
- }
77
-
78
- public void ToggleFullTextDiff ( )
79
- {
80
- Preferences . Instance . UseFullTextDiff = ! Preferences . Instance . UseFullTextDiff ;
81
- LoadDiffContent ( ) ;
124
+ LoadContent ( ) ;
82
125
}
83
126
84
127
public void IncrUnified ( )
85
128
{
86
129
UnifiedLines = _unifiedLines + 1 ;
87
- LoadDiffContent ( ) ;
130
+ LoadContent ( ) ;
88
131
}
89
132
90
133
public void DecrUnified ( )
91
134
{
92
135
UnifiedLines = Math . Max ( 4 , _unifiedLines - 1 ) ;
93
- LoadDiffContent ( ) ;
136
+ LoadContent ( ) ;
94
137
}
95
138
96
139
public void OpenExternalMergeTool ( )
97
140
{
98
141
new Commands . DiffTool ( _repo , _option ) . Open ( ) ;
99
142
}
100
143
101
- private void LoadDiffContent ( )
144
+ public void CheckSettings ( )
145
+ {
146
+ if ( Content is ITextDiffContext ctx )
147
+ {
148
+ if ( ( ShowEntireFile && _info . UnifiedLines != _entireFileLine ) ||
149
+ ( ! ShowEntireFile && _info . UnifiedLines == _entireFileLine ) ||
150
+ ( IgnoreWhitespace != _info . IgnoreWhitespace ) )
151
+ {
152
+ LoadContent ( ) ;
153
+ return ;
154
+ }
155
+
156
+ if ( ctx . IsSideBySide ( ) != UseSideBySide )
157
+ {
158
+ ctx = ctx . SwitchMode ( ) ;
159
+ Content = ctx ;
160
+ }
161
+
162
+ ctx . ResetBlockNavigation ( UseBlockNavigation ) ;
163
+ }
164
+ }
165
+
166
+ private void LoadContent ( )
102
167
{
103
168
if ( _option . Path . EndsWith ( '/' ) )
104
169
{
@@ -109,7 +174,7 @@ private void LoadDiffContent()
109
174
110
175
Task . Run ( async ( ) =>
111
176
{
112
- var numLines = Preferences . Instance . UseFullTextDiff ? 999999999 : _unifiedLines ;
177
+ var numLines = Preferences . Instance . UseFullTextDiff ? _entireFileLine : _unifiedLines ;
113
178
var ignoreWhitespace = Preferences . Instance . IgnoreWhitespaceChangesInDiff ;
114
179
115
180
var latest = await new Commands . Diff ( _repo , _option , numLines , ignoreWhitespace )
@@ -228,12 +293,23 @@ private void LoadDiffContent()
228
293
229
294
Dispatcher . UIThread . Post ( ( ) =>
230
295
{
231
- if ( _content is Models . TextDiff old && rs is Models . TextDiff cur && old . File == cur . File )
232
- cur . ScrollOffset = old . ScrollOffset ;
233
-
234
296
FileModeChange = latest . FileModeChange ;
235
- Content = rs ;
236
- IsTextDiff = rs is Models . TextDiff ;
297
+
298
+ if ( rs is Models . TextDiff cur )
299
+ {
300
+ IsTextDiff = true ;
301
+
302
+ var hasBlockNavigation = Preferences . Instance . UseBlockNavigationInDiffView ;
303
+ if ( Preferences . Instance . UseSideBySideDiff )
304
+ Content = new TwoSideTextDiff ( cur , hasBlockNavigation , _content as TwoSideTextDiff ) ;
305
+ else
306
+ Content = new CombinedTextDiff ( cur , hasBlockNavigation , _content as CombinedTextDiff ) ;
307
+ }
308
+ else
309
+ {
310
+ IsTextDiff = false ;
311
+ Content = rs ;
312
+ }
237
313
} ) ;
238
314
} ) ;
239
315
}
@@ -279,6 +355,7 @@ public bool IsSame(Info other)
279
355
}
280
356
}
281
357
358
+ private readonly int _entireFileLine = 999999999 ;
282
359
private readonly string _repo ;
283
360
private readonly Models . DiffOption _option = null ;
284
361
private string _fileModeChange = string . Empty ;
0 commit comments