mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
refactor: use view locator instead of creating views manually in viewmodels (#1213)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
413669741d
commit
5fd074a9b6
60 changed files with 52 additions and 140 deletions
|
@ -47,7 +47,6 @@ namespace SourceGit.ViewModels
|
|||
public AddRemote(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
View = new Views.AddRemote() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateRemoteName(string name, ValidationContext ctx)
|
||||
|
|
|
@ -31,7 +31,6 @@ namespace SourceGit.ViewModels
|
|||
public AddSubmodule(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
View = new Views.AddSubmodule() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateURL(string url, ValidationContext ctx)
|
||||
|
|
|
@ -78,8 +78,6 @@ namespace SourceGit.ViewModels
|
|||
SelectedTrackingBranch = RemoteBranches[0];
|
||||
else
|
||||
SelectedTrackingBranch = string.Empty;
|
||||
|
||||
View = new Views.AddWorktree() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateWorktreePath(string path, ValidationContext ctx)
|
||||
|
|
|
@ -31,7 +31,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
|
||||
SelectedWhiteSpaceMode = Models.ApplyWhiteSpaceMode.Supported[0];
|
||||
View = new Views.Apply() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidatePatchFile(string file, ValidationContext _)
|
||||
|
|
|
@ -26,7 +26,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
_repo = repo;
|
||||
Stash = stash;
|
||||
View = new Views.ApplyStash() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -25,7 +25,6 @@ namespace SourceGit.ViewModels
|
|||
_revision = branch.Head;
|
||||
_saveFile = $"archive-{Path.GetFileName(branch.Name)}.zip";
|
||||
BasedOn = branch;
|
||||
View = new Views.Archive() { DataContext = this };
|
||||
}
|
||||
|
||||
public Archive(Repository repo, Models.Commit commit)
|
||||
|
@ -34,7 +33,6 @@ namespace SourceGit.ViewModels
|
|||
_revision = commit.SHA;
|
||||
_saveFile = $"archive-{commit.SHA.Substring(0, 10)}.zip";
|
||||
BasedOn = commit;
|
||||
View = new Views.Archive() { DataContext = this };
|
||||
}
|
||||
|
||||
public Archive(Repository repo, Models.Tag tag)
|
||||
|
@ -43,7 +41,6 @@ namespace SourceGit.ViewModels
|
|||
_revision = tag.SHA;
|
||||
_saveFile = $"archive-{Path.GetFileName(tag.Name)}.zip";
|
||||
BasedOn = tag;
|
||||
View = new Views.Archive() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -20,7 +20,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
Branch = branch;
|
||||
DiscardLocalChanges = false;
|
||||
View = new Views.Checkout() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -20,7 +20,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
Commit = commit;
|
||||
DiscardLocalChanges = false;
|
||||
View = new Views.CheckoutCommit() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -50,7 +50,6 @@ namespace SourceGit.ViewModels
|
|||
MainlineForMergeCommit = 0;
|
||||
AppendSourceToMessage = true;
|
||||
AutoCommit = true;
|
||||
View = new Views.CherryPick() { DataContext = this };
|
||||
}
|
||||
|
||||
public CherryPick(Repository repo, Models.Commit merge, List<Models.Commit> parents)
|
||||
|
@ -62,7 +61,6 @@ namespace SourceGit.ViewModels
|
|||
MainlineForMergeCommit = 0;
|
||||
AppendSourceToMessage = true;
|
||||
AutoCommit = true;
|
||||
View = new Views.CherryPick() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace SourceGit.ViewModels
|
|||
public Cleanup(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
View = new Views.Cleanup() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace SourceGit.ViewModels
|
|||
public ClearStashes(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
View = new Views.ClearStashes() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -68,8 +68,6 @@ namespace SourceGit.ViewModels
|
|||
if (string.IsNullOrEmpty(ParentFolder))
|
||||
_parentFolder = Preferences.Instance.GitDefaultCloneDir;
|
||||
|
||||
View = new Views.Clone() { DataContext = this };
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
|
|
|
@ -48,7 +48,6 @@ namespace SourceGit.ViewModels
|
|||
|
||||
BasedOn = branch;
|
||||
DiscardLocalChanges = false;
|
||||
View = new Views.CreateBranch() { DataContext = this };
|
||||
}
|
||||
|
||||
public CreateBranch(Repository repo, Models.Commit commit)
|
||||
|
@ -58,7 +57,6 @@ namespace SourceGit.ViewModels
|
|||
|
||||
BasedOn = commit;
|
||||
DiscardLocalChanges = false;
|
||||
View = new Views.CreateBranch() { DataContext = this };
|
||||
}
|
||||
|
||||
public CreateBranch(Repository repo, Models.Tag tag)
|
||||
|
@ -68,7 +66,6 @@ namespace SourceGit.ViewModels
|
|||
|
||||
BasedOn = tag;
|
||||
DiscardLocalChanges = false;
|
||||
View = new Views.CreateBranch() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateBranchName(string name, ValidationContext ctx)
|
||||
|
@ -97,7 +94,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var succ = false;
|
||||
bool succ;
|
||||
if (CheckoutAfterCreated && !_repo.IsBare)
|
||||
{
|
||||
var changes = new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).Result();
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace SourceGit.ViewModels
|
|||
public CreateGroup(RepositoryNode parent)
|
||||
{
|
||||
_parent = parent;
|
||||
View = new Views.CreateGroup() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -52,7 +52,6 @@ namespace SourceGit.ViewModels
|
|||
|
||||
BasedOn = branch;
|
||||
SignTag = new Commands.Config(repo.FullPath).Get("tag.gpgsign").Equals("true", StringComparison.OrdinalIgnoreCase);
|
||||
View = new Views.CreateTag() { DataContext = this };
|
||||
}
|
||||
|
||||
public CreateTag(Repository repo, Models.Commit commit)
|
||||
|
@ -62,7 +61,6 @@ namespace SourceGit.ViewModels
|
|||
|
||||
BasedOn = commit;
|
||||
SignTag = new Commands.Config(repo.FullPath).Get("tag.gpgsign").Equals("true", StringComparison.OrdinalIgnoreCase);
|
||||
View = new Views.CreateTag() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateTagName(string name, ValidationContext ctx)
|
||||
|
|
|
@ -39,8 +39,6 @@ namespace SourceGit.ViewModels
|
|||
if (TrackingRemoteBranch != null)
|
||||
DeleteTrackingRemoteTip = new Views.NameHighlightedTextBlock("DeleteBranch.WithTrackingRemote", TrackingRemoteBranch.FriendlyName);
|
||||
}
|
||||
|
||||
View = new Views.DeleteBranch() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -15,7 +15,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
_isLocal = isLocal;
|
||||
Targets = branches;
|
||||
View = new Views.DeleteMultipleBranches() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -14,7 +14,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
_repo = repo;
|
||||
Remote = remote;
|
||||
View = new Views.DeleteRemote() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -6,23 +6,19 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
public RepositoryNode Node
|
||||
{
|
||||
get => _node;
|
||||
set => SetProperty(ref _node, value);
|
||||
get;
|
||||
}
|
||||
|
||||
public DeleteRepositoryNode(RepositoryNode node)
|
||||
{
|
||||
_node = node;
|
||||
View = new Views.DeleteRepositoryNode() { DataContext = this };
|
||||
Node = node;
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
{
|
||||
Preferences.Instance.RemoveNode(_node, true);
|
||||
Preferences.Instance.RemoveNode(Node, true);
|
||||
Welcome.Instance.Refresh();
|
||||
return null;
|
||||
}
|
||||
|
||||
private RepositoryNode _node = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
public class DeleteSubmodule : Popup
|
||||
{
|
||||
|
||||
public string Submodule
|
||||
{
|
||||
get;
|
||||
|
@ -15,7 +14,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
_repo = repo;
|
||||
Submodule = submodule;
|
||||
View = new Views.DeleteSubmodule() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -20,7 +20,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
_repo = repo;
|
||||
Target = tag;
|
||||
View = new Views.DeleteTag() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -40,9 +40,7 @@ namespace SourceGit.ViewModels
|
|||
public Discard(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
|
||||
Mode = new DiscardAllMode();
|
||||
View = new Views.Discard { DataContext = this };
|
||||
}
|
||||
|
||||
public Discard(Repository repo, List<Models.Change> changes)
|
||||
|
@ -56,8 +54,6 @@ namespace SourceGit.ViewModels
|
|||
Mode = new DiscardSingleFile() { Path = _changes[0].Path };
|
||||
else
|
||||
Mode = new DiscardMultipleFiles() { Count = _changes.Count };
|
||||
|
||||
View = new Views.Discard() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -4,13 +4,12 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
public class DropStash : Popup
|
||||
{
|
||||
public Models.Stash Stash { get; private set; }
|
||||
public Models.Stash Stash { get; }
|
||||
|
||||
public DropStash(Repository repo, Models.Stash stash)
|
||||
{
|
||||
_repo = repo;
|
||||
Stash = stash;
|
||||
View = new Views.DropStash() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -56,8 +56,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
SSHKey = new Commands.Config(repo.FullPath).Get($"remote.{remote.Name}.sshkey");
|
||||
}
|
||||
|
||||
View = new Views.EditRemote() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateRemoteName(string name, ValidationContext ctx)
|
||||
|
|
|
@ -37,8 +37,6 @@ namespace SourceGit.ViewModels
|
|||
_name = node.Name;
|
||||
_isRepository = node.IsRepository;
|
||||
_bookmark = node.Bookmark;
|
||||
|
||||
View = new Views.EditRepositoryNode() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace SourceGit.ViewModels
|
|||
public Models.CustomAction CustomAction
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public ExecuteCustomAction(Repository repo, Models.CustomAction action)
|
||||
|
@ -16,7 +15,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
_args = action.Arguments.Replace("${REPO}", GetWorkdir());
|
||||
CustomAction = action;
|
||||
View = new Views.ExecuteCustomAction() { DataContext = this };
|
||||
}
|
||||
|
||||
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Branch branch)
|
||||
|
@ -24,7 +22,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
_args = action.Arguments.Replace("${REPO}", GetWorkdir()).Replace("${BRANCH}", branch.FriendlyName);
|
||||
CustomAction = action;
|
||||
View = new Views.ExecuteCustomAction() { DataContext = this };
|
||||
}
|
||||
|
||||
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Commit commit)
|
||||
|
@ -32,7 +29,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
_args = action.Arguments.Replace("${REPO}", GetWorkdir()).Replace("${SHA}", commit.SHA);
|
||||
CustomAction = action;
|
||||
View = new Views.ExecuteCustomAction() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
@ -58,6 +54,6 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
private readonly Repository _repo = null;
|
||||
private string _args = string.Empty;
|
||||
private readonly string _args;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,11 @@ namespace SourceGit.ViewModels
|
|||
public Models.Branch Local
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public Models.Branch To
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public FastForwardWithoutCheckout(Repository repo, Models.Branch local, Models.Branch upstream)
|
||||
|
@ -21,7 +19,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
Local = local;
|
||||
To = upstream;
|
||||
View = new Views.FastForwardWithoutCheckout() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -55,8 +55,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
SelectedRemote = _repo.Remotes[0];
|
||||
}
|
||||
|
||||
View = new Views.Fetch() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -7,13 +7,11 @@ namespace SourceGit.ViewModels
|
|||
public Models.Branch Local
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public Models.Branch Upstream
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public FetchInto(Repository repo, Models.Branch local, Models.Branch upstream)
|
||||
|
@ -21,7 +19,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
Local = local;
|
||||
Upstream = upstream;
|
||||
View = new Views.FetchInto() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -7,8 +7,7 @@ namespace SourceGit.ViewModels
|
|||
public Models.Branch Branch
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = null;
|
||||
}
|
||||
|
||||
public bool IsFeature => _type == "feature";
|
||||
public bool IsRelease => _type == "release";
|
||||
|
@ -25,9 +24,7 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
_type = type;
|
||||
_prefix = prefix;
|
||||
|
||||
Branch = branch;
|
||||
View = new Views.GitFlowFinish() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -28,8 +28,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
_type = type;
|
||||
_prefix = Commands.GitFlow.GetPrefix(repo.FullPath, type);
|
||||
|
||||
View = new Views.GitFlowStart() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateBranchName(string name, ValidationContext ctx)
|
||||
|
|
|
@ -21,9 +21,7 @@ namespace SourceGit.ViewModels
|
|||
_pageId = pageId;
|
||||
_targetPath = path;
|
||||
_parentNode = parent;
|
||||
|
||||
Reason = string.IsNullOrEmpty(reason) ? "Invalid repository detected!" : reason;
|
||||
View = new Views.Init() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
@ -51,8 +49,8 @@ namespace SourceGit.ViewModels
|
|||
});
|
||||
}
|
||||
|
||||
private string _pageId = null;
|
||||
private readonly string _pageId = null;
|
||||
private string _targetPath = null;
|
||||
private RepositoryNode _parentNode = null;
|
||||
private readonly RepositoryNode _parentNode = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,8 +78,6 @@ namespace SourceGit.ViewModels
|
|||
_master = localBranches[0];
|
||||
else
|
||||
_master = "master";
|
||||
|
||||
View = new Views.InitGitFlow() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateBaseBranch(string _, ValidationContext ctx)
|
||||
|
|
|
@ -17,7 +17,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
_repo = repo;
|
||||
SelectedRemote = _repo.Remotes[0];
|
||||
View = new Views.LFSFetch() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace SourceGit.ViewModels
|
|||
public LFSPrune(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
View = new Views.LFSPrune() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -17,7 +17,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
_repo = repo;
|
||||
SelectedRemote = _repo.Remotes[0];
|
||||
View = new Views.LFSPull() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -17,7 +17,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
_repo = repo;
|
||||
SelectedRemote = _repo.Remotes[0];
|
||||
View = new Views.LFSPush() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -21,7 +21,6 @@ namespace SourceGit.ViewModels
|
|||
public LFSTrackCustomPattern(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
View = new Views.LFSTrackCustomPattern() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -29,7 +29,6 @@ namespace SourceGit.ViewModels
|
|||
Source = source;
|
||||
Into = into;
|
||||
Mode = forceFastForward ? Models.MergeMode.Supported[1] : AutoSelectMergeMode();
|
||||
View = new Views.Merge() { DataContext = this };
|
||||
}
|
||||
|
||||
public Merge(Repository repo, Models.Commit source, string into)
|
||||
|
@ -40,7 +39,6 @@ namespace SourceGit.ViewModels
|
|||
Source = source;
|
||||
Into = into;
|
||||
Mode = AutoSelectMergeMode();
|
||||
View = new Views.Merge() { DataContext = this };
|
||||
}
|
||||
|
||||
public Merge(Repository repo, Models.Tag source, string into)
|
||||
|
@ -51,7 +49,6 @@ namespace SourceGit.ViewModels
|
|||
Source = source;
|
||||
Into = into;
|
||||
Mode = AutoSelectMergeMode();
|
||||
View = new Views.Merge() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
@ -99,6 +96,6 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
private readonly Repository _repo = null;
|
||||
private readonly string _sourceName = string.Empty;
|
||||
private readonly string _sourceName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace SourceGit.ViewModels
|
|||
public List<object> Targets
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = [];
|
||||
|
||||
public bool AutoCommit
|
||||
|
@ -29,7 +28,6 @@ namespace SourceGit.ViewModels
|
|||
Targets.AddRange(commits);
|
||||
AutoCommit = true;
|
||||
Strategy = Models.MergeStrategy.ForMultiple[0];
|
||||
View = new Views.MergeMultiple() { DataContext = this };
|
||||
}
|
||||
|
||||
public MergeMultiple(Repository repo, List<Models.Branch> branches)
|
||||
|
@ -38,7 +36,6 @@ namespace SourceGit.ViewModels
|
|||
Targets.AddRange(branches);
|
||||
AutoCommit = true;
|
||||
Strategy = Models.MergeStrategy.ForMultiple[0];
|
||||
View = new Views.MergeMultiple() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -9,13 +9,11 @@ namespace SourceGit.ViewModels
|
|||
public RepositoryNode Target
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = null;
|
||||
|
||||
public List<RepositoryNode> Rows
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = [];
|
||||
|
||||
public RepositoryNode Selected
|
||||
|
@ -34,8 +32,6 @@ namespace SourceGit.ViewModels
|
|||
Id = Guid.NewGuid().ToString()
|
||||
});
|
||||
MakeRows(Preferences.Instance.RepositoryNodes, 1);
|
||||
|
||||
View = new Views.MoveRepositoryNode() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -10,12 +10,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
public class Popup : ObservableValidator
|
||||
{
|
||||
public object View
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool InProgress
|
||||
{
|
||||
get => _inProgress;
|
||||
|
|
|
@ -7,14 +7,12 @@ namespace SourceGit.ViewModels
|
|||
public Models.Remote Remote
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public PruneRemote(Repository repo, Models.Remote remote)
|
||||
{
|
||||
_repo = repo;
|
||||
Remote = remote;
|
||||
View = new Views.PruneRemote() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace SourceGit.ViewModels
|
|||
public PruneWorktrees(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
View = new Views.PruneWorktrees() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
@ -27,6 +26,6 @@ namespace SourceGit.ViewModels
|
|||
});
|
||||
}
|
||||
|
||||
private Repository _repo = null;
|
||||
private readonly Repository _repo = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
} = false;
|
||||
|
||||
public bool UseRebase
|
||||
{
|
||||
|
@ -110,8 +110,6 @@ namespace SourceGit.ViewModels
|
|||
PostRemoteSelected();
|
||||
HasSpecifiedRemoteBranch = false;
|
||||
}
|
||||
|
||||
View = new Views.Pull() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -148,8 +148,6 @@ namespace SourceGit.ViewModels
|
|||
|
||||
// Auto select preferred remote branch.
|
||||
AutoSelectBranchByRemote();
|
||||
|
||||
View = new Views.Push() { DataContext = this };
|
||||
}
|
||||
|
||||
public override bool CanStartDirectly()
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace SourceGit.ViewModels
|
|||
public Models.Tag Target
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<Models.Remote> Remotes
|
||||
|
@ -33,7 +32,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
Target = target;
|
||||
SelectedRemote = _repo.Remotes[0];
|
||||
View = new Views.PushTag() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -29,7 +29,6 @@ namespace SourceGit.ViewModels
|
|||
Current = current;
|
||||
On = on;
|
||||
AutoStash = true;
|
||||
View = new Views.Rebase() { DataContext = this };
|
||||
}
|
||||
|
||||
public Rebase(Repository repo, Models.Branch current, Models.Commit on)
|
||||
|
@ -39,7 +38,6 @@ namespace SourceGit.ViewModels
|
|||
Current = current;
|
||||
On = on;
|
||||
AutoStash = true;
|
||||
View = new Views.Rebase() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -7,8 +7,7 @@ namespace SourceGit.ViewModels
|
|||
public Models.Worktree Target
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = null;
|
||||
}
|
||||
|
||||
public bool Force
|
||||
{
|
||||
|
@ -20,7 +19,6 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
_repo = repo;
|
||||
Target = target;
|
||||
View = new Views.RemoveWorktree() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
@ -40,6 +38,6 @@ namespace SourceGit.ViewModels
|
|||
});
|
||||
}
|
||||
|
||||
private Repository _repo = null;
|
||||
private readonly Repository _repo = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
_name = target.Name;
|
||||
Target = target;
|
||||
View = new Views.RenameBranch() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateBranchName(string name, ValidationContext ctx)
|
||||
|
|
|
@ -7,13 +7,11 @@ namespace SourceGit.ViewModels
|
|||
public Models.Branch Current
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public Models.Commit To
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public Models.ResetMode SelectedMode
|
||||
|
@ -28,7 +26,6 @@ namespace SourceGit.ViewModels
|
|||
Current = current;
|
||||
To = to;
|
||||
SelectedMode = Models.ResetMode.Supported[1];
|
||||
View = new Views.Reset() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace SourceGit.ViewModels
|
|||
public Models.Commit Target
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool AutoCommit
|
||||
|
@ -21,7 +20,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
Target = target;
|
||||
AutoCommit = true;
|
||||
View = new Views.Revert() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace SourceGit.ViewModels
|
|||
public Models.Commit Head
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Required(ErrorMessage = "Commit message is required!!!")]
|
||||
|
@ -24,9 +23,7 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
_oldMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).Result();
|
||||
_message = _oldMessage;
|
||||
|
||||
Head = head;
|
||||
View = new Views.Reword() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
@ -50,7 +47,7 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
private readonly Repository _repo;
|
||||
private readonly string _oldMessage;
|
||||
private string _message;
|
||||
private string _oldMessage;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,15 +13,12 @@ namespace SourceGit.ViewModels
|
|||
public string RootDir
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public ScanRepositories(string rootDir)
|
||||
{
|
||||
GetManagedRepositories(Preferences.Instance.RepositoryNodes, _managed);
|
||||
|
||||
RootDir = rootDir;
|
||||
View = new Views.ScanRepositories() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace SourceGit.ViewModels
|
|||
public Models.Branch Local
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<Models.Branch> RemoteBranches
|
||||
|
@ -49,8 +48,6 @@ namespace SourceGit.ViewModels
|
|||
if (upstream != null)
|
||||
SelectedRemoteBranch = upstream;
|
||||
}
|
||||
|
||||
View = new Views.SetUpstream() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
@ -75,7 +72,7 @@ namespace SourceGit.ViewModels
|
|||
});
|
||||
}
|
||||
|
||||
private Repository _repo;
|
||||
private readonly Repository _repo;
|
||||
private bool _unset = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
public Models.Commit Target
|
||||
{
|
||||
get => _target;
|
||||
get;
|
||||
}
|
||||
|
||||
[Required(ErrorMessage = "Commit message is required!!!")]
|
||||
|
@ -20,10 +20,8 @@ namespace SourceGit.ViewModels
|
|||
public Squash(Repository repo, Models.Commit target, string shaToGetPreferMessage)
|
||||
{
|
||||
_repo = repo;
|
||||
_target = target;
|
||||
_message = new Commands.QueryCommitFullMessage(_repo.FullPath, shaToGetPreferMessage).Result();
|
||||
|
||||
View = new Views.Squash() { DataContext = this };
|
||||
Target = target;
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
@ -66,7 +64,6 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
private readonly Repository _repo;
|
||||
private Models.Commit _target;
|
||||
private string _message;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,6 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
_changes = changes;
|
||||
HasSelectedFiles = hasSelectedFiles;
|
||||
|
||||
View = new Views.StashChanges() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -8,8 +8,7 @@ namespace SourceGit.ViewModels
|
|||
public List<string> Submodules
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new List<string>();
|
||||
} = [];
|
||||
|
||||
public string SelectedSubmodule
|
||||
{
|
||||
|
@ -49,7 +48,6 @@ namespace SourceGit.ViewModels
|
|||
Submodules.Add(submodule.Path);
|
||||
|
||||
SelectedSubmodule = Submodules.Count > 0 ? Submodules[0] : string.Empty;
|
||||
View = new Views.UpdateSubmodules() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
<StackPanel Orientation="Vertical" Background="{DynamicResource Brush.Popup}">
|
||||
<!-- Popup Widget -->
|
||||
<ContentPresenter Margin="8,16,8,8"
|
||||
Content="{Binding View}"
|
||||
DataContextChanged="OnPopupDataContextChanged"
|
||||
IsHitTestVisible="{Binding InProgress, Converter={x:Static BoolConverters.Not}}"/>
|
||||
|
||||
<!-- Options -->
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Presenters;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
|
@ -48,5 +50,35 @@ namespace SourceGit.Views
|
|||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnPopupDataContextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is ContentPresenter presenter)
|
||||
{
|
||||
if (presenter.DataContext == null || presenter.DataContext is not ViewModels.Popup)
|
||||
{
|
||||
presenter.Content = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var dataTypeName = presenter.DataContext.GetType().FullName;
|
||||
if (string.IsNullOrEmpty(dataTypeName))
|
||||
{
|
||||
presenter.Content = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var viewTypeName = dataTypeName.Replace("ViewModels", "Views");
|
||||
var viewType = Type.GetType(viewTypeName);
|
||||
if (viewType == null)
|
||||
{
|
||||
presenter.Content = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var view = Activator.CreateInstance(viewType);
|
||||
presenter.Content = view;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue