mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-26 21:04:59 +00:00
fix: show AddFolder menu in context menu of RepositoryNode
This commit is contained in:
parent
4b027f4349
commit
d5885da683
2 changed files with 26 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
|
@ -481,6 +482,12 @@ namespace SourceGit.ViewModels
|
|||
File.WriteAllText(_savePath, data);
|
||||
}
|
||||
|
||||
public static RepositoryNode FindParentNode(RepositoryNode node)
|
||||
{
|
||||
var container = FindNodeContainer(node, _instance._repositoryNodes);
|
||||
return container == null ? null : _instance._repositoryNodes.FirstOrDefault(parentNode => parentNode.SubNodes == container);
|
||||
}
|
||||
|
||||
private static RepositoryNode FindNodeRecursive(string id, AvaloniaList<RepositoryNode> collection)
|
||||
{
|
||||
foreach (var node in collection)
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace SourceGit.ViewModels
|
|||
set
|
||||
{
|
||||
if (SetProperty(ref _searchFilter, value))
|
||||
Referesh();
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,9 @@ namespace SourceGit.ViewModels
|
|||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(edit);
|
||||
|
||||
var parentNode = Preference.FindParentNode(node);
|
||||
var folderNode = !node.IsRepository ? node : (parentNode is { IsRepository: false } ? parentNode : null);
|
||||
|
||||
if (node.IsRepository)
|
||||
{
|
||||
|
@ -147,6 +150,19 @@ namespace SourceGit.ViewModels
|
|||
};
|
||||
menu.Items.Add(terminal);
|
||||
}
|
||||
|
||||
if (folderNode == null)
|
||||
{
|
||||
var addFolder = new MenuItem();
|
||||
addFolder.Header = App.Text("Welcome.AddRootFolder");
|
||||
addFolder.Icon = App.CreateMenuIcon("Icons.Folder.Add");
|
||||
addFolder.Click += (_, e) =>
|
||||
{
|
||||
AddRootNode();
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(addFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
var addSubFolder = new MenuItem();
|
||||
|
@ -154,7 +170,7 @@ namespace SourceGit.ViewModels
|
|||
addSubFolder.Icon = App.CreateMenuIcon("Icons.Folder.Add");
|
||||
addSubFolder.Click += (_, e) =>
|
||||
{
|
||||
node.AddSubFolder();
|
||||
folderNode.AddSubFolder();
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(addSubFolder);
|
||||
|
@ -173,7 +189,7 @@ namespace SourceGit.ViewModels
|
|||
return menu;
|
||||
}
|
||||
|
||||
private void Referesh()
|
||||
private void Refresh()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchFilter))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue