mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 13:20:30 +08:00
code_style: general cleanup (#1525)
This commit is contained in:
@@ -45,8 +45,7 @@ namespace SourceGit
|
||||
public static readonly Command QuitCommand = new Command(_ => Quit(0));
|
||||
public static readonly Command CopyTextBlockCommand = new Command(async p =>
|
||||
{
|
||||
var textBlock = p as TextBlock;
|
||||
if (textBlock == null)
|
||||
if (p is not TextBlock textBlock)
|
||||
return;
|
||||
|
||||
if (textBlock.Inlines is { Count: > 0 } inlines)
|
||||
|
||||
@@ -186,9 +186,7 @@ namespace SourceGit
|
||||
|
||||
public static void SetLocale(string localeKey)
|
||||
{
|
||||
var app = Current as App;
|
||||
var targetLocale = app?.Resources[localeKey] as ResourceDictionary;
|
||||
if (targetLocale == null || targetLocale == app._activeLocale)
|
||||
if (Current is not App app || app.Resources[localeKey] is not ResourceDictionary targetLocale || targetLocale == app._activeLocale)
|
||||
return;
|
||||
|
||||
if (app._activeLocale != null)
|
||||
@@ -200,8 +198,7 @@ namespace SourceGit
|
||||
|
||||
public static void SetTheme(string theme, string themeOverridesFile)
|
||||
{
|
||||
var app = Current as App;
|
||||
if (app == null)
|
||||
if (Current is not App app)
|
||||
return;
|
||||
|
||||
if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase))
|
||||
@@ -254,8 +251,7 @@ namespace SourceGit
|
||||
|
||||
public static void SetFonts(string defaultFont, string monospaceFont, bool onlyUseMonospaceFontInEditor)
|
||||
{
|
||||
var app = Current as App;
|
||||
if (app == null)
|
||||
if (Current is not App app)
|
||||
return;
|
||||
|
||||
if (app._fontsOverrides != null)
|
||||
|
||||
@@ -40,9 +40,7 @@ namespace SourceGit.Commands
|
||||
foreach (var line in _result.LineInfos)
|
||||
{
|
||||
if (line.CommitSHA.Length > _minSHALen)
|
||||
{
|
||||
line.CommitSHA = line.CommitSHA.Substring(0, _minSHALen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,9 +131,9 @@ namespace SourceGit.Commands
|
||||
}
|
||||
|
||||
var rs = new Result() { IsSuccess = true };
|
||||
rs.StdOut = await proc.StandardOutput.ReadToEndAsync().ConfigureAwait(false);
|
||||
rs.StdErr = await proc.StandardError.ReadToEndAsync().ConfigureAwait(false);
|
||||
await proc.WaitForExitAsync().ConfigureAwait(false);
|
||||
rs.StdOut = await proc.StandardOutput.ReadToEndAsync(CancellationToken).ConfigureAwait(false);
|
||||
rs.StdErr = await proc.StandardError.ReadToEndAsync(CancellationToken).ConfigureAwait(false);
|
||||
await proc.WaitForExitAsync(CancellationToken).ConfigureAwait(false);
|
||||
|
||||
rs.IsSuccess = proc.ExitCode == 0;
|
||||
proc.Close();
|
||||
|
||||
@@ -249,14 +249,10 @@ namespace SourceGit.Commands
|
||||
foreach (var chunk in chunks)
|
||||
{
|
||||
if (chunk.DeletedCount > 0)
|
||||
{
|
||||
left.Highlights.Add(new Models.TextInlineRange(chunk.DeletedStart, chunk.DeletedCount));
|
||||
}
|
||||
|
||||
if (chunk.AddedCount > 0)
|
||||
{
|
||||
right.Highlights.Add(new Models.TextInlineRange(chunk.AddedStart, chunk.AddedCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace SourceGit.Commands
|
||||
if (data.Length < 8)
|
||||
return;
|
||||
|
||||
_current.Parents.AddRange(data.Split(separator: ' ', options: StringSplitOptions.RemoveEmptyEntries));
|
||||
_current.Parents.AddRange(data.Split(' ', StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
|
||||
private async Task MarkFirstMergedAsync()
|
||||
@@ -133,9 +133,7 @@ namespace SourceGit.Commands
|
||||
if (shas.Length == 0)
|
||||
return;
|
||||
|
||||
var set = new HashSet<string>();
|
||||
foreach (var sha in shas)
|
||||
set.Add(sha);
|
||||
var set = new HashSet<string>(shas);
|
||||
|
||||
foreach (var c in _commits)
|
||||
{
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace SourceGit.Commands
|
||||
if (data.Length < 8)
|
||||
return;
|
||||
|
||||
_current.Commit.Parents.AddRange(data.Split(separator: ' ', options: StringSplitOptions.RemoveEmptyEntries));
|
||||
_current.Commit.Parents.AddRange(data.Split(' ', StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
|
||||
private List<Models.InteractiveCommit> _commits = [];
|
||||
|
||||
@@ -21,15 +21,10 @@ namespace SourceGit.Commands
|
||||
return false;
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
Args = $"submodule update --init --recursive -- \"{relativePath}\"";
|
||||
return await ExecAsync().ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Args = $"submodule update --init -- \"{relativePath}\"";
|
||||
return await ExecAsync().ConfigureAwait(false);
|
||||
}
|
||||
return await ExecAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<bool> SetURL(string path, string url)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class ApplyWhiteSpaceMode
|
||||
public class ApplyWhiteSpaceMode(string n, string d, string a)
|
||||
{
|
||||
public static readonly ApplyWhiteSpaceMode[] Supported =
|
||||
[
|
||||
@@ -10,15 +10,8 @@
|
||||
new ApplyWhiteSpaceMode("Error All", "Similar to 'error', but shows more", "error-all"),
|
||||
];
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Desc { get; set; }
|
||||
public string Arg { get; set; }
|
||||
|
||||
public ApplyWhiteSpaceMode(string n, string d, string a)
|
||||
{
|
||||
Name = n;
|
||||
Desc = d;
|
||||
Arg = a;
|
||||
}
|
||||
public string Name { get; set; } = n;
|
||||
public string Desc { get; set; } = d;
|
||||
public string Arg { get; set; } = a;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +197,10 @@ namespace SourceGit.Models
|
||||
|
||||
_resources[email] = image;
|
||||
|
||||
_requesting.Remove(email);
|
||||
lock (_synclock)
|
||||
{
|
||||
_requesting.Remove(email);
|
||||
}
|
||||
|
||||
var store = Path.Combine(_storePath, GetEmailHash(email));
|
||||
File.Copy(file, store, true);
|
||||
|
||||
@@ -2,23 +2,16 @@
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class CRLFMode
|
||||
public class CRLFMode(string name, string value, string desc)
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string Desc { get; set; }
|
||||
public string Name { get; set; } = name;
|
||||
public string Value { get; set; } = value;
|
||||
public string Desc { get; set; } = desc;
|
||||
|
||||
public static readonly List<CRLFMode> Supported = new List<CRLFMode>() {
|
||||
new CRLFMode("TRUE", "true", "Commit as LF, checkout as CRLF"),
|
||||
new CRLFMode("INPUT", "input", "Only convert for commit"),
|
||||
new CRLFMode("FALSE", "false", "Do NOT convert"),
|
||||
};
|
||||
|
||||
public CRLFMode(string name, string value, string desc)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
Desc = desc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace SourceGit.Models
|
||||
{
|
||||
_workingCopyChange = change;
|
||||
_isUnstaged = isUnstaged;
|
||||
_path = change.Path;
|
||||
_orgPath = change.OriginalPath;
|
||||
|
||||
if (isUnstaged)
|
||||
{
|
||||
@@ -37,13 +39,8 @@ namespace SourceGit.Models
|
||||
case ChangeState.Added:
|
||||
case ChangeState.Untracked:
|
||||
_extra = "--no-index";
|
||||
_path = change.Path;
|
||||
_orgPath = "/dev/null";
|
||||
break;
|
||||
default:
|
||||
_path = change.Path;
|
||||
_orgPath = change.OriginalPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -52,9 +49,6 @@ namespace SourceGit.Models
|
||||
_extra = $"--cached {change.DataForAmend.ParentSHA}";
|
||||
else
|
||||
_extra = "--cached";
|
||||
|
||||
_path = change.Path;
|
||||
_orgPath = change.OriginalPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -210,21 +210,12 @@ namespace SourceGit.Models
|
||||
var line = Lines[i];
|
||||
if (line.Type == TextDiffLineType.Indicator)
|
||||
break;
|
||||
if (revert)
|
||||
if (line.Type == TextDiffLineType.Normal ||
|
||||
(revert && line.Type == TextDiffLineType.Added) ||
|
||||
(!revert && line.Type == TextDiffLineType.Deleted))
|
||||
{
|
||||
if (line.Type == TextDiffLineType.Normal || line.Type == TextDiffLineType.Added)
|
||||
{
|
||||
tail = line.Content;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (line.Type == TextDiffLineType.Normal || line.Type == TextDiffLineType.Deleted)
|
||||
{
|
||||
tail = line.Content;
|
||||
break;
|
||||
}
|
||||
tail = line.Content;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,9 +281,7 @@ namespace SourceGit.Models
|
||||
if (line.Type == TextDiffLineType.Indicator)
|
||||
{
|
||||
if (!ProcessIndicatorForPatch(writer, line, i, selection.StartLine, selection.EndLine, selection.IgnoredDeletes, selection.IgnoredAdds, revert, tail != null))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (line.Type == TextDiffLineType.Normal)
|
||||
{
|
||||
@@ -414,9 +403,7 @@ namespace SourceGit.Models
|
||||
if (line.Type == TextDiffLineType.Indicator)
|
||||
{
|
||||
if (!ProcessIndicatorForPatchSingleSide(writer, line, i, selection.StartLine, selection.EndLine, selection.IgnoredDeletes, selection.IgnoredAdds, revert, isOldSide, tail != null))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (line.Type == TextDiffLineType.Normal)
|
||||
{
|
||||
|
||||
@@ -93,9 +93,7 @@ namespace SourceGit.Models
|
||||
public string[] GetPatterns()
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
return Exec.Split(';');
|
||||
}
|
||||
|
||||
var choices = Exec.Split(';', StringSplitOptions.RemoveEmptyEntries);
|
||||
return Array.ConvertAll(choices, Path.GetFileName);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class MergeMode
|
||||
public class MergeMode(string n, string d, string a)
|
||||
{
|
||||
public static readonly MergeMode Default =
|
||||
new MergeMode("Default", "Fast-forward if possible", "");
|
||||
@@ -26,15 +26,8 @@
|
||||
DontCommit,
|
||||
];
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Desc { get; set; }
|
||||
public string Arg { get; set; }
|
||||
|
||||
public MergeMode(string n, string d, string a)
|
||||
{
|
||||
Name = n;
|
||||
Desc = d;
|
||||
Arg = a;
|
||||
}
|
||||
public string Name { get; set; } = n;
|
||||
public string Desc { get; set; } = d;
|
||||
public string Arg { get; set; } = a;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class ResetMode
|
||||
public class ResetMode(string n, string d, string a, string k, IBrush b)
|
||||
{
|
||||
public static readonly ResetMode[] Supported =
|
||||
[
|
||||
@@ -13,19 +13,10 @@ namespace SourceGit.Models
|
||||
new ResetMode("Hard", "Discard all changes", "--hard", "H", Brushes.Red),
|
||||
];
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Desc { get; set; }
|
||||
public string Arg { get; set; }
|
||||
public string Key { get; set; }
|
||||
public IBrush Color { get; set; }
|
||||
|
||||
public ResetMode(string n, string d, string a, string k, IBrush b)
|
||||
{
|
||||
Name = n;
|
||||
Desc = d;
|
||||
Arg = a;
|
||||
Key = k;
|
||||
Color = b;
|
||||
}
|
||||
public string Name { get; set; } = n;
|
||||
public string Desc { get; set; } = d;
|
||||
public string Arg { get; set; } = a;
|
||||
public string Key { get; set; } = k;
|
||||
public IBrush Color { get; set; } = b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,9 +88,7 @@ namespace SourceGit.Models
|
||||
{
|
||||
var c = Peek();
|
||||
if (c is not null)
|
||||
{
|
||||
_pos++;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -129,7 +127,7 @@ namespace SourceGit.Models
|
||||
{
|
||||
case ESCAPE:
|
||||
// allow to escape only \ and $
|
||||
if (Peek() is { } nc && (nc == ESCAPE || nc == VARIABLE_ANCHOR))
|
||||
if (Peek() is ESCAPE or VARIABLE_ANCHOR)
|
||||
{
|
||||
esc = true;
|
||||
FlushText(tok, _pos - 1);
|
||||
@@ -320,9 +318,7 @@ namespace SourceGit.Models
|
||||
private static string EvalVariable(Context context, string name)
|
||||
{
|
||||
if (!s_variables.TryGetValue(name, out var getter))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return getter(context);
|
||||
}
|
||||
|
||||
@@ -334,9 +330,7 @@ namespace SourceGit.Models
|
||||
private static string EvalVariable(Context context, SlicedVariable variable)
|
||||
{
|
||||
if (!s_slicedVariables.TryGetValue(variable.name, out var getter))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return getter(context, variable.count);
|
||||
}
|
||||
|
||||
|
||||
@@ -295,16 +295,12 @@ namespace SourceGit.Models
|
||||
|
||||
private static void AddChunk(List<Chunk> chunks, Dictionary<string, int> hashes, string data, int start)
|
||||
{
|
||||
if (hashes.TryGetValue(data, out var hash))
|
||||
{
|
||||
chunks.Add(new Chunk(hash, start, data.Length));
|
||||
}
|
||||
else
|
||||
if (!hashes.TryGetValue(data, out var hash))
|
||||
{
|
||||
hash = hashes.Count;
|
||||
hashes.Add(data, hash);
|
||||
chunks.Add(new Chunk(hash, start, data.Length));
|
||||
}
|
||||
chunks.Add(new Chunk(hash, start, data.Length));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace SourceGit.Models
|
||||
var extension = Path.GetExtension(file);
|
||||
if (extension == ".h")
|
||||
extension = ".cpp";
|
||||
else if (extension == ".resx" || extension == ".plist" || extension == ".manifest")
|
||||
else if (extension is ".resx" or ".plist" or ".manifest")
|
||||
extension = ".xml";
|
||||
else if (extension == ".command")
|
||||
extension = ".sh";
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace SourceGit.Native
|
||||
window.ExtendClientAreaToDecorationsHint = true;
|
||||
window.Classes.Add("fix_maximized_padding");
|
||||
|
||||
Win32Properties.AddWndProcHookCallback(window, (IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
|
||||
Win32Properties.AddWndProcHookCallback(window, (IntPtr hWnd, uint msg, IntPtr _, IntPtr lParam, ref bool handled) =>
|
||||
{
|
||||
// Custom WM_NCHITTEST
|
||||
if (msg == 0x0084)
|
||||
|
||||
@@ -82,8 +82,7 @@ namespace SourceGit.ViewModels
|
||||
|
||||
public static ValidationResult ValidateWorktreePath(string path, ValidationContext ctx)
|
||||
{
|
||||
var creator = ctx.ObjectInstance as AddWorktree;
|
||||
if (creator == null)
|
||||
if (ctx.ObjectInstance is not AddWorktree creator)
|
||||
return new ValidationResult("Missing runtime context to create branch!");
|
||||
|
||||
if (string.IsNullOrEmpty(path))
|
||||
|
||||
@@ -70,9 +70,7 @@ namespace SourceGit.ViewModels
|
||||
foreach (var line in lines)
|
||||
{
|
||||
lineIdx++;
|
||||
if (line.Type == Models.TextDiffLineType.Added ||
|
||||
line.Type == Models.TextDiffLineType.Deleted ||
|
||||
line.Type == Models.TextDiffLineType.None)
|
||||
if (line.Type is Models.TextDiffLineType.Added or Models.TextDiffLineType.Deleted or Models.TextDiffLineType.None)
|
||||
{
|
||||
if (isNewBlock)
|
||||
{
|
||||
|
||||
@@ -63,9 +63,7 @@ namespace SourceGit.ViewModels
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _searchFilter, value))
|
||||
{
|
||||
RefreshVisible();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,13 +125,13 @@ namespace SourceGit.ViewModels
|
||||
var diffWithMerger = new MenuItem();
|
||||
diffWithMerger.Header = App.Text("DiffWithMerger");
|
||||
diffWithMerger.Icon = App.CreateMenuIcon("Icons.OpenWith");
|
||||
diffWithMerger.Click += (_, ev) =>
|
||||
diffWithMerger.Click += async (_, ev) =>
|
||||
{
|
||||
var toolType = Preferences.Instance.ExternalMergeToolType;
|
||||
var toolPath = Preferences.Instance.ExternalMergeToolPath;
|
||||
var opt = new Models.DiffOption(_based.Head, _to.Head, change);
|
||||
|
||||
_ = Commands.MergeTool.OpenForDiffAsync(_repo, toolType, toolPath, opt);
|
||||
await Commands.MergeTool.OpenForDiffAsync(_repo, toolType, toolPath, opt);
|
||||
ev.Handled = true;
|
||||
};
|
||||
menu.Items.Add(diffWithMerger);
|
||||
|
||||
@@ -41,10 +41,6 @@ namespace SourceGit.ViewModels
|
||||
var log = _repo.CreateLog($"Checkout '{Branch}'");
|
||||
Use(log);
|
||||
|
||||
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
|
||||
var succ = false;
|
||||
var needPopStash = false;
|
||||
|
||||
if (_repo.CurrentBranch is { IsDetachedHead: true })
|
||||
{
|
||||
var refs = await new Commands.QueryRefsContainsCommit(_repo.FullPath, _repo.CurrentBranch.Head).GetResultAsync();
|
||||
@@ -60,6 +56,9 @@ namespace SourceGit.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
var succ = false;
|
||||
var needPopStash = false;
|
||||
|
||||
if (DiscardLocalChanges)
|
||||
{
|
||||
succ = await new Commands.Checkout(_repo.FullPath)
|
||||
@@ -91,7 +90,7 @@ namespace SourceGit.ViewModels
|
||||
|
||||
if (succ)
|
||||
{
|
||||
if (updateSubmodules)
|
||||
if (IsRecurseSubmoduleVisible && RecurseSubmodules)
|
||||
{
|
||||
var submodules = await new Commands.QueryUpdatableSubmodules(_repo.FullPath).GetResultAsync();
|
||||
if (submodules.Count > 0)
|
||||
|
||||
@@ -46,10 +46,6 @@ namespace SourceGit.ViewModels
|
||||
var log = _repo.CreateLog($"Checkout and Fast-Forward '{LocalBranch.Name}' ...");
|
||||
Use(log);
|
||||
|
||||
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
|
||||
var succ = false;
|
||||
var needPopStash = false;
|
||||
|
||||
if (_repo.CurrentBranch is { IsDetachedHead: true })
|
||||
{
|
||||
var refs = await new Commands.QueryRefsContainsCommit(_repo.FullPath, _repo.CurrentBranch.Head).GetResultAsync();
|
||||
@@ -65,13 +61,10 @@ namespace SourceGit.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
if (DiscardLocalChanges)
|
||||
{
|
||||
succ = await new Commands.Checkout(_repo.FullPath)
|
||||
.Use(log)
|
||||
.BranchAsync(LocalBranch.Name, RemoteBranch.Head, true, true);
|
||||
}
|
||||
else
|
||||
var succ = false;
|
||||
var needPopStash = false;
|
||||
|
||||
if (!DiscardLocalChanges)
|
||||
{
|
||||
var changes = await new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).GetResultAsync();
|
||||
if (changes > 0)
|
||||
@@ -88,15 +81,15 @@ namespace SourceGit.ViewModels
|
||||
|
||||
needPopStash = true;
|
||||
}
|
||||
|
||||
succ = await new Commands.Checkout(_repo.FullPath)
|
||||
.Use(log)
|
||||
.BranchAsync(LocalBranch.Name, RemoteBranch.Head, false, true);
|
||||
}
|
||||
|
||||
succ = await new Commands.Checkout(_repo.FullPath)
|
||||
.Use(log)
|
||||
.BranchAsync(LocalBranch.Name, RemoteBranch.Head, DiscardLocalChanges, true);
|
||||
|
||||
if (succ)
|
||||
{
|
||||
if (updateSubmodules)
|
||||
if (IsRecurseSubmoduleVisible && RecurseSubmodules)
|
||||
{
|
||||
var submodules = await new Commands.QueryUpdatableSubmodules(_repo.FullPath).GetResultAsync();
|
||||
|
||||
|
||||
@@ -325,13 +325,13 @@ namespace SourceGit.ViewModels
|
||||
var diffWithMerger = new MenuItem();
|
||||
diffWithMerger.Header = App.Text("DiffWithMerger");
|
||||
diffWithMerger.Icon = App.CreateMenuIcon("Icons.OpenWith");
|
||||
diffWithMerger.Click += (_, ev) =>
|
||||
diffWithMerger.Click += async (_, ev) =>
|
||||
{
|
||||
var toolType = Preferences.Instance.ExternalMergeToolType;
|
||||
var toolPath = Preferences.Instance.ExternalMergeToolPath;
|
||||
var opt = new Models.DiffOption(_commit, change);
|
||||
|
||||
_ = Commands.MergeTool.OpenForDiffAsync(_repo.FullPath, toolType, toolPath, opt);
|
||||
await Commands.MergeTool.OpenForDiffAsync(_repo.FullPath, toolType, toolPath, opt);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -17,13 +17,9 @@ namespace SourceGit.ViewModels
|
||||
|
||||
public ConflictSourceBranch(Repository repo, Models.Branch branch)
|
||||
{
|
||||
var revision = new Commands.QuerySingleCommit(repo.FullPath, branch.Head).GetResultAsync().Result;
|
||||
if (revision == null)
|
||||
revision = new Models.Commit() { SHA = branch.Head };
|
||||
|
||||
Name = branch.Name;
|
||||
Head = branch.Head;
|
||||
Revision = revision;
|
||||
Revision = new Commands.QuerySingleCommit(repo.FullPath, branch.Head).GetResultAsync().Result ?? new Models.Commit() { SHA = branch.Head };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,36 +71,33 @@ namespace SourceGit.ViewModels
|
||||
IsResolved = new Commands.IsConflictResolved(repo.FullPath, change).GetResultAsync().Result;
|
||||
}
|
||||
|
||||
var context = wc.InProgressContext;
|
||||
if (context is CherryPickInProgress cherryPick)
|
||||
switch (wc.InProgressContext)
|
||||
{
|
||||
Theirs = cherryPick.Head;
|
||||
Mine = new ConflictSourceBranch(repo, repo.CurrentBranch);
|
||||
}
|
||||
else if (context is RebaseInProgress rebase)
|
||||
{
|
||||
var b = repo.Branches.Find(x => x.IsLocal && x.Name == rebase.HeadName);
|
||||
if (b != null)
|
||||
Theirs = new ConflictSourceBranch(b.Name, b.Head, rebase.StoppedAt);
|
||||
else
|
||||
Theirs = new ConflictSourceBranch(rebase.HeadName, rebase.StoppedAt?.SHA ?? "----------", rebase.StoppedAt);
|
||||
case CherryPickInProgress cherryPick:
|
||||
Theirs = cherryPick.Head;
|
||||
Mine = new ConflictSourceBranch(repo, repo.CurrentBranch);
|
||||
break;
|
||||
case RebaseInProgress rebase:
|
||||
var b = repo.Branches.Find(x => x.IsLocal && x.Name == rebase.HeadName);
|
||||
if (b != null)
|
||||
Theirs = new ConflictSourceBranch(b.Name, b.Head, rebase.StoppedAt);
|
||||
else
|
||||
Theirs = new ConflictSourceBranch(rebase.HeadName, rebase.StoppedAt?.SHA ?? "----------", rebase.StoppedAt);
|
||||
|
||||
Mine = rebase.Onto;
|
||||
}
|
||||
else if (context is RevertInProgress revert)
|
||||
{
|
||||
Theirs = revert.Head;
|
||||
Mine = new ConflictSourceBranch(repo, repo.CurrentBranch);
|
||||
}
|
||||
else if (context is MergeInProgress merge)
|
||||
{
|
||||
Theirs = merge.Source;
|
||||
Mine = new ConflictSourceBranch(repo, repo.CurrentBranch);
|
||||
}
|
||||
else
|
||||
{
|
||||
Theirs = "Stash or Patch";
|
||||
Mine = new ConflictSourceBranch(repo, repo.CurrentBranch);
|
||||
Mine = rebase.Onto;
|
||||
break;
|
||||
case RevertInProgress revert:
|
||||
Theirs = revert.Head;
|
||||
Mine = new ConflictSourceBranch(repo, repo.CurrentBranch);
|
||||
break;
|
||||
case MergeInProgress merge:
|
||||
Theirs = merge.Source;
|
||||
Mine = new ConflictSourceBranch(repo, repo.CurrentBranch);
|
||||
break;
|
||||
default:
|
||||
Theirs = "Stash or Patch";
|
||||
Mine = new ConflictSourceBranch(repo, repo.CurrentBranch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public partial class CreateBranch : Popup
|
||||
public class CreateBranch : Popup
|
||||
{
|
||||
[Required(ErrorMessage = "Branch name is required!")]
|
||||
[RegularExpression(@"^[\w \-/\.#\+]+$", ErrorMessage = "Bad branch name format!")]
|
||||
|
||||
@@ -456,25 +456,24 @@ namespace SourceGit.ViewModels
|
||||
{
|
||||
foreach (var d in commit.Decorators)
|
||||
{
|
||||
if (d.Type == Models.DecoratorType.CurrentBranchHead)
|
||||
switch (d.Type)
|
||||
{
|
||||
FillCurrentBranchMenu(menu, current);
|
||||
}
|
||||
else if (d.Type == Models.DecoratorType.LocalBranchHead)
|
||||
{
|
||||
var b = _repo.Branches.Find(x => x.IsLocal && d.Name == x.Name);
|
||||
FillOtherLocalBranchMenu(menu, b, current, commit.IsMerged);
|
||||
}
|
||||
else if (d.Type == Models.DecoratorType.RemoteBranchHead)
|
||||
{
|
||||
var b = _repo.Branches.Find(x => !x.IsLocal && d.Name == x.FriendlyName);
|
||||
FillRemoteBranchMenu(menu, b, current, commit.IsMerged);
|
||||
}
|
||||
else if (d.Type == Models.DecoratorType.Tag)
|
||||
{
|
||||
var t = _repo.Tags.Find(x => x.Name == d.Name);
|
||||
if (t != null)
|
||||
tags.Add(t);
|
||||
case Models.DecoratorType.CurrentBranchHead:
|
||||
FillCurrentBranchMenu(menu, current);
|
||||
break;
|
||||
case Models.DecoratorType.LocalBranchHead:
|
||||
var lb = _repo.Branches.Find(x => x.IsLocal && d.Name == x.Name);
|
||||
FillOtherLocalBranchMenu(menu, lb, current, commit.IsMerged);
|
||||
break;
|
||||
case Models.DecoratorType.RemoteBranchHead:
|
||||
var rb = _repo.Branches.Find(x => !x.IsLocal && d.Name == x.FriendlyName);
|
||||
FillRemoteBranchMenu(menu, rb, current, commit.IsMerged);
|
||||
break;
|
||||
case Models.DecoratorType.Tag:
|
||||
var t = _repo.Tags.Find(x => x.Name == d.Name);
|
||||
if (t != null)
|
||||
tags.Add(t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -600,10 +599,7 @@ namespace SourceGit.ViewModels
|
||||
var parents = new List<Models.Commit>();
|
||||
foreach (var sha in commit.Parents)
|
||||
{
|
||||
var parent = _commits.Find(x => x.SHA == sha);
|
||||
if (parent == null)
|
||||
parent = await new Commands.QuerySingleCommit(_repo.FullPath, sha).GetResultAsync();
|
||||
|
||||
var parent = _commits.Find(x => x.SHA == sha) ?? await new Commands.QuerySingleCommit(_repo.FullPath, sha).GetResultAsync();
|
||||
if (parent != null)
|
||||
parents.Add(parent);
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ namespace SourceGit.ViewModels
|
||||
|
||||
public static async Task<ImageSource> FromFileAsync(string fullpath, Models.ImageDecoder decoder)
|
||||
{
|
||||
await using (var stream = File.OpenRead(fullpath))
|
||||
return await Task.Run(() => LoadFromStream(stream, decoder)).ConfigureAwait(false);
|
||||
await using var stream = File.OpenRead(fullpath);
|
||||
return await Task.Run(() => LoadFromStream(stream, decoder)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static async Task<ImageSource> FromRevisionAsync(string repo, string revision, string file, Models.ImageDecoder decoder)
|
||||
{
|
||||
var stream = await Commands.QueryFileContent.RunAsync(repo, revision, file).ConfigureAwait(false);
|
||||
await using var stream = await Commands.QueryFileContent.RunAsync(repo, revision, file).ConfigureAwait(false);
|
||||
return await Task.Run(() => LoadFromStream(stream, decoder)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public partial class RenameBranch : Popup
|
||||
public class RenameBranch : Popup
|
||||
{
|
||||
public Models.Branch Target
|
||||
{
|
||||
@@ -35,9 +35,7 @@ namespace SourceGit.ViewModels
|
||||
foreach (var b in rename._repo.Branches)
|
||||
{
|
||||
if (b.IsLocal && b != rename.Target && b.Name.Equals(fixedName, StringComparison.Ordinal))
|
||||
{
|
||||
return new ValidationResult("A branch with same name already exists!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -823,15 +823,13 @@ namespace SourceGit.ViewModels
|
||||
if (!CanCreatePopup())
|
||||
return;
|
||||
|
||||
ExecuteCustomAction popup;
|
||||
if (scope is Models.Branch b)
|
||||
popup = new ExecuteCustomAction(this, action, b);
|
||||
else if (scope is Models.Commit c)
|
||||
popup = new ExecuteCustomAction(this, action, c);
|
||||
else if (scope is Models.Tag t)
|
||||
popup = new ExecuteCustomAction(this, action, t);
|
||||
else
|
||||
popup = new ExecuteCustomAction(this, action);
|
||||
var popup = scope switch
|
||||
{
|
||||
Models.Branch b => new ExecuteCustomAction(this, action, b),
|
||||
Models.Commit c => new ExecuteCustomAction(this, action, c),
|
||||
Models.Tag t => new ExecuteCustomAction(this, action, t),
|
||||
_ => new ExecuteCustomAction(this, action)
|
||||
};
|
||||
|
||||
if (action.Controls.Count == 0)
|
||||
ShowAndStartPopup(popup);
|
||||
|
||||
@@ -331,20 +331,8 @@ namespace SourceGit.ViewModels
|
||||
|
||||
private async Task SetIfChangedAsync(string key, string value, string defValue)
|
||||
{
|
||||
bool changed = false;
|
||||
if (_cached.TryGetValue(key, out var old))
|
||||
{
|
||||
changed = old != value;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(value) && value != defValue)
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
if (value != _cached.GetValueOrDefault(key, defValue))
|
||||
await new Commands.Config(_repo.FullPath).SetAsync(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Repository _repo = null;
|
||||
|
||||
@@ -58,9 +58,7 @@ namespace SourceGit.ViewModels
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _searchFilter, value))
|
||||
{
|
||||
RefreshVisible();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -389,9 +389,7 @@ namespace SourceGit.ViewModels
|
||||
if (!change.IsConflicted)
|
||||
continue;
|
||||
|
||||
if (change.ConflictReason == Models.ConflictReason.BothDeleted ||
|
||||
change.ConflictReason == Models.ConflictReason.DeletedByThem ||
|
||||
change.ConflictReason == Models.ConflictReason.AddedByUs)
|
||||
if (change.ConflictReason is Models.ConflictReason.BothDeleted or Models.ConflictReason.DeletedByThem or Models.ConflictReason.AddedByUs)
|
||||
{
|
||||
var fullpath = Path.Combine(_repo.FullPath, change.Path);
|
||||
if (File.Exists(fullpath))
|
||||
@@ -438,9 +436,7 @@ namespace SourceGit.ViewModels
|
||||
if (!change.IsConflicted)
|
||||
continue;
|
||||
|
||||
if (change.ConflictReason == Models.ConflictReason.BothDeleted ||
|
||||
change.ConflictReason == Models.ConflictReason.DeletedByUs ||
|
||||
change.ConflictReason == Models.ConflictReason.AddedByThem)
|
||||
if (change.ConflictReason is Models.ConflictReason.BothDeleted or Models.ConflictReason.DeletedByUs or Models.ConflictReason.AddedByThem)
|
||||
{
|
||||
var fullpath = Path.Combine(_repo.FullPath, change.Path);
|
||||
if (File.Exists(fullpath))
|
||||
@@ -622,7 +618,6 @@ namespace SourceGit.ViewModels
|
||||
{
|
||||
var useTheirs = new MenuItem();
|
||||
useTheirs.Icon = App.CreateMenuIcon("Icons.Incoming");
|
||||
useTheirs.Header = App.Text("FileCM.UseTheirs");
|
||||
useTheirs.Click += (_, e) =>
|
||||
{
|
||||
UseTheirs(_selectedUnstaged);
|
||||
@@ -631,7 +626,6 @@ namespace SourceGit.ViewModels
|
||||
|
||||
var useMine = new MenuItem();
|
||||
useMine.Icon = App.CreateMenuIcon("Icons.Local");
|
||||
useMine.Header = App.Text("FileCM.UseMine");
|
||||
useMine.Click += (_, e) =>
|
||||
{
|
||||
UseMine(_selectedUnstaged);
|
||||
@@ -647,25 +641,28 @@ namespace SourceGit.ViewModels
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
if (_inProgressContext is CherryPickInProgress cherryPick)
|
||||
switch (_inProgressContext)
|
||||
{
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", cherryPick.HeadName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
}
|
||||
else if (_inProgressContext is RebaseInProgress rebase)
|
||||
{
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", rebase.HeadName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", rebase.BaseName);
|
||||
}
|
||||
else if (_inProgressContext is RevertInProgress revert)
|
||||
{
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", $"{revert.Head.SHA.AsSpan(0, 10)} (revert)");
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
}
|
||||
else if (_inProgressContext is MergeInProgress merge)
|
||||
{
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", merge.SourceName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
case CherryPickInProgress cherryPick:
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", cherryPick.HeadName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
break;
|
||||
case RebaseInProgress rebase:
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", rebase.HeadName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", rebase.BaseName);
|
||||
break;
|
||||
case RevertInProgress revert:
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", $"{revert.Head.SHA.AsSpan(0, 10)} (revert)");
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
break;
|
||||
case MergeInProgress merge:
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", merge.SourceName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
break;
|
||||
default:
|
||||
useTheirs.Header = App.Text("FileCM.UseTheirs");
|
||||
useMine.Header = App.Text("FileCM.UseMine");
|
||||
break;
|
||||
}
|
||||
|
||||
menu.Items.Add(useTheirs);
|
||||
@@ -1020,7 +1017,6 @@ namespace SourceGit.ViewModels
|
||||
|
||||
var useTheirs = new MenuItem();
|
||||
useTheirs.Icon = App.CreateMenuIcon("Icons.Incoming");
|
||||
useTheirs.Header = App.Text("FileCM.UseTheirs");
|
||||
useTheirs.Click += (_, e) =>
|
||||
{
|
||||
UseTheirs(_selectedUnstaged);
|
||||
@@ -1029,32 +1025,34 @@ namespace SourceGit.ViewModels
|
||||
|
||||
var useMine = new MenuItem();
|
||||
useMine.Icon = App.CreateMenuIcon("Icons.Local");
|
||||
useMine.Header = App.Text("FileCM.UseMine");
|
||||
useMine.Click += (_, e) =>
|
||||
{
|
||||
UseMine(_selectedUnstaged);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
if (_inProgressContext is CherryPickInProgress cherryPick)
|
||||
switch (_inProgressContext)
|
||||
{
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", cherryPick.HeadName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
}
|
||||
else if (_inProgressContext is RebaseInProgress rebase)
|
||||
{
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", rebase.HeadName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", rebase.BaseName);
|
||||
}
|
||||
else if (_inProgressContext is RevertInProgress revert)
|
||||
{
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", $"{revert.Head.SHA.AsSpan(0, 10)} (revert)");
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
}
|
||||
else if (_inProgressContext is MergeInProgress merge)
|
||||
{
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", merge.SourceName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
case CherryPickInProgress cherryPick:
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", cherryPick.HeadName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
break;
|
||||
case RebaseInProgress rebase:
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", rebase.HeadName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", rebase.BaseName);
|
||||
break;
|
||||
case RevertInProgress revert:
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", $"{revert.Head.SHA.AsSpan(0, 10)} (revert)");
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
break;
|
||||
case MergeInProgress merge:
|
||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", merge.SourceName);
|
||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||
break;
|
||||
default:
|
||||
useTheirs.Header = App.Text("FileCM.UseTheirs");
|
||||
useMine.Header = App.Text("FileCM.UseMine");
|
||||
break;
|
||||
}
|
||||
|
||||
menu.Items.Add(useTheirs);
|
||||
|
||||
@@ -72,9 +72,7 @@ namespace SourceGit.Views
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
if (change.Property == ContentProperty)
|
||||
{
|
||||
Text = Content;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
||||
|
||||
@@ -70,8 +70,7 @@ namespace SourceGit.Views
|
||||
|
||||
private void CreateContent(Thickness margin, string iconKey, bool highlight)
|
||||
{
|
||||
var geo = this.FindResource(iconKey) as StreamGeometry;
|
||||
if (geo == null)
|
||||
if (this.FindResource(iconKey) is not StreamGeometry geo)
|
||||
return;
|
||||
|
||||
var path = new Path()
|
||||
@@ -481,7 +480,7 @@ namespace SourceGit.Views
|
||||
};
|
||||
menu.Items.Add(deleteMulti);
|
||||
|
||||
menu?.Open(this);
|
||||
menu.Open(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -174,8 +174,7 @@ namespace SourceGit.Views
|
||||
{
|
||||
_items.Clear();
|
||||
|
||||
var commit = DataContext as Models.Commit;
|
||||
if (commit == null)
|
||||
if (DataContext is not Models.Commit commit)
|
||||
return new Size(0, 0);
|
||||
|
||||
var refs = commit.Decorators;
|
||||
@@ -196,8 +195,7 @@ namespace SourceGit.Views
|
||||
if (!showTags && decorator.Type == Models.DecoratorType.Tag)
|
||||
continue;
|
||||
|
||||
var isHead = decorator.Type == Models.DecoratorType.CurrentBranchHead ||
|
||||
decorator.Type == Models.DecoratorType.CurrentCommitHead;
|
||||
var isHead = decorator.Type is Models.DecoratorType.CurrentBranchHead or Models.DecoratorType.CurrentCommitHead;
|
||||
|
||||
var label = new FormattedText(
|
||||
decorator.Name,
|
||||
|
||||
@@ -118,8 +118,7 @@ namespace SourceGit.Views
|
||||
|
||||
private string GetDisplayText()
|
||||
{
|
||||
var commit = DataContext as Models.Commit;
|
||||
if (commit == null)
|
||||
if (DataContext is not Models.Commit commit)
|
||||
return string.Empty;
|
||||
|
||||
if (ShowAsDateTime)
|
||||
|
||||
@@ -36,8 +36,7 @@ namespace SourceGit.Views
|
||||
|
||||
var control = sender as Control;
|
||||
|
||||
var selector = control?.DataContext as ViewModels.CustomActionControlPathSelector;
|
||||
if (selector == null)
|
||||
if (control?.DataContext is not ViewModels.CustomActionControlPathSelector selector)
|
||||
return;
|
||||
|
||||
if (selector.IsFolder)
|
||||
|
||||
@@ -57,12 +57,10 @@ namespace SourceGit.Views
|
||||
{
|
||||
var repoView = this.FindAncestorOfType<Repository>();
|
||||
|
||||
var repo = repoView?.DataContext as ViewModels.Repository;
|
||||
if (repo == null)
|
||||
if (repoView?.DataContext is not ViewModels.Repository repo)
|
||||
return;
|
||||
|
||||
var button = sender as Button;
|
||||
if (button == null)
|
||||
if (sender is not Button button)
|
||||
return;
|
||||
|
||||
var menu = new ContextMenu();
|
||||
|
||||
@@ -236,8 +236,7 @@ namespace SourceGit.Views
|
||||
{
|
||||
var repoView = this.FindAncestorOfType<Repository>();
|
||||
|
||||
var repo = repoView?.DataContext as ViewModels.Repository;
|
||||
if (repo == null || !repo.CanCreatePopup())
|
||||
if (repoView?.DataContext is not ViewModels.Repository repo || !repo.CanCreatePopup())
|
||||
return;
|
||||
|
||||
if (selected.Count == 1 && selected[0] is Models.Commit commit)
|
||||
|
||||
@@ -16,8 +16,7 @@ namespace SourceGit.Views
|
||||
/// <param name="e"></param>
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
var vm = DataContext as ViewModels.InteractiveRebase;
|
||||
if (vm == null)
|
||||
if (DataContext is not ViewModels.InteractiveRebase vm)
|
||||
return;
|
||||
|
||||
var item = vm.SelectedItem;
|
||||
@@ -154,8 +153,7 @@ namespace SourceGit.Views
|
||||
|
||||
private async void OnStartJobs(object _1, RoutedEventArgs _2)
|
||||
{
|
||||
var vm = DataContext as ViewModels.InteractiveRebase;
|
||||
if (vm == null)
|
||||
if (DataContext is not ViewModels.InteractiveRebase vm)
|
||||
return;
|
||||
|
||||
Running.IsVisible = true;
|
||||
|
||||
@@ -145,8 +145,7 @@ namespace SourceGit.Views
|
||||
|
||||
protected override async void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
var vm = DataContext as ViewModels.Launcher;
|
||||
if (vm == null)
|
||||
if (DataContext is not ViewModels.Launcher vm)
|
||||
return;
|
||||
|
||||
// We should clear all unhandled key modifiers.
|
||||
@@ -243,39 +242,28 @@ namespace SourceGit.Views
|
||||
|
||||
if (vm.ActivePage.Data is ViewModels.Repository repo)
|
||||
{
|
||||
if (e.Key == Key.D1 || e.Key == Key.NumPad1)
|
||||
switch (e.Key)
|
||||
{
|
||||
repo.SelectedViewIndex = 0;
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.Key == Key.D2 || e.Key == Key.NumPad2)
|
||||
{
|
||||
repo.SelectedViewIndex = 1;
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.Key == Key.D3 || e.Key == Key.NumPad3)
|
||||
{
|
||||
repo.SelectedViewIndex = 2;
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.Key == Key.F)
|
||||
{
|
||||
repo.IsSearching = true;
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.Key == Key.H && e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
||||
{
|
||||
repo.IsSearching = false;
|
||||
e.Handled = true;
|
||||
return;
|
||||
case Key.D1 or Key.NumPad1:
|
||||
repo.SelectedViewIndex = 0;
|
||||
e.Handled = true;
|
||||
return;
|
||||
case Key.D2 or Key.NumPad2:
|
||||
repo.SelectedViewIndex = 1;
|
||||
e.Handled = true;
|
||||
return;
|
||||
case Key.D3 or Key.NumPad3:
|
||||
repo.SelectedViewIndex = 2;
|
||||
e.Handled = true;
|
||||
return;
|
||||
case Key.F:
|
||||
repo.IsSearching = true;
|
||||
e.Handled = true;
|
||||
return;
|
||||
case Key.H when e.KeyModifiers.HasFlag(KeyModifiers.Shift):
|
||||
repo.IsSearching = false;
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -121,8 +121,7 @@ namespace SourceGit.Views
|
||||
|
||||
private void OnSearchKeyDown(object _, KeyEventArgs e)
|
||||
{
|
||||
var repo = DataContext as ViewModels.Repository;
|
||||
if (repo == null)
|
||||
if (DataContext is not ViewModels.Repository repo)
|
||||
return;
|
||||
|
||||
if (e.Key == Key.Enter)
|
||||
@@ -199,9 +198,7 @@ namespace SourceGit.Views
|
||||
private void OnDoubleTappedWorktree(object sender, TappedEventArgs e)
|
||||
{
|
||||
if (sender is ListBox { SelectedItem: Models.Worktree worktree } && DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
repo.OpenWorktree(worktree);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
@@ -343,8 +340,7 @@ namespace SourceGit.Views
|
||||
|
||||
private void OnSearchSuggestionBoxKeyDown(object _, KeyEventArgs e)
|
||||
{
|
||||
var repo = DataContext as ViewModels.Repository;
|
||||
if (repo == null)
|
||||
if (DataContext is not ViewModels.Repository repo)
|
||||
return;
|
||||
|
||||
if (e.Key == Key.Escape)
|
||||
@@ -363,8 +359,7 @@ namespace SourceGit.Views
|
||||
|
||||
private void OnSearchSuggestionDoubleTapped(object sender, TappedEventArgs e)
|
||||
{
|
||||
var repo = DataContext as ViewModels.Repository;
|
||||
if (repo == null)
|
||||
if (DataContext is not ViewModels.Repository repo)
|
||||
return;
|
||||
|
||||
var content = (sender as StackPanel)?.DataContext as string;
|
||||
|
||||
@@ -37,8 +37,7 @@ namespace SourceGit.Views
|
||||
if (topLevel == null)
|
||||
return;
|
||||
|
||||
var vm = DataContext as ViewModels.RevisionCompare;
|
||||
if (vm == null)
|
||||
if (DataContext is not ViewModels.RevisionCompare vm)
|
||||
return;
|
||||
|
||||
var options = new FilePickerSaveOptions();
|
||||
|
||||
@@ -81,8 +81,7 @@ namespace SourceGit.Views
|
||||
|
||||
private void CreateContent(string iconKey, Thickness margin, IBrush fill = null)
|
||||
{
|
||||
var geo = this.FindResource(iconKey) as StreamGeometry;
|
||||
if (geo == null)
|
||||
if (this.FindResource(iconKey) is not StreamGeometry geo)
|
||||
return;
|
||||
|
||||
var icon = new Avalonia.Controls.Shapes.Path()
|
||||
@@ -320,8 +319,7 @@ namespace SourceGit.Views
|
||||
if (node.Children.Count > 0)
|
||||
return node.Children;
|
||||
|
||||
var vm = DataContext as ViewModels.CommitDetail;
|
||||
if (vm == null)
|
||||
if (DataContext is not ViewModels.CommitDetail vm)
|
||||
return null;
|
||||
|
||||
var objects = await vm.GetRevisionFilesUnderFolderAsync(node.Backend.Path + "/");
|
||||
|
||||
@@ -13,8 +13,7 @@ namespace SourceGit.Views
|
||||
|
||||
private async void OnSearchBoxKeyDown(object _, KeyEventArgs e)
|
||||
{
|
||||
var vm = DataContext as ViewModels.CommitDetail;
|
||||
if (vm == null)
|
||||
if (DataContext is not ViewModels.CommitDetail vm)
|
||||
return;
|
||||
|
||||
if (e.Key == Key.Enter)
|
||||
@@ -47,8 +46,7 @@ namespace SourceGit.Views
|
||||
|
||||
private async void OnSearchSuggestionBoxKeyDown(object _, KeyEventArgs e)
|
||||
{
|
||||
var vm = DataContext as ViewModels.CommitDetail;
|
||||
if (vm == null)
|
||||
if (DataContext is not ViewModels.CommitDetail vm)
|
||||
return;
|
||||
|
||||
if (e.Key == Key.Escape)
|
||||
@@ -67,8 +65,7 @@ namespace SourceGit.Views
|
||||
|
||||
private async void OnSearchSuggestionDoubleTapped(object sender, TappedEventArgs e)
|
||||
{
|
||||
var vm = DataContext as ViewModels.CommitDetail;
|
||||
if (vm == null)
|
||||
if (DataContext is not ViewModels.CommitDetail vm)
|
||||
return;
|
||||
|
||||
var content = (sender as StackPanel)?.DataContext as string;
|
||||
|
||||
@@ -12,8 +12,7 @@ namespace SourceGit.Views
|
||||
|
||||
private void OnMainLayoutSizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
var grid = sender as Grid;
|
||||
if (grid == null)
|
||||
if (sender is not Grid grid)
|
||||
return;
|
||||
|
||||
var layout = ViewModels.Preferences.Instance.Layout;
|
||||
|
||||
@@ -71,8 +71,7 @@ namespace SourceGit.Views
|
||||
|
||||
private void CreateContent(Thickness margin, string iconKey)
|
||||
{
|
||||
var geo = this.FindResource(iconKey) as StreamGeometry;
|
||||
if (geo == null)
|
||||
if (this.FindResource(iconKey) is not StreamGeometry geo)
|
||||
return;
|
||||
|
||||
Content = new Avalonia.Controls.Shapes.Path()
|
||||
|
||||
@@ -71,8 +71,7 @@ namespace SourceGit.Views
|
||||
|
||||
private void CreateContent(Thickness margin, string iconKey)
|
||||
{
|
||||
var geo = this.FindResource(iconKey) as StreamGeometry;
|
||||
if (geo == null)
|
||||
if (this.FindResource(iconKey) is not StreamGeometry geo)
|
||||
return;
|
||||
|
||||
Content = new Avalonia.Controls.Shapes.Path()
|
||||
@@ -181,8 +180,7 @@ namespace SourceGit.Views
|
||||
|
||||
private void OnItemContextRequested(object sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
var control = sender as Control;
|
||||
if (control == null)
|
||||
if (sender is not Control control)
|
||||
return;
|
||||
|
||||
Models.Tag selected;
|
||||
|
||||
@@ -634,9 +634,7 @@ namespace SourceGit.Views
|
||||
for (var idx = lastLineIdx + 1; idx < lines.Count; idx++)
|
||||
{
|
||||
var nextType = lines[idx].Type;
|
||||
if (nextType == Models.TextDiffLineType.None ||
|
||||
nextType == Models.TextDiffLineType.Added ||
|
||||
nextType == Models.TextDiffLineType.Deleted)
|
||||
if (nextType is Models.TextDiffLineType.None or Models.TextDiffLineType.Added or Models.TextDiffLineType.Deleted)
|
||||
{
|
||||
if (findNormalLine)
|
||||
{
|
||||
@@ -1005,15 +1003,10 @@ namespace SourceGit.Views
|
||||
|
||||
if (startIdx == endIdx)
|
||||
{
|
||||
var line = lines[startIdx];
|
||||
if (line.Type == Models.TextDiffLineType.Indicator ||
|
||||
line.Type == Models.TextDiffLineType.None)
|
||||
{
|
||||
if (lines[startIdx].Type is Models.TextDiffLineType.Indicator or Models.TextDiffLineType.None)
|
||||
await App.CopyTextAsync(string.Empty);
|
||||
return;
|
||||
}
|
||||
|
||||
await App.CopyTextAsync(SelectedText);
|
||||
else
|
||||
await App.CopyTextAsync(SelectedText);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1021,8 +1014,7 @@ namespace SourceGit.Views
|
||||
for (var i = startIdx; i <= endIdx && i <= lines.Count - 1; i++)
|
||||
{
|
||||
var line = lines[i];
|
||||
if (line.Type == Models.TextDiffLineType.Indicator ||
|
||||
line.Type == Models.TextDiffLineType.None)
|
||||
if (line.Type is Models.TextDiffLineType.Indicator or Models.TextDiffLineType.None)
|
||||
continue;
|
||||
|
||||
// The first selected line (partial selection)
|
||||
@@ -1094,8 +1086,7 @@ namespace SourceGit.Views
|
||||
|
||||
public override void UpdateSelectedChunk(double y)
|
||||
{
|
||||
var diff = DataContext as Models.TextDiff;
|
||||
if (diff == null)
|
||||
if (DataContext is not Models.TextDiff diff)
|
||||
return;
|
||||
|
||||
var view = TextArea.TextView;
|
||||
@@ -1321,8 +1312,7 @@ namespace SourceGit.Views
|
||||
|
||||
public override void UpdateSelectedChunk(double y)
|
||||
{
|
||||
var diff = DataContext as ViewModels.TwoSideTextDiff;
|
||||
if (diff == null)
|
||||
if (DataContext is not ViewModels.TwoSideTextDiff diff)
|
||||
return;
|
||||
|
||||
var parent = this.FindAncestorOfType<TextDiffView>();
|
||||
@@ -1835,8 +1825,7 @@ namespace SourceGit.Views
|
||||
|
||||
var repoView = this.FindAncestorOfType<Repository>();
|
||||
|
||||
var repo = repoView?.DataContext as ViewModels.Repository;
|
||||
if (repo == null)
|
||||
if (repoView?.DataContext is not ViewModels.Repository repo)
|
||||
return;
|
||||
|
||||
repo.SetWatcherEnabled(false);
|
||||
@@ -1889,8 +1878,7 @@ namespace SourceGit.Views
|
||||
|
||||
var repoView = this.FindAncestorOfType<Repository>();
|
||||
|
||||
var repo = repoView?.DataContext as ViewModels.Repository;
|
||||
if (repo == null)
|
||||
if (repoView?.DataContext is not ViewModels.Repository repo)
|
||||
return;
|
||||
|
||||
repo.SetWatcherEnabled(false);
|
||||
@@ -1939,8 +1927,7 @@ namespace SourceGit.Views
|
||||
|
||||
var repoView = this.FindAncestorOfType<Repository>();
|
||||
|
||||
var repo = repoView?.DataContext as ViewModels.Repository;
|
||||
if (repo == null)
|
||||
if (repoView?.DataContext is not ViewModels.Repository repo)
|
||||
return;
|
||||
|
||||
repo.SetWatcherEnabled(false);
|
||||
|
||||
@@ -209,8 +209,7 @@ namespace SourceGit.Views
|
||||
{
|
||||
var grid = sender as Grid;
|
||||
|
||||
var to = grid?.DataContext as ViewModels.RepositoryNode;
|
||||
if (to == null)
|
||||
if (grid?.DataContext is not ViewModels.RepositoryNode)
|
||||
return;
|
||||
|
||||
e.DragEffects = DragDropEffects.Move;
|
||||
@@ -223,8 +222,7 @@ namespace SourceGit.Views
|
||||
if (sender is not Grid grid)
|
||||
return;
|
||||
|
||||
var to = grid.DataContext as ViewModels.RepositoryNode;
|
||||
if (to == null)
|
||||
if (grid.DataContext is not ViewModels.RepositoryNode to)
|
||||
{
|
||||
e.Handled = true;
|
||||
return;
|
||||
|
||||
@@ -14,8 +14,7 @@ namespace SourceGit.Views
|
||||
|
||||
private void OnMainLayoutSizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
var grid = sender as Grid;
|
||||
if (grid == null)
|
||||
if (sender is not Grid grid)
|
||||
return;
|
||||
|
||||
var layout = ViewModels.Preferences.Instance.Layout;
|
||||
|
||||
Reference in New Issue
Block a user