mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-07 20:04:59 +00:00
feature: git command logs
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
928a0ad3c5
commit
8b39df32cc
101 changed files with 1040 additions and 573 deletions
87
src/ViewModels/CommandLog.cs
Normal file
87
src/ViewModels/CommandLog.cs
Normal file
|
@ -0,0 +1,87 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using Avalonia.Threading;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class CommandLog : ObservableObject, Models.ICommandLog
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = string.Empty;
|
||||
|
||||
public DateTime Time
|
||||
{
|
||||
get;
|
||||
} = DateTime.Now;
|
||||
|
||||
public string TimeStr
|
||||
{
|
||||
get => Time.ToString("T");
|
||||
}
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = false;
|
||||
|
||||
public string Content
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsComplete ? _content : _builder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public CommandLog(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public void Register(Action<string> handler)
|
||||
{
|
||||
if (!IsComplete)
|
||||
_onNewLineReceived += handler;
|
||||
}
|
||||
|
||||
public void AppendLine(string line = null)
|
||||
{
|
||||
var newline = line ?? string.Empty;
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
_builder.AppendLine(newline);
|
||||
_onNewLineReceived?.Invoke(newline);
|
||||
});
|
||||
}
|
||||
|
||||
public void Complete()
|
||||
{
|
||||
IsComplete = true;
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
_content = _builder.ToString();
|
||||
_builder.Clear();
|
||||
_builder = null;
|
||||
|
||||
OnPropertyChanged(nameof(IsComplete));
|
||||
|
||||
if (_onNewLineReceived != null)
|
||||
{
|
||||
var dumpHandlers = _onNewLineReceived.GetInvocationList();
|
||||
foreach (var d in dumpHandlers)
|
||||
_onNewLineReceived -= (Action<string>)d;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private string _content = string.Empty;
|
||||
private StringBuilder _builder = new StringBuilder();
|
||||
private event Action<string> _onNewLineReceived;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue