feature: add dirty state indicator icon to repository tab (#1227)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-04-30 11:01:39 +08:00
parent 847a1e727b
commit 80aead3a17
No known key found for this signature in database
5 changed files with 71 additions and 10 deletions

View file

@ -1,5 +1,8 @@
using System;
using Avalonia.Collections;
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels
@ -18,6 +21,12 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _data, value);
}
public IBrush DirtyBrush
{
get => _dirtyBrush;
private set => SetProperty(ref _dirtyBrush, value);
}
public Popup Popup
{
get => _popup;
@ -56,6 +65,26 @@ namespace SourceGit.ViewModels
App.CopyText(_node.Id);
}
public void ChangeDirtyState(Models.DirtyState flag, bool remove)
{
if (remove)
{
if (_dirtyState.HasFlag(flag))
_dirtyState -= flag;
}
else
{
_dirtyState |= flag;
}
if (_dirtyState.HasFlag(Models.DirtyState.HasLocalChanges))
DirtyBrush = Brushes.Gray;
else if (_dirtyState.HasFlag(Models.DirtyState.HasPendingPullOrPush))
DirtyBrush = Brushes.RoyalBlue;
else
DirtyBrush = null;
}
public bool CanCreatePopup()
{
return _popup == null || !_popup.InProgress;
@ -104,6 +133,8 @@ namespace SourceGit.ViewModels
private RepositoryNode _node = null;
private object _data = null;
private IBrush _dirtyBrush = null;
private Models.DirtyState _dirtyState = Models.DirtyState.None;
private Popup _popup = null;
}
}

View file

@ -994,6 +994,8 @@ namespace SourceGit.ViewModels
if (_workingCopy != null)
_workingCopy.HasRemotes = remotes.Count > 0;
GetOwnerPage()?.ChangeDirtyState(Models.DirtyState.HasPendingPullOrPush, !CurrentBranch.TrackStatus.IsVisible);
});
}
@ -1101,6 +1103,7 @@ namespace SourceGit.ViewModels
{
LocalChangesCount = changes.Count;
OnPropertyChanged(nameof(InProgressContext));
GetOwnerPage()?.ChangeDirtyState(Models.DirtyState.HasLocalChanges, changes.Count == 0);
});
}