1- using System . Collections . Generic ;
1+ using System ;
2+ using System . Collections . Generic ;
23using System . IO ;
34using System . Threading . Tasks ;
45
@@ -63,6 +64,16 @@ public Vector SyncScrollOffset
6364 set => SetProperty ( ref _syncScrollOffset , value ) ;
6465 }
6566
67+ public int Unified
68+ {
69+ get => _unified ;
70+ set
71+ {
72+ if ( SetProperty ( ref _unified , value ) )
73+ LoadDiffContent ( ) ;
74+ }
75+ }
76+
6677 public DiffContext ( string repo , Models . DiffOption option , DiffContext previous = null )
6778 {
6879 _repo = repo ;
@@ -74,9 +85,40 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
7485 _content = previous . _content ;
7586 }
7687
88+ LoadDiffContent ( ) ;
89+ }
90+
91+ public void IncrUnified ( )
92+ {
93+ Unified = _unified + 1 ;
94+ }
95+
96+ public void DecrUnified ( )
97+ {
98+ Unified = Math . Max ( 4 , _unified - 1 ) ;
99+ }
100+
101+ public void OpenExternalMergeTool ( )
102+ {
103+ var type = Preference . Instance . ExternalMergeToolType ;
104+ var exec = Preference . Instance . ExternalMergeToolPath ;
105+
106+ var tool = Models . ExternalMerger . Supported . Find ( x => x . Type == type ) ;
107+ if ( tool == null || ! File . Exists ( exec ) )
108+ {
109+ App . RaiseException ( _repo , "Invalid merge tool in preference setting!" ) ;
110+ return ;
111+ }
112+
113+ var args = tool . Type != 0 ? tool . DiffCmd : Preference . Instance . ExternalMergeToolDiffCmd ;
114+ Task . Run ( ( ) => Commands . MergeTool . OpenForDiff ( _repo , exec , args , _option ) ) ;
115+ }
116+
117+ private void LoadDiffContent ( )
118+ {
77119 Task . Run ( ( ) =>
78120 {
79- var latest = new Commands . Diff ( repo , option ) . Result ( ) ;
121+ var latest = new Commands . Diff ( _repo , _option , _unified ) . Result ( ) ;
80122 var rs = null as object ;
81123
82124 if ( latest . TextDiff != null )
@@ -92,31 +134,31 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
92134 if ( IMG_EXTS . Contains ( ext ) )
93135 {
94136 var imgDiff = new Models . ImageDiff ( ) ;
95- if ( option . Revisions . Count == 2 )
137+ if ( _option . Revisions . Count == 2 )
96138 {
97- imgDiff . Old = BitmapFromRevisionFile ( repo , option . Revisions [ 0 ] , oldPath ) ;
98- imgDiff . New = BitmapFromRevisionFile ( repo , option . Revisions [ 1 ] , oldPath ) ;
139+ imgDiff . Old = BitmapFromRevisionFile ( _repo , _option . Revisions [ 0 ] , oldPath ) ;
140+ imgDiff . New = BitmapFromRevisionFile ( _repo , _option . Revisions [ 1 ] , oldPath ) ;
99141 }
100142 else
101143 {
102- var fullPath = Path . Combine ( repo , _option . Path ) ;
103- imgDiff . Old = BitmapFromRevisionFile ( repo , "HEAD" , oldPath ) ;
144+ var fullPath = Path . Combine ( _repo , _option . Path ) ;
145+ imgDiff . Old = BitmapFromRevisionFile ( _repo , "HEAD" , oldPath ) ;
104146 imgDiff . New = File . Exists ( fullPath ) ? new Bitmap ( fullPath ) : null ;
105147 }
106148 rs = imgDiff ;
107149 }
108150 else
109151 {
110152 var binaryDiff = new Models . BinaryDiff ( ) ;
111- if ( option . Revisions . Count == 2 )
153+ if ( _option . Revisions . Count == 2 )
112154 {
113- binaryDiff . OldSize = new Commands . QueryFileSize ( repo , oldPath , option . Revisions [ 0 ] ) . Result ( ) ;
114- binaryDiff . NewSize = new Commands . QueryFileSize ( repo , _option . Path , option . Revisions [ 1 ] ) . Result ( ) ;
155+ binaryDiff . OldSize = new Commands . QueryFileSize ( _repo , oldPath , _option . Revisions [ 0 ] ) . Result ( ) ;
156+ binaryDiff . NewSize = new Commands . QueryFileSize ( _repo , _option . Path , _option . Revisions [ 1 ] ) . Result ( ) ;
115157 }
116158 else
117159 {
118- var fullPath = Path . Combine ( repo , _option . Path ) ;
119- binaryDiff . OldSize = new Commands . QueryFileSize ( repo , oldPath , "HEAD" ) . Result ( ) ;
160+ var fullPath = Path . Combine ( _repo , _option . Path ) ;
161+ binaryDiff . OldSize = new Commands . QueryFileSize ( _repo , oldPath , "HEAD" ) . Result ( ) ;
120162 binaryDiff . NewSize = File . Exists ( fullPath ) ? new FileInfo ( fullPath ) . Length : 0 ;
121163 }
122164 rs = binaryDiff ;
@@ -146,22 +188,6 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
146188 } ) ;
147189 }
148190
149- public void OpenExternalMergeTool ( )
150- {
151- var type = Preference . Instance . ExternalMergeToolType ;
152- var exec = Preference . Instance . ExternalMergeToolPath ;
153-
154- var tool = Models . ExternalMerger . Supported . Find ( x => x . Type == type ) ;
155- if ( tool == null || ! File . Exists ( exec ) )
156- {
157- App . RaiseException ( _repo , "Invalid merge tool in preference setting!" ) ;
158- return ;
159- }
160-
161- var args = tool . Type != 0 ? tool . DiffCmd : Preference . Instance . ExternalMergeToolDiffCmd ;
162- Task . Run ( ( ) => Commands . MergeTool . OpenForDiff ( _repo , exec , args , _option ) ) ;
163- }
164-
165191 private Bitmap BitmapFromRevisionFile ( string repo , string revision , string file )
166192 {
167193 var stream = Commands . QueryFileContent . Run ( repo , revision , file ) ;
@@ -181,5 +207,6 @@ private Bitmap BitmapFromRevisionFile(string repo, string revision, string file)
181207 private bool _isTextDiff = false ;
182208 private object _content = null ;
183209 private Vector _syncScrollOffset = Vector . Zero ;
210+ private int _unified = 4 ;
184211 }
185212}
0 commit comments