2024-03-17 18:37:06 -07:00
|
|
|
|
using System;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2024-08-30 05:42:09 -07:00
|
|
|
|
using System.Linq;
|
2024-06-30 22:30:57 -07:00
|
|
|
|
using System.Text.RegularExpressions;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-08-05 03:18:57 -07:00
|
|
|
|
using Avalonia.Collections;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia.Controls;
|
2024-04-07 18:57:41 -07:00
|
|
|
|
using Avalonia.Media.Imaging;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia.Platform.Storage;
|
|
|
|
|
using Avalonia.Threading;
|
|
|
|
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
2024-06-30 22:30:57 -07:00
|
|
|
|
public partial class CommitDetail : ObservableObject
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
|
|
|
|
public DiffContext DiffContext
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _diffContext;
|
|
|
|
|
private set => SetProperty(ref _diffContext, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public int ActivePageIndex
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _activePageIndex;
|
|
|
|
|
set => SetProperty(ref _activePageIndex, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Models.Commit Commit
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _commit;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
set
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (SetProperty(ref _commit, value))
|
|
|
|
|
Refresh();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 21:19:48 -07:00
|
|
|
|
public string FullMessage
|
|
|
|
|
{
|
|
|
|
|
get => _fullMessage;
|
|
|
|
|
private set => SetProperty(ref _fullMessage, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<Models.Change> Changes
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _changes;
|
|
|
|
|
set => SetProperty(ref _changes, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<Models.Change> VisibleChanges
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _visibleChanges;
|
|
|
|
|
set => SetProperty(ref _visibleChanges, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 06:19:53 -07:00
|
|
|
|
public List<Models.Change> SelectedChanges
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-05-28 06:19:53 -07:00
|
|
|
|
get => _selectedChanges;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
set
|
|
|
|
|
{
|
2024-05-28 06:19:53 -07:00
|
|
|
|
if (SetProperty(ref _selectedChanges, value))
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-05-28 06:19:53 -07:00
|
|
|
|
if (value == null || value.Count != 1)
|
2024-02-05 23:08:37 -08:00
|
|
|
|
DiffContext = null;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
else
|
2024-08-13 02:15:17 -07:00
|
|
|
|
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(_commit, value[0]), _diffContext);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string SearchChangeFilter
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _searchChangeFilter;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _searchChangeFilter, value))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
RefreshVisibleChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public object ViewRevisionFileContent
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _viewRevisionFileContent;
|
|
|
|
|
set => SetProperty(ref _viewRevisionFileContent, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 02:15:17 -07:00
|
|
|
|
public AvaloniaList<Models.CommitLink> WebLinks
|
|
|
|
|
{
|
2024-08-13 04:30:10 -07:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
} = new AvaloniaList<Models.CommitLink>();
|
2024-08-13 02:15:17 -07:00
|
|
|
|
|
2024-08-05 03:18:57 -07:00
|
|
|
|
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
|
2024-08-05 02:34:49 -07:00
|
|
|
|
{
|
2024-08-13 02:15:17 -07:00
|
|
|
|
get => _repo.Settings?.IssueTrackerRules;
|
2024-08-05 02:34:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 02:15:17 -07:00
|
|
|
|
public CommitDetail(Repository repo)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
2024-08-13 04:30:10 -07:00
|
|
|
|
|
|
|
|
|
foreach (var remote in repo.Remotes)
|
|
|
|
|
{
|
|
|
|
|
if (remote.TryGetVisitURL(out var url))
|
|
|
|
|
{
|
|
|
|
|
if (url.StartsWith("https://github.com/", StringComparison.Ordinal))
|
2024-08-14 19:39:31 -07:00
|
|
|
|
WebLinks.Add(new Models.CommitLink() { Name = "Github", URLPrefix = $"{url}/commit/" });
|
2024-08-13 04:30:10 -07:00
|
|
|
|
else if (url.StartsWith("https://gitlab.com/", StringComparison.Ordinal))
|
2024-08-14 19:39:31 -07:00
|
|
|
|
WebLinks.Add(new Models.CommitLink() { Name = "GitLab", URLPrefix = $"{url}/-/commit/" });
|
2024-08-13 04:30:10 -07:00
|
|
|
|
else if (url.StartsWith("https://gitee.com/", StringComparison.Ordinal))
|
2024-08-14 19:39:31 -07:00
|
|
|
|
WebLinks.Add(new Models.CommitLink() { Name = "Gitee", URLPrefix = $"{url}/commit/" });
|
|
|
|
|
else if (url.StartsWith("https://bitbucket.org/", StringComparison.Ordinal))
|
2024-08-14 19:43:38 -07:00
|
|
|
|
WebLinks.Add(new Models.CommitLink() { Name = "Bitbucket", URLPrefix = $"{url}/commits/" });
|
2024-08-13 04:30:10 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
2024-02-20 02:27:59 -08:00
|
|
|
|
_repo = null;
|
|
|
|
|
_commit = null;
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_changes != null)
|
|
|
|
|
_changes.Clear();
|
|
|
|
|
if (_visibleChanges != null)
|
|
|
|
|
_visibleChanges.Clear();
|
2024-05-28 06:19:53 -07:00
|
|
|
|
if (_selectedChanges != null)
|
|
|
|
|
_selectedChanges.Clear();
|
2024-02-20 02:27:59 -08:00
|
|
|
|
_searchChangeFilter = null;
|
|
|
|
|
_diffContext = null;
|
|
|
|
|
_viewRevisionFileContent = null;
|
|
|
|
|
_cancelToken = null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void NavigateTo(string commitSHA)
|
|
|
|
|
{
|
2024-08-13 02:15:17 -07:00
|
|
|
|
_repo?.NavigateToCommit(commitSHA);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-23 01:52:55 -07:00
|
|
|
|
public List<Models.Decorator> GetRefsContainsThisCommit()
|
|
|
|
|
{
|
|
|
|
|
return new Commands.QueryRefsContainsCommit(_repo.FullPath, _commit.SHA).Result();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void ClearSearchChangeFilter()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
SearchChangeFilter = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 01:32:06 -07:00
|
|
|
|
public List<Models.Object> GetRevisionFilesUnderFolder(string parentFolder)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-08-13 02:15:17 -07:00
|
|
|
|
return new Commands.QueryRevisionObjects(_repo.FullPath, _commit.SHA, parentFolder).Result();
|
2024-06-07 01:32:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ViewRevisionFile(Models.Object file)
|
|
|
|
|
{
|
|
|
|
|
if (file == null)
|
|
|
|
|
{
|
|
|
|
|
ViewRevisionFileContent = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (file.Type)
|
|
|
|
|
{
|
|
|
|
|
case Models.ObjectType.Blob:
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-08-13 02:15:17 -07:00
|
|
|
|
var isBinary = new Commands.IsBinary(_repo.FullPath, _commit.SHA, file.Path).Result();
|
2024-06-07 01:32:06 -07:00
|
|
|
|
if (isBinary)
|
|
|
|
|
{
|
|
|
|
|
var ext = Path.GetExtension(file.Path);
|
|
|
|
|
if (IMG_EXTS.Contains(ext))
|
|
|
|
|
{
|
2024-08-13 02:15:17 -07:00
|
|
|
|
var stream = Commands.QueryFileContent.Run(_repo.FullPath, _commit.SHA, file.Path);
|
2024-06-07 01:32:06 -07:00
|
|
|
|
var bitmap = stream.Length > 0 ? new Bitmap(stream) : null;
|
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
ViewRevisionFileContent = new Models.RevisionImageFile() { Image = bitmap };
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-08-13 02:15:17 -07:00
|
|
|
|
var size = new Commands.QueryFileSize(_repo.FullPath, file.Path, _commit.SHA).Result();
|
2024-06-07 01:32:06 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
ViewRevisionFileContent = new Models.RevisionBinaryFile() { Size = size };
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 02:15:17 -07:00
|
|
|
|
var contentStream = Commands.QueryFileContent.Run(_repo.FullPath, _commit.SHA, file.Path);
|
2024-06-07 01:32:06 -07:00
|
|
|
|
var content = new StreamReader(contentStream).ReadToEnd();
|
2024-06-30 22:30:57 -07:00
|
|
|
|
var matchLFS = REG_LFS_FORMAT().Match(content);
|
|
|
|
|
if (matchLFS.Success)
|
2024-06-07 01:32:06 -07:00
|
|
|
|
{
|
|
|
|
|
var obj = new Models.RevisionLFSObject() { Object = new Models.LFSObject() };
|
2024-06-30 22:30:57 -07:00
|
|
|
|
obj.Object.Oid = matchLFS.Groups[1].Value;
|
|
|
|
|
obj.Object.Size = long.Parse(matchLFS.Groups[2].Value);
|
2024-06-07 01:32:06 -07:00
|
|
|
|
|
2024-06-30 22:30:57 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = obj);
|
|
|
|
|
}
|
|
|
|
|
else
|
2024-06-07 01:32:06 -07:00
|
|
|
|
{
|
2024-08-07 19:12:39 -07:00
|
|
|
|
var txt = new Models.RevisionTextFile() { FileName = file.Path, Content = content };
|
2024-07-14 09:30:31 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = txt);
|
2024-06-30 22:30:57 -07:00
|
|
|
|
}
|
2024-06-07 01:32:06 -07:00
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case Models.ObjectType.Commit:
|
2024-06-18 23:24:49 -07:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-08-13 02:15:17 -07:00
|
|
|
|
var submoduleRoot = Path.Combine(_repo.FullPath, file.Path);
|
2024-06-18 23:24:49 -07:00
|
|
|
|
var commit = new Commands.QuerySingleCommit(submoduleRoot, file.SHA).Result();
|
|
|
|
|
if (commit != null)
|
|
|
|
|
{
|
|
|
|
|
var body = new Commands.QueryCommitFullMessage(submoduleRoot, file.SHA).Result();
|
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
ViewRevisionFileContent = new Models.RevisionSubmodule()
|
|
|
|
|
{
|
|
|
|
|
Commit = commit,
|
|
|
|
|
FullMessage = body,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
ViewRevisionFileContent = new Models.RevisionSubmodule()
|
|
|
|
|
{
|
|
|
|
|
Commit = new Models.Commit() { SHA = file.SHA },
|
|
|
|
|
FullMessage = string.Empty,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-06-07 01:32:06 -07:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ViewRevisionFileContent = null;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public ContextMenu CreateChangeContextMenu(Models.Change change)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var menu = new ContextMenu();
|
|
|
|
|
|
2024-04-07 05:02:43 -07:00
|
|
|
|
var diffWithMerger = new MenuItem();
|
|
|
|
|
diffWithMerger.Header = App.Text("DiffWithMerger");
|
2024-07-15 00:40:15 -07:00
|
|
|
|
diffWithMerger.Icon = App.CreateMenuIcon("Icons.OpenWith");
|
2024-04-07 05:02:43 -07:00
|
|
|
|
diffWithMerger.Click += (_, ev) =>
|
|
|
|
|
{
|
2024-06-17 21:10:38 -07:00
|
|
|
|
var toolType = Preference.Instance.ExternalMergeToolType;
|
|
|
|
|
var toolPath = Preference.Instance.ExternalMergeToolPath;
|
2024-04-07 05:02:43 -07:00
|
|
|
|
var opt = new Models.DiffOption(_commit, change);
|
|
|
|
|
|
2024-08-13 02:15:17 -07:00
|
|
|
|
Task.Run(() => Commands.MergeTool.OpenForDiff(_repo.FullPath, toolType, toolPath, opt));
|
2024-04-07 05:02:43 -07:00
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
menu.Items.Add(diffWithMerger);
|
2024-08-15 07:13:20 -07:00
|
|
|
|
menu.Items.Add(new MenuItem { Header = "-" });
|
|
|
|
|
|
2024-08-15 23:49:26 -07:00
|
|
|
|
var fullPath = Path.Combine(_repo.FullPath, change.Path);
|
|
|
|
|
if (File.Exists(fullPath))
|
2024-08-15 07:13:20 -07:00
|
|
|
|
{
|
2024-08-15 23:49:26 -07:00
|
|
|
|
var explore = new MenuItem();
|
|
|
|
|
explore.Header = App.Text("RevealFile");
|
|
|
|
|
explore.Icon = App.CreateMenuIcon("Icons.Explore");
|
|
|
|
|
explore.Click += (_, ev) =>
|
|
|
|
|
{
|
|
|
|
|
Native.OS.OpenInFileManager(fullPath, true);
|
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-15 07:13:20 -07:00
|
|
|
|
menu.Items.Add(new MenuItem { Header = "-" });
|
2024-08-15 23:49:26 -07:00
|
|
|
|
menu.Items.Add(explore);
|
|
|
|
|
menu.Items.Add(new MenuItem { Header = "-" });
|
2024-08-15 07:13:20 -07:00
|
|
|
|
}
|
2024-04-07 05:02:43 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (change.Index != Models.ChangeState.Deleted)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var history = new MenuItem();
|
|
|
|
|
history.Header = App.Text("FileHistory");
|
2024-02-27 02:26:05 -08:00
|
|
|
|
history.Icon = App.CreateMenuIcon("Icons.Histories");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
history.Click += (_, ev) =>
|
|
|
|
|
{
|
2024-08-13 02:15:17 -07:00
|
|
|
|
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, change.Path) };
|
2024-02-05 23:08:37 -08:00
|
|
|
|
window.Show();
|
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var blame = new MenuItem();
|
|
|
|
|
blame.Header = App.Text("Blame");
|
2024-02-27 02:26:05 -08:00
|
|
|
|
blame.Icon = App.CreateMenuIcon("Icons.Blame");
|
2024-07-14 09:30:31 -07:00
|
|
|
|
blame.Click += (_, ev) =>
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-08-13 02:15:17 -07:00
|
|
|
|
var window = new Views.Blame() { DataContext = new Blame(_repo.FullPath, change.Path, _commit.SHA) };
|
2024-02-05 23:08:37 -08:00
|
|
|
|
window.Show();
|
|
|
|
|
ev.Handled = true;
|
2024-08-18 08:14:44 -07:00
|
|
|
|
};
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
menu.Items.Add(history);
|
|
|
|
|
menu.Items.Add(blame);
|
2024-04-07 05:02:43 -07:00
|
|
|
|
menu.Items.Add(new MenuItem { Header = "-" });
|
2024-04-07 18:57:41 -07:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-08-30 05:42:09 -07:00
|
|
|
|
var resetToThisRevision = new MenuItem();
|
|
|
|
|
resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision");
|
|
|
|
|
resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout");
|
|
|
|
|
resetToThisRevision.Click += (_, ev) =>
|
|
|
|
|
{
|
|
|
|
|
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_commit.SHA}");
|
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var resetToFirstParent = new MenuItem();
|
|
|
|
|
resetToFirstParent.Header = App.Text("ChangeCM.CheckoutFirstParentRevision");
|
|
|
|
|
resetToFirstParent.Icon = App.CreateMenuIcon("Icons.File.Checkout");
|
|
|
|
|
resetToFirstParent.IsEnabled = _commit.Parents.Count > 0;
|
|
|
|
|
resetToFirstParent.Click += (_, ev) =>
|
|
|
|
|
{
|
|
|
|
|
if (change.Index == Models.ChangeState.Renamed)
|
|
|
|
|
{
|
|
|
|
|
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.OriginalPath, $"{_commit.SHA}~1");
|
|
|
|
|
}
|
|
|
|
|
new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_commit.SHA}~1");
|
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var copyPath = new MenuItem();
|
|
|
|
|
copyPath.Header = App.Text("CopyPath");
|
2024-02-27 02:26:05 -08:00
|
|
|
|
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
copyPath.Click += (_, ev) =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
App.CopyText(change.Path);
|
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
2024-05-31 21:34:16 -07:00
|
|
|
|
|
|
|
|
|
var copyFileName = new MenuItem();
|
|
|
|
|
copyFileName.Header = App.Text("CopyFileName");
|
|
|
|
|
copyFileName.Icon = App.CreateMenuIcon("Icons.Copy");
|
2024-05-31 07:37:36 -07:00
|
|
|
|
copyFileName.Click += (_, e) =>
|
|
|
|
|
{
|
|
|
|
|
App.CopyText(Path.GetFileName(change.Path));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
2024-08-30 05:42:09 -07:00
|
|
|
|
|
|
|
|
|
menu.Items.Add(resetToThisRevision);
|
|
|
|
|
menu.Items.Add(resetToFirstParent);
|
|
|
|
|
menu.Items.Add(new MenuItem { Header = "-" });
|
|
|
|
|
menu.Items.Add(copyPath);
|
2024-05-31 07:37:36 -07:00
|
|
|
|
menu.Items.Add(copyFileName);
|
2024-06-06 00:31:02 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public ContextMenu CreateRevisionFileContextMenu(Models.Object file)
|
|
|
|
|
{
|
2024-08-15 23:49:26 -07:00
|
|
|
|
var fullPath = Path.Combine(_repo.FullPath, file.Path);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-08-15 23:49:26 -07:00
|
|
|
|
var resetToThisRevision = new MenuItem();
|
|
|
|
|
resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision");
|
|
|
|
|
resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout");
|
|
|
|
|
resetToThisRevision.IsEnabled = File.Exists(fullPath);
|
|
|
|
|
resetToThisRevision.Click += (_, ev) =>
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-08-15 23:49:26 -07:00
|
|
|
|
new Commands.Checkout(_repo.FullPath).FileWithRevision(file.Path, $"{_commit.SHA}");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-30 05:42:09 -07:00
|
|
|
|
var resetToFirstParent = new MenuItem();
|
|
|
|
|
resetToFirstParent.Header = App.Text("ChangeCM.CheckoutFirstParentRevision");
|
|
|
|
|
resetToFirstParent.Icon = App.CreateMenuIcon("Icons.File.Checkout");
|
|
|
|
|
var fileInChanges = _changes.Find(x => x.Path == file.Path);
|
|
|
|
|
var fileIndex = fileInChanges?.Index;
|
|
|
|
|
resetToFirstParent.IsEnabled = _commit.Parents.Count > 0 && fileIndex != Models.ChangeState.Renamed;
|
|
|
|
|
resetToFirstParent.Click += (_, ev) =>
|
|
|
|
|
{
|
|
|
|
|
new Commands.Checkout(_repo.FullPath).FileWithRevision(file.Path, $"{_commit.SHA}~1");
|
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var explore = new MenuItem();
|
|
|
|
|
explore.Header = App.Text("RevealFile");
|
2024-07-15 00:40:15 -07:00
|
|
|
|
explore.Icon = App.CreateMenuIcon("Icons.Explore");
|
2024-08-15 23:49:26 -07:00
|
|
|
|
explore.IsEnabled = File.Exists(fullPath);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
explore.Click += (_, ev) =>
|
|
|
|
|
{
|
2024-08-15 23:49:26 -07:00
|
|
|
|
Native.OS.OpenInFileManager(fullPath, file.Type == Models.ObjectType.Blob);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var saveAs = new MenuItem();
|
|
|
|
|
saveAs.Header = App.Text("SaveAs");
|
2024-02-27 02:26:05 -08:00
|
|
|
|
saveAs.Icon = App.CreateMenuIcon("Icons.Save");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
saveAs.IsEnabled = file.Type == Models.ObjectType.Blob;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
saveAs.Click += async (_, ev) =>
|
|
|
|
|
{
|
2024-08-18 21:49:04 -07:00
|
|
|
|
var storageProvider = App.GetStorageProvider();
|
|
|
|
|
if (storageProvider == null)
|
2024-03-31 01:54:29 -07:00
|
|
|
|
return;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
2024-08-26 19:40:49 -07:00
|
|
|
|
try
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-08-26 19:40:49 -07:00
|
|
|
|
var selected = await storageProvider.OpenFolderPickerAsync(options);
|
|
|
|
|
if (selected.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
var saveTo = Path.Combine(selected[0].Path.LocalPath, Path.GetFileName(file.Path));
|
|
|
|
|
Commands.SaveRevisionFile.Run(_repo.FullPath, _commit.SHA, file.Path, saveTo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
App.RaiseException(_repo.FullPath, $"Failed to save file: {e.Message}");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-15 23:49:26 -07:00
|
|
|
|
var history = new MenuItem();
|
|
|
|
|
history.Header = App.Text("FileHistory");
|
|
|
|
|
history.Icon = App.CreateMenuIcon("Icons.Histories");
|
|
|
|
|
history.Click += (_, ev) =>
|
|
|
|
|
{
|
|
|
|
|
var window = new Views.FileHistories() { DataContext = new FileHistories(_repo, file.Path) };
|
|
|
|
|
window.Show();
|
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var blame = new MenuItem();
|
|
|
|
|
blame.Header = App.Text("Blame");
|
|
|
|
|
blame.Icon = App.CreateMenuIcon("Icons.Blame");
|
|
|
|
|
blame.IsEnabled = file.Type == Models.ObjectType.Blob;
|
|
|
|
|
blame.Click += (_, ev) =>
|
|
|
|
|
{
|
|
|
|
|
var window = new Views.Blame() { DataContext = new Blame(_repo.FullPath, file.Path, _commit.SHA) };
|
|
|
|
|
window.Show();
|
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
2024-08-18 08:14:44 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var copyPath = new MenuItem();
|
|
|
|
|
copyPath.Header = App.Text("CopyPath");
|
2024-02-27 02:26:05 -08:00
|
|
|
|
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
copyPath.Click += (_, ev) =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
App.CopyText(file.Path);
|
|
|
|
|
ev.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-31 21:34:16 -07:00
|
|
|
|
var copyFileName = new MenuItem();
|
|
|
|
|
copyFileName.Header = App.Text("CopyFileName");
|
|
|
|
|
copyFileName.Icon = App.CreateMenuIcon("Icons.Copy");
|
2024-05-31 07:37:36 -07:00
|
|
|
|
copyFileName.Click += (_, e) =>
|
|
|
|
|
{
|
|
|
|
|
App.CopyText(Path.GetFileName(file.Path));
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var menu = new ContextMenu();
|
2024-08-15 23:49:26 -07:00
|
|
|
|
menu.Items.Add(resetToThisRevision);
|
2024-08-30 05:42:09 -07:00
|
|
|
|
menu.Items.Add(resetToFirstParent);
|
2024-08-15 23:49:26 -07:00
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
2024-02-05 23:08:37 -08:00
|
|
|
|
menu.Items.Add(explore);
|
|
|
|
|
menu.Items.Add(saveAs);
|
2024-08-15 23:49:26 -07:00
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
|
|
|
|
menu.Items.Add(history);
|
|
|
|
|
menu.Items.Add(blame);
|
|
|
|
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
2024-02-05 23:08:37 -08:00
|
|
|
|
menu.Items.Add(copyPath);
|
2024-05-31 07:37:36 -07:00
|
|
|
|
menu.Items.Add(copyFileName);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private void Refresh()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_changes = null;
|
2024-06-07 21:19:48 -07:00
|
|
|
|
FullMessage = string.Empty;
|
2024-07-29 00:07:41 -07:00
|
|
|
|
Changes = [];
|
2024-02-05 23:08:37 -08:00
|
|
|
|
VisibleChanges = null;
|
2024-05-28 06:19:53 -07:00
|
|
|
|
SelectedChanges = null;
|
2024-06-11 21:13:45 -07:00
|
|
|
|
ViewRevisionFileContent = null;
|
2024-05-28 06:19:53 -07:00
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_commit == null)
|
|
|
|
|
return;
|
2024-06-07 01:32:06 -07:00
|
|
|
|
|
2024-08-23 01:52:55 -07:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
var fullMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, _commit.SHA).Result();
|
|
|
|
|
Dispatcher.UIThread.Invoke(() => FullMessage = fullMessage);
|
|
|
|
|
});
|
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_cancelToken != null)
|
|
|
|
|
_cancelToken.Requested = true;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
_cancelToken = new Commands.Command.CancelToken();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-06-07 01:32:06 -07:00
|
|
|
|
var parent = _commit.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : _commit.Parents[0];
|
2024-08-13 02:15:17 -07:00
|
|
|
|
var cmdChanges = new Commands.CompareRevisions(_repo.FullPath, parent, _commit.SHA) { Cancel = _cancelToken };
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var changes = cmdChanges.Result();
|
|
|
|
|
var visible = changes;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(_searchChangeFilter))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
visible = new List<Models.Change>();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
foreach (var c in changes)
|
|
|
|
|
{
|
|
|
|
|
if (c.Path.Contains(_searchChangeFilter, StringComparison.OrdinalIgnoreCase))
|
2024-02-05 23:08:37 -08:00
|
|
|
|
visible.Add(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 01:32:06 -07:00
|
|
|
|
if (!cmdChanges.Cancel.Requested)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-06-07 01:32:06 -07:00
|
|
|
|
Dispatcher.UIThread.Post(() =>
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-06-07 01:32:06 -07:00
|
|
|
|
Changes = changes;
|
|
|
|
|
VisibleChanges = visible;
|
|
|
|
|
});
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private void RefreshVisibleChanges()
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_changes == null)
|
|
|
|
|
return;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (string.IsNullOrEmpty(_searchChangeFilter))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
VisibleChanges = _changes;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var visible = new List<Models.Change>();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
foreach (var c in _changes)
|
|
|
|
|
{
|
|
|
|
|
if (c.Path.Contains(_searchChangeFilter, StringComparison.OrdinalIgnoreCase))
|
2024-02-05 23:08:37 -08:00
|
|
|
|
visible.Add(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VisibleChanges = visible;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 22:30:57 -07:00
|
|
|
|
[GeneratedRegex(@"^version https://git-lfs.github.com/spec/v\d+\r?\noid sha256:([0-9a-f]+)\r?\nsize (\d+)[\r\n]*$")]
|
|
|
|
|
private static partial Regex REG_LFS_FORMAT();
|
|
|
|
|
|
2024-03-27 06:38:38 -07:00
|
|
|
|
private static readonly HashSet<string> IMG_EXTS = new HashSet<string>()
|
|
|
|
|
{
|
2024-08-28 03:58:01 -07:00
|
|
|
|
".ico", ".bmp", ".jpg", ".png", ".jpeg", ".webp"
|
2024-03-27 06:38:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
2024-08-13 02:15:17 -07:00
|
|
|
|
private Repository _repo = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private int _activePageIndex = 0;
|
|
|
|
|
private Models.Commit _commit = null;
|
2024-06-07 21:19:48 -07:00
|
|
|
|
private string _fullMessage = string.Empty;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private List<Models.Change> _changes = null;
|
|
|
|
|
private List<Models.Change> _visibleChanges = null;
|
2024-05-28 06:19:53 -07:00
|
|
|
|
private List<Models.Change> _selectedChanges = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private string _searchChangeFilter = string.Empty;
|
|
|
|
|
private DiffContext _diffContext = null;
|
|
|
|
|
private object _viewRevisionFileContent = null;
|
|
|
|
|
private Commands.Command.CancelToken _cancelToken = null;
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|