fix: try to fix issue #338

* upgrade Avalonia to `11.1.3`
* use reactive property instead of simple getter
This commit is contained in:
leo 2024-08-13 17:38:58 +08:00
parent 34a598d421
commit f3406e93fc
No known key found for this signature in database
5 changed files with 30 additions and 23 deletions

View file

@ -37,11 +37,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.13" /> <PackageReference Include="Avalonia" Version="11.1.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.13" /> <PackageReference Include="Avalonia.Desktop" Version="11.1.3" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.13" /> <PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.3" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.13" /> <PackageReference Include="Avalonia.Controls.DataGrid" Version="11.1.3" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.13" Condition="'$(Configuration)' == 'Debug'" /> <PackageReference Include="Avalonia.Diagnostics" Version="11.1.3" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.1.0" /> <PackageReference Include="Avalonia.AvaloniaEdit" Version="11.1.0" />
<PackageReference Include="AvaloniaEdit.TextMate" Version="11.1.0" /> <PackageReference Include="AvaloniaEdit.TextMate" Version="11.1.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />

View file

@ -243,7 +243,7 @@ namespace SourceGit.ViewModels
reword.Icon = App.CreateMenuIcon("Icons.Edit"); reword.Icon = App.CreateMenuIcon("Icons.Edit");
reword.Click += (_, e) => reword.Click += (_, e) =>
{ {
if (_repo.WorkingCopyChangesCount > 0) if (_repo.LocalChangesCount > 0)
{ {
App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first."); App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first.");
return; return;
@ -261,7 +261,7 @@ namespace SourceGit.ViewModels
squash.IsEnabled = commit.Parents.Count == 1; squash.IsEnabled = commit.Parents.Count == 1;
squash.Click += (_, e) => squash.Click += (_, e) =>
{ {
if (_repo.WorkingCopyChangesCount > 0) if (_repo.LocalChangesCount > 0)
{ {
App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first."); App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first.");
return; return;
@ -322,7 +322,7 @@ namespace SourceGit.ViewModels
interactiveRebase.IsVisible = current.Head != commit.SHA; interactiveRebase.IsVisible = current.Head != commit.SHA;
interactiveRebase.Click += (_, e) => interactiveRebase.Click += (_, e) =>
{ {
if (_repo.WorkingCopyChangesCount > 0) if (_repo.LocalChangesCount > 0)
{ {
App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first."); App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first.");
return; return;
@ -379,7 +379,7 @@ namespace SourceGit.ViewModels
}; };
menu.Items.Add(compareWithHead); menu.Items.Add(compareWithHead);
if (_repo.WorkingCopyChangesCount > 0) if (_repo.LocalChangesCount > 0)
{ {
var compareWithWorktree = new MenuItem(); var compareWithWorktree = new MenuItem();
compareWithWorktree.Header = App.Text("CommitCM.CompareWithWorktree"); compareWithWorktree.Header = App.Text("CommitCM.CompareWithWorktree");

View file

@ -142,14 +142,16 @@ namespace SourceGit.ViewModels
private set => SetProperty(ref _submodules, value); private set => SetProperty(ref _submodules, value);
} }
public int WorkingCopyChangesCount public int LocalChangesCount
{ {
get => _workingCopy == null ? 0 : _workingCopy.Count; get => _localChangesCount;
private set => SetProperty(ref _localChangesCount, value);
} }
public int StashesCount public int StashesCount
{ {
get => _stashesPage == null ? 0 : _stashesPage.Stashes.Count; get => _stashesCount;
private set => SetProperty(ref _stashesCount, value);
} }
public bool IncludeUntracked public bool IncludeUntracked
@ -350,6 +352,9 @@ namespace SourceGit.ViewModels
_stashesPage = null; _stashesPage = null;
_inProgressContext = null; _inProgressContext = null;
_localChangesCount = 0;
_stashesCount = 0;
_remotes.Clear(); _remotes.Clear();
_branches.Clear(); _branches.Clear();
_localBranchTrees.Clear(); _localBranchTrees.Clear();
@ -834,7 +839,7 @@ namespace SourceGit.ViewModels
{ {
InProgressContext = inProgress; InProgressContext = inProgress;
HasUnsolvedConflicts = hasUnsolvedConflict; HasUnsolvedConflicts = hasUnsolvedConflict;
OnPropertyChanged(nameof(WorkingCopyChangesCount)); LocalChangesCount = changes.Count;
}); });
} }
@ -845,7 +850,8 @@ namespace SourceGit.ViewModels
{ {
if (_stashesPage != null) if (_stashesPage != null)
_stashesPage.Stashes = stashes; _stashesPage.Stashes = stashes;
OnPropertyChanged(nameof(StashesCount));
StashesCount = stashes.Count;
}); });
} }
@ -878,7 +884,7 @@ namespace SourceGit.ViewModels
if (branch.IsLocal) if (branch.IsLocal)
{ {
if (WorkingCopyChangesCount > 0) if (_localChangesCount > 0)
PopupHost.ShowPopup(new Checkout(this, branch.Name)); PopupHost.ShowPopup(new Checkout(this, branch.Name));
else else
PopupHost.ShowAndStartPopup(new Checkout(this, branch.Name)); PopupHost.ShowAndStartPopup(new Checkout(this, branch.Name));
@ -1215,7 +1221,7 @@ namespace SourceGit.ViewModels
var discard = new MenuItem(); var discard = new MenuItem();
discard.Header = App.Text("BranchCM.DiscardAll"); discard.Header = App.Text("BranchCM.DiscardAll");
discard.Icon = App.CreateMenuIcon("Icons.Undo"); discard.Icon = App.CreateMenuIcon("Icons.Undo");
discard.IsEnabled = _workingCopy.Count > 0; discard.IsEnabled = _localChangesCount > 0;
discard.Click += (_, e) => discard.Click += (_, e) =>
{ {
if (PopupHost.CanCreatePopup()) if (PopupHost.CanCreatePopup())
@ -1319,7 +1325,7 @@ namespace SourceGit.ViewModels
menu.Items.Add(merge); menu.Items.Add(merge);
menu.Items.Add(rebase); menu.Items.Add(rebase);
if (WorkingCopyChangesCount > 0) if (_localChangesCount > 0)
{ {
var compareWithWorktree = new MenuItem(); var compareWithWorktree = new MenuItem();
compareWithWorktree.Header = App.Text("BranchCM.CompareWithWorktree"); compareWithWorktree.Header = App.Text("BranchCM.CompareWithWorktree");
@ -1342,7 +1348,7 @@ namespace SourceGit.ViewModels
var compareWithBranch = CreateMenuItemToCompareBranches(branch); var compareWithBranch = CreateMenuItemToCompareBranches(branch);
if (compareWithBranch != null) if (compareWithBranch != null)
{ {
if (WorkingCopyChangesCount == 0) if (_localChangesCount == 0)
menu.Items.Add(new MenuItem() { Header = "-" }); menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(compareWithBranch); menu.Items.Add(compareWithBranch);
@ -1619,7 +1625,7 @@ namespace SourceGit.ViewModels
} }
var hasCompare = false; var hasCompare = false;
if (WorkingCopyChangesCount > 0) if (_localChangesCount > 0)
{ {
var compareWithWorktree = new MenuItem(); var compareWithWorktree = new MenuItem();
compareWithWorktree.Header = App.Text("BranchCM.CompareWithWorktree"); compareWithWorktree.Header = App.Text("BranchCM.CompareWithWorktree");
@ -1981,6 +1987,9 @@ namespace SourceGit.ViewModels
private int _selectedViewIndex = 0; private int _selectedViewIndex = 0;
private object _selectedView = null; private object _selectedView = null;
private int _localChangesCount = 0;
private int _stashesCount = 0;
private bool _isSearching = false; private bool _isSearching = false;
private bool _isSearchLoadingVisible = false; private bool _isSearchLoadingVisible = false;
private bool _isSearchCommitSuggestionOpen = false; private bool _isSearchCommitSuggestionOpen = false;

View file

@ -177,8 +177,6 @@ namespace SourceGit.ViewModels
} }
} }
public int Count => _count;
public object DetailContext public object DetailContext
{ {
get => _detailContext; get => _detailContext;

View file

@ -97,8 +97,8 @@
CornerRadius="9" CornerRadius="9"
VerticalAlignment="Center" VerticalAlignment="Center"
Background="{DynamicResource Brush.Badge}" Background="{DynamicResource Brush.Badge}"
IsVisible="{Binding WorkingCopyChangesCount, Converter={x:Static c:IntConverters.IsGreaterThanZero}}"> IsVisible="{Binding LocalChangesCount, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
<TextBlock Classes="primary" FontSize="10" HorizontalAlignment="Center" Margin="9,0" Text="{Binding WorkingCopyChangesCount}" Foreground="{DynamicResource Brush.BadgeFG}"/> <TextBlock Classes="primary" FontSize="10" HorizontalAlignment="Center" Margin="9,0" Text="{Binding LocalChangesCount}" Foreground="{DynamicResource Brush.BadgeFG}"/>
</Border> </Border>
</Grid> </Grid>
</ListBoxItem> </ListBoxItem>