Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/App.Commands.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Windows.Input;
using Avalonia.Controls;

Expand Down Expand Up @@ -37,16 +37,15 @@ public static bool IsCheckForUpdateCommandVisible
}
}

public static readonly Command OpenPreferencesCommand = new Command(_ => OpenDialog(new Views.Preferences()));
public static readonly Command OpenHotkeysCommand = new Command(_ => OpenDialog(new Views.Hotkeys()));
public static readonly Command OpenAppDataDirCommand = new Command(_ => Native.OS.OpenInFileManager(Native.OS.DataDir));
public static readonly Command OpenAboutCommand = new Command(_ => OpenDialog(new Views.About()));
public static readonly Command CheckForUpdateCommand = new Command(_ => (Current as App)?.Check4Update(true));
public static readonly Command QuitCommand = new Command(_ => Quit(0));
public static readonly Command CopyTextBlockCommand = new Command(p =>
public static readonly Command OpenPreferencesCommand = new(_ => OpenDialog(new Views.Preferences()));
public static readonly Command OpenHotkeysCommand = new(_ => OpenDialog(new Views.Hotkeys()));
public static readonly Command OpenAppDataDirCommand = new(_ => Native.OS.OpenInFileManager(Native.OS.DataDir));
public static readonly Command OpenAboutCommand = new(_ => OpenDialog(new Views.About()));
public static readonly Command CheckForUpdateCommand = new(_ => (Current as App)?.Check4Update(true));
public static readonly Command QuitCommand = new(_ => Quit(0));
public static readonly Command CopyTextBlockCommand = new(p =>
{
var textBlock = p as TextBlock;
if (textBlock == null)
if (p is not TextBlock textBlock)
return;

if (textBlock.Inlines is { Count: > 0 } inlines)
Expand Down
14 changes: 8 additions & 6 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -283,10 +283,12 @@ public static string Text(string key, params object[] args)

public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key)
{
var icon = new Avalonia.Controls.Shapes.Path();
icon.Width = 12;
icon.Height = 12;
icon.Stretch = Stretch.Uniform;
var icon = new Avalonia.Controls.Shapes.Path
{
Width = 12,
Height = 12,
Stretch = Stretch.Uniform
};

var geo = Current?.FindResource(key) as StreamGeometry;
if (geo != null)
Expand Down Expand Up @@ -429,7 +431,7 @@ private static bool TryLaunchAsRebaseMessageEditor(string[] args, out int exitCo
if (!File.Exists(doneFile))
return true;

var done = File.ReadAllText(doneFile).Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
var done = File.ReadAllText(doneFile).Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries);
if (done.Length > collection.Jobs.Count)
return true;

Expand Down
12 changes: 4 additions & 8 deletions src/Converters/DoubleConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ namespace SourceGit.Converters
{
public static class DoubleConverters
{
public static readonly FuncValueConverter<double, double> Increase =
new FuncValueConverter<double, double>(v => v + 1.0);
public static readonly FuncValueConverter<double, double> Increase = new(v => v + 1.0);

public static readonly FuncValueConverter<double, double> Decrease =
new FuncValueConverter<double, double>(v => v - 1.0);
public static readonly FuncValueConverter<double, double> Decrease = new(v => v - 1.0);

public static readonly FuncValueConverter<double, string> ToPercentage =
new FuncValueConverter<double, string>(v => (v * 100).ToString("F3") + "%");
public static readonly FuncValueConverter<double, string> ToPercentage = new(v => $"{v * 100:F3}%");

public static readonly FuncValueConverter<double, string> OneMinusToPercentage =
new FuncValueConverter<double, string>(v => ((1.0 - v) * 100).ToString("F3") + "%");
public static readonly FuncValueConverter<double, string> OneMinusToPercentage = new(v => $"{(1.0 - v) * 100:F3}%");
}
}
15 changes: 6 additions & 9 deletions src/Converters/FilterModeConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ namespace SourceGit.Converters
public static class FilterModeConverters
{
public static readonly FuncValueConverter<Models.FilterMode, IBrush> ToBorderBrush =
new FuncValueConverter<Models.FilterMode, IBrush>(v =>
new(v =>
{
switch (v)
return v switch
{
case Models.FilterMode.Included:
return Brushes.Green;
case Models.FilterMode.Excluded:
return Brushes.Red;
default:
return Brushes.Transparent;
}
Models.FilterMode.Included => Brushes.Green,
Models.FilterMode.Excluded => Brushes.Red,
_ => Brushes.Transparent,
};
});
}
}
26 changes: 9 additions & 17 deletions src/Converters/IntConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,24 @@ namespace SourceGit.Converters
{
public static class IntConverters
{
public static readonly FuncValueConverter<int, bool> IsGreaterThanZero =
new FuncValueConverter<int, bool>(v => v > 0);
public static readonly FuncValueConverter<int, bool> IsGreaterThanZero = new(v => v > 0);

public static readonly FuncValueConverter<int, bool> IsGreaterThanFour =
new FuncValueConverter<int, bool>(v => v > 4);
public static readonly FuncValueConverter<int, bool> IsGreaterThanFour = new(v => v > 4);

public static readonly FuncValueConverter<int, bool> IsZero =
new FuncValueConverter<int, bool>(v => v == 0);
public static readonly FuncValueConverter<int, bool> IsZero = new(v => v == 0);

public static readonly FuncValueConverter<int, bool> IsOne =
new FuncValueConverter<int, bool>(v => v == 1);
public static readonly FuncValueConverter<int, bool> IsOne = new(v => v == 1);

public static readonly FuncValueConverter<int, bool> IsNotOne =
new FuncValueConverter<int, bool>(v => v != 1);
public static readonly FuncValueConverter<int, bool> IsNotOne = new(v => v != 1);

public static readonly FuncValueConverter<int, bool> IsSubjectLengthBad =
new FuncValueConverter<int, bool>(v => v > ViewModels.Preferences.Instance.SubjectGuideLength);
public static readonly FuncValueConverter<int, bool> IsSubjectLengthBad = new(v => v > ViewModels.Preferences.Instance.SubjectGuideLength);

public static readonly FuncValueConverter<int, bool> IsSubjectLengthGood =
new FuncValueConverter<int, bool>(v => v <= ViewModels.Preferences.Instance.SubjectGuideLength);
public static readonly FuncValueConverter<int, bool> IsSubjectLengthGood = new(v => v <= ViewModels.Preferences.Instance.SubjectGuideLength);

public static readonly FuncValueConverter<int, Thickness> ToTreeMargin =
new FuncValueConverter<int, Thickness>(v => new Thickness(v * 16, 0, 0, 0));
public static readonly FuncValueConverter<int, Thickness> ToTreeMargin = new(v => new Thickness(v * 16, 0, 0, 0));

public static readonly FuncValueConverter<int, IBrush> ToBookmarkBrush =
new FuncValueConverter<int, IBrush>(bookmark =>
new(bookmark =>
{
if (bookmark == 0)
return Application.Current?.FindResource("Brush.FG1") as IBrush;
Expand Down
50 changes: 19 additions & 31 deletions src/Converters/InteractiveRebaseActionConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,34 @@ namespace SourceGit.Converters
public static class InteractiveRebaseActionConverters
{
public static readonly FuncValueConverter<Models.InteractiveRebaseAction, IBrush> ToIconBrush =
new FuncValueConverter<Models.InteractiveRebaseAction, IBrush>(v =>
new(v =>
{
switch (v)
return v switch
{
case Models.InteractiveRebaseAction.Pick:
return Brushes.Green;
case Models.InteractiveRebaseAction.Edit:
return Brushes.Orange;
case Models.InteractiveRebaseAction.Reword:
return Brushes.Orange;
case Models.InteractiveRebaseAction.Squash:
return Brushes.LightGray;
case Models.InteractiveRebaseAction.Fixup:
return Brushes.LightGray;
default:
return Brushes.Red;
}
Models.InteractiveRebaseAction.Pick => Brushes.Green,
Models.InteractiveRebaseAction.Edit => Brushes.Orange,
Models.InteractiveRebaseAction.Reword => Brushes.Orange,
Models.InteractiveRebaseAction.Squash => Brushes.LightGray,
Models.InteractiveRebaseAction.Fixup => Brushes.LightGray,
_ => Brushes.Red,
};
});

public static readonly FuncValueConverter<Models.InteractiveRebaseAction, string> ToName =
new FuncValueConverter<Models.InteractiveRebaseAction, string>(v =>
new(v =>
{
switch (v)
return v switch
{
case Models.InteractiveRebaseAction.Pick:
return "Pick";
case Models.InteractiveRebaseAction.Edit:
return "Edit";
case Models.InteractiveRebaseAction.Reword:
return "Reword";
case Models.InteractiveRebaseAction.Squash:
return "Squash";
case Models.InteractiveRebaseAction.Fixup:
return "Fixup";
default:
return "Drop";
}
Models.InteractiveRebaseAction.Pick => "Pick",
Models.InteractiveRebaseAction.Edit => "Edit",
Models.InteractiveRebaseAction.Reword => "Reword",
Models.InteractiveRebaseAction.Squash => "Squash",
Models.InteractiveRebaseAction.Fixup => "Fixup",
_ => "Drop",
};
});

public static readonly FuncValueConverter<Models.InteractiveRebaseAction, bool> CanEditMessage =
new FuncValueConverter<Models.InteractiveRebaseAction, bool>(v => v == Models.InteractiveRebaseAction.Reword || v == Models.InteractiveRebaseAction.Squash);
new(v => v == Models.InteractiveRebaseAction.Reword || v == Models.InteractiveRebaseAction.Squash);
}
}
10 changes: 5 additions & 5 deletions src/Converters/ListConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ namespace SourceGit.Converters
public static class ListConverters
{
public static readonly FuncValueConverter<IList, string> ToCount =
new FuncValueConverter<IList, string>(v => v == null ? " (0)" : $" ({v.Count})");
new(v => v == null ? " (0)" : $" ({v.Count})");

public static readonly FuncValueConverter<IList, bool> IsNullOrEmpty =
new FuncValueConverter<IList, bool>(v => v == null || v.Count == 0);
new(v => v == null || v.Count == 0);

public static readonly FuncValueConverter<IList, bool> IsNotNullOrEmpty =
new FuncValueConverter<IList, bool>(v => v != null && v.Count > 0);
new(v => v != null && v.Count > 0);

public static readonly FuncValueConverter<List<Models.Change>, List<Models.Change>> Top100Changes =
new FuncValueConverter<List<Models.Change>, List<Models.Change>>(v => (v == null || v.Count < 100) ? v : v.GetRange(0, 100));
new(v => (v == null || v.Count < 100) ? v : v.GetRange(0, 100));

public static readonly FuncValueConverter<IList, bool> IsOnlyTop100Shows =
new FuncValueConverter<IList, bool>(v => v != null && v.Count > 100);
new(v => v != null && v.Count > 100);
}
}
2 changes: 1 addition & 1 deletion src/Converters/PathConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class PathConverters
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
if (v.StartsWith(home, StringComparison.Ordinal))
return "~" + v.Substring(prefixLen);
return $"~{v.AsSpan()[prefixLen..]}";

return v;
});
Expand Down
16 changes: 8 additions & 8 deletions src/Converters/StringConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
}
}

public static readonly ToLocaleConverter ToLocale = new ToLocaleConverter();
public static readonly ToLocaleConverter ToLocale = new();

public class ToThemeConverter : IValueConverter
{
Expand All @@ -46,7 +46,7 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
}
}

public static readonly ToThemeConverter ToTheme = new ToThemeConverter();
public static readonly ToThemeConverter ToTheme = new();

public class FormatByResourceKeyConverter : IValueConverter
{
Expand All @@ -62,24 +62,24 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
}
}

public static readonly FormatByResourceKeyConverter FormatByResourceKey = new FormatByResourceKeyConverter();
public static readonly FormatByResourceKeyConverter FormatByResourceKey = new();

public static readonly FuncValueConverter<string, string> ToShortSHA =
new FuncValueConverter<string, string>(v => v == null ? string.Empty : (v.Length > 10 ? v.Substring(0, 10) : v));
new(v => v == null ? string.Empty : (v.Length > 10 ? v.Substring(0, 10) : v));

public static readonly FuncValueConverter<string, string> TrimRefsPrefix =
new FuncValueConverter<string, string>(v =>
new(v =>
{
if (v == null)
return string.Empty;
if (v.StartsWith("refs/heads/", StringComparison.Ordinal))
return v.Substring(11);
return v[11..];
if (v.StartsWith("refs/remotes/", StringComparison.Ordinal))
return v.Substring(13);
return v[13..];
return v;
});

public static readonly FuncValueConverter<string, bool> ContainsSpaces =
new FuncValueConverter<string, bool>(v => v != null && v.Contains(' '));
new(v => v != null && v.Contains(' '));
}
}
Loading