mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
enhance: disable some MenuItems if repository that linked by node has been auto-removed from Preference (#90).
This commit is contained in:
parent
9b5e8429b9
commit
32e685622b
3 changed files with 81 additions and 34 deletions
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using Avalonia.Collections;
|
using Avalonia.Collections;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
@ -79,7 +80,7 @@ namespace SourceGit.ViewModels
|
||||||
SearchFilter = string.Empty;
|
SearchFilter = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddFolder()
|
public void AddRootNode()
|
||||||
{
|
{
|
||||||
if (PopupHost.CanCreatePopup())
|
if (PopupHost.CanCreatePopup())
|
||||||
PopupHost.ShowPopup(new CreateGroup(null));
|
PopupHost.ShowPopup(new CreateGroup(null));
|
||||||
|
@ -90,6 +91,72 @@ namespace SourceGit.ViewModels
|
||||||
Preference.MoveNode(from, to);
|
Preference.MoveNode(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ContextMenu CreateContextMenu(RepositoryNode node)
|
||||||
|
{
|
||||||
|
var menu = new ContextMenu();
|
||||||
|
var hasRepo = Preference.FindRepository(node.Id) != null;
|
||||||
|
|
||||||
|
var edit = new MenuItem();
|
||||||
|
edit.Header = App.Text("Welcome.Edit");
|
||||||
|
edit.Icon = App.CreateMenuIcon("Icons.Edit");
|
||||||
|
edit.IsEnabled = !node.IsRepository || hasRepo;
|
||||||
|
edit.Click += (_, e) =>
|
||||||
|
{
|
||||||
|
node.Edit();
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
menu.Items.Add(edit);
|
||||||
|
|
||||||
|
if (node.IsRepository)
|
||||||
|
{
|
||||||
|
var explore = new MenuItem();
|
||||||
|
explore.Header = App.Text("Repository.Explore");
|
||||||
|
explore.Icon = App.CreateMenuIcon("Icons.Folder.Open");
|
||||||
|
explore.IsEnabled = hasRepo;
|
||||||
|
explore.Click += (_, e) =>
|
||||||
|
{
|
||||||
|
node.OpenInFileManager();
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
menu.Items.Add(explore);
|
||||||
|
|
||||||
|
var terminal = new MenuItem();
|
||||||
|
terminal.Header = App.Text("Repository.Terminal");
|
||||||
|
terminal.Icon = App.CreateMenuIcon("Icons.Terminal");
|
||||||
|
terminal.IsEnabled = hasRepo;
|
||||||
|
terminal.Click += (_, e) =>
|
||||||
|
{
|
||||||
|
node.OpenTerminal();
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
menu.Items.Add(terminal);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var addSubFolder = new MenuItem();
|
||||||
|
addSubFolder.Header = App.Text("Welcome.AddSubFolder");
|
||||||
|
addSubFolder.Icon = App.CreateMenuIcon("Icons.Folder.Add");
|
||||||
|
addSubFolder.Click += (_, e) =>
|
||||||
|
{
|
||||||
|
node.AddSubFolder();
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
menu.Items.Add(addSubFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
var delete = new MenuItem();
|
||||||
|
delete.Header = App.Text("Welcome.Delete");
|
||||||
|
delete.Icon = App.CreateMenuIcon("Icons.Clear");
|
||||||
|
delete.Click += (_, e) =>
|
||||||
|
{
|
||||||
|
node.Delete();
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
menu.Items.Add(delete);
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
private void Referesh()
|
private void Referesh()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(_searchFilter))
|
if (string.IsNullOrWhiteSpace(_searchFilter))
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
LostFocus="OnTreeViewLostFocus">
|
LostFocus="OnTreeViewLostFocus">
|
||||||
<TreeView.ContextMenu>
|
<TreeView.ContextMenu>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<MenuItem Header="{DynamicResource Text.Welcome.AddRootFolder}" Command="{Binding AddFolder}">
|
<MenuItem Header="{DynamicResource Text.Welcome.AddRootFolder}" Command="{Binding AddRootNode}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<Path Width="12" Height="12" Data="{DynamicResource Icons.Folder.Add}"/>
|
<Path Width="12" Height="12" Data="{DynamicResource Icons.Folder.Add}"/>
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
|
@ -70,37 +70,6 @@
|
||||||
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
|
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
|
||||||
<Setter Property="IsVisible" Value="{Binding IsVisible}"/>
|
<Setter Property="IsVisible" Value="{Binding IsVisible}"/>
|
||||||
<Setter Property="CornerRadius" Value="4"/>
|
<Setter Property="CornerRadius" Value="4"/>
|
||||||
<Setter Property="ContextMenu">
|
|
||||||
<Setter.Value>
|
|
||||||
<ContextMenu>
|
|
||||||
<MenuItem Header="{DynamicResource Text.Welcome.Edit}" Command="{Binding Edit}">
|
|
||||||
<MenuItem.Icon>
|
|
||||||
<Path Width="12" Height="12" Data="{DynamicResource Icons.Edit}"/>
|
|
||||||
</MenuItem.Icon>
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem Header="{DynamicResource Text.Welcome.AddSubFolder}" Command="{Binding AddSubFolder}" IsVisible="{Binding !IsRepository}">
|
|
||||||
<MenuItem.Icon>
|
|
||||||
<Path Width="12" Height="12" Data="{DynamicResource Icons.Folder.Add}"/>
|
|
||||||
</MenuItem.Icon>
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem Header="{DynamicResource Text.Repository.Explore}" Command="{Binding OpenInFileManager}" IsVisible="{Binding IsRepository}">
|
|
||||||
<MenuItem.Icon>
|
|
||||||
<Path Width="12" Height="12" Data="{DynamicResource Icons.Folder.Open}"/>
|
|
||||||
</MenuItem.Icon>
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem Header="{DynamicResource Text.Repository.Terminal}" Command="{Binding OpenTerminal}" IsVisible="{Binding IsRepository}">
|
|
||||||
<MenuItem.Icon>
|
|
||||||
<Path Width="12" Height="12" Data="{DynamicResource Icons.Terminal}"/>
|
|
||||||
</MenuItem.Icon>
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem Header="{DynamicResource Text.Welcome.Delete}" Command="{Binding Delete}">
|
|
||||||
<MenuItem.Icon>
|
|
||||||
<Path Width="12" Height="12" Data="{DynamicResource Icons.Clear}"/>
|
|
||||||
</MenuItem.Icon>
|
|
||||||
</MenuItem>
|
|
||||||
</ContextMenu>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
</Style>
|
</Style>
|
||||||
</TreeView.Styles>
|
</TreeView.Styles>
|
||||||
|
|
||||||
|
@ -109,11 +78,12 @@
|
||||||
<Grid Height="30"
|
<Grid Height="30"
|
||||||
ColumnDefinitions="Auto,Auto,*"
|
ColumnDefinitions="Auto,Auto,*"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
|
Loaded="SetupTreeNodeDragAndDrop"
|
||||||
|
ContextRequested="OnTreeNodeContextRequested"
|
||||||
PointerPressed="OnPointerPressedTreeNode"
|
PointerPressed="OnPointerPressedTreeNode"
|
||||||
PointerMoved="OnPointerMovedOverTreeNode"
|
PointerMoved="OnPointerMovedOverTreeNode"
|
||||||
PointerReleased="OnPointerReleasedOnTreeNode"
|
PointerReleased="OnPointerReleasedOnTreeNode"
|
||||||
DoubleTapped="OnDoubleTappedTreeNode"
|
DoubleTapped="OnDoubleTappedTreeNode"
|
||||||
Loaded="SetupTreeNodeDragAndDrop"
|
|
||||||
ClipToBounds="True">
|
ClipToBounds="True">
|
||||||
<Path Grid.Column="0" Width="12" Height="12" Margin="0,0,8,0"
|
<Path Grid.Column="0" Width="12" Height="12" Margin="0,0,8,0"
|
||||||
Fill="{Binding Bookmark, Converter={x:Static c:BookmarkConverters.ToBrush}}"
|
Fill="{Binding Bookmark, Converter={x:Static c:BookmarkConverters.ToBrush}}"
|
||||||
|
|
|
@ -37,6 +37,16 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnTreeNodeContextRequested(object sender, ContextRequestedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is Grid grid && DataContext is ViewModels.Welcome vm)
|
||||||
|
{
|
||||||
|
var menu = vm.CreateContextMenu(grid.DataContext as ViewModels.RepositoryNode);
|
||||||
|
menu?.Open(grid);
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnPointerPressedTreeNode(object sender, PointerPressedEventArgs e)
|
private void OnPointerPressedTreeNode(object sender, PointerPressedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.GetCurrentPoint(sender as Visual).Properties.IsLeftButtonPressed)
|
if (e.GetCurrentPoint(sender as Visual).Properties.IsLeftButtonPressed)
|
||||||
|
|
Loading…
Reference in a new issue