2024-03-17 18:37:06 -07:00
|
|
|
|
using System;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Platform.Storage;
|
|
|
|
|
using Avalonia.Threading;
|
|
|
|
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class CountSelectedCommits
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
public int Count { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public class Histories : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
public bool IsLoading
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _isLoading;
|
|
|
|
|
set => SetProperty(ref _isLoading, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public double DataGridRowHeight
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _dataGridRowHeight;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<Models.Commit> Commits
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _commits;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
set
|
|
|
|
|
{
|
2024-04-30 06:22:48 -07:00
|
|
|
|
var oldAutoSelectedCommitSHA = AutoSelectedCommit?.SHA;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (SetProperty(ref _commits, value))
|
|
|
|
|
{
|
2024-04-30 06:22:48 -07:00
|
|
|
|
Models.Commit newSelectedCommit = null;
|
|
|
|
|
if (value.Count > 0 && oldAutoSelectedCommitSHA != null)
|
|
|
|
|
{
|
|
|
|
|
newSelectedCommit = value.Find(x => x.SHA == oldAutoSelectedCommitSHA);
|
|
|
|
|
}
|
|
|
|
|
if (newSelectedCommit != AutoSelectedCommit)
|
|
|
|
|
{
|
|
|
|
|
AutoSelectedCommit = newSelectedCommit;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Graph = null;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var graph = Models.CommitGraph.Parse(value, DataGridRowHeight, 8);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Graph = graph;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Models.CommitGraph Graph
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _graph;
|
|
|
|
|
set => SetProperty(ref _graph, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Models.Commit AutoSelectedCommit
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _autoSelectedCommit;
|
2024-05-27 02:21:28 -07:00
|
|
|
|
set => SetProperty(ref _autoSelectedCommit, value);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 06:19:02 -07:00
|
|
|
|
public long NavigationId
|
|
|
|
|
{
|
|
|
|
|
get => _navigationId;
|
|
|
|
|
private set => SetProperty(ref _navigationId, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public object DetailContext
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _detailContext;
|
2024-05-27 02:21:28 -07:00
|
|
|
|
set => SetProperty(ref _detailContext, value);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Histories(Repository repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
2024-02-20 02:27:59 -08:00
|
|
|
|
Commits = new List<Models.Commit>();
|
|
|
|
|
|
|
|
|
|
_repo = null;
|
|
|
|
|
_graph = null;
|
|
|
|
|
_autoSelectedCommit = null;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (_detailContext is CommitDetail cd)
|
|
|
|
|
{
|
2024-02-20 02:27:59 -08:00
|
|
|
|
cd.Cleanup();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (_detailContext is RevisionCompare rc)
|
|
|
|
|
{
|
2024-02-20 02:27:59 -08:00
|
|
|
|
rc.Cleanup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_detailContext = null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void NavigateTo(string commitSHA)
|
|
|
|
|
{
|
2024-03-13 20:09:05 -07:00
|
|
|
|
var commit = _commits.Find(x => x.SHA.StartsWith(commitSHA, StringComparison.Ordinal));
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (commit != null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
AutoSelectedCommit = commit;
|
2024-04-07 06:19:02 -07:00
|
|
|
|
NavigationId = _navigationId + 1;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (_detailContext is CommitDetail detail)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
detail.Commit = commit;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var commitDetail = new CommitDetail(_repo.FullPath);
|
|
|
|
|
commitDetail.Commit = commit;
|
|
|
|
|
DetailContext = commitDetail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Select(IList commits)
|
|
|
|
|
{
|
|
|
|
|
if (commits.Count == 0)
|
|
|
|
|
{
|
2024-05-10 01:30:34 -07:00
|
|
|
|
_repo.SearchResultSelectedCommit = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
DetailContext = null;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (commits.Count == 1)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var commit = commits[0] as Models.Commit;
|
2024-05-10 01:30:34 -07:00
|
|
|
|
_repo.SearchResultSelectedCommit = commit;
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
AutoSelectedCommit = commit;
|
2024-04-11 05:50:19 -07:00
|
|
|
|
NavigationId = _navigationId + 1;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (_detailContext is CommitDetail detail)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
detail.Commit = commit;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var commitDetail = new CommitDetail(_repo.FullPath);
|
|
|
|
|
commitDetail.Commit = commit;
|
|
|
|
|
DetailContext = commitDetail;
|
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (commits.Count == 2)
|
|
|
|
|
{
|
2024-05-10 01:30:34 -07:00
|
|
|
|
_repo.SearchResultSelectedCommit = null;
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var end = commits[0] as Models.Commit;
|
|
|
|
|
var start = commits[1] as Models.Commit;
|
|
|
|
|
DetailContext = new RevisionCompare(_repo.FullPath, start, end);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-10 01:30:34 -07:00
|
|
|
|
_repo.SearchResultSelectedCommit = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
DetailContext = new CountSelectedCommits() { Count = commits.Count };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 02:21:28 -07:00
|
|
|
|
public ContextMenu MakeContextMenu(DataGrid datagrid)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-05-27 02:21:28 -07:00
|
|
|
|
if (datagrid.SelectedItems.Count != 1)
|
2024-03-31 01:54:29 -07:00
|
|
|
|
return null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
var current = _repo.Branches.Find(x => x.IsCurrent);
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (current == null)
|
|
|
|
|
return null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-05-27 02:21:28 -07:00
|
|
|
|
var commit = datagrid.SelectedItem as Models.Commit;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var menu = new ContextMenu();
|
|
|
|
|
var tags = new List<Models.Tag>();
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (commit.HasDecorators)
|
|
|
|
|
{
|
|
|
|
|
foreach (var d in commit.Decorators)
|
|
|
|
|
{
|
|
|
|
|
if (d.Type == Models.DecoratorType.CurrentBranchHead)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
FillCurrentBranchMenu(menu, current);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (d.Type == Models.DecoratorType.LocalBranchHead)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var b = _repo.Branches.Find(x => x.IsLocal && d.Name == x.Name);
|
|
|
|
|
FillOtherLocalBranchMenu(menu, b, current, commit.IsMerged);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (d.Type == Models.DecoratorType.RemoteBranchHead)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var b = _repo.Branches.Find(x => !x.IsLocal && d.Name == $"{x.Remote}/{x.Name}");
|
|
|
|
|
FillRemoteBranchMenu(menu, b, current, commit.IsMerged);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (d.Type == Models.DecoratorType.Tag)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var t = _repo.Tags.Find(x => x.Name == d.Name);
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (t != null)
|
|
|
|
|
tags.Add(t);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (menu.Items.Count > 0)
|
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (tags.Count > 0)
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
foreach (var tag in tags)
|
|
|
|
|
FillTagMenu(menu, tag);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (current.Head != commit.SHA)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var reset = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
reset.Header = new Views.NameHighlightedTextBlock("CommitCM.Reset", current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
reset.Icon = App.CreateMenuIcon("Icons.Reset");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
reset.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new Reset(_repo, current, commit));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(reset);
|
2024-05-25 11:11:24 -07:00
|
|
|
|
|
|
|
|
|
var checkoutCommit = new MenuItem();
|
2024-05-25 23:35:57 -07:00
|
|
|
|
checkoutCommit.Header = App.Text("CommitCM.Checkout");
|
2024-05-25 11:11:24 -07:00
|
|
|
|
checkoutCommit.Icon = App.CreateMenuIcon("Icons.Check");
|
|
|
|
|
checkoutCommit.Click += (o, e) =>
|
|
|
|
|
{
|
2024-05-25 23:35:57 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new CheckoutCommit(_repo, commit));
|
2024-05-25 11:11:24 -07:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(checkoutCommit);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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-03-17 18:37:06 -07:00
|
|
|
|
reword.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new Reword(_repo, commit));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
squash.Click += (o, e) =>
|
|
|
|
|
{
|
|
|
|
|
if (commit.Parents.Count == 1)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var parent = _commits.Find(x => x.SHA == commit.Parents[0]);
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (parent != null && PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new Squash(_repo, commit, parent));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(squash);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (!commit.IsMerged)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var rebase = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
rebase.Header = new Views.NameHighlightedTextBlock("CommitCM.Rebase", current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
rebase.Icon = App.CreateMenuIcon("Icons.Rebase");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
rebase.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new Rebase(_repo, current, commit));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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-03-17 18:37:06 -07:00
|
|
|
|
cherryPick.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new CherryPick(_repo, commit));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(cherryPick);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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-03-17 18:37:06 -07:00
|
|
|
|
revert.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new Revert(_repo, commit));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(revert);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
|
2024-05-27 02:21:28 -07:00
|
|
|
|
if (current.Head != commit.SHA)
|
|
|
|
|
{
|
|
|
|
|
var compare = new MenuItem();
|
|
|
|
|
compare.Header = App.Text("CommitCM.CompareWithHead");
|
|
|
|
|
compare.Icon = App.CreateMenuIcon("Icons.Compare");
|
|
|
|
|
compare.Click += (o, e) =>
|
|
|
|
|
{
|
|
|
|
|
var head = _commits.Find(x => x.SHA == current.Head);
|
|
|
|
|
if (head == null)
|
|
|
|
|
{
|
|
|
|
|
_repo.SearchResultSelectedCommit = null;
|
|
|
|
|
head = new Commands.QuerySingleCommit(_repo.FullPath, current.Head).Result();
|
|
|
|
|
if (head != null)
|
|
|
|
|
DetailContext = new RevisionCompare(_repo.FullPath, commit, head);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
datagrid.SelectedItems.Add(head);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(compare);
|
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
createBranch.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new CreateBranch(_repo, commit));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
createTag.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new CreateTag(_repo, commit));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
saveToPatch.Click += async (_, e) =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var topLevel = App.GetTopLevel();
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (topLevel == null)
|
|
|
|
|
return;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
|
|
|
|
var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (selected.Count == 1)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var succ = new Commands.FormatPatch(_repo.FullPath, commit.SHA, selected[0].Path.LocalPath).Exec();
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (succ)
|
|
|
|
|
App.SendNotification(_repo.FullPath, App.Text("SaveAsPatchSuccess"));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
archive.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new Archive(_repo, commit));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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-03-17 18:37:06 -07:00
|
|
|
|
copySHA.Click += (o, e) =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
App.CopyText(commit.SHA);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(copySHA);
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (!string.IsNullOrEmpty(current.Upstream))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var upstream = current.Upstream.Substring(13);
|
|
|
|
|
|
|
|
|
|
var fastForward = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
fastForward.Header = new Views.NameHighlightedTextBlock("BranchCM.FastForward", upstream);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
fastForward.Icon = App.CreateMenuIcon("Icons.FastForward");
|
2024-03-31 01:54:29 -07:00
|
|
|
|
fastForward.IsEnabled = !string.IsNullOrEmpty(current.UpstreamTrackStatus) && current.UpstreamTrackStatus.IndexOf('↑') < 0;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
fastForward.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowAndStartPopup(new Merge(_repo, upstream, current.Name));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(fastForward);
|
|
|
|
|
|
|
|
|
|
var pull = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
pull.Header = new Views.NameHighlightedTextBlock("BranchCM.Pull", upstream);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
pull.Icon = App.CreateMenuIcon("Icons.Pull");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
pull.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new Pull(_repo, null));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(pull);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var push = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
push.Header = new Views.NameHighlightedTextBlock("BranchCM.Push", current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
push.Icon = App.CreateMenuIcon("Icons.Push");
|
2024-03-01 03:12:22 -08:00
|
|
|
|
push.IsEnabled = _repo.Remotes.Count > 0;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
push.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new Push(_repo, current));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(push);
|
|
|
|
|
submenu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
|
|
|
|
|
var type = _repo.GitFlow.GetBranchType(current.Name);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (type != Models.GitFlowBranchType.None)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var finish = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
finish.Header = new Views.NameHighlightedTextBlock("BranchCM.Finish", current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
finish.Icon = App.CreateMenuIcon("Icons.Flow");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
finish.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new GitFlowFinish(_repo, current, type));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(finish);
|
|
|
|
|
submenu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rename = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
rename.Header = new Views.NameHighlightedTextBlock("BranchCM.Rename", current.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
rename.Icon = App.CreateMenuIcon("Icons.Rename");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
rename.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new RenameBranch(_repo, current));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(rename);
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(submenu);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private void FillOtherLocalBranchMenu(ContextMenu menu, Models.Branch branch, Models.Branch current, bool merged)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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-28 02:55:23 -08:00
|
|
|
|
checkout.Header = new Views.NameHighlightedTextBlock("BranchCM.Checkout", branch.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
checkout.Click += (o, e) =>
|
|
|
|
|
{
|
2024-04-29 02:22:22 -07:00
|
|
|
|
_repo.CheckoutLocalBranch(branch.Name);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(checkout);
|
|
|
|
|
|
|
|
|
|
var merge = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
merge.Header = new Views.NameHighlightedTextBlock("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;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
merge.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new Merge(_repo, branch.Name, current.Name));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(merge);
|
|
|
|
|
submenu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
|
|
|
|
|
var type = _repo.GitFlow.GetBranchType(branch.Name);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (type != Models.GitFlowBranchType.None)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var finish = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
finish.Header = new Views.NameHighlightedTextBlock("BranchCM.Finish", branch.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
finish.Icon = App.CreateMenuIcon("Icons.Flow");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
finish.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new GitFlowFinish(_repo, branch, type));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(finish);
|
|
|
|
|
submenu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rename = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
rename.Header = new Views.NameHighlightedTextBlock("BranchCM.Rename", branch.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
rename.Icon = App.CreateMenuIcon("Icons.Rename");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
rename.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new RenameBranch(_repo, branch));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(rename);
|
|
|
|
|
|
|
|
|
|
var delete = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
delete.Header = new Views.NameHighlightedTextBlock("BranchCM.Delete", branch.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
delete.Icon = App.CreateMenuIcon("Icons.Clear");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
delete.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new DeleteBranch(_repo, branch));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(delete);
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(submenu);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private void FillRemoteBranchMenu(ContextMenu menu, Models.Branch branch, Models.Branch current, bool merged)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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-28 02:55:23 -08:00
|
|
|
|
checkout.Header = new Views.NameHighlightedTextBlock("BranchCM.Checkout", name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
checkout.Icon = App.CreateMenuIcon("Icons.Check");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
checkout.Click += (o, e) =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var b in _repo.Branches)
|
|
|
|
|
{
|
|
|
|
|
if (b.IsLocal && b.Upstream == branch.FullName)
|
|
|
|
|
{
|
2024-04-29 02:22:22 -07:00
|
|
|
|
if (!b.IsCurrent)
|
|
|
|
|
_repo.CheckoutLocalBranch(b.Name);
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new CreateBranch(_repo, branch));
|
2024-04-29 02:22:22 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(checkout);
|
|
|
|
|
|
|
|
|
|
var merge = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
merge.Header = new Views.NameHighlightedTextBlock("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;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
merge.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new Merge(_repo, name, current.Name));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
submenu.Items.Add(merge);
|
|
|
|
|
submenu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
|
|
|
|
|
var delete = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
delete.Header = new Views.NameHighlightedTextBlock("BranchCM.Delete", name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
delete.Icon = App.CreateMenuIcon("Icons.Clear");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
delete.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new DeleteBranch(_repo, branch));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(delete);
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(submenu);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private void FillTagMenu(ContextMenu menu, Models.Tag tag)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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-28 02:55:23 -08:00
|
|
|
|
push.Header = new Views.NameHighlightedTextBlock("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;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
push.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new PushTag(_repo, tag));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(push);
|
|
|
|
|
|
|
|
|
|
var delete = new MenuItem();
|
2024-02-28 02:55:23 -08:00
|
|
|
|
delete.Header = new Views.NameHighlightedTextBlock("TagCM.Delete", tag.Name);
|
2024-02-27 02:26:05 -08:00
|
|
|
|
delete.Icon = App.CreateMenuIcon("Icons.Clear");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
delete.Click += (o, e) =>
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
PopupHost.ShowPopup(new DeleteTag(_repo, tag));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
submenu.Items.Add(delete);
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(submenu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Repository _repo = null;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly double _dataGridRowHeight = 28;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private bool _isLoading = true;
|
|
|
|
|
private List<Models.Commit> _commits = new List<Models.Commit>();
|
|
|
|
|
private Models.CommitGraph _graph = null;
|
|
|
|
|
private Models.Commit _autoSelectedCommit = null;
|
2024-04-07 06:19:02 -07:00
|
|
|
|
private long _navigationId = 0;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private object _detailContext = null;
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|