Skip to content

Feature: Updated Git status icons #12910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Files.App/Data/Items/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Files.Shared.Services.DateTimeFormatter;
using FluentFTP;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using System.IO;
Expand Down Expand Up @@ -631,11 +632,11 @@ public override string Name

public class GitItem : ListedItem
{
private string? _UnmergedGitStatusLabel;
public string? UnmergedGitStatusLabel
private Style? _UnmergedGitStatusIcon;
public Style? UnmergedGitStatusIcon
{
get => _UnmergedGitStatusLabel;
set => SetProperty(ref _UnmergedGitStatusLabel, value);
get => _UnmergedGitStatusIcon;
set => SetProperty(ref _UnmergedGitStatusIcon, value);
}

private string? _UnmergedGitStatusName;
Expand All @@ -645,8 +646,6 @@ public string? UnmergedGitStatusName
set => SetProperty(ref _UnmergedGitStatusName, value);
}

public SolidColorBrush UnmergedGitStatusLabelForeground { get; init; }

private DateTimeOffset? _GitLastCommitDate;
public DateTimeOffset? GitLastCommitDate
{
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/Data/Models/GitItemModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LibGit2Sharp;
using Microsoft.UI.Xaml;

namespace Files.App.Data.Models
{
Expand All @@ -14,14 +15,13 @@ internal class GitItemModel
/// This is often showed as A(Added), D(Deleted), M(Modified), U(Untracked) in VS Code.
/// </remarks>
public ChangeKind Status { get; init; }

/// <summary>
/// Gets or initializes file change kind symbol
/// Gets or initializes file change kind icon
/// </summary>
/// <remarks>
/// This is often showed as A(Added), D(Deleted), M(Modified), U(Untracked) in VS Code.
/// </remarks>
public string? StatusSymbol { get; init; }
public Style? StatusIcon { get; init; }

/// <summary>
/// Gets or initializes file change kind humanized string
Expand Down
15 changes: 9 additions & 6 deletions src/Files.App/Data/Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Utils.Cloud;
using Files.App.Utils.Search;
using Files.App.Utils.StorageEnumerators;
using Files.App.Utils.StorageItems;
using Files.App.Helpers.StorageCache;
using Files.App.Utils.Shell;
using Files.App.ViewModels.Previews;
using Files.Core.Services.SizeProvider;
using Files.Shared.Cloud;
using Files.Shared.EventArguments;
using Files.Shared.Services;
using LibGit2Sharp;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media;
Expand Down Expand Up @@ -1223,7 +1219,14 @@ await SafetyExtensions.IgnoreExceptions(() =>
return dispatcherQueue.EnqueueOrInvokeAsync(() =>
{
var gitItem = item.AsGitItem;
gitItem.UnmergedGitStatusLabel = gitItemModel.StatusSymbol;
gitItem.UnmergedGitStatusIcon = gitItemModel.Status switch
{
ChangeKind.Added => (Microsoft.UI.Xaml.Style)Microsoft.UI.Xaml.Application.Current.Resources["ColorIconGitAdded"],
ChangeKind.Deleted => (Microsoft.UI.Xaml.Style)Microsoft.UI.Xaml.Application.Current.Resources["ColorIconGitDeleted"],
ChangeKind.Modified => (Microsoft.UI.Xaml.Style)Microsoft.UI.Xaml.Application.Current.Resources["ColorIconGitModified"],
ChangeKind.Untracked => (Microsoft.UI.Xaml.Style)Microsoft.UI.Xaml.Application.Current.Resources["ColorIconGitUntracked"],
_ => null,
};
gitItem.UnmergedGitStatusName = gitItemModel.StatusHumanized;
gitItem.GitLastCommitDate = gitItemModel.LastCommit?.Author.When;
gitItem.GitLastCommitMessage = gitItemModel.LastCommit?.MessageShort;
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ResourceDictionaries/PathIcons.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,7 @@
<Path
x:Name="Path1"
Data="M4 1C2.34315 1 1 2.34315 1 4V12C1 13.6569 2.34315 15 4 15H12C13.6569 15 15 13.6569 15 12V4C15 2.34315 13.6569 1 12 1H4ZM2 4C2 2.89543 2.89543 2 4 2H12C13.1046 2 14 2.89543 14 4V12C14 13.1046 13.1046 14 12 14H4C2.89543 14 2 13.1046 2 12V4ZM4.5 7.50021C4.22386 7.50021 4 7.72407 4 8.00021C4 8.27636 4.22386 8.50021 4.5 8.50021C10.3343 8.50021 5.66567 8.50021 11.5 8.50021C11.7761 8.50021 12 8.27636 12 8.00021C12 7.72407 11.7761 7.50021 11.5 7.50021C5.66567 7.50021 10.3343 7.50021 4.5 7.50021Z"
Fill="{ThemeResource SystemFillColorSuccessBrush}" />
Fill="{ThemeResource SystemFillColorCriticalBrush}" />
</Grid>

<VisualStateManager.VisualStateGroups>
Expand Down
17 changes: 1 addition & 16 deletions src/Files.App/Utils/Git/GitHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See the LICENSE.

using Files.App.Dialogs;
using Files.App.Utils.StorageItems;
using Files.App.ViewModels.Dialogs;
using LibGit2Sharp;
using Microsoft.AppCenter.Analytics;
Expand Down Expand Up @@ -510,19 +509,6 @@ public static GitItemModel GetGitInformationForItem(Repository repository, strin
}
}

string? changeKindSymbol = null;
if (changeKind is not ChangeKind.Ignored)
{
changeKindSymbol = changeKind switch
{
ChangeKind.Added => "A",
ChangeKind.Deleted => "D",
ChangeKind.Modified => "M",
ChangeKind.Untracked => "U",
_ => null,
};
}

string? changeKindHumanized = null;
if (changeKind is not ChangeKind.Ignored)
{
Expand All @@ -539,7 +525,6 @@ public static GitItemModel GetGitInformationForItem(Repository repository, strin
var gitItemModel = new GitItemModel()
{
Status = changeKind,
StatusSymbol = changeKindSymbol,
StatusHumanized = changeKindHumanized,
LastCommit = commit,
Path = relativePath,
Expand Down Expand Up @@ -593,7 +578,7 @@ public static void InitializeRepository(string? path)
private static void CheckoutRemoteBranch(Repository repository, Branch branch)
{
var uniqueName = branch.FriendlyName.Substring(END_OF_ORIGIN_PREFIX);

// TODO: This is a temp fix to avoid an issue where Files would create many branches in a loop
if (repository.Branches.Any(b => !b.IsRemote && b.FriendlyName == uniqueName))
return;
Expand Down
19 changes: 10 additions & 9 deletions src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1015,20 +1015,21 @@
</Grid>

<!-- Item Git Status -->
<TextBlock
<Border
x:Name="ItemGitStatusTextBlock"
Width="{Binding ColumnsViewModel.GitStatusColumn.LengthIncludingGridSplitter.Value, ElementName=PageRoot, Mode=OneWay}"
Padding="12,0,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
x:Load="{x:Bind IsGitItem}"
FontWeight="SemiBold"
Foreground="{ThemeResource SystemFillColorSuccessBrush}"
Style="{StaticResource ColumnContentTextBlock}"
Text="{x:Bind AsGitItem.UnmergedGitStatusLabel, Mode=OneWay}"
TextTrimming="CharacterEllipsis"
ToolTipService.ToolTip="{x:Bind AsGitItem.UnmergedGitStatusName, Mode=OneWay}"
Visibility="{Binding ColumnsViewModel.GitStatusColumn.Visibility, ElementName=PageRoot, Mode=OneWay}" />
x:Load="{x:Bind IsGitItem}">
<uc:OpacityIcon
Width="16"
Height="16"
HorizontalAlignment="Left"
Style="{x:Bind AsGitItem.UnmergedGitStatusIcon, Mode=OneWay}"
ToolTipService.ToolTip="{x:Bind AsGitItem.UnmergedGitStatusName, Mode=OneWay}"
Visibility="{Binding ColumnsViewModel.GitStatusColumn.Visibility, ElementName=PageRoot, Mode=OneWay}" />
</Border>

<!-- Item Git Last Commit Date -->
<TextBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ private void ResizeColumnToFit(int columnToResize)
{
1 => 40, // Check all items columns
2 => FileList.Items.Cast<ListedItem>().Select(x => x.Name?.Length ?? 0).Max(), // file name column
3 => FileList.Items.Cast<ListedItem>().Select(x => (x as GitItem)?.UnmergedGitStatusLabel?.Length ?? 0).Max(), // git
4 => FileList.Items.Cast<ListedItem>().Select(x => (x as GitItem)?.GitLastCommitDateHumanized?.Length ?? 0).Max(), // git
5 => FileList.Items.Cast<ListedItem>().Select(x => (x as GitItem)?.GitLastCommitMessage?.Length ?? 0).Max(), // git
6 => FileList.Items.Cast<ListedItem>().Select(x => (x as GitItem)?.GitLastCommitAuthor?.Length ?? 0).Max(), // git
Expand Down