11using System ;
22using System . Collections . Generic ;
3+ using System . ComponentModel ;
34using System . IO ;
45using System . Threading . Tasks ;
56
@@ -149,10 +150,92 @@ public object DetailContext
149150 set
150151 {
151152 if ( SetProperty ( ref _detailContext , value ) )
153+ {
154+ ShowGraph ( ) ;
155+ ObserveDetailContext ( value ) ;
152156 OnPropertyChanged ( nameof ( IsOpenAsStandaloneVisible ) ) ;
157+ }
158+ }
159+ }
160+
161+ public DiffContext FocusedDiff
162+ {
163+ get => _focusedDiff ;
164+ private set
165+ {
166+ if ( SetProperty ( ref _focusedDiff , value ) )
167+ OnPropertyChanged ( nameof ( IsFocusedDiffVisible ) ) ;
153168 }
154169 }
155170
171+ public string FocusedDiffPath
172+ {
173+ get => _focusedDiffPath ;
174+ private set => SetProperty ( ref _focusedDiffPath , value ) ;
175+ }
176+
177+ public bool IsFocusedDiffVisible => Preferences . Instance . IsFocusedHistoryLayout && FocusedDiff != null ;
178+
179+ public void OpenFocusedDiff ( )
180+ {
181+ if ( ! Preferences . Instance . IsFocusedHistoryLayout )
182+ return ;
183+
184+ ChangeSelection selection ;
185+ DiffContext diff ;
186+ if ( DetailContext is CommitDetail detail )
187+ {
188+ selection = detail . ChangeSelection ;
189+ if ( detail . DiffContext == null )
190+ detail . UpdateDetails ( ) ;
191+ diff = detail . DiffContext ;
192+ }
193+ else if ( DetailContext is RevisionCompare compare )
194+ {
195+ selection = compare . ChangeSelection ;
196+ diff = compare . DiffContext ;
197+ }
198+ else
199+ {
200+ return ;
201+ }
202+
203+ if ( selection is { Count : 1 , HasFolder : false } && diff != null )
204+ {
205+ FocusedDiffPath = selection . Changes [ 0 ] . Path ;
206+ FocusedDiff = diff ;
207+ }
208+ }
209+
210+ public void ShowGraph ( )
211+ {
212+ FocusedDiff = null ;
213+ FocusedDiffPath = string . Empty ;
214+ }
215+
216+ public void UpdateLayout ( )
217+ {
218+ ShowGraph ( ) ;
219+ OnPropertyChanged ( nameof ( RightArea ) ) ;
220+ OnPropertyChanged ( nameof ( BottomArea ) ) ;
221+ }
222+
223+ private void ObserveDetailContext ( object context )
224+ {
225+ if ( _observedDetailContext != null )
226+ _observedDetailContext . PropertyChanged -= OnDetailContextPropertyChanged ;
227+ _observedDetailContext = context as INotifyPropertyChanged ;
228+ if ( _observedDetailContext != null )
229+ _observedDetailContext . PropertyChanged += OnDetailContextPropertyChanged ;
230+ }
231+
232+ private void OnDetailContextPropertyChanged ( object sender , PropertyChangedEventArgs e )
233+ {
234+ if ( e . PropertyName is nameof ( CommitDetail . Commit ) or nameof ( RevisionCompare . IsLoading ) or
235+ nameof ( RevisionCompare . StartPoint ) or nameof ( RevisionCompare . EndPoint ) )
236+ ShowGraph ( ) ;
237+ }
238+
156239 public Models . Bisect Bisect
157240 {
158241 get => _bisect ;
@@ -184,8 +267,20 @@ public GridLength LeftArea
184267
185268 public GridLength RightArea
186269 {
187- get => _rightArea ;
188- set => SetProperty ( ref _rightArea , value ) ;
270+ get => Preferences . Instance . IsFocusedHistoryLayout ? new GridLength ( _repo . UIStates . FocusedHistoryDetailsWidth ) : _rightArea ;
271+ set
272+ {
273+ if ( Preferences . Instance . IsFocusedHistoryLayout )
274+ {
275+ if ( value . IsAbsolute && value . Value >= 260 )
276+ {
277+ _repo . UIStates . FocusedHistoryDetailsWidth = value . Value ;
278+ OnPropertyChanged ( ) ;
279+ }
280+ }
281+ else
282+ SetProperty ( ref _rightArea , value ) ;
283+ }
189284 }
190285
191286 public GridLength TopArea
@@ -199,7 +294,7 @@ public GridLength BottomArea
199294 get => _isCollapseDetails ? new GridLength ( 28 , GridUnitType . Pixel ) : _bottomArea ;
200295 set
201296 {
202- if ( ! Preferences . Instance . UseTwoColumnsLayoutInHistories && ! _isCollapseDetails )
297+ if ( ! Preferences . Instance . IsHorizontalHistoryLayout && ! _isCollapseDetails )
203298 SetProperty ( ref _bottomArea , value ) ;
204299 }
205300 }
@@ -220,7 +315,7 @@ public bool IsCollapseDetails
220315 get => _isCollapseDetails ;
221316 set
222317 {
223- if ( ! Preferences . Instance . UseTwoColumnsLayoutInHistories && SetProperty ( ref _isCollapseDetails , value ) )
318+ if ( ! Preferences . Instance . IsHorizontalHistoryLayout && SetProperty ( ref _isCollapseDetails , value ) )
224319 {
225320 OnPropertyChanged ( nameof ( TopArea ) ) ;
226321 OnPropertyChanged ( nameof ( BottomArea ) ) ;
@@ -588,6 +683,9 @@ private void GenerateGraph(List<Models.Commit> commits)
588683 private Models . Bisect _bisect = null ;
589684 private object _detailContext = Models . Null . Instance ;
590685 private bool _ignoreSelectionChange = false ;
686+ private INotifyPropertyChanged _observedDetailContext = null ;
687+ private DiffContext _focusedDiff = null ;
688+ private string _focusedDiffPath = string . Empty ;
591689
592690 private bool _isSearchingCommits = false ;
593691 private SearchCommitContext _searchCommitContext = null ;
0 commit comments