2024-03-17 18:37:06 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
using Avalonia.Collections;
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class Welcome : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
public bool IsClearSearchVisible
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => !string.IsNullOrEmpty(_searchFilter);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public AvaloniaList<RepositoryNode> RepositoryNodes
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => Preference.Instance.RepositoryNodes;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string SearchFilter
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _searchFilter;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _searchFilter, value))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Referesh();
|
|
|
|
|
OnPropertyChanged(nameof(IsClearSearchVisible));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void InitRepository(string path)
|
|
|
|
|
{
|
|
|
|
|
if (!Preference.Instance.IsGitConfigured)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
App.RaiseException(PopupHost.Active.GetId(), App.Text("NotConfigured"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
PopupHost.ShowPopup(new Init(path));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Clone(object param)
|
|
|
|
|
{
|
2024-02-21 19:05:20 -08:00
|
|
|
|
var launcher = param as Launcher;
|
|
|
|
|
var page = launcher.ActivePage;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (!Preference.Instance.IsGitConfigured)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
App.RaiseException(page.GetId(), App.Text("NotConfigured"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
{
|
2024-02-21 19:05:20 -08:00
|
|
|
|
PopupHost.ShowPopup(new Clone(launcher, page));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void OpenTerminal()
|
|
|
|
|
{
|
|
|
|
|
if (!Preference.Instance.IsGitConfigured)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
App.RaiseException(PopupHost.Active.GetId(), App.Text("NotConfigured"));
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Native.OS.OpenTerminal(null);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void ClearSearchFilter()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
SearchFilter = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void AddFolder()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new CreateGroup(null));
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void MoveNode(RepositoryNode from, RepositoryNode to)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Preference.MoveNode(from, to);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private void Referesh()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(_searchFilter))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
foreach (var node in RepositoryNodes) ResetVisibility(node);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
foreach (var node in RepositoryNodes) SetVisibilityBySearch(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private void ResetVisibility(RepositoryNode node)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
node.IsVisible = true;
|
|
|
|
|
foreach (var subNode in node.SubNodes) ResetVisibility(subNode);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private void SetVisibilityBySearch(RepositoryNode node)
|
|
|
|
|
{
|
|
|
|
|
if (!node.IsRepository)
|
|
|
|
|
{
|
|
|
|
|
if (node.Name.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
node.IsVisible = true;
|
|
|
|
|
foreach (var subNode in node.SubNodes) ResetVisibility(subNode);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
bool hasVisibleSubNode = false;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
foreach (var subNode in node.SubNodes)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
SetVisibilityBySearch(subNode);
|
|
|
|
|
hasVisibleSubNode |= subNode.IsVisible;
|
|
|
|
|
}
|
|
|
|
|
node.IsVisible = hasVisibleSubNode;
|
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
node.IsVisible = node.Name.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _searchFilter = string.Empty;
|
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|