diff --git a/src/App.Commands.cs b/src/App.Commands.cs index 4a594766..8a485029 100644 --- a/src/App.Commands.cs +++ b/src/App.Commands.cs @@ -6,7 +6,7 @@ namespace SourceGit { public partial class App { - public class SimpleCommand : ICommand + public class Command : ICommand { public event EventHandler CanExecuteChanged { @@ -14,26 +14,7 @@ namespace SourceGit remove { } } - public SimpleCommand(Action action) - { - _action = action; - } - - public bool CanExecute(object parameter) => _action != null; - public void Execute(object parameter) => _action?.Invoke(); - - private Action _action = null; - } - - public class ParameterCommand : ICommand - { - public event EventHandler CanExecuteChanged - { - add { } - remove { } - } - - public ParameterCommand(Action action) + public Command(Action action) { _action = action; } @@ -44,22 +25,12 @@ namespace SourceGit private Action _action = null; } - public static readonly SimpleCommand OpenPreferenceCommand = new SimpleCommand(() => OpenDialog(new Views.Preference())); - public static readonly SimpleCommand OpenHotkeysCommand = new SimpleCommand(() => OpenDialog(new Views.Hotkeys())); - public static readonly SimpleCommand OpenAppDataDirCommand = new SimpleCommand(() => Native.OS.OpenInFileManager(Native.OS.DataDir)); - public static readonly SimpleCommand OpenAboutCommand = new SimpleCommand(() => OpenDialog(new Views.About())); - public static readonly SimpleCommand CheckForUpdateCommand = new SimpleCommand(() => Check4Update(true)); - public static readonly SimpleCommand QuitCommand = new SimpleCommand(() => Quit(0)); - - public static readonly ParameterCommand CopyTextCommand = new ParameterCommand(param => - { - if (param is TextBlock textBlock) - { - if (textBlock.Inlines is { Count: > 0 } inlines) - CopyText(inlines.Text); - else - CopyText(textBlock.Text); - } - }); + public static readonly Command OpenPreferenceCommand = new Command(_ => OpenDialog(new Views.Preference())); + 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(_ => Check4Update(true)); + public static readonly Command QuitCommand = new Command(_ => Quit(0)); + public static readonly Command CopyTextBlockCommand = new Command(p => CopyTextBlock(p as TextBlock)); } } diff --git a/src/App.axaml.cs b/src/App.axaml.cs index f4ec6a11..b64e65c0 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -318,6 +318,17 @@ namespace SourceGit } } + private static void CopyTextBlock(TextBlock textBlock) + { + if (textBlock == null) + return; + + if (textBlock.Inlines is { Count: > 0 } inlines) + CopyText(inlines.Text); + else if (!string.IsNullOrEmpty(textBlock.Text)) + CopyText(textBlock.Text); + } + private static void LogException(Exception ex) { if (ex == null) diff --git a/src/Models/Statistics.cs b/src/Models/Statistics.cs index 60517e59..21f1e65d 100644 --- a/src/Models/Statistics.cs +++ b/src/Models/Statistics.cs @@ -62,7 +62,7 @@ namespace SourceGit.Models for (int i = 0; i < monthDays; i++) Month.Samples.Add(new StatisticsSample($"{i + 1}")); - string[] weekDayNames = [ "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" ]; + string[] weekDayNames = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]; for (int i = 0; i < weekDayNames.Length; i++) Week.Samples.Add(new StatisticsSample(weekDayNames[i])); } diff --git a/src/Resources/Styles.axaml b/src/Resources/Styles.axaml index 91563527..31c4cd59 100644 --- a/src/Resources/Styles.axaml +++ b/src/Resources/Styles.axaml @@ -339,7 +339,7 @@ diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index 758d853a..95a2f5e1 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -262,7 +262,7 @@ namespace SourceGit.ViewModels Task.Run(() => Commands.MergeTool.OpenForDiff(_repo.FullPath, toolType, toolPath, opt)); ev.Handled = true; }; - + var fullPath = Path.Combine(_repo.FullPath, change.Path); var explore = new MenuItem(); explore.Header = App.Text("RevealFile"); @@ -320,11 +320,11 @@ namespace SourceGit.ViewModels { if (change.Index == Models.ChangeState.Renamed) new Commands.Checkout(_repo.FullPath).FileWithRevision(change.OriginalPath, $"{_commit.SHA}~1"); - + new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_commit.SHA}~1"); ev.Handled = true; }; - + menu.Items.Add(resetToThisRevision); menu.Items.Add(resetToFirstParent); menu.Items.Add(new MenuItem { Header = "-" }); @@ -413,7 +413,7 @@ namespace SourceGit.ViewModels window.Show(); ev.Handled = true; }; - + var resetToThisRevision = new MenuItem(); resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision"); resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout"); diff --git a/src/ViewModels/MoveRepositoryNode.cs b/src/ViewModels/MoveRepositoryNode.cs index e22de212..766d2e78 100644 --- a/src/ViewModels/MoveRepositoryNode.cs +++ b/src/ViewModels/MoveRepositoryNode.cs @@ -27,10 +27,11 @@ namespace SourceGit.ViewModels public MoveRepositoryNode(RepositoryNode target) { Target = target; - Rows.Add(new RepositoryNode() { - Name = "ROOT", - Depth = 0, - Id = Guid.NewGuid().ToString() + Rows.Add(new RepositoryNode() + { + Name = "ROOT", + Depth = 0, + Id = Guid.NewGuid().ToString() }); MakeRows(Preference.Instance.RepositoryNodes, 1); diff --git a/src/ViewModels/ScanRepositories.cs b/src/ViewModels/ScanRepositories.cs index 73bb6916..6130801d 100644 --- a/src/ViewModels/ScanRepositories.cs +++ b/src/ViewModels/ScanRepositories.cs @@ -42,7 +42,7 @@ namespace SourceGit.ViewModels Dispatcher.UIThread.Invoke(() => { var normalizedRoot = rootDir.FullName.Replace("\\", "/"); - + foreach (var f in founded) { var parent = new DirectoryInfo(f).Parent!.FullName.Replace("\\", "/"); diff --git a/src/Views/CaptionButtons.axaml.cs b/src/Views/CaptionButtons.axaml.cs index f585083d..650ccef0 100644 --- a/src/Views/CaptionButtons.axaml.cs +++ b/src/Views/CaptionButtons.axaml.cs @@ -15,7 +15,7 @@ namespace SourceGit.Views get => GetValue(IsCloseButtonOnlyProperty); set => SetValue(IsCloseButtonOnlyProperty, value); } - + public CaptionButtons() { InitializeComponent(); diff --git a/src/Views/CaptionButtonsMacOS.axaml.cs b/src/Views/CaptionButtonsMacOS.axaml.cs index ec1f2b2c..98bbb88f 100644 --- a/src/Views/CaptionButtonsMacOS.axaml.cs +++ b/src/Views/CaptionButtonsMacOS.axaml.cs @@ -15,7 +15,7 @@ namespace SourceGit.Views get => GetValue(IsCloseButtonOnlyProperty); set => SetValue(IsCloseButtonOnlyProperty, value); } - + public CaptionButtonsMacOS() { InitializeComponent(); diff --git a/src/Views/Welcome.axaml.cs b/src/Views/Welcome.axaml.cs index 93e673cd..4add5d1d 100644 --- a/src/Views/Welcome.axaml.cs +++ b/src/Views/Welcome.axaml.cs @@ -224,7 +224,7 @@ namespace SourceGit.Views return; } - if (e.Data.Contains("MovedRepositoryTreeNode") && + if (e.Data.Contains("MovedRepositoryTreeNode") && e.Data.Get("MovedRepositoryTreeNode") is ViewModels.RepositoryNode moved) { e.Handled = true;