diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 6b42700d..935e2e19 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -95,7 +95,7 @@ namespace SourceGit builder.Append($"App Start Time: {Process.GetCurrentProcess().StartTime}\n"); builder.Append($"Exception Time: {DateTime.Now}\n"); builder.Append($"Memory Usage: {Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024} MB\n"); - builder.Append($"---------------------------\n\n"); + builder.Append("---------------------------\n\n"); builder.Append(ex); var time = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); diff --git a/src/Commands/Branch.cs b/src/Commands/Branch.cs index 0d1b1f8f..f207e976 100644 --- a/src/Commands/Branch.cs +++ b/src/Commands/Branch.cs @@ -9,7 +9,7 @@ namespace SourceGit.Commands var cmd = new Command(); cmd.WorkingDirectory = repo; cmd.Context = repo; - cmd.Args = $"branch --show-current"; + cmd.Args = "branch --show-current"; return cmd.ReadToEnd().StdOut.Trim(); } diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 975922fc..a5ec0b56 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -169,18 +169,12 @@ namespace SourceGit.Commands } // Force using this app as git editor. - switch (Editor) + start.Arguments += Editor switch { - case EditorType.CoreEditor: - start.Arguments += $"-c core.editor=\"\\\"{selfExecFile}\\\" --core-editor\" "; - break; - case EditorType.RebaseEditor: - start.Arguments += $"-c core.editor=\"\\\"{selfExecFile}\\\" --rebase-message-editor\" -c sequence.editor=\"\\\"{selfExecFile}\\\" --rebase-todo-editor\" -c rebase.abbreviateCommands=true "; - break; - default: - start.Arguments += "-c core.editor=true "; - break; - } + EditorType.CoreEditor => $"-c core.editor=\"\\\"{selfExecFile}\\\" --core-editor\" ", + EditorType.RebaseEditor => $"-c core.editor=\"\\\"{selfExecFile}\\\" --rebase-message-editor\" -c sequence.editor=\"\\\"{selfExecFile}\\\" --rebase-todo-editor\" -c rebase.abbreviateCommands=true ", + _ => "-c core.editor=true ", + }; // Append command args start.Arguments += Args; diff --git a/src/Commands/QueryFileContent.cs b/src/Commands/QueryFileContent.cs index 83d0a575..648b9058 100644 --- a/src/Commands/QueryFileContent.cs +++ b/src/Commands/QueryFileContent.cs @@ -41,7 +41,7 @@ namespace SourceGit.Commands var starter = new ProcessStartInfo(); starter.WorkingDirectory = repo; starter.FileName = Native.OS.GitExecutable; - starter.Arguments = $"lfs smudge"; + starter.Arguments = "lfs smudge"; starter.UseShellExecute = false; starter.CreateNoWindow = true; starter.WindowStyle = ProcessWindowStyle.Hidden; diff --git a/src/Commands/QueryRevisionObjects.cs b/src/Commands/QueryRevisionObjects.cs index de3406e8..5c582dcc 100644 --- a/src/Commands/QueryRevisionObjects.cs +++ b/src/Commands/QueryRevisionObjects.cs @@ -51,21 +51,14 @@ namespace SourceGit.Commands obj.Type = Models.ObjectType.Blob; obj.Path = match.Groups[3].Value; - switch (match.Groups[1].Value) + obj.Type = match.Groups[1].Value switch { - case "blob": - obj.Type = Models.ObjectType.Blob; - break; - case "tree": - obj.Type = Models.ObjectType.Tree; - break; - case "tag": - obj.Type = Models.ObjectType.Tag; - break; - case "commit": - obj.Type = Models.ObjectType.Commit; - break; - } + "blob" => Models.ObjectType.Blob, + "tree" => Models.ObjectType.Tree, + "tag" => Models.ObjectType.Tag, + "commit" => Models.ObjectType.Commit, + _ => obj.Type, + }; _objects.Add(obj); } diff --git a/src/Commands/QueryStashes.cs b/src/Commands/QueryStashes.cs index 2b8987b6..2a84b34a 100644 --- a/src/Commands/QueryStashes.cs +++ b/src/Commands/QueryStashes.cs @@ -9,7 +9,7 @@ namespace SourceGit.Commands { WorkingDirectory = repo; Context = repo; - Args = $"stash list -z --no-show-signature --format=\"%H%n%P%n%ct%n%gd%n%B\""; + Args = "stash list -z --no-show-signature --format=\"%H%n%P%n%ct%n%gd%n%B\""; } public List Result() diff --git a/src/Commands/SaveRevisionFile.cs b/src/Commands/SaveRevisionFile.cs index 64e8f8a5..b6127ea6 100644 --- a/src/Commands/SaveRevisionFile.cs +++ b/src/Commands/SaveRevisionFile.cs @@ -18,7 +18,7 @@ namespace SourceGit.Commands if (isLFSFiltered) { var pointerStream = QueryFileContent.Run(repo, revision, file); - ExecCmd(repo, $"lfs smudge", saveTo, pointerStream); + ExecCmd(repo, "lfs smudge", saveTo, pointerStream); } else { diff --git a/src/Converters/FilterModeConverters.cs b/src/Converters/FilterModeConverters.cs index c486af5e..016613e8 100644 --- a/src/Converters/FilterModeConverters.cs +++ b/src/Converters/FilterModeConverters.cs @@ -8,15 +8,12 @@ namespace SourceGit.Converters public static readonly FuncValueConverter ToBorderBrush = new FuncValueConverter(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, + }; }); } } diff --git a/src/Converters/InteractiveRebaseActionConverters.cs b/src/Converters/InteractiveRebaseActionConverters.cs index dbd183bd..3534c809 100644 --- a/src/Converters/InteractiveRebaseActionConverters.cs +++ b/src/Converters/InteractiveRebaseActionConverters.cs @@ -8,42 +8,19 @@ namespace SourceGit.Converters public static readonly FuncValueConverter ToIconBrush = new FuncValueConverter(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 ToName = - new FuncValueConverter(v => - { - switch (v) - { - 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"; - } - }); + new FuncValueConverter(v => v.ToString()); public static readonly FuncValueConverter CanEditMessage = new FuncValueConverter(v => v == Models.InteractiveRebaseAction.Reword || v == Models.InteractiveRebaseAction.Squash); diff --git a/src/Models/AvatarManager.cs b/src/Models/AvatarManager.cs index bc9fbe95..f0006652 100644 --- a/src/Models/AvatarManager.cs +++ b/src/Models/AvatarManager.cs @@ -185,7 +185,7 @@ namespace SourceGit.Models { try { - Bitmap image = null; + Bitmap image; using (var stream = File.OpenRead(file)) { diff --git a/src/Models/CommitSignInfo.cs b/src/Models/CommitSignInfo.cs index 44b95e61..99317e94 100644 --- a/src/Models/CommitSignInfo.cs +++ b/src/Models/CommitSignInfo.cs @@ -13,21 +13,13 @@ namespace SourceGit.Models { get { - switch (VerifyResult) + return VerifyResult switch { - case 'G': - case 'U': - return Brushes.Green; - case 'X': - case 'Y': - case 'R': - return Brushes.DarkOrange; - case 'B': - case 'E': - return Brushes.Red; - default: - return Brushes.Transparent; - } + 'G' or 'U' => Brushes.Green, + 'X' or 'Y' or 'R' => Brushes.DarkOrange, + 'B' or 'E' => Brushes.Red, + _ => Brushes.Transparent, + }; } } @@ -35,25 +27,17 @@ namespace SourceGit.Models { get { - switch (VerifyResult) + return VerifyResult switch { - case 'G': - return "Good signature."; - case 'U': - return "Good signature with unknown validity."; - case 'X': - return "Good signature but has expired."; - case 'Y': - return "Good signature made by expired key."; - case 'R': - return "Good signature made by a revoked key."; - case 'B': - return "Bad signature."; - case 'E': - return "Signature cannot be checked."; - default: - return "No signature."; - } + 'G' => "Good signature.", + 'U' => "Good signature with unknown validity.", + 'X' => "Good signature but has expired.", + 'Y' => "Good signature made by expired key.", + 'R' => "Good signature made by a revoked key.", + 'B' => "Bad signature.", + 'E' => "Signature cannot be checked.", + _ => "No signature.", + }; } } } diff --git a/src/Models/DiffResult.cs b/src/Models/DiffResult.cs index 71ed2d9e..2f06c0cf 100644 --- a/src/Models/DiffResult.cs +++ b/src/Models/DiffResult.cs @@ -100,7 +100,7 @@ namespace SourceGit.Models rs.HasChanges = true; break; } - else if (isOldSide) + if (isOldSide) { rs.HasLeftChanges = true; } @@ -116,7 +116,7 @@ namespace SourceGit.Models rs.HasChanges = true; break; } - else if (isOldSide) + if (isOldSide) { rs.HasChanges = true; } @@ -163,7 +163,7 @@ namespace SourceGit.Models if (revert) { var totalLines = Lines.Count - 1; - builder.Append($"@@ -0,").Append(totalLines - additions).Append(" +0,").Append(totalLines).Append(" @@"); + builder.Append("@@ -0,").Append(totalLines - additions).Append(" +0,").Append(totalLines).Append(" @@"); for (int i = 1; i <= totalLines; i++) { var line = Lines[i]; @@ -645,12 +645,6 @@ namespace SourceGit.Models public class NoOrEOLChange; - public class FileModeDiff - { - public string Old { get; set; } = string.Empty; - public string New { get; set; } = string.Empty; - } - public class SubmoduleDiff { public RevisionSubmodule Old { get; set; } = null; diff --git a/src/Models/GitFlow.cs b/src/Models/GitFlow.cs index 5d26072b..05ade0ac 100644 --- a/src/Models/GitFlow.cs +++ b/src/Models/GitFlow.cs @@ -30,17 +30,13 @@ public string GetPrefix(GitFlowBranchType type) { - switch (type) + return type switch { - case GitFlowBranchType.Feature: - return FeaturePrefix; - case GitFlowBranchType.Release: - return ReleasePrefix; - case GitFlowBranchType.Hotfix: - return HotfixPrefix; - default: - return string.Empty; - } + GitFlowBranchType.Feature => FeaturePrefix, + GitFlowBranchType.Release => ReleasePrefix, + GitFlowBranchType.Hotfix => HotfixPrefix, + _ => string.Empty, + }; } } } diff --git a/src/Models/OpenAI.cs b/src/Models/OpenAI.cs index 22fbcd51..ab2a92b3 100644 --- a/src/Models/OpenAI.cs +++ b/src/Models/OpenAI.cs @@ -177,18 +177,10 @@ namespace SourceGit.Models { var server = new Uri(_server); var key = new ApiKeyCredential(_apiKey); - var client = null as ChatClient; - if (_server.Contains("openai.azure.com/", StringComparison.Ordinal)) - { - var azure = new AzureOpenAIClient(server, key); - client = azure.GetChatClient(_model); - } - else - { - var openai = new OpenAIClient(key, new() { Endpoint = server }); - client = openai.GetChatClient(_model); - } - + var oaiClient = _server.Contains("openai.azure.com/", StringComparison.Ordinal) + ? new AzureOpenAIClient(server, key) + : new OpenAIClient(key, new() { Endpoint = server }); + var client = oaiClient.GetChatClient(_model); var messages = new List(); messages.Add(_model.Equals("o1-mini", StringComparison.Ordinal) ? new UserChatMessage(prompt) : new SystemChatMessage(prompt)); messages.Add(new UserChatMessage(question)); diff --git a/src/Native/MacOS.cs b/src/Native/MacOS.cs index b76d239a..8ee84cb5 100644 --- a/src/Native/MacOS.cs +++ b/src/Native/MacOS.cs @@ -57,21 +57,15 @@ namespace SourceGit.Native public string FindTerminal(Models.ShellOrTerminal shell) { - switch (shell.Type) + return shell.Type switch { - case "mac-terminal": - return "Terminal"; - case "iterm2": - return "iTerm"; - case "warp": - return "Warp"; - case "ghostty": - return "Ghostty"; - case "kitty": - return "kitty"; - } - - return string.Empty; + "mac-terminal" => "Terminal", + "iterm2" => "iTerm", + "warp" => "Warp", + "ghostty" => "Ghostty", + "kitty" => "kitty", + _ => string.Empty, + }; } public List FindExternalTools() diff --git a/src/Native/OS.cs b/src/Native/OS.cs index ad6f8104..3e616b18 100644 --- a/src/Native/OS.cs +++ b/src/Native/OS.cs @@ -165,7 +165,7 @@ namespace SourceGit.Native public static void OpenTerminal(string workdir) { if (string.IsNullOrEmpty(ShellOrTerminal)) - App.RaiseException(workdir, $"Terminal is not specified! Please confirm that the correct shell/terminal has been configured."); + App.RaiseException(workdir, "Terminal is not specified! Please confirm that the correct shell/terminal has been configured."); else _backend.OpenTerminal(workdir); } diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index 06d80bf0..02d8142b 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -94,27 +94,18 @@ namespace SourceGit.Native y = 2; var zone = y * 3 + x; - switch (zone) + return zone switch { - case 0: - return 13; // HTTOPLEFT - case 1: - return 12; // HTTOP - case 2: - return 14; // HTTOPRIGHT - case 3: - return 10; // HTLEFT - case 4: - return 1; // HTCLIENT - case 5: - return 11; // HTRIGHT - case 6: - return 16; // HTBOTTOMLEFT - case 7: - return 15; // HTBOTTOM - default: - return 17; // HTBOTTOMRIGHT - } + 0 => 13, // HTTOPLEFT + 1 => 12, // HTTOP + 2 => 14, // HTTOPRIGHT + 3 => 10, // HTLEFT + 4 => 1, // HTCLIENT + 5 => 11, // HTRIGHT + 6 => 16, // HTBOTTOMLEFT + 7 => 15, // HTBOTTOM + _ => 17, + }; } return IntPtr.Zero; @@ -211,7 +202,7 @@ namespace SourceGit.Native { if (!File.Exists(OS.ShellOrTerminal)) { - App.RaiseException(workdir, $"Terminal is not specified! Please confirm that the correct shell/terminal has been configured."); + App.RaiseException(workdir, "Terminal is not specified! Please confirm that the correct shell/terminal has been configured."); return; } diff --git a/src/ViewModels/Checkout.cs b/src/ViewModels/Checkout.cs index ddcbb295..45dcd9a4 100644 --- a/src/ViewModels/Checkout.cs +++ b/src/ViewModels/Checkout.cs @@ -44,7 +44,7 @@ namespace SourceGit.ViewModels var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules; return Task.Run(() => { - var succ = false; + bool succ; var needPopStash = false; if (!_repo.ConfirmCheckoutBranch()) diff --git a/src/ViewModels/CheckoutCommit.cs b/src/ViewModels/CheckoutCommit.cs index 3acc457c..f477538d 100644 --- a/src/ViewModels/CheckoutCommit.cs +++ b/src/ViewModels/CheckoutCommit.cs @@ -44,7 +44,7 @@ namespace SourceGit.ViewModels var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules; return Task.Run(() => { - var succ = false; + bool succ; var needPop = false; if (!_repo.ConfirmCheckoutBranch()) diff --git a/src/ViewModels/CherryPick.cs b/src/ViewModels/CherryPick.cs index d5238bb3..2d929f3a 100644 --- a/src/ViewModels/CherryPick.cs +++ b/src/ViewModels/CherryPick.cs @@ -67,7 +67,7 @@ namespace SourceGit.ViewModels { _repo.SetWatcherEnabled(false); _repo.ClearCommitMessage(); - ProgressDescription = $"Cherry-Pick commit(s) ..."; + ProgressDescription = "Cherry-Pick commit(s) ..."; var log = _repo.CreateLog("Cherry-Pick"); Use(log); diff --git a/src/ViewModels/CommandLog.cs b/src/ViewModels/CommandLog.cs index e73bc1ec..896869cf 100644 --- a/src/ViewModels/CommandLog.cs +++ b/src/ViewModels/CommandLog.cs @@ -11,7 +11,7 @@ namespace SourceGit.ViewModels { get; private set; - } = string.Empty; + } public DateTime StartTime { diff --git a/src/ViewModels/CreateBranch.cs b/src/ViewModels/CreateBranch.cs index 3c245589..6e01eb39 100644 --- a/src/ViewModels/CreateBranch.cs +++ b/src/ViewModels/CreateBranch.cs @@ -129,7 +129,7 @@ namespace SourceGit.ViewModels var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules; return Task.Run(() => { - bool succ = false; + bool succ; if (CheckoutAfterCreated && !_repo.ConfirmCheckoutBranch()) { diff --git a/src/ViewModels/FileHistories.cs b/src/ViewModels/FileHistories.cs index b901700f..45468e6b 100644 --- a/src/ViewModels/FileHistories.cs +++ b/src/ViewModels/FileHistories.cs @@ -284,18 +284,12 @@ namespace SourceGit.ViewModels if (_viewContent is FileHistoriesSingleRevision singleRevision) _prevIsDiffMode = singleRevision.IsDiffMode; - switch (SelectedCommits.Count) + ViewContent = SelectedCommits.Count switch { - case 1: - ViewContent = new FileHistoriesSingleRevision(_repo, file, SelectedCommits[0], _prevIsDiffMode); - break; - case 2: - ViewContent = new FileHistoriesCompareRevisions(_repo, file, SelectedCommits[0], SelectedCommits[1]); - break; - default: - ViewContent = SelectedCommits.Count; - break; - } + 1 => new FileHistoriesSingleRevision(_repo, file, SelectedCommits[0], _prevIsDiffMode), + 2 => new FileHistoriesCompareRevisions(_repo, file, SelectedCommits[0], SelectedCommits[1]), + _ => SelectedCommits.Count, + }; }; } diff --git a/src/ViewModels/ImageSource.cs b/src/ViewModels/ImageSource.cs index f0e2df30..039403f4 100644 --- a/src/ViewModels/ImageSource.cs +++ b/src/ViewModels/ImageSource.cs @@ -27,25 +27,13 @@ namespace SourceGit.ViewModels { var ext = (Path.GetExtension(file) ?? ".invalid_img").ToLower(CultureInfo.CurrentCulture); - switch (ext) + return ext switch { - case ".ico": - case ".bmp": - case ".gif": - case ".jpg": - case ".jpeg": - case ".png": - case ".webp": - return Models.ImageDecoder.Builtin; - case ".tga": - case ".dds": - return Models.ImageDecoder.Pfim; - case ".tif": - case ".tiff": - return Models.ImageDecoder.Tiff; - default: - return Models.ImageDecoder.None; - } + ".ico" or ".bmp" or ".gif" or ".jpg" or ".jpeg" or ".png" or ".webp" => Models.ImageDecoder.Builtin, + ".tga" or ".dds" => Models.ImageDecoder.Pfim, + ".tif" or ".tiff" => Models.ImageDecoder.Tiff, + _ => Models.ImageDecoder.None, + }; } public static ImageSource FromFile(string fullpath, Models.ImageDecoder decoder) diff --git a/src/ViewModels/InProgressContexts.cs b/src/ViewModels/InProgressContexts.cs index a1a87a42..d26e50c9 100644 --- a/src/ViewModels/InProgressContexts.cs +++ b/src/ViewModels/InProgressContexts.cs @@ -112,11 +112,9 @@ namespace SourceGit.ViewModels HeadName = HeadName.Substring(10); var stoppedSHAPath = Path.Combine(repo.GitDir, "rebase-merge", "stopped-sha"); - var stoppedSHA = string.Empty; - if (File.Exists(stoppedSHAPath)) - stoppedSHA = File.ReadAllText(stoppedSHAPath).Trim(); - else - stoppedSHA = new Commands.QueryRevisionByRefName(repo.FullPath, HeadName).Result(); + var stoppedSHA = File.Exists(stoppedSHAPath) + ? File.ReadAllText(stoppedSHAPath).Trim() + : new Commands.QueryRevisionByRefName(repo.FullPath, HeadName).Result(); if (!string.IsNullOrEmpty(stoppedSHA)) StoppedAt = new Commands.QuerySingleCommit(repo.FullPath, stoppedSHA).Result() ?? new Models.Commit() { SHA = stoppedSHA }; @@ -132,7 +130,7 @@ namespace SourceGit.ViewModels WorkingDirectory = _repo, Context = _repo, Editor = Commands.Command.EditorType.RebaseEditor, - Args = $"rebase --continue", + Args = "rebase --continue", }.Exec(); } } diff --git a/src/ViewModels/InitGitFlow.cs b/src/ViewModels/InitGitFlow.cs index 265a73d3..c5aeceec 100644 --- a/src/ViewModels/InitGitFlow.cs +++ b/src/ViewModels/InitGitFlow.cs @@ -110,7 +110,7 @@ namespace SourceGit.ViewModels return Task.Run(() => { - var succ = false; + bool succ; var current = _repo.CurrentBranch; var masterBranch = _repo.Branches.Find(x => x.IsLocal && x.Name.Equals(_master, StringComparison.Ordinal)); diff --git a/src/ViewModels/LFSFetch.cs b/src/ViewModels/LFSFetch.cs index 43ca88fb..99d9babb 100644 --- a/src/ViewModels/LFSFetch.cs +++ b/src/ViewModels/LFSFetch.cs @@ -22,7 +22,7 @@ namespace SourceGit.ViewModels public override Task Sure() { _repo.SetWatcherEnabled(false); - ProgressDescription = $"Fetching LFS objects from remote ..."; + ProgressDescription = "Fetching LFS objects from remote ..."; var log = _repo.CreateLog("LFS Fetch"); Use(log); diff --git a/src/ViewModels/LFSPull.cs b/src/ViewModels/LFSPull.cs index 8bac8bbb..1943c02e 100644 --- a/src/ViewModels/LFSPull.cs +++ b/src/ViewModels/LFSPull.cs @@ -22,7 +22,7 @@ namespace SourceGit.ViewModels public override Task Sure() { _repo.SetWatcherEnabled(false); - ProgressDescription = $"Pull LFS objects from remote ..."; + ProgressDescription = "Pull LFS objects from remote ..."; var log = _repo.CreateLog("LFS Pull"); Use(log); diff --git a/src/ViewModels/LFSPush.cs b/src/ViewModels/LFSPush.cs index 0013ee29..ea111eff 100644 --- a/src/ViewModels/LFSPush.cs +++ b/src/ViewModels/LFSPush.cs @@ -22,7 +22,7 @@ namespace SourceGit.ViewModels public override Task Sure() { _repo.SetWatcherEnabled(false); - ProgressDescription = $"Push LFS objects to remote ..."; + ProgressDescription = "Push LFS objects to remote ..."; var log = _repo.CreateLog("LFS Push"); Use(log); diff --git a/src/ViewModels/PushTag.cs b/src/ViewModels/PushTag.cs index 8cdf9767..82a3af00 100644 --- a/src/ViewModels/PushTag.cs +++ b/src/ViewModels/PushTag.cs @@ -37,7 +37,7 @@ namespace SourceGit.ViewModels public override Task Sure() { _repo.SetWatcherEnabled(false); - ProgressDescription = $"Pushing tag ..."; + ProgressDescription = "Pushing tag ..."; var log = _repo.CreateLog("Push Tag"); Use(log); diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 9b43bd99..3202c44c 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -75,18 +75,12 @@ namespace SourceGit.ViewModels { if (SetProperty(ref _selectedViewIndex, value)) { - switch (value) + SelectedView = value switch { - case 1: - SelectedView = _workingCopy; - break; - case 2: - SelectedView = _stashesPage; - break; - default: - SelectedView = _histories; - break; - } + 1 => _workingCopy, + 2 => _stashesPage, + _ => _histories, + }; } } } @@ -829,7 +823,7 @@ namespace SourceGit.ViewModels if (!CanCreatePopup()) return; - var popup = null as ExecuteCustomAction; + ExecuteCustomAction popup; if (scope is Models.Branch b) popup = new ExecuteCustomAction(this, action, b); else if (scope is Models.Commit c) @@ -877,7 +871,7 @@ namespace SourceGit.ViewModels Task.Run(() => { - var visible = null as List; + List visible; var method = (Models.CommitSearchMethod)_searchCommitFilterType; if (method == Models.CommitSearchMethod.BySHA) @@ -1733,7 +1727,7 @@ namespace SourceGit.ViewModels var log = CreateLog("Install LFS"); var succ = new Commands.LFS(_fullpath).Install(log); if (succ) - App.SendNotification(_fullpath, $"LFS enabled successfully!"); + App.SendNotification(_fullpath, "LFS enabled successfully!"); log.Complete(); e.Handled = true; diff --git a/src/ViewModels/ResetWithoutCheckout.cs b/src/ViewModels/ResetWithoutCheckout.cs index 3a9582ef..9ec3f6b3 100644 --- a/src/ViewModels/ResetWithoutCheckout.cs +++ b/src/ViewModels/ResetWithoutCheckout.cs @@ -48,6 +48,6 @@ namespace SourceGit.ViewModels } private readonly Repository _repo = null; - private readonly string _revision = string.Empty; + private readonly string _revision; } } diff --git a/src/ViewModels/Reword.cs b/src/ViewModels/Reword.cs index 72dd9e58..8517c1bf 100644 --- a/src/ViewModels/Reword.cs +++ b/src/ViewModels/Reword.cs @@ -32,7 +32,7 @@ namespace SourceGit.ViewModels return null; _repo.SetWatcherEnabled(false); - ProgressDescription = $"Editing head commit message ..."; + ProgressDescription = "Editing head commit message ..."; var log = _repo.CreateLog("Reword HEAD"); Use(log); diff --git a/src/ViewModels/Squash.cs b/src/ViewModels/Squash.cs index 8e9bae8b..9574beb0 100644 --- a/src/ViewModels/Squash.cs +++ b/src/ViewModels/Squash.cs @@ -36,7 +36,7 @@ namespace SourceGit.ViewModels { var signOff = _repo.Settings.EnableSignOffForCommit; var autoStashed = false; - var succ = false; + bool succ; if (_repo.LocalChangesCount > 0) { diff --git a/src/ViewModels/StashChanges.cs b/src/ViewModels/StashChanges.cs index 639a0a7b..0fb243f5 100644 --- a/src/ViewModels/StashChanges.cs +++ b/src/ViewModels/StashChanges.cs @@ -53,7 +53,7 @@ namespace SourceGit.ViewModels public override Task Sure() { _repo.SetWatcherEnabled(false); - ProgressDescription = $"Stash changes ..."; + ProgressDescription = "Stash changes ..."; var log = _repo.CreateLog("Stash Local Changes"); Use(log); @@ -62,7 +62,7 @@ namespace SourceGit.ViewModels { var mode = (DealWithChangesAfterStashing)ChangesAfterStashing; var keepIndex = mode == DealWithChangesAfterStashing.KeepIndex; - var succ = false; + bool succ; if (!HasSelectedFiles) { diff --git a/src/Views/AIAssistant.axaml b/src/Views/AIAssistant.axaml index 96ce56ec..bef13df2 100644 --- a/src/Views/AIAssistant.axaml +++ b/src/Views/AIAssistant.axaml @@ -4,7 +4,6 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:v="using:SourceGit.Views" xmlns:vm="using:SourceGit.ViewModels" - xmlns:c="using:SourceGit.Converters" mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="120" x:Class="SourceGit.Views.AIAssistant" x:DataType="vm:AIAssistant" diff --git a/src/Views/AddWorktree.axaml.cs b/src/Views/AddWorktree.axaml.cs index 8e16642e..c39c8928 100644 --- a/src/Views/AddWorktree.axaml.cs +++ b/src/Views/AddWorktree.axaml.cs @@ -26,7 +26,7 @@ namespace SourceGit.Views { var folder = selected[0]; var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder?.Path.ToString(); - TxtLocation.Text = folderPath.TrimEnd(['\\', '/']); + TxtLocation.Text = folderPath.TrimEnd('\\', '/'); } } catch (Exception exception) diff --git a/src/Views/BranchTree.axaml.cs b/src/Views/BranchTree.axaml.cs index 0f97edf5..57cfa88d 100644 --- a/src/Views/BranchTree.axaml.cs +++ b/src/Views/BranchTree.axaml.cs @@ -268,7 +268,7 @@ namespace SourceGit.Views } } - var target = treePath[treePath.Count - 1]; + var target = treePath[^1]; BranchesPresenter.SelectedItem = target; BranchesPresenter.ScrollIntoView(target); diff --git a/src/Views/ChangeViewModeSwitcher.axaml b/src/Views/ChangeViewModeSwitcher.axaml index 911fb41d..b72fcbcb 100644 --- a/src/Views/ChangeViewModeSwitcher.axaml +++ b/src/Views/ChangeViewModeSwitcher.axaml @@ -3,7 +3,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="using:SourceGit.Models" - xmlns:v="using:SourceGit.Views" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SourceGit.Views.ChangeViewModeSwitcher" x:Name="ThisControl"> diff --git a/src/Views/Checkout.axaml b/src/Views/Checkout.axaml index 42b9cec5..14ee84b5 100644 --- a/src/Views/Checkout.axaml +++ b/src/Views/Checkout.axaml @@ -2,9 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" - xmlns:ac="using:Avalonia.Controls.Converters" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SourceGit.Views.Checkout" x:DataType="vm:Checkout"> diff --git a/src/Views/CheckoutAndFastForward.axaml b/src/Views/CheckoutAndFastForward.axaml index 40ca3e14..ad0422b3 100644 --- a/src/Views/CheckoutAndFastForward.axaml +++ b/src/Views/CheckoutAndFastForward.axaml @@ -2,7 +2,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SourceGit.Views.CheckoutAndFastForward" diff --git a/src/Views/CommitRefsPresenter.cs b/src/Views/CommitRefsPresenter.cs index a5717c6c..7a473f8b 100644 --- a/src/Views/CommitRefsPresenter.cs +++ b/src/Views/CommitRefsPresenter.cs @@ -186,7 +186,6 @@ namespace SourceGit.Views var fg = Foreground; var normalBG = UseGraphColor ? commit.Brush : Brushes.Gray; var labelSize = FontSize; - var requiredWidth = 0.0; var requiredHeight = 16.0; var x = 0.0; var allowWrap = AllowWrap; @@ -260,11 +259,9 @@ namespace SourceGit.Views } } - if (allowWrap && requiredHeight > 16.0) - requiredWidth = availableSize.Width; - else - requiredWidth = x + 2; - + var requiredWidth = allowWrap && requiredHeight > 16.0 + ? availableSize.Width + : x + 2; InvalidateVisual(); return new Size(requiredWidth, requiredHeight); } diff --git a/src/Views/CreateBranch.axaml b/src/Views/CreateBranch.axaml index 3266e312..c52d8696 100644 --- a/src/Views/CreateBranch.axaml +++ b/src/Views/CreateBranch.axaml @@ -6,7 +6,6 @@ xmlns:vm="using:SourceGit.ViewModels" xmlns:v="using:SourceGit.Views" xmlns:c="using:SourceGit.Converters" - xmlns:ac="using:Avalonia.Controls.Converters" mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450" x:Class="SourceGit.Views.CreateBranch" x:DataType="vm:CreateBranch"> diff --git a/src/Views/DeinitSubmodule.axaml b/src/Views/DeinitSubmodule.axaml index d3e0b641..f589d5bc 100644 --- a/src/Views/DeinitSubmodule.axaml +++ b/src/Views/DeinitSubmodule.axaml @@ -3,7 +3,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:SourceGit.ViewModels" - xmlns:v="using:SourceGit.Views" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SourceGit.Views.DeinitSubmodule" x:DataType="vm:DeinitSubmodule"> diff --git a/src/Views/GitFlowFinish.axaml b/src/Views/GitFlowFinish.axaml index fa847bba..43fde72d 100644 --- a/src/Views/GitFlowFinish.axaml +++ b/src/Views/GitFlowFinish.axaml @@ -4,7 +4,6 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" - xmlns:c="using:SourceGit.Converters" mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450" x:Class="SourceGit.Views.GitFlowFinish" x:DataType="vm:GitFlowFinish"> diff --git a/src/Views/GitFlowStart.axaml b/src/Views/GitFlowStart.axaml index aed970de..9a22e045 100644 --- a/src/Views/GitFlowStart.axaml +++ b/src/Views/GitFlowStart.axaml @@ -5,7 +5,6 @@ xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" xmlns:v="using:SourceGit.Views" - xmlns:c="using:SourceGit.Converters" mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450" x:Class="SourceGit.Views.GitFlowStart" x:DataType="vm:GitFlowStart"> diff --git a/src/Views/MoveRepositoryNode.axaml b/src/Views/MoveRepositoryNode.axaml index 7c408487..fb11cf3e 100644 --- a/src/Views/MoveRepositoryNode.axaml +++ b/src/Views/MoveRepositoryNode.axaml @@ -2,7 +2,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:v="using:SourceGit.Views" xmlns:vm="using:SourceGit.ViewModels" xmlns:c="using:SourceGit.Converters" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" diff --git a/src/Views/Pull.axaml b/src/Views/Pull.axaml index 96d308b4..11f88336 100644 --- a/src/Views/Pull.axaml +++ b/src/Views/Pull.axaml @@ -4,7 +4,6 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" - xmlns:ac="using:Avalonia.Controls.Converters" mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450" x:Class="SourceGit.Views.Pull" x:DataType="vm:Pull"> diff --git a/src/Views/PushRevision.axaml b/src/Views/PushRevision.axaml index 71afd300..092212c1 100644 --- a/src/Views/PushRevision.axaml +++ b/src/Views/PushRevision.axaml @@ -2,7 +2,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" xmlns:c="using:SourceGit.Converters" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" diff --git a/src/Views/RepositoryToolbar.axaml.cs b/src/Views/RepositoryToolbar.axaml.cs index ea1e3257..e18b0e81 100644 --- a/src/Views/RepositoryToolbar.axaml.cs +++ b/src/Views/RepositoryToolbar.axaml.cs @@ -157,7 +157,7 @@ namespace SourceGit.Views { if (DataContext is ViewModels.Repository { CurrentBranch: not null } repo) { - var repoView = TopLevel.GetTopLevel(this)?.FindDescendantOfType(false); + var repoView = TopLevel.GetTopLevel(this)?.FindDescendantOfType(); repoView?.LocalBranchTree?.Select(repo.CurrentBranch); repo.NavigateToCommit(repo.CurrentBranch.Head); diff --git a/src/Views/StashChanges.axaml b/src/Views/StashChanges.axaml index 52af4edd..8ddc3adf 100644 --- a/src/Views/StashChanges.axaml +++ b/src/Views/StashChanges.axaml @@ -25,12 +25,7 @@ HorizontalAlignment="Stretch"> - - - - - - + diff --git a/src/Views/StashSubjectPresenter.cs b/src/Views/StashSubjectPresenter.cs index 727ee2fd..e404c181 100644 --- a/src/Views/StashSubjectPresenter.cs +++ b/src/Views/StashSubjectPresenter.cs @@ -63,7 +63,7 @@ namespace SourceGit.Views if (string.IsNullOrEmpty(subject)) return; - var typeface = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Normal); + var typeface = new Typeface(FontFamily); var foreground = Foreground; var x = 0.0; var h = Bounds.Height; @@ -117,7 +117,7 @@ namespace SourceGit.Views protected override Size MeasureOverride(Size availableSize) { - var typeface = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Normal); + var typeface = new Typeface(FontFamily); var test = new FormattedText("fgl|", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, FontSize, Brushes.White); var h = Math.Max(18, test.Height); return new Size(availableSize.Width, h); diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index e08554e9..b84a6423 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -225,7 +225,7 @@ namespace SourceGit.Views var typeface = TextView.CreateTypeface(); var test = new FormattedText( - $"-", + "-", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, @@ -332,17 +332,13 @@ namespace SourceGit.Views private IBrush GetBrushByLineType(Models.TextDiffLineType type) { - switch (type) + return type switch { - case Models.TextDiffLineType.None: - return _presenter.EmptyContentBackground; - case Models.TextDiffLineType.Added: - return _presenter.AddedContentBackground; - case Models.TextDiffLineType.Deleted: - return _presenter.DeletedContentBackground; - default: - return null; - } + Models.TextDiffLineType.None => _presenter.EmptyContentBackground, + Models.TextDiffLineType.Added => _presenter.AddedContentBackground, + Models.TextDiffLineType.Deleted => _presenter.DeletedContentBackground, + _ => null, + }; } private ThemedTextDiffPresenter _presenter = null; diff --git a/src/Views/WorkingCopy.axaml b/src/Views/WorkingCopy.axaml index 787dcda5..39ae1a7e 100644 --- a/src/Views/WorkingCopy.axaml +++ b/src/Views/WorkingCopy.axaml @@ -2,7 +2,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" xmlns:v="using:SourceGit.Views" xmlns:c="using:SourceGit.Converters" diff --git a/src/Views/WorkingCopy.axaml.cs b/src/Views/WorkingCopy.axaml.cs index bbc95d8d..f7161e6f 100644 --- a/src/Views/WorkingCopy.axaml.cs +++ b/src/Views/WorkingCopy.axaml.cs @@ -32,7 +32,7 @@ namespace SourceGit.Views { var container = control.FindDescendantOfType(); var selectedSingleFolder = string.Empty; - if (container is { SelectedItems: { Count: 1 }, SelectedItem: ViewModels.ChangeTreeNode { IsFolder: true } node }) + if (container is { SelectedItems.Count: 1, SelectedItem: ViewModels.ChangeTreeNode { IsFolder: true } node }) selectedSingleFolder = node.FullPath; var menu = vm.CreateContextMenuForUnstagedChanges(selectedSingleFolder); @@ -47,7 +47,7 @@ namespace SourceGit.Views { var container = control.FindDescendantOfType(); var selectedSingleFolder = string.Empty; - if (container is { SelectedItems: { Count: 1 }, SelectedItem: ViewModels.ChangeTreeNode { IsFolder: true } node }) + if (container is { SelectedItems.Count: 1, SelectedItem: ViewModels.ChangeTreeNode { IsFolder: true } node }) selectedSingleFolder = node.FullPath; var menu = vm.CreateContextMenuForStagedChanges(selectedSingleFolder);