mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
code_style: simplify static commands used by styles and main menu; run dotnet format
This commit is contained in:
parent
e27d2d6a3f
commit
998230edff
10 changed files with 35 additions and 52 deletions
|
@ -6,7 +6,7 @@ namespace SourceGit
|
||||||
{
|
{
|
||||||
public partial class App
|
public partial class App
|
||||||
{
|
{
|
||||||
public class SimpleCommand : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public event EventHandler CanExecuteChanged
|
public event EventHandler CanExecuteChanged
|
||||||
{
|
{
|
||||||
|
@ -14,26 +14,7 @@ namespace SourceGit
|
||||||
remove { }
|
remove { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleCommand(Action action)
|
public Command(Action<object> 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<object> action)
|
|
||||||
{
|
{
|
||||||
_action = action;
|
_action = action;
|
||||||
}
|
}
|
||||||
|
@ -44,22 +25,12 @@ namespace SourceGit
|
||||||
private Action<object> _action = null;
|
private Action<object> _action = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly SimpleCommand OpenPreferenceCommand = new SimpleCommand(() => OpenDialog(new Views.Preference()));
|
public static readonly Command OpenPreferenceCommand = new Command(_ => OpenDialog(new Views.Preference()));
|
||||||
public static readonly SimpleCommand OpenHotkeysCommand = new SimpleCommand(() => OpenDialog(new Views.Hotkeys()));
|
public static readonly Command OpenHotkeysCommand = new Command(_ => OpenDialog(new Views.Hotkeys()));
|
||||||
public static readonly SimpleCommand OpenAppDataDirCommand = new SimpleCommand(() => Native.OS.OpenInFileManager(Native.OS.DataDir));
|
public static readonly Command OpenAppDataDirCommand = new Command(_ => Native.OS.OpenInFileManager(Native.OS.DataDir));
|
||||||
public static readonly SimpleCommand OpenAboutCommand = new SimpleCommand(() => OpenDialog(new Views.About()));
|
public static readonly Command OpenAboutCommand = new Command(_ => OpenDialog(new Views.About()));
|
||||||
public static readonly SimpleCommand CheckForUpdateCommand = new SimpleCommand(() => Check4Update(true));
|
public static readonly Command CheckForUpdateCommand = new Command(_ => Check4Update(true));
|
||||||
public static readonly SimpleCommand QuitCommand = new SimpleCommand(() => Quit(0));
|
public static readonly Command QuitCommand = new Command(_ => Quit(0));
|
||||||
|
public static readonly Command CopyTextBlockCommand = new Command(p => CopyTextBlock(p as TextBlock));
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
private static void LogException(Exception ex)
|
||||||
{
|
{
|
||||||
if (ex == null)
|
if (ex == null)
|
||||||
|
|
|
@ -62,7 +62,7 @@ namespace SourceGit.Models
|
||||||
for (int i = 0; i < monthDays; i++)
|
for (int i = 0; i < monthDays; i++)
|
||||||
Month.Samples.Add(new StatisticsSample($"{i + 1}"));
|
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++)
|
for (int i = 0; i < weekDayNames.Length; i++)
|
||||||
Week.Samples.Add(new StatisticsSample(weekDayNames[i]));
|
Week.Samples.Add(new StatisticsSample(weekDayNames[i]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,7 +339,7 @@
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
||||||
<MenuItem Header="{DynamicResource Text.CopyAllText}"
|
<MenuItem Header="{DynamicResource Text.CopyAllText}"
|
||||||
Command="{x:Static s:App.CopyTextCommand}"
|
Command="{x:Static s:App.CopyTextBlockCommand}"
|
||||||
CommandParameter="{Binding $parent[SelectableTextBlock]}">
|
CommandParameter="{Binding $parent[SelectableTextBlock]}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<Path Width="11" Height="11" Data="{StaticResource Icons.Copy}" VerticalAlignment="Center"/>
|
<Path Width="11" Height="11" Data="{StaticResource Icons.Copy}" VerticalAlignment="Center"/>
|
||||||
|
|
|
@ -262,7 +262,7 @@ namespace SourceGit.ViewModels
|
||||||
Task.Run(() => Commands.MergeTool.OpenForDiff(_repo.FullPath, toolType, toolPath, opt));
|
Task.Run(() => Commands.MergeTool.OpenForDiff(_repo.FullPath, toolType, toolPath, opt));
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
var fullPath = Path.Combine(_repo.FullPath, change.Path);
|
var fullPath = Path.Combine(_repo.FullPath, change.Path);
|
||||||
var explore = new MenuItem();
|
var explore = new MenuItem();
|
||||||
explore.Header = App.Text("RevealFile");
|
explore.Header = App.Text("RevealFile");
|
||||||
|
@ -320,11 +320,11 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if (change.Index == Models.ChangeState.Renamed)
|
if (change.Index == Models.ChangeState.Renamed)
|
||||||
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.OriginalPath, $"{_commit.SHA}~1");
|
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.OriginalPath, $"{_commit.SHA}~1");
|
||||||
|
|
||||||
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_commit.SHA}~1");
|
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_commit.SHA}~1");
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
menu.Items.Add(resetToThisRevision);
|
menu.Items.Add(resetToThisRevision);
|
||||||
menu.Items.Add(resetToFirstParent);
|
menu.Items.Add(resetToFirstParent);
|
||||||
menu.Items.Add(new MenuItem { Header = "-" });
|
menu.Items.Add(new MenuItem { Header = "-" });
|
||||||
|
@ -413,7 +413,7 @@ namespace SourceGit.ViewModels
|
||||||
window.Show();
|
window.Show();
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
var resetToThisRevision = new MenuItem();
|
var resetToThisRevision = new MenuItem();
|
||||||
resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision");
|
resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision");
|
||||||
resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout");
|
resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout");
|
||||||
|
|
|
@ -27,10 +27,11 @@ namespace SourceGit.ViewModels
|
||||||
public MoveRepositoryNode(RepositoryNode target)
|
public MoveRepositoryNode(RepositoryNode target)
|
||||||
{
|
{
|
||||||
Target = target;
|
Target = target;
|
||||||
Rows.Add(new RepositoryNode() {
|
Rows.Add(new RepositoryNode()
|
||||||
Name = "ROOT",
|
{
|
||||||
Depth = 0,
|
Name = "ROOT",
|
||||||
Id = Guid.NewGuid().ToString()
|
Depth = 0,
|
||||||
|
Id = Guid.NewGuid().ToString()
|
||||||
});
|
});
|
||||||
MakeRows(Preference.Instance.RepositoryNodes, 1);
|
MakeRows(Preference.Instance.RepositoryNodes, 1);
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace SourceGit.ViewModels
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
var normalizedRoot = rootDir.FullName.Replace("\\", "/");
|
var normalizedRoot = rootDir.FullName.Replace("\\", "/");
|
||||||
|
|
||||||
foreach (var f in founded)
|
foreach (var f in founded)
|
||||||
{
|
{
|
||||||
var parent = new DirectoryInfo(f).Parent!.FullName.Replace("\\", "/");
|
var parent = new DirectoryInfo(f).Parent!.FullName.Replace("\\", "/");
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace SourceGit.Views
|
||||||
get => GetValue(IsCloseButtonOnlyProperty);
|
get => GetValue(IsCloseButtonOnlyProperty);
|
||||||
set => SetValue(IsCloseButtonOnlyProperty, value);
|
set => SetValue(IsCloseButtonOnlyProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CaptionButtons()
|
public CaptionButtons()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace SourceGit.Views
|
||||||
get => GetValue(IsCloseButtonOnlyProperty);
|
get => GetValue(IsCloseButtonOnlyProperty);
|
||||||
set => SetValue(IsCloseButtonOnlyProperty, value);
|
set => SetValue(IsCloseButtonOnlyProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CaptionButtonsMacOS()
|
public CaptionButtonsMacOS()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
|
@ -224,7 +224,7 @@ namespace SourceGit.Views
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.Data.Contains("MovedRepositoryTreeNode") &&
|
if (e.Data.Contains("MovedRepositoryTreeNode") &&
|
||||||
e.Data.Get("MovedRepositoryTreeNode") is ViewModels.RepositoryNode moved)
|
e.Data.Get("MovedRepositoryTreeNode") is ViewModels.RepositoryNode moved)
|
||||||
{
|
{
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
|
|
Loading…
Reference in a new issue