2024-07-14 09:30:31 -07:00
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
using Avalonia.Platform.Storage;
|
|
|
|
using Avalonia.VisualTree;
|
|
|
|
|
|
|
|
namespace SourceGit.Views
|
|
|
|
{
|
|
|
|
public partial class WelcomeToolbar : UserControl
|
|
|
|
{
|
|
|
|
public WelcomeToolbar()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
|
|
|
private async void OpenLocalRepository(object _1, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
if (!ViewModels.PopupHost.CanCreatePopup())
|
|
|
|
return;
|
|
|
|
|
|
|
|
var topLevel = TopLevel.GetTopLevel(this);
|
|
|
|
if (topLevel == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
|
|
|
var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
|
|
|
|
if (selected.Count == 1)
|
|
|
|
OpenOrInitRepository(selected[0].Path.LocalPath);
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OpenOrInitRepository(string path, ViewModels.RepositoryNode parent = null)
|
|
|
|
{
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
{
|
|
|
|
if (File.Exists(path))
|
|
|
|
path = Path.GetDirectoryName(path);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var root = new Commands.QueryRepositoryRootPath(path).Result();
|
|
|
|
if (string.IsNullOrEmpty(root))
|
|
|
|
{
|
2024-07-22 00:34:31 -07:00
|
|
|
ViewModels.Welcome.Instance.InitRepository(path, parent);
|
2024-07-14 09:30:31 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var normalizedPath = root.Replace("\\", "/");
|
2024-07-22 00:34:31 -07:00
|
|
|
var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, parent, true);
|
2024-07-14 09:30:31 -07:00
|
|
|
var launcher = this.FindAncestorOfType<Launcher>()?.DataContext as ViewModels.Launcher;
|
|
|
|
launcher?.OpenRepositoryInTab(node, launcher.ActivePage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|