Skip to content

Commit 46f15aa

Browse files
committed
Add ViewModel metthods.
1 parent 6140864 commit 46f15aa

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

tests/Stratis.DevEx.Wpf.Test/BlockchainExplorer/BlockchainExplorerToolWindowControl.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<!-- bindings for context menu commands -->
4545
<CommandBinding Command="{x:Static stratisui:BlockchainExplorerTree.NewNetworkCmd}" Executed="NewNetworkCmdExecuted" />
4646
<CommandBinding Command="{x:Static stratisui:BlockchainExplorerTree.NewEndpointCmd}" Executed="NewEndpointCmd_Executed" />
47+
<CommandBinding Command="{x:Static stratisui:BlockchainExplorerTree.DeleteEndpointCmd}" Executed="DeleteEndpointCmd_Executed" CanExecute="DeleteEndpointCmd_CanExecute" />
4748
</UserControl.CommandBindings>
4849

4950
</UserControl>

tests/Stratis.DevEx.Wpf.Test/BlockchainExplorer/BlockchainExplorerToolWindowControl.xaml.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private async void NewNetworkCmdExecuted(object sender, ExecutedRoutedEventArgs
118118
else
119119
{
120120
validForClose = false;
121-
ShowValidationErrors(errors, "Enter a network name and a valid JSON-RPC URL.");
121+
ShowValidationErrors(errors, "Enter a network name and a valid JSON-RPC endpoint URL.");
122122
}
123123
}
124124
else
@@ -203,6 +203,12 @@ private async void NewEndpointCmd_Executed(object sender, ExecutedRoutedEventArg
203203
}
204204
}
205205

206+
private BlockchainInfo GetSelectedItem(object sender)
207+
{
208+
var window = (BlockchainExplorerToolWindowControl)sender;
209+
var tree = window.BlockchainExplorerTree;
210+
return tree.SelectedItem;
211+
}
206212
private void ShowValidationErrors(Wpc.TextBlock textBlock, string message)
207213
{
208214
textBlock.Visibility = Visibility.Visible;
@@ -226,8 +232,24 @@ private void HideProgressRing(ProgressRing progressRing)
226232

227233
#region Fields
228234
internal BlockchainExplorerToolWindow window;
235+
229236
#endregion
230237

238+
private void DeleteEndpointCmd_Executed(object sender, ExecutedRoutedEventArgs e)
239+
{
240+
var item = GetSelectedItem(sender);
241+
item.Parent.DeleteChild(item);
242+
}
231243

244+
private void DeleteEndpointCmd_CanExecute(object sender, CanExecuteRoutedEventArgs e)
245+
{
246+
var item = GetSelectedItem(sender);
247+
var endpoints = item.GetEndPoints();
248+
if (endpoints.Count() == 1)
249+
{
250+
e.CanExecute = false;
251+
}
252+
e.CanExecute = (item.Parent.Name == "Stratis MainNet");
253+
}
232254
}
233255
}

tests/Stratis.DevEx.Wpf.Test/BlockchainExplorer/BlockchainExplorerTree.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class BlockchainExplorerTree : TreeViewBase<BlockchainInfo>
1717
public static RoutedCommand NewNetworkCmd { get; } = new RoutedCommand();
1818

1919
public static RoutedCommand NewEndpointCmd { get; } = new RoutedCommand();
20+
21+
public static RoutedCommand DeleteEndpointCmd { get; } = new RoutedCommand();
2022
#endregion
2123

2224
#region Methods
@@ -37,6 +39,10 @@ protected override TreeViewItem CreateTreeViewItem(BlockchainInfo data)
3739
{
3840
item.ContextMenu = (ContextMenu)TryFindResource("NetworkContextMenu");
3941
}
42+
else if (data.Kind == BlockchainInfoKind.Endpoint)
43+
{
44+
item.ContextMenu = (ContextMenu)TryFindResource("EndpointContextMenu");
45+
}
4046
return item;
4147
}
4248
#endregion

tests/Stratis.DevEx.Wpf.Test/BlockchainExplorer/BlockchainExplorerTreeResources.xaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,34 @@
9292
</DrawingImage.Drawing>
9393
</DrawingImage>
9494

95+
<DrawingImage x:Key="DeleteFileDrawingImage">
96+
<DrawingImage.Drawing>
97+
<DrawingGroup ClipGeometry="M0,0 V24 H24 V0 H0 Z">
98+
<GeometryDrawing>
99+
<GeometryDrawing.Pen>
100+
<Pen Brush="{DynamicResource TextFillColorPrimaryBrush}" Thickness="2" StartLineCap="Round" EndLineCap="Round" LineJoin="Round" />
101+
</GeometryDrawing.Pen>
102+
<GeometryDrawing.Geometry>
103+
<LineGeometry StartPoint="10.5,10.5" EndPoint="13.5,13.5" />
104+
</GeometryDrawing.Geometry>
105+
</GeometryDrawing>
106+
<GeometryDrawing>
107+
<GeometryDrawing.Pen>
108+
<Pen Brush="{DynamicResource TextFillColorPrimaryBrush}" Thickness="2" StartLineCap="Round" EndLineCap="Round" LineJoin="Round" />
109+
</GeometryDrawing.Pen>
110+
<GeometryDrawing.Geometry>
111+
<LineGeometry StartPoint="13.5,10.5" EndPoint="10.5,13.5" />
112+
</GeometryDrawing.Geometry>
113+
</GeometryDrawing>
114+
<GeometryDrawing Geometry="F1 M24,24z M0,0z M6,21A1,1,0,0,1,5,20L5,4A1,1,0,0,1,6,3L15,3 19,7 19,20A1,1,0,0,1,18,21z">
115+
<GeometryDrawing.Pen>
116+
<Pen Brush="{DynamicResource TextFillColorPrimaryBrush}" Thickness="2" StartLineCap="Round" EndLineCap="Round" LineJoin="Round" />
117+
</GeometryDrawing.Pen>
118+
</GeometryDrawing>
119+
</DrawingGroup>
120+
</DrawingImage.Drawing>
121+
</DrawingImage>
122+
95123
<!-- TreeView items data template-->
96124
<DataTemplate x:Key="BlockchainInfoTemplate" DataType="{x:Type vm:BlockchainInfo}">
97125
<StackPanel x:Name="GroupPanel" Orientation="Horizontal" Margin="0,2,0,2">
@@ -173,6 +201,14 @@
173201
</MenuItem>
174202
</ContextMenu>
175203

204+
<ContextMenu x:Key="EndpointContextMenu" Style="{DynamicResource ContextMenuStyle}">
205+
<MenuItem Header="Delete" Command="{x:Static stratisui:BlockchainExplorerTree.DeleteEndpointCmd}">
206+
<MenuItem.Icon>
207+
<Image Source="{StaticResource DeleteFileDrawingImage}" />
208+
</MenuItem.Icon>
209+
</MenuItem>
210+
</ContextMenu>
211+
176212
<ContextMenu x:Key="StratisNetworkContextMenu" Style="{DynamicResource ContextMenuStyle}">
177213
<MenuItem Header="Statistics" Command="{x:Static stratisui:BlockchainExplorerTree.NewEndpointCmd}">
178214
<MenuItem.Icon>

tests/Stratis.DevEx.Wpf.Test/BlockchainExplorer/BlockchainViewModel.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ public BlockchainInfo AddChild(BlockchainInfoKind kind, string name, object data
5454
return info;
5555
}
5656

57-
public BlockchainInfo GetChild(string name, BlockchainInfoKind kind) => Children.Single(c => c.Name == name && c.Kind == kind);
57+
public void DeleteChild(BlockchainInfo child) => Children.Remove(child);
58+
59+
public void DeleteChild(string name, BlockchainInfoKind kind) => Children.Remove(GetChild(name, kind));
60+
61+
public BlockchainInfo GetChild(string name, BlockchainInfoKind kind) => Children.Single(c => c.Name == name && c.Kind == kind);
62+
63+
public IEnumerable<BlockchainInfo> GetChildren(BlockchainInfoKind kind) => Children.Where(c => c.Kind == kind);
64+
65+
public IEnumerable<BlockchainInfo> GetEndPoints() => GetChildren(BlockchainInfoKind.Endpoint);
5866
#endregion
5967
}
6068

0 commit comments

Comments
 (0)