2024-02-05 23:08:37 -08:00
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Platform.Storage;
|
|
|
|
|
using Avalonia.Threading;
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.ViewModels {
|
|
|
|
|
public class CountSelectedCommits {
|
|
|
|
|
public int Count { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Histories : ObservableObject {
|
|
|
|
|
public bool IsLoading {
|
|
|
|
|
get => _isLoading;
|
|
|
|
|
set => SetProperty(ref _isLoading, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double DataGridRowHeight {
|
|
|
|
|
get => _dataGridRowHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Models.Commit> Commits {
|
|
|
|
|
get => _commits;
|
|
|
|
|
set {
|
|
|
|
|
if (SetProperty(ref _commits, value)) {
|
|
|
|
|
Graph = null;
|
|
|
|
|
Task.Run(() => {
|
|
|
|
|
var graph = Models.CommitGraph.Parse(value, DataGridRowHeight, 8);
|
|
|
|
|
Dispatcher.UIThread.Invoke(() => {
|
|
|
|
|
Graph = graph;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Models.CommitGraph Graph {
|
|
|
|
|
get => _graph;
|
|
|
|
|
set => SetProperty(ref _graph, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Models.Commit AutoSelectedCommit {
|
|
|
|
|
get => _autoSelectedCommit;
|
|
|
|
|
private set => SetProperty(ref _autoSelectedCommit, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object DetailContext {
|
|
|
|
|
get => _detailContext;
|
|
|
|
|
private set => SetProperty(ref _detailContext, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Histories(Repository repo) {
|
|
|
|
|
_repo = repo;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 02:27:59 -08:00
|
|
|
|
public void Cleanup() {
|
|
|
|
|
Commits = new List<Models.Commit>();
|
|
|
|
|
|
|
|
|
|
_repo = null;
|
|
|
|
|
_graph = null;
|
|
|
|
|
_autoSelectedCommit = null;
|
|
|
|
|
|
|
|
|
|
if (_detailContext is CommitDetail cd) {
|
|
|
|
|
cd.Cleanup();
|
|
|
|
|
} else if (_detailContext is RevisionCompare rc) {
|
|
|
|
|
rc.Cleanup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_detailContext = null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
public void NavigateTo(string commitSHA) {
|
|
|
|
|
var commit = _commits.Find(x => x.SHA.StartsWith(commitSHA));
|
|
|
|
|
if (commit != null) {
|
|
|
|
|
AutoSelectedCommit = commit;
|
|
|
|
|
|
|
|
|
|
if (_detailContext is CommitDetail detail) {
|
|
|
|
|
detail.Commit = commit;
|
|
|
|
|
} else {
|
|
|
|
|
var commitDetail = new CommitDetail(_repo.FullPath);
|
|
|
|
|
commitDetail.Commit = commit;
|
|
|
|
|
DetailContext = commitDetail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Select(IList commits) {
|
|
|
|
|
if (commits.Count == 0) {
|
|
|
|
|
DetailContext = null;
|
|
|
|
|
} else if (commits.Count == 1) {
|
|
|
|
|
var commit = commits[0] as Models.Commit;
|
|
|
|
|
AutoSelectedCommit = commit;
|
|
|
|
|
|
|
|
|
|
if (_detailContext is CommitDetail detail) {
|
|
|
|
|
detail.Commit = commit;
|
|
|
|
|
} else {
|
|
|
|
|
var commitDetail = new CommitDetail(_repo.FullPath);
|
|
|
|
|
commitDetail.Commit = commit;
|
|
|
|
|
DetailContext = commitDetail;
|
|
|
|
|
}
|
|
|
|
|
} else if (commits.Count == 2) {
|
|
|
|
|
var end = commits[0] as Models.Commit;
|
|
|
|
|
var start = commits[1] as Models.Commit;
|
|
|
|
|
DetailContext = new RevisionCompare(_repo.FullPath, start, end);
|
|
|
|
|
} else {
|
|
|
|
|
DetailContext = new CountSelectedCommits() { Count = commits.Count };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ContextMenu MakeContextMenu() {
|
|
|
|
|
var detail = _detailContext as CommitDetail;
|
|
|
|
|
if (detail == null) return null;
|
|
|
|
|
|
|
|
|
|
var current = _repo.Branches.Find(x => x.IsCurrent);
|
|
|
|
|
if (current == null) return null;
|
|
|
|
|
|
|
|
|
|
var commit = detail.Commit;
|
|
|
|
|
var menu = new ContextMenu();
|
|
|
|
|
var tags = new List<Models.Tag>();
|
|
|
|
|
|
|
|
|
|
if (commit.HasDecorators) {
|
|
|
|
|
foreach (var d in commit.Decorators) {
|
|
|
|
|
if (d.Type == Models.DecoratorType.CurrentBranchHead) {
|
|
|
|
|
FillCurrentBranchMenu(menu, current);
|
|
|
|
|
} else if (d.Type == Models.DecoratorType.LocalBranchHead) {
|
|
|
|
|
var b = _repo.Branches.Find(x => x.IsLocal && d.Name == x.Name);
|
|
|
|
|
FillOtherLocalBranchMenu(menu, b, current, commit.IsMerged);
|
|
|
|
|
} else if (d.Type == Models.DecoratorType.RemoteBranchHead) {
|
|
|
|
|
var b = _repo.Branches.Find(x => !x.IsLocal && d.Name == $"{x.Remote}/{x.Name}");
|
|
|
|
|
FillRemoteBranchMenu(menu, b, current, commit.IsMerged);
|
|
|
|
|
} else if (d.Type == Models.DecoratorType.Tag) {
|
|
|
|
|
var t = _repo.Tags.Find(x => x.Name == d.Name);
|
|
|
|
|
if (t != null) tags.Add(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (menu.Items.Count > 0) menu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tags.Count > 0) {
|
|
|
|
|
foreach (var tag in tags) FillTagMenu(menu, tag);
|
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current.Head != commit.SHA) {
|
|
|
|
|
var reset = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
reset.Header = CreateHighlightLabel("CommitCM.Reset", current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
reset.Icon = App.CreateMenuIcon("Icons.Reset");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
reset.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Reset(_repo, current, commit));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(reset);
|
|
|
|
|
} else {
|
|
|
|
|
var reword = new MenuItem();
|
|
|
|
|
reword.Header = App.Text("CommitCM.Reword");
|
2024-02-27 02:26:05 -08:00
|
|
|
|
reword.Icon = App.CreateMenuIcon("Icons.Edit");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
reword.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Reword(_repo, commit));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(reword);
|
|
|
|
|
|
|
|
|
|
var squash = new MenuItem();
|
|
|
|
|
squash.Header = App.Text("CommitCM.Squash");
|
2024-02-27 02:26:05 -08:00
|
|
|
|
squash.Icon = App.CreateMenuIcon("Icons.SquashIntoParent");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
squash.IsEnabled = commit.Parents.Count == 1;
|
|
|
|
|
squash.Click += (o, e) => {
|
|
|
|
|
if (commit.Parents.Count == 1) {
|
|
|
|
|
var parent = _commits.Find(x => x.SHA == commit.Parents[0]);
|
|
|
|
|
if (parent != null && PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Squash(_repo, commit, parent));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(squash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!commit.IsMerged) {
|
|
|
|
|
var rebase = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
rebase.Header = CreateHighlightLabel("CommitCM.Rebase", current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
rebase.Icon = App.CreateMenuIcon("Icons.Rebase");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
rebase.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Rebase(_repo, current, commit));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(rebase);
|
|
|
|
|
|
|
|
|
|
var cherryPick = new MenuItem();
|
|
|
|
|
cherryPick.Header = App.Text("CommitCM.CherryPick");
|
2024-02-27 02:26:05 -08:00
|
|
|
|
cherryPick.Icon = App.CreateMenuIcon("Icons.CherryPick");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
cherryPick.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CherryPick(_repo, commit));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(cherryPick);
|
|
|
|
|
} else {
|
|
|
|
|
var revert = new MenuItem();
|
|
|
|
|
revert.Header = App.Text("CommitCM.Revert");
|
2024-02-27 02:26:05 -08:00
|
|
|
|
revert.Icon = App.CreateMenuIcon("Icons.Undo");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
revert.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Revert(_repo, commit));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(revert);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
|
|
|
|
|
var createBranch = new MenuItem();
|
2024-02-27 02:26:05 -08:00
|
|
|
|
createBranch.Icon = App.CreateMenuIcon("Icons.Branch.Add");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
createBranch.Header = App.Text("CreateBranch");
|
|
|
|
|
createBranch.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateBranch(_repo, commit));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(createBranch);
|
|
|
|
|
|
|
|
|
|
var createTag = new MenuItem();
|
2024-02-27 02:26:05 -08:00
|
|
|
|
createTag.Icon = App.CreateMenuIcon("Icons.Tag.Add");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
createTag.Header = App.Text("CreateTag");
|
|
|
|
|
createTag.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateTag(_repo, commit));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(createTag);
|
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
|
|
|
|
|
var saveToPatch = new MenuItem();
|
2024-02-27 02:26:05 -08:00
|
|
|
|
saveToPatch.Icon = App.CreateMenuIcon("Icons.Diff");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
saveToPatch.Header = App.Text("CommitCM.SaveAsPatch");
|
|
|
|
|
saveToPatch.Click += async (_, e) => {
|
|
|
|
|
var topLevel = App.GetTopLevel();
|
|
|
|
|
if (topLevel == null) return;
|
|
|
|
|
|
|
|
|
|
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
|
|
|
|
var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
|
|
|
|
|
if (selected.Count == 1) {
|
|
|
|
|
var succ = new Commands.FormatPatch(_repo.FullPath, commit.SHA, selected[0].Path.LocalPath).Exec();
|
|
|
|
|
if (succ) App.SendNotification(_repo.FullPath, App.Text("SaveAsPatchSuccess"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(saveToPatch);
|
|
|
|
|
|
|
|
|
|
var archive = new MenuItem();
|
2024-02-27 02:26:05 -08:00
|
|
|
|
archive.Icon = App.CreateMenuIcon("Icons.Archive");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
archive.Header = App.Text("Archive");
|
|
|
|
|
archive.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Archive(_repo, commit));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(archive);
|
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
|
|
|
|
|
var copySHA = new MenuItem();
|
|
|
|
|
copySHA.Header = App.Text("CommitCM.CopySHA");
|
2024-02-27 02:26:05 -08:00
|
|
|
|
copySHA.Icon = App.CreateMenuIcon("Icons.Copy");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
copySHA.Click += (o, e) => {
|
|
|
|
|
App.CopyText(commit.SHA);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(copySHA);
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current) {
|
|
|
|
|
var submenu = new MenuItem();
|
2024-02-27 02:26:05 -08:00
|
|
|
|
submenu.Icon = App.CreateMenuIcon("Icons.Branch");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
submenu.Header = current.Name;
|
|
|
|
|
|
|
|
|
|
var dirty = !string.IsNullOrEmpty(current.UpstreamTrackStatus);
|
|
|
|
|
if (!string.IsNullOrEmpty(current.Upstream)) {
|
|
|
|
|
var upstream = current.Upstream.Substring(13);
|
|
|
|
|
|
|
|
|
|
var fastForward = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
fastForward.Header = CreateHighlightLabel("BranchCM.FastForward", upstream);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
fastForward.Icon = App.CreateMenuIcon("Icons.FastForward");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
fastForward.IsEnabled = dirty;
|
|
|
|
|
fastForward.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Merge(_repo, upstream, current.Name));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(fastForward);
|
|
|
|
|
|
|
|
|
|
var pull = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
pull.Header = CreateHighlightLabel("BranchCM.Pull", upstream);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
pull.Icon = App.CreateMenuIcon("Icons.Pull");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
pull.IsEnabled = dirty;
|
|
|
|
|
pull.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(_repo, null));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(pull);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var push = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
push.Header = CreateHighlightLabel("BranchCM.Push", current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
push.Icon = App.CreateMenuIcon("Icons.Push");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
push.IsEnabled = _repo.Remotes.Count > 0 && dirty;
|
|
|
|
|
push.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Push(_repo, current));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(push);
|
|
|
|
|
submenu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
|
|
|
|
|
var type = _repo.GitFlow.GetBranchType(current.Name);
|
|
|
|
|
if (type != Models.GitFlowBranchType.None) {
|
|
|
|
|
var finish = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
finish.Header = CreateHighlightLabel("BranchCM.Finish", current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
finish.Icon = App.CreateMenuIcon("Icons.Flow");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
finish.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new GitFlowFinish(_repo, current, type));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(finish);
|
|
|
|
|
submenu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rename = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
rename.Header = CreateHighlightLabel("BranchCM.Rename", current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
rename.Icon = App.CreateMenuIcon("Icons.Rename");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
rename.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new RenameBranch(_repo, current));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(rename);
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(submenu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FillOtherLocalBranchMenu(ContextMenu menu, Models.Branch branch, Models.Branch current, bool merged) {
|
|
|
|
|
var submenu = new MenuItem();
|
2024-02-27 02:26:05 -08:00
|
|
|
|
submenu.Icon = App.CreateMenuIcon("Icons.Branch");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
submenu.Header = branch.Name;
|
|
|
|
|
|
|
|
|
|
var checkout = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
checkout.Header = CreateHighlightLabel("BranchCM.Checkout", branch.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
checkout.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Checkout(_repo, branch.Name));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(checkout);
|
|
|
|
|
|
|
|
|
|
var merge = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
merge.Header = CreateHighlightLabel("BranchCM.Merge", branch.Name, current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
merge.Icon = App.CreateMenuIcon("Icons.Merge");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
merge.IsEnabled = !merged;
|
|
|
|
|
merge.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Merge(_repo, branch.Name, current.Name));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(merge);
|
|
|
|
|
submenu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
|
|
|
|
|
var type = _repo.GitFlow.GetBranchType(branch.Name);
|
|
|
|
|
if (type != Models.GitFlowBranchType.None) {
|
|
|
|
|
var finish = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
finish.Header = CreateHighlightLabel("BranchCM.Finish", branch.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
finish.Icon = App.CreateMenuIcon("Icons.Flow");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
finish.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new GitFlowFinish(_repo, branch, type));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(finish);
|
|
|
|
|
submenu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rename = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
rename.Header = CreateHighlightLabel("BranchCM.Rename", branch.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
rename.Icon = App.CreateMenuIcon("Icons.Rename");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
rename.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new RenameBranch(_repo, branch));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(rename);
|
|
|
|
|
|
|
|
|
|
var delete = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
delete.Header = CreateHighlightLabel("BranchCM.Delete", branch.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
delete.Icon = App.CreateMenuIcon("Icons.Clear");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
delete.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteBranch(_repo, branch));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(delete);
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(submenu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FillRemoteBranchMenu(ContextMenu menu, Models.Branch branch, Models.Branch current, bool merged) {
|
|
|
|
|
var name = $"{branch.Remote}/{branch.Name}";
|
|
|
|
|
|
|
|
|
|
var submenu = new MenuItem();
|
2024-02-27 02:26:05 -08:00
|
|
|
|
submenu.Icon = App.CreateMenuIcon("Icons.Branch");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
submenu.Header = name;
|
|
|
|
|
|
|
|
|
|
var checkout = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
checkout.Header = CreateHighlightLabel("BranchCM.Checkout", name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
checkout.Click += (o, e) => {
|
|
|
|
|
foreach (var b in _repo.Branches) {
|
|
|
|
|
if (b.IsLocal && b.Upstream == branch.FullName) {
|
|
|
|
|
if (b.IsCurrent) return;
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Checkout(_repo, b.Name));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateBranch(_repo, branch));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(checkout);
|
|
|
|
|
|
|
|
|
|
var merge = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
merge.Header = CreateHighlightLabel("BranchCM.Merge", name, current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
merge.Icon = App.CreateMenuIcon("Icons.Merge");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
merge.IsEnabled = !merged;
|
|
|
|
|
merge.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Merge(_repo, name, current.Name));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
submenu.Items.Add(merge);
|
|
|
|
|
submenu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
|
|
|
|
|
var delete = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
delete.Header = CreateHighlightLabel("BranchCM.Delete", name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
delete.Icon = App.CreateMenuIcon("Icons.Clear");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
delete.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteBranch(_repo, branch));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(delete);
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(submenu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FillTagMenu(ContextMenu menu, Models.Tag tag) {
|
|
|
|
|
var submenu = new MenuItem();
|
|
|
|
|
submenu.Header = tag.Name;
|
2024-02-27 02:26:05 -08:00
|
|
|
|
submenu.Icon = App.CreateMenuIcon("Icons.Tag");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
submenu.MinWidth = 200;
|
|
|
|
|
|
|
|
|
|
var push = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
push.Header = CreateHighlightLabel("TagCM.Push", tag.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
push.Icon = App.CreateMenuIcon("Icons.Push");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
push.IsEnabled = _repo.Remotes.Count > 0;
|
|
|
|
|
push.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new PushTag(_repo, tag));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(push);
|
|
|
|
|
|
|
|
|
|
var delete = new MenuItem();
|
2024-02-06 03:07:17 -08:00
|
|
|
|
delete.Header = CreateHighlightLabel("TagCM.Delete", tag.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
delete.Icon = App.CreateMenuIcon("Icons.Clear");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
delete.Click += (o, e) => {
|
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new DeleteTag(_repo, tag));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(delete);
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(submenu);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 03:07:17 -08:00
|
|
|
|
private object CreateHighlightLabel(string key, params object[] args) {
|
|
|
|
|
var label = new Views.NameHighlightedTextBlock();
|
|
|
|
|
label.Text = App.Text(key, args);
|
|
|
|
|
label.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center;
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private Repository _repo = null;
|
|
|
|
|
private double _dataGridRowHeight = 28;
|
|
|
|
|
private bool _isLoading = true;
|
|
|
|
|
private List<Models.Commit> _commits = new List<Models.Commit>();
|
|
|
|
|
private Models.CommitGraph _graph = null;
|
|
|
|
|
private Models.Commit _autoSelectedCommit = null;
|
|
|
|
|
private object _detailContext = null;
|
|
|
|
|
}
|
|
|
|
|
}
|