diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 9ef0faf84..d71ca8812 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -32,7 +32,7 @@ public enum EditorType public bool RaiseError { get; set; } = true; public Models.ICommandLog Log { get; set; } = null; - public bool Exec() + public virtual bool Exec() { Log?.AppendLine($"$ git {Args}\n"); diff --git a/src/Commands/Fetch.cs b/src/Commands/Fetch.cs index edf2a6dd8..630caf42b 100644 --- a/src/Commands/Fetch.cs +++ b/src/Commands/Fetch.cs @@ -6,7 +6,7 @@ public Fetch(string repo, string remote, bool noTags, bool force) { WorkingDirectory = repo; Context = repo; - SSHKey = new Config(repo).Get($"remote.{remote}.sshkey"); + _remote = remote; Args = "fetch --progress --verbose "; if (noTags) @@ -24,8 +24,16 @@ public Fetch(string repo, Models.Branch local, Models.Branch remote) { WorkingDirectory = repo; Context = repo; - SSHKey = new Config(repo).Get($"remote.{remote.Remote}.sshkey"); + _remote = remote.Remote; Args = $"fetch --progress --verbose {remote.Remote} {remote.Name}:{local.Name}"; } + + public override bool Exec() + { + SSHKey = new Config(Context).Get($"remote.{_remote}.sshkey"); + return base.Exec(); + } + + private readonly string _remote; } } diff --git a/src/Commands/Pull.cs b/src/Commands/Pull.cs index 698fbfcee..12e7e1b38 100644 --- a/src/Commands/Pull.cs +++ b/src/Commands/Pull.cs @@ -6,7 +6,7 @@ public Pull(string repo, string remote, string branch, bool useRebase) { WorkingDirectory = repo; Context = repo; - SSHKey = new Config(repo).Get($"remote.{remote}.sshkey"); + _remote = remote; Args = "pull --verbose --progress "; if (useRebase) @@ -14,5 +14,13 @@ public Pull(string repo, string remote, string branch, bool useRebase) Args += $"{remote} {branch}"; } + + public override bool Exec() + { + SSHKey = new Config(Context).Get($"remote.{_remote}.sshkey"); + return base.Exec(); + } + + private readonly string _remote; } } diff --git a/src/Commands/Push.cs b/src/Commands/Push.cs index 8a5fe33c3..2ab13c431 100644 --- a/src/Commands/Push.cs +++ b/src/Commands/Push.cs @@ -6,7 +6,7 @@ public Push(string repo, string local, string remote, string remoteBranch, bool { WorkingDirectory = repo; Context = repo; - SSHKey = new Config(repo).Get($"remote.{remote}.sshkey"); + _remote = remote; Args = "push --progress --verbose "; if (withTags) @@ -25,7 +25,7 @@ public Push(string repo, string remote, string refname, bool isDelete) { WorkingDirectory = repo; Context = repo; - SSHKey = new Config(repo).Get($"remote.{remote}.sshkey"); + _remote = remote; Args = "push "; if (isDelete) @@ -33,5 +33,13 @@ public Push(string repo, string remote, string refname, bool isDelete) Args += $"{remote} {refname}"; } + + public override bool Exec() + { + SSHKey = new Config(Context).Get($"remote.{_remote}.sshkey"); + return base.Exec(); + } + + private readonly string _remote; } } diff --git a/src/ViewModels/AIAssistant.cs b/src/ViewModels/AIAssistant.cs index 8756a30b0..0de380980 100644 --- a/src/ViewModels/AIAssistant.cs +++ b/src/ViewModels/AIAssistant.cs @@ -30,8 +30,6 @@ public AIAssistant(Repository repo, Models.OpenAIService service, List(); + } + public void Load() + { Task.Run(() => { var collect = new Commands.QueryAssumeUnchangedFiles(_repo.FullPath).Result(); diff --git a/src/ViewModels/BranchCompare.cs b/src/ViewModels/BranchCompare.cs index 600ae1b63..fde4cd960 100644 --- a/src/ViewModels/BranchCompare.cs +++ b/src/ViewModels/BranchCompare.cs @@ -80,8 +80,6 @@ public BranchCompare(string repo, Models.Branch baseBranch, Models.Branch toBran _repo = repo; _based = baseBranch; _to = toBranch; - - Refresh(); } public void NavigateTo(string commitSHA) @@ -176,7 +174,7 @@ public ContextMenu CreateChangeContextMenu() return menu; } - private void Refresh() + public void Refresh() { Task.Run(() => { diff --git a/src/ViewModels/Clone.cs b/src/ViewModels/Clone.cs index 6db6902a8..74584a28f 100644 --- a/src/ViewModels/Clone.cs +++ b/src/ViewModels/Clone.cs @@ -67,7 +67,10 @@ public Clone(string pageId) _parentFolder = activeWorkspace?.DefaultCloneDir; if (string.IsNullOrEmpty(ParentFolder)) _parentFolder = Preferences.Instance.GitDefaultCloneDir; + } + public void Load() + { Task.Run(async () => { try diff --git a/src/ViewModels/Conflict.cs b/src/ViewModels/Conflict.cs index bf93b5bc6..12a082751 100644 --- a/src/ViewModels/Conflict.cs +++ b/src/ViewModels/Conflict.cs @@ -15,11 +15,11 @@ public ConflictSourceBranch(string name, string head, Models.Commit revision) Revision = revision; } - public ConflictSourceBranch(Repository repo, Models.Branch branch) + public ConflictSourceBranch(Models.Branch branch, Models.Commit revision) { Name = branch.Name; Head = branch.Head; - Revision = new Commands.QuerySingleCommit(repo.FullPath, branch.Head).Result() ?? new Models.Commit() { SHA = branch.Head }; + Revision = revision ?? new Models.Commit() { SHA = branch.Head }; } } @@ -61,25 +61,31 @@ public bool CanUseExternalMergeTool public Conflict(Repository repo, WorkingCopy wc, Models.Change change) { + _repo = repo; _wc = wc; _change = change; + } - var isSubmodule = repo.Submodules.Find(x => x.Path.Equals(change.Path, StringComparison.Ordinal)) != null; + public void Load() + { + var isSubmodule = _repo.Submodules.Find(x => x.Path.Equals(_change.Path, StringComparison.Ordinal)) != null; if (!isSubmodule && (_change.ConflictReason == Models.ConflictReason.BothAdded || _change.ConflictReason == Models.ConflictReason.BothModified)) { CanUseExternalMergeTool = true; - IsResolved = new Commands.IsConflictResolved(repo.FullPath, change).Result(); + IsResolved = new Commands.IsConflictResolved(_repo.FullPath, _change).Result(); } - var context = wc.InProgressContext; + var context = _wc.InProgressContext; + var revision = new Commands.QuerySingleCommit(_repo.FullPath, _repo.CurrentBranch.Head).Result(); + var mine = new ConflictSourceBranch(_repo.CurrentBranch, revision); if (context is CherryPickInProgress cherryPick) { Theirs = cherryPick.Head; - Mine = new ConflictSourceBranch(repo, repo.CurrentBranch); + Mine = mine; } else if (context is RebaseInProgress rebase) { - var b = repo.Branches.Find(x => x.IsLocal && x.Name == rebase.HeadName); + 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 @@ -90,17 +96,17 @@ public Conflict(Repository repo, WorkingCopy wc, Models.Change change) else if (context is RevertInProgress revert) { Theirs = revert.Head; - Mine = new ConflictSourceBranch(repo, repo.CurrentBranch); + Mine = mine; } else if (context is MergeInProgress merge) { Theirs = merge.Source; - Mine = new ConflictSourceBranch(repo, repo.CurrentBranch); + Mine = mine; } else { Theirs = "Stash or Patch"; - Mine = new ConflictSourceBranch(repo, repo.CurrentBranch); + Mine = mine; } } @@ -119,6 +125,7 @@ public void OpenExternalMergeTool() _wc.UseExternalMergeTool(_change); } + private readonly Repository _repo; private WorkingCopy _wc = null; private Models.Change _change = null; } diff --git a/src/ViewModels/CreateTag.cs b/src/ViewModels/CreateTag.cs index d3cd512bc..c57a925f5 100644 --- a/src/ViewModels/CreateTag.cs +++ b/src/ViewModels/CreateTag.cs @@ -51,7 +51,6 @@ public CreateTag(Repository repo, Models.Branch branch) _basedOn = branch.Head; BasedOn = branch; - SignTag = new Commands.Config(repo.FullPath).Get("tag.gpgsign").Equals("true", StringComparison.OrdinalIgnoreCase); } public CreateTag(Repository repo, Models.Commit commit) @@ -60,7 +59,11 @@ public CreateTag(Repository repo, Models.Commit commit) _basedOn = commit.SHA; BasedOn = commit; - SignTag = new Commands.Config(repo.FullPath).Get("tag.gpgsign").Equals("true", StringComparison.OrdinalIgnoreCase); + } + + public void Load() + { + SignTag = new Commands.Config(_repo.FullPath).Get("tag.gpgsign").Equals("true", StringComparison.OrdinalIgnoreCase); } public static ValidationResult ValidateTagName(string name, ValidationContext ctx) diff --git a/src/ViewModels/EditRemote.cs b/src/ViewModels/EditRemote.cs index 763c8ce1e..fede98993 100644 --- a/src/ViewModels/EditRemote.cs +++ b/src/ViewModels/EditRemote.cs @@ -51,10 +51,13 @@ public EditRemote(Repository repo, Models.Remote remote) _name = remote.Name; _url = remote.URL; _useSSH = Models.Remote.IsSSH(remote.URL); + } + public void Load() + { if (_useSSH) { - SSHKey = new Commands.Config(repo.FullPath).Get($"remote.{remote.Name}.sshkey"); + SSHKey = new Commands.Config(_repo.FullPath).Get($"remote.{_remote.Name}.sshkey"); } } diff --git a/src/ViewModels/FileHistories.cs b/src/ViewModels/FileHistories.cs index f7a295dcb..decc9606a 100644 --- a/src/ViewModels/FileHistories.cs +++ b/src/ViewModels/FileHistories.cs @@ -34,15 +34,20 @@ public object ViewContent set => SetProperty(ref _viewContent, value); } - public FileHistoriesSingleRevision(Repository repo, string file, Models.Commit revision, bool prevIsDiffMode) + public static FileHistoriesSingleRevision Create(Repository repo, string file, Models.Commit revision, bool prevIsDiffMode) + { + var obj = new FileHistoriesSingleRevision(repo, file, revision, prevIsDiffMode); + obj.RefreshViewContent(); + return obj; + } + + private FileHistoriesSingleRevision(Repository repo, string file, Models.Commit revision, bool prevIsDiffMode) { _repo = repo; _file = file; _revision = revision; _isDiffMode = prevIsDiffMode; _viewContent = null; - - RefreshViewContent(); } public Task ResetToSelectedRevision() @@ -188,13 +193,19 @@ public DiffContext ViewContent set => SetProperty(ref _viewContent, value); } - public FileHistoriesCompareRevisions(Repository repo, string file, Models.Commit start, Models.Commit end) + public static FileHistoriesCompareRevisions Create(Repository repo, string file, Models.Commit start, Models.Commit end) + { + var obj = new FileHistoriesCompareRevisions(repo, file, start, end); + obj.RefreshViewContent(); + return obj; + } + + private FileHistoriesCompareRevisions(Repository repo, string file, Models.Commit start, Models.Commit end) { _repo = repo; _file = file; _startPoint = start; _endPoint = end; - RefreshViewContent(); } public void Swap() @@ -275,11 +286,16 @@ public FileHistories(Repository repo, string file, string commit = null) Title = file; _repo = repo; + _file = file; + _commit = commit; + } + public void Load() + { Task.Run(() => { - var based = commit ?? string.Empty; - var commits = new Commands.QueryCommits(_repo.FullPath, $"--date-order -n 10000 {based} -- \"{file}\"", false).Result(); + var based = _commit ?? string.Empty; + var commits = new Commands.QueryCommits(_repo.FullPath, $"--date-order -n 10000 {based} -- \"{_file}\"", false).Result(); Dispatcher.UIThread.Invoke(() => { IsLoading = false; @@ -296,8 +312,8 @@ public FileHistories(Repository repo, string file, string commit = null) ViewContent = SelectedCommits.Count switch { - 1 => new FileHistoriesSingleRevision(_repo, file, SelectedCommits[0], _prevIsDiffMode), - 2 => new FileHistoriesCompareRevisions(_repo, file, SelectedCommits[0], SelectedCommits[1]), + 1 => FileHistoriesSingleRevision.Create(_repo, _file, SelectedCommits[0], _prevIsDiffMode), + 2 => FileHistoriesCompareRevisions.Create(_repo, _file, SelectedCommits[0], SelectedCommits[1]), _ => SelectedCommits.Count, }; }; @@ -320,6 +336,8 @@ public string GetCommitFullMessage(Models.Commit commit) } private readonly Repository _repo = null; + private readonly string _file; + private readonly string _commit; private bool _isLoading = true; private bool _prevIsDiffMode = true; private List _commits = null; diff --git a/src/ViewModels/InProgressContexts.cs b/src/ViewModels/InProgressContexts.cs index d26e50c97..78e545fed 100644 --- a/src/ViewModels/InProgressContexts.cs +++ b/src/ViewModels/InProgressContexts.cs @@ -71,10 +71,16 @@ public string HeadName get => GetFriendlyNameOfCommit(Head); } - public CherryPickInProgress(Repository repo) : base(repo.FullPath, "cherry-pick") + public static CherryPickInProgress Create(Repository repo) { + var ipc = new CherryPickInProgress(repo); var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "CHERRY_PICK_HEAD")).Trim(); - Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).Result() ?? new Models.Commit() { SHA = headSHA }; + ipc.Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).Result() ?? new Models.Commit() { SHA = headSHA }; + return ipc; + } + + private CherryPickInProgress(Repository repo) : base(repo.FullPath, "cherry-pick") + { } } @@ -103,24 +109,30 @@ public Models.Commit Onto private set; } - public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase") + public static RebaseInProgress Create(Repository repo) { - HeadName = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "head-name")).Trim(); - if (HeadName.StartsWith("refs/heads/")) - HeadName = HeadName.Substring(11); - else if (HeadName.StartsWith("refs/tags/")) - HeadName = HeadName.Substring(10); + var ipc = new RebaseInProgress(repo); + ipc.HeadName = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "head-name")).Trim(); + if (ipc.HeadName.StartsWith("refs/heads/")) + ipc.HeadName = ipc.HeadName.Substring(11); + else if (ipc.HeadName.StartsWith("refs/tags/")) + ipc.HeadName = ipc.HeadName.Substring(10); var stoppedSHAPath = Path.Combine(repo.GitDir, "rebase-merge", "stopped-sha"); var stoppedSHA = File.Exists(stoppedSHAPath) ? File.ReadAllText(stoppedSHAPath).Trim() - : new Commands.QueryRevisionByRefName(repo.FullPath, HeadName).Result(); + : new Commands.QueryRevisionByRefName(repo.FullPath, ipc.HeadName).Result(); if (!string.IsNullOrEmpty(stoppedSHA)) - StoppedAt = new Commands.QuerySingleCommit(repo.FullPath, stoppedSHA).Result() ?? new Models.Commit() { SHA = stoppedSHA }; + ipc.StoppedAt = new Commands.QuerySingleCommit(repo.FullPath, stoppedSHA).Result() ?? new Models.Commit() { SHA = stoppedSHA }; var ontoSHA = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "onto")).Trim(); - Onto = new Commands.QuerySingleCommit(repo.FullPath, ontoSHA).Result() ?? new Models.Commit() { SHA = ontoSHA }; + ipc.Onto = new Commands.QuerySingleCommit(repo.FullPath, ontoSHA).Result() ?? new Models.Commit() { SHA = ontoSHA }; + return ipc; + } + + private RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase") + { } public override bool Continue() @@ -143,10 +155,16 @@ public Models.Commit Head private set; } - public RevertInProgress(Repository repo) : base(repo.FullPath, "revert") + public static RevertInProgress Create(Repository repo) { + var ipc = new RevertInProgress(repo); var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "REVERT_HEAD")).Trim(); - Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).Result() ?? new Models.Commit() { SHA = headSHA }; + ipc.Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).Result() ?? new Models.Commit() { SHA = headSHA }; + return ipc; + } + + private RevertInProgress(Repository repo) : base(repo.FullPath, "revert") + { } } @@ -169,12 +187,18 @@ public string SourceName get => GetFriendlyNameOfCommit(Source); } - public MergeInProgress(Repository repo) : base(repo.FullPath, "merge") + public static MergeInProgress Create(Repository repo) { - Current = Commands.Branch.ShowCurrent(repo.FullPath); + var ipc = new MergeInProgress(repo); + ipc.Current = Commands.Branch.ShowCurrent(repo.FullPath); var sourceSHA = File.ReadAllText(Path.Combine(repo.GitDir, "MERGE_HEAD")).Trim(); - Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).Result() ?? new Models.Commit() { SHA = sourceSHA }; + ipc.Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).Result() ?? new Models.Commit() { SHA = sourceSHA }; + return ipc; + } + + private MergeInProgress(Repository repo) : base(repo.FullPath, "merge") + { } public override bool Skip() diff --git a/src/ViewModels/InteractiveRebase.cs b/src/ViewModels/InteractiveRebase.cs index 40b2dcc3b..eb5b54f3c 100644 --- a/src/ViewModels/InteractiveRebase.cs +++ b/src/ViewModels/InteractiveRebase.cs @@ -123,17 +123,19 @@ public CommitDetail DetailContext public InteractiveRebase(Repository repo, Models.Branch current, Models.Commit on) { - var repoPath = repo.FullPath; _repo = repo; Current = current; On = on; IsLoading = true; DetailContext = new CommitDetail(repo, false); + } + public void Load() + { Task.Run(() => { - var commits = new Commands.QueryCommitsForInteractiveRebase(repoPath, on.SHA).Result(); + var commits = new Commands.QueryCommitsForInteractiveRebase(_repo.FullPath, On.SHA).Result(); var list = new List(); for (var i = 0; i < commits.Count; i++) diff --git a/src/ViewModels/LFSLocks.cs b/src/ViewModels/LFSLocks.cs index 8d8ad0378..248506db5 100644 --- a/src/ViewModels/LFSLocks.cs +++ b/src/ViewModels/LFSLocks.cs @@ -41,7 +41,11 @@ public LFSLocks(Repository repo, string remote) { _repo = repo; _remote = remote; - _userName = new Commands.Config(repo.FullPath).Get("user.name"); + } + + public void Load() + { + _userName = new Commands.Config(_repo.FullPath).Get("user.name"); HasValidUserName = !string.IsNullOrEmpty(_userName); diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 05afbf3f1..2c4e581c1 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -53,13 +53,18 @@ public IDisposable Switcher public Launcher(string startupRepo) { + _startupRepo = startupRepo; _ignoreIndexChange = true; Pages = new AvaloniaList(); + } + + public void Load() + { AddNewTab(); var pref = Preferences.Instance; - if (string.IsNullOrEmpty(startupRepo)) + if (string.IsNullOrEmpty(_startupRepo)) { ActiveWorkspace = pref.GetActiveWorkspace(); @@ -96,13 +101,13 @@ public Launcher(string startupRepo) foreach (var w in pref.Workspaces) w.IsActive = false; - var test = new Commands.QueryRepositoryRootPath(startupRepo).ReadToEnd(); + var test = new Commands.QueryRepositoryRootPath(_startupRepo).ReadToEnd(); if (!test.IsSuccess || string.IsNullOrEmpty(test.StdOut)) { Pages[0].Notifications.Add(new Models.Notification { IsError = true, - Message = $"Given path: '{startupRepo}' is NOT a valid repository!" + Message = $"Given path: '{_startupRepo}' is NOT a valid repository!" }); } else @@ -607,6 +612,7 @@ private void UpdateTitle() } } + private readonly string _startupRepo; private Workspace _activeWorkspace = null; private LauncherPage _activePage = null; private bool _ignoreIndexChange = false; diff --git a/src/ViewModels/Merge.cs b/src/ViewModels/Merge.cs index b00db6b69..27cbf72d9 100644 --- a/src/ViewModels/Merge.cs +++ b/src/ViewModels/Merge.cs @@ -33,7 +33,9 @@ public Merge(Repository repo, Models.Branch source, string into, bool forceFastF Source = source; Into = into; - Mode = forceFastForward ? Models.MergeMode.FastForward : AutoSelectMergeMode(); + + if (forceFastForward) + Mode = Models.MergeMode.FastForward; } public Merge(Repository repo, Models.Commit source, string into) @@ -43,7 +45,6 @@ public Merge(Repository repo, Models.Commit source, string into) Source = source; Into = into; - Mode = AutoSelectMergeMode(); } public Merge(Repository repo, Models.Tag source, string into) @@ -53,7 +54,12 @@ public Merge(Repository repo, Models.Tag source, string into) Source = source; Into = into; - Mode = AutoSelectMergeMode(); + } + + public void Load() + { + if (Mode == null) + Mode = AutoSelectMergeMode(); } public override Task Sure() diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index d69ff711c..a946de9cb 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -158,8 +158,11 @@ public RepositoryConfigure(Repository repo) if (!AvailableOpenAIServices.Contains(PreferredOpenAIService)) PreferredOpenAIService = "---"; + } - _cached = new Commands.Config(repo.FullPath).ListAll(); + public void Load() + { + _cached = new Commands.Config(_repo.FullPath).ListAll(); if (_cached.TryGetValue("user.name", out var name)) UserName = name; if (_cached.TryGetValue("user.email", out var email)) @@ -346,7 +349,7 @@ private void SetIfChanged(string key, string value, string defValue) } private readonly Repository _repo = null; - private readonly Dictionary _cached = null; + private Dictionary _cached = null; private string _httpProxy; private Models.CommitTemplate _selectedCommitTemplate = null; private Models.IssueTrackerRule _selectedIssueTrackerRule = null; diff --git a/src/ViewModels/RevisionCompare.cs b/src/ViewModels/RevisionCompare.cs index 573bac54c..bef28b5f4 100644 --- a/src/ViewModels/RevisionCompare.cs +++ b/src/ViewModels/RevisionCompare.cs @@ -76,8 +76,6 @@ public RevisionCompare(string repo, Models.Commit startPoint, Models.Commit endP _startPoint = (object)startPoint ?? new Models.Null(); _endPoint = (object)endPoint ?? new Models.Null(); CanSaveAsPatch = startPoint != null && endPoint != null; - - Task.Run(Refresh); } public void Dispose() @@ -212,7 +210,7 @@ private void RefreshVisible() } } - private void Refresh() + public void Refresh() { _changes = new Commands.CompareRevisions(_repo, GetSHA(_startPoint), GetSHA(_endPoint)).Result(); diff --git a/src/ViewModels/Reword.cs b/src/ViewModels/Reword.cs index 8517c1bff..a6ae20f51 100644 --- a/src/ViewModels/Reword.cs +++ b/src/ViewModels/Reword.cs @@ -21,11 +21,15 @@ public string Message public Reword(Repository repo, Models.Commit head) { _repo = repo; - _oldMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).Result(); - _message = _oldMessage; Head = head; } + public void Load() + { + _oldMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, Head.SHA).Result(); + _message = _oldMessage; + } + public override Task Sure() { if (string.Compare(_message, _oldMessage, StringComparison.Ordinal) == 0) @@ -49,7 +53,7 @@ public override Task Sure() } private readonly Repository _repo; - private readonly string _oldMessage; + private string _oldMessage; private string _message; } } diff --git a/src/ViewModels/Squash.cs b/src/ViewModels/Squash.cs index 9574beb06..e77fbb05f 100644 --- a/src/ViewModels/Squash.cs +++ b/src/ViewModels/Squash.cs @@ -20,8 +20,13 @@ public string Message public Squash(Repository repo, Models.Commit target, string shaToGetPreferMessage) { _repo = repo; - _message = new Commands.QueryCommitFullMessage(_repo.FullPath, shaToGetPreferMessage).Result(); Target = target; + _shaToGetPreferMessage = shaToGetPreferMessage; + } + + public void Load() + { + _message = new Commands.QueryCommitFullMessage(_repo.FullPath, _shaToGetPreferMessage).Result(); } public override Task Sure() @@ -66,5 +71,6 @@ public override Task Sure() private readonly Repository _repo; private string _message; + private readonly string _shaToGetPreferMessage; } } diff --git a/src/ViewModels/Statistics.cs b/src/ViewModels/Statistics.cs index 3a87607ec..13c2a8c0c 100644 --- a/src/ViewModels/Statistics.cs +++ b/src/ViewModels/Statistics.cs @@ -55,10 +55,15 @@ public IBrush SampleBrush } public Statistics(string repo) + { + _repo = repo; + } + + public void Load() { Task.Run(() => { - var result = new Commands.Statistics(repo, Preferences.Instance.MaxHistoryCommits).Result(); + var result = new Commands.Statistics(_repo, Preferences.Instance.MaxHistoryCommits).Result(); Dispatcher.UIThread.Invoke(() => { _data = result; @@ -84,6 +89,7 @@ private void RefreshReport() SelectedReport = report; } + private readonly string _repo; private bool _isLoading = true; private Models.Statistics _data = null; private Models.StatisticsReport _selectedReport = null; diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 6dbd4cdc6..8b2ed0a48 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -1746,11 +1746,11 @@ private void UpdateInProgressState() if (File.Exists(Path.Combine(_repo.GitDir, "CHERRY_PICK_HEAD"))) { - InProgressContext = new CherryPickInProgress(_repo); + InProgressContext = CherryPickInProgress.Create(_repo); } else if (Directory.Exists(Path.Combine(_repo.GitDir, "rebase-merge")) || Directory.Exists(Path.Combine(_repo.GitDir, "rebase-apply"))) { - var rebasing = new RebaseInProgress(_repo); + var rebasing = RebaseInProgress.Create(_repo); InProgressContext = rebasing; if (string.IsNullOrEmpty(_commitMessage)) @@ -1764,11 +1764,11 @@ private void UpdateInProgressState() } else if (File.Exists(Path.Combine(_repo.GitDir, "REVERT_HEAD"))) { - InProgressContext = new RevertInProgress(_repo); + InProgressContext = RevertInProgress.Create(_repo); } else if (File.Exists(Path.Combine(_repo.GitDir, "MERGE_HEAD"))) { - InProgressContext = new MergeInProgress(_repo); + InProgressContext = MergeInProgress.Create(_repo); } else { diff --git a/src/Views/AIAssistant.axaml.cs b/src/Views/AIAssistant.axaml.cs index f865cabef..1ad5e2296 100644 --- a/src/Views/AIAssistant.axaml.cs +++ b/src/Views/AIAssistant.axaml.cs @@ -118,6 +118,13 @@ public AIAssistant() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.AIAssistant vm) + vm.Gen(); + } + protected override void OnClosing(WindowClosingEventArgs e) { base.OnClosing(e); diff --git a/src/Views/AssumeUnchangedManager.axaml.cs b/src/Views/AssumeUnchangedManager.axaml.cs index a0a5a3529..916054a93 100644 --- a/src/Views/AssumeUnchangedManager.axaml.cs +++ b/src/Views/AssumeUnchangedManager.axaml.cs @@ -10,6 +10,13 @@ public AssumeUnchangedManager() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.AssumeUnchangedManager vm) + vm.Load(); + } + private void OnRemoveButtonClicked(object sender, RoutedEventArgs e) { if (DataContext is ViewModels.AssumeUnchangedManager vm && sender is Button button) diff --git a/src/Views/BranchCompare.axaml.cs b/src/Views/BranchCompare.axaml.cs index ca90a180f..1894b1a13 100644 --- a/src/Views/BranchCompare.axaml.cs +++ b/src/Views/BranchCompare.axaml.cs @@ -1,5 +1,6 @@ using Avalonia.Controls; using Avalonia.Input; +using Avalonia.Interactivity; namespace SourceGit.Views { @@ -10,6 +11,13 @@ public BranchCompare() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.BranchCompare vm) + vm.Refresh(); + } + private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e) { if (DataContext is ViewModels.BranchCompare vm && sender is ChangeCollectionView view) diff --git a/src/Views/Clone.axaml.cs b/src/Views/Clone.axaml.cs index 9316721a1..ca2ef26e6 100644 --- a/src/Views/Clone.axaml.cs +++ b/src/Views/Clone.axaml.cs @@ -12,6 +12,13 @@ public Clone() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.Clone vm) + vm.Load(); + } + private async void SelectParentFolder(object _, RoutedEventArgs e) { var options = new FolderPickerOpenOptions() { AllowMultiple = false }; diff --git a/src/Views/Conflict.axaml.cs b/src/Views/Conflict.axaml.cs index 6121b5c8c..ca62b2651 100644 --- a/src/Views/Conflict.axaml.cs +++ b/src/Views/Conflict.axaml.cs @@ -1,5 +1,6 @@ using Avalonia.Controls; using Avalonia.Input; +using Avalonia.Interactivity; using Avalonia.VisualTree; namespace SourceGit.Views @@ -11,6 +12,13 @@ public Conflict() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.Conflict vm) + vm.Load(); + } + private void OnPressedSHA(object sender, PointerPressedEventArgs e) { var repoView = this.FindAncestorOfType(); diff --git a/src/Views/CreateTag.axaml.cs b/src/Views/CreateTag.axaml.cs index 153c06d78..c732a5a68 100644 --- a/src/Views/CreateTag.axaml.cs +++ b/src/Views/CreateTag.axaml.cs @@ -1,4 +1,5 @@ using Avalonia.Controls; +using Avalonia.Interactivity; namespace SourceGit.Views { @@ -8,5 +9,12 @@ public CreateTag() { InitializeComponent(); } + + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.CreateTag vm) + vm.Load(); + } } } diff --git a/src/Views/EditRemote.axaml.cs b/src/Views/EditRemote.axaml.cs index 7d88704e5..24dc1aaae 100644 --- a/src/Views/EditRemote.axaml.cs +++ b/src/Views/EditRemote.axaml.cs @@ -11,6 +11,13 @@ public EditRemote() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.EditRemote vm) + vm.Load(); + } + private async void SelectSSHKey(object _, RoutedEventArgs e) { var toplevel = TopLevel.GetTopLevel(this); diff --git a/src/Views/FileHistories.axaml.cs b/src/Views/FileHistories.axaml.cs index 6a67d1204..2e8d2e71f 100644 --- a/src/Views/FileHistories.axaml.cs +++ b/src/Views/FileHistories.axaml.cs @@ -14,6 +14,13 @@ public FileHistories() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.FileHistories vm) + vm.Load(); + } + private void OnPressCommitSHA(object sender, PointerPressedEventArgs e) { if (sender is TextBlock { DataContext: Models.Commit commit } && diff --git a/src/Views/InteractiveRebase.axaml.cs b/src/Views/InteractiveRebase.axaml.cs index e40ce276a..540fbecf8 100644 --- a/src/Views/InteractiveRebase.axaml.cs +++ b/src/Views/InteractiveRebase.axaml.cs @@ -10,6 +10,13 @@ public class InteractiveRebaseListBox : ListBox { protected override Type StyleKeyOverride => typeof(ListBox); + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.InteractiveRebase vm) + vm.Load(); + } + /// /// Prevent ListBox handle the arrow keys. /// @@ -71,6 +78,13 @@ public InteractiveRebase() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.InteractiveRebase vm) + vm.Load(); + } + private void CloseWindow(object _1, RoutedEventArgs _2) { Close(); diff --git a/src/Views/LFSLocks.axaml.cs b/src/Views/LFSLocks.axaml.cs index 695341f42..1f7ddc37f 100644 --- a/src/Views/LFSLocks.axaml.cs +++ b/src/Views/LFSLocks.axaml.cs @@ -10,6 +10,13 @@ public LFSLocks() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.AssumeUnchangedManager vm) + vm.Load(); + } + private void OnUnlockButtonClicked(object sender, RoutedEventArgs e) { if (DataContext is ViewModels.LFSLocks vm && sender is Button button) diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index d4ecb3c9d..67f22eb62 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -85,6 +85,13 @@ public Launcher() WindowStartupLocation = WindowStartupLocation.CenterScreen; } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.Launcher vm) + vm.Load(); + } + public void BringToTop() { if (WindowState == WindowState.Minimized) diff --git a/src/Views/Merge.axaml.cs b/src/Views/Merge.axaml.cs index 8fecbbace..409972c7d 100644 --- a/src/Views/Merge.axaml.cs +++ b/src/Views/Merge.axaml.cs @@ -1,4 +1,5 @@ using Avalonia.Controls; +using Avalonia.Interactivity; namespace SourceGit.Views { @@ -8,5 +9,12 @@ public Merge() { InitializeComponent(); } + + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.Merge vm) + vm.Load(); + } } } diff --git a/src/Views/RepositoryConfigure.axaml.cs b/src/Views/RepositoryConfigure.axaml.cs index 47895ba1b..e04033bc7 100644 --- a/src/Views/RepositoryConfigure.axaml.cs +++ b/src/Views/RepositoryConfigure.axaml.cs @@ -12,6 +12,13 @@ public RepositoryConfigure() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.RepositoryConfigure vm) + vm.Load(); + } + protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); diff --git a/src/Views/RevisionCompare.axaml.cs b/src/Views/RevisionCompare.axaml.cs index 2c5482409..3565e233a 100644 --- a/src/Views/RevisionCompare.axaml.cs +++ b/src/Views/RevisionCompare.axaml.cs @@ -12,6 +12,13 @@ public RevisionCompare() InitializeComponent(); } + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.RevisionCompare vm) + vm.Refresh(); + } + private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e) { if (DataContext is ViewModels.RevisionCompare vm && sender is ChangeCollectionView view) diff --git a/src/Views/Reword.axaml.cs b/src/Views/Reword.axaml.cs index f05f708af..0eeec71e4 100644 --- a/src/Views/Reword.axaml.cs +++ b/src/Views/Reword.axaml.cs @@ -1,4 +1,5 @@ using Avalonia.Controls; +using Avalonia.Interactivity; namespace SourceGit.Views { @@ -8,5 +9,12 @@ public Reword() { InitializeComponent(); } + + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.Reword vm) + vm.Load(); + } } } diff --git a/src/Views/Squash.axaml.cs b/src/Views/Squash.axaml.cs index 552faec25..9b2ed11da 100644 --- a/src/Views/Squash.axaml.cs +++ b/src/Views/Squash.axaml.cs @@ -1,4 +1,5 @@ using Avalonia.Controls; +using Avalonia.Interactivity; namespace SourceGit.Views { @@ -8,5 +9,12 @@ public Squash() { InitializeComponent(); } + + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.Squash vm) + vm.Load(); + } } } diff --git a/src/Views/Statistics.axaml.cs b/src/Views/Statistics.axaml.cs index 4ebf90166..4c8e4bc16 100644 --- a/src/Views/Statistics.axaml.cs +++ b/src/Views/Statistics.axaml.cs @@ -1,3 +1,5 @@ +using Avalonia.Interactivity; + namespace SourceGit.Views { public partial class Statistics : ChromelessWindow @@ -6,5 +8,12 @@ public Statistics() { InitializeComponent(); } + + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + if (DataContext is ViewModels.Statistics vm) + vm.Load(); + } } }