Skip to content

Commit 80aead3

Browse files
committed
feature: add dirty state indicator icon to repository tab (#1227)
Signed-off-by: leo <[email protected]>
1 parent 847a1e7 commit 80aead3

File tree

5 files changed

+71
-10
lines changed

5 files changed

+71
-10
lines changed

src/Models/Bisect.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public enum BisectState
1414
public enum BisectCommitFlag
1515
{
1616
None = 0,
17-
Good = 1,
18-
Bad = 2,
17+
Good = 1 << 0,
18+
Bad = 1 << 1,
1919
}
2020

2121
public class Bisect

src/Models/DirtyState.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace SourceGit.Models
4+
{
5+
[Flags]
6+
public enum DirtyState
7+
{
8+
None = 0,
9+
HasLocalChanges = 1 << 0,
10+
HasPendingPullOrPush = 1 << 1,
11+
}
12+
}

src/ViewModels/LauncherPage.cs

+31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
2+
23
using Avalonia.Collections;
4+
using Avalonia.Media;
5+
36
using CommunityToolkit.Mvvm.ComponentModel;
47

58
namespace SourceGit.ViewModels
@@ -18,6 +21,12 @@ public object Data
1821
set => SetProperty(ref _data, value);
1922
}
2023

24+
public IBrush DirtyBrush
25+
{
26+
get => _dirtyBrush;
27+
private set => SetProperty(ref _dirtyBrush, value);
28+
}
29+
2130
public Popup Popup
2231
{
2332
get => _popup;
@@ -56,6 +65,26 @@ public void CopyPath()
5665
App.CopyText(_node.Id);
5766
}
5867

68+
public void ChangeDirtyState(Models.DirtyState flag, bool remove)
69+
{
70+
if (remove)
71+
{
72+
if (_dirtyState.HasFlag(flag))
73+
_dirtyState -= flag;
74+
}
75+
else
76+
{
77+
_dirtyState |= flag;
78+
}
79+
80+
if (_dirtyState.HasFlag(Models.DirtyState.HasLocalChanges))
81+
DirtyBrush = Brushes.Gray;
82+
else if (_dirtyState.HasFlag(Models.DirtyState.HasPendingPullOrPush))
83+
DirtyBrush = Brushes.RoyalBlue;
84+
else
85+
DirtyBrush = null;
86+
}
87+
5988
public bool CanCreatePopup()
6089
{
6190
return _popup == null || !_popup.InProgress;
@@ -104,6 +133,8 @@ public void CancelPopup()
104133

105134
private RepositoryNode _node = null;
106135
private object _data = null;
136+
private IBrush _dirtyBrush = null;
137+
private Models.DirtyState _dirtyState = Models.DirtyState.None;
107138
private Popup _popup = null;
108139
}
109140
}

src/ViewModels/Repository.cs

+3
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,8 @@ public void RefreshBranches()
994994

995995
if (_workingCopy != null)
996996
_workingCopy.HasRemotes = remotes.Count > 0;
997+
998+
GetOwnerPage()?.ChangeDirtyState(Models.DirtyState.HasPendingPullOrPush, !CurrentBranch.TrackStatus.IsVisible);
997999
});
9981000
}
9991001

@@ -1101,6 +1103,7 @@ public void RefreshWorkingCopyChanges()
11011103
{
11021104
LocalChangesCount = changes.Count;
11031105
OnPropertyChanged(nameof(InProgressContext));
1106+
GetOwnerPage()?.ChangeDirtyState(Models.DirtyState.HasLocalChanges, changes.Count == 0);
11041107
});
11051108
}
11061109

src/Views/LauncherTabBar.axaml

+23-8
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,29 @@
6868
Data="{StaticResource Icons.Repositories}"
6969
IsVisible="{Binding !Node.IsRepository}"
7070
IsHitTestVisible="False"/>
71-
<TextBlock Grid.Column="1"
72-
Classes="primary"
73-
HorizontalAlignment="Stretch" VerticalAlignment="Center"
74-
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
75-
TextAlignment="Center"
76-
Text="{Binding Node.Name}"
77-
IsVisible="{Binding Node.IsRepository}"
78-
IsHitTestVisible="False"/>
71+
72+
<Grid Grid.Column="1"
73+
HorizontalAlignment="Center" VerticalAlignment="Center"
74+
ColumnDefinitions="Auto,*"
75+
IsHitTestVisible="False"
76+
IsVisible="{Binding Node.IsRepository}">
77+
<Ellipse Grid.Column="0"
78+
Width="8" Height="8"
79+
Margin="0,0,6,0"
80+
VerticalAlignment="Center"
81+
IsVisible="{Binding DirtyBrush, Converter={x:Static ObjectConverters.IsNotNull}}"
82+
Fill="{Binding DirtyBrush}"/>
83+
84+
<TextBlock Grid.Column="1"
85+
Classes="primary"
86+
VerticalAlignment="Center"
87+
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
88+
TextAlignment="Center"
89+
Text="{Binding Node.Name}"
90+
IsVisible="{Binding Node.IsRepository}"
91+
IsHitTestVisible="False"/>
92+
</Grid>
93+
7994
<TextBlock Grid.Column="1"
8095
Classes="primary"
8196
HorizontalAlignment="Stretch" VerticalAlignment="Center"

0 commit comments

Comments
 (0)