mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-21 18:35:00 +00:00
using the new syntax
This commit is contained in:
parent
81f02a20c5
commit
478280625d
9 changed files with 69 additions and 95 deletions
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using Avalonia.Controls;
|
||||
|
||||
|
@ -37,16 +37,15 @@ namespace SourceGit
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
@ -283,10 +283,12 @@ namespace SourceGit
|
|||
|
||||
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)
|
||||
|
@ -429,7 +431,7 @@ namespace SourceGit
|
|||
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;
|
||||
|
||||
|
|
|
@ -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}%");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace SourceGit.Converters
|
|||
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;
|
||||
});
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace SourceGit.Converters
|
|||
}
|
||||
}
|
||||
|
||||
public static readonly ToLocaleConverter ToLocale = new ToLocaleConverter();
|
||||
public static readonly ToLocaleConverter ToLocale = new();
|
||||
|
||||
public class ToThemeConverter : IValueConverter
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ namespace SourceGit.Converters
|
|||
}
|
||||
}
|
||||
|
||||
public static readonly ToThemeConverter ToTheme = new ToThemeConverter();
|
||||
public static readonly ToThemeConverter ToTheme = new();
|
||||
|
||||
public class FormatByResourceKeyConverter : IValueConverter
|
||||
{
|
||||
|
@ -62,24 +62,24 @@ namespace SourceGit.Converters
|
|||
}
|
||||
}
|
||||
|
||||
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…
Add table
Add a link
Reference in a new issue