Skip to content

Commit e6f486c

Browse files
committed
fix UI
1 parent 75e1a5b commit e6f486c

File tree

11 files changed

+267
-63
lines changed

11 files changed

+267
-63
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Windows.Input;
3+
4+
namespace Diol.Wpf.Core.Services
5+
{
6+
public class RelayCommand : ICommand
7+
{
8+
private readonly Action<object> _execute;
9+
private readonly Func<object, bool> _canExecute;
10+
11+
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
12+
{
13+
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
14+
_canExecute = canExecute;
15+
}
16+
17+
public bool CanExecute(object parameter) => _canExecute?.Invoke(parameter) ?? true;
18+
19+
public void Execute(object parameter) => _execute(parameter);
20+
21+
public event EventHandler CanExecuteChanged
22+
{
23+
add => CommandManager.RequerySuggested += value;
24+
remove => CommandManager.RequerySuggested -= value;
25+
}
26+
}
27+
}

source/Diol/src/Diol.Wpf.Core/ViewModels/AspnetDetailViewModel.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
using Diol.Wpf.Core.Features.Aspnetcores;
22
using Diol.Wpf.Core.Features.Shared;
3+
using Diol.Wpf.Core.Services;
34
using Prism.Commands;
45
using Prism.Events;
56
using Prism.Mvvm;
67
using System.Collections.Generic;
78
using System.Collections.ObjectModel;
9+
using System.Text;
10+
using System.Windows;
11+
using System.Windows.Controls;
12+
using System.Windows.Input;
813

914
namespace Diol.Wpf.Core.ViewModels
1015
{
@@ -88,6 +93,8 @@ public string ResponseBodyAsString
8893
public ObservableCollection<KeyValuePair<string, string>> ResponseHeaders { get; set; } =
8994
new ObservableCollection<KeyValuePair<string, string>>();
9095

96+
public ICommand CopyCommand { get; }
97+
9198
/// <summary>
9299
/// Initializes a new instance of the <see cref="AspnetDetailViewModel"/> class.
93100
/// </summary>
@@ -107,6 +114,8 @@ public AspnetDetailViewModel(
107114
this.eventAggregator
108115
.GetEvent<ClearDataEvent>()
109116
.Subscribe(HandleClearDataEvent, ThreadOption.UIThread);
117+
118+
this.CopyCommand = new RelayCommand(CopySelectedData);
110119
}
111120

112121
private DelegateCommand _closeCommand = null;
@@ -172,5 +181,18 @@ private void HandleClearDataEvent(string obj)
172181
this.ResponseHeaders.Clear();
173182
this.ResponseBodyAsString = string.Empty;
174183
}
184+
185+
private void CopySelectedData(object parameter)
186+
{
187+
if (parameter is DataGrid dataGrid && dataGrid.SelectedItems != null)
188+
{
189+
var sb = new StringBuilder();
190+
foreach (var item in dataGrid.SelectedItems)
191+
{
192+
sb.AppendLine(item.ToString());
193+
}
194+
Clipboard.SetText(sb.ToString());
195+
}
196+
}
175197
}
176198
}

source/Diol/src/Diol.Wpf.Core/ViewModels/HttpDetailViewModel.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
using Diol.Share.Features.Httpclients;
22
using Diol.Wpf.Core.Features.Https;
33
using Diol.Wpf.Core.Features.Shared;
4+
using Diol.Wpf.Core.Services;
45
using Prism.Commands;
56
using Prism.Events;
67
using Prism.Mvvm;
78
using System.Collections.Generic;
89
using System.Collections.ObjectModel;
10+
using System.Text;
11+
using System.Windows;
12+
using System.Windows.Controls;
13+
using System.Windows.Input;
914

1015
namespace Diol.Wpf.Core.ViewModels
1116
{
@@ -49,6 +54,8 @@ public RequestPipelineEndDto Response
4954
public ObservableCollection<KeyValuePair<string, string>> ResponseHeaders { get; set; } =
5055
new ObservableCollection<KeyValuePair<string, string>>();
5156

57+
public ICommand CopyCommand { get; }
58+
5259
/// <summary>
5360
/// Initializes a new instance of the <see cref="HttpDetailViewModel"/> class.
5461
/// </summary>
@@ -68,6 +75,8 @@ public HttpDetailViewModel(
6875
this.eventAggregator
6976
.GetEvent<ClearDataEvent>()
7077
.Subscribe(HandleClearDataEvent, ThreadOption.UIThread);
78+
79+
this.CopyCommand = new RelayCommand(CopySelectedData);
7180
}
7281

7382
private DelegateCommand _closeCommand = null;
@@ -123,5 +132,18 @@ private void HandleHttpItemSelectedEvent(string obj)
123132
}
124133
}
125134
}
135+
136+
private void CopySelectedData(object parameter)
137+
{
138+
if (parameter is DataGrid dataGrid && dataGrid.SelectedItems != null)
139+
{
140+
var sb = new StringBuilder();
141+
foreach (var item in dataGrid.SelectedItems)
142+
{
143+
sb.AppendLine(item.ToString());
144+
}
145+
Clipboard.SetText(sb.ToString());
146+
}
147+
}
126148
}
127149
}

source/Diol/src/Diol.Wpf.Core/Views/AspnetComponent.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
<GridSplitter
2525
Grid.Column="1"
2626
Width="5"
27-
HorizontalAlignment="Stretch"/>
27+
HorizontalAlignment="Stretch"
28+
IsEnabled="False"/>
2829

2930
<local:AspnetDetail Grid.Column="2" />
3031

source/Diol/src/Diol.Wpf.Core/Views/AspnetDetail.xaml

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
Command="{Binding CloseCommand}"
2020
FontFamily="Segoe UI Symbol"
2121
Content="&#xE10A;" />
22-
2322
<GroupBox
2423
Header="General">
2524
<StackPanel>
@@ -41,25 +40,49 @@
4140
IsReadOnly="True" />
4241
</StackPanel>
4342
</GroupBox>
44-
4543
<GroupBox
4644
Header="Request headers">
4745
<DataGrid
4846
ItemsSource="{Binding RequestHeaders}"
4947
AutoGenerateColumns="False"
5048
IsReadOnly="True"
51-
HeadersVisibility="None">
49+
HeadersVisibility="None"
50+
ScrollViewer.CanContentScroll="False"
51+
ScrollViewer.VerticalScrollBarVisibility="Disabled"
52+
PreviewMouseWheel="DataGrid_PreviewMouseWheel">
5253
<DataGrid.Columns>
53-
<DataGridTextColumn
54+
<DataGridTemplateColumn
5455
Header="Key"
5556
Width="auto"
56-
MinWidth="70"
57-
Binding="{Binding Key}"/>
58-
<DataGridTextColumn
59-
Header="Value"
60-
Width="*"
61-
Binding="{Binding Value}"/>
57+
MaxWidth="70">
58+
<DataGridTemplateColumn.CellTemplate>
59+
<DataTemplate>
60+
<TextBlock
61+
Text="{Binding Key}"
62+
TextWrapping="Wrap"
63+
FontWeight="Bold"/>
64+
</DataTemplate>
65+
</DataGridTemplateColumn.CellTemplate>
66+
</DataGridTemplateColumn>
67+
<DataGridTemplateColumn
68+
Header="Key"
69+
Width="*">
70+
<DataGridTemplateColumn.CellTemplate>
71+
<DataTemplate>
72+
<TextBlock
73+
Text="{Binding Value}"
74+
TextWrapping="Wrap"/>
75+
</DataTemplate>
76+
</DataGridTemplateColumn.CellTemplate>
77+
</DataGridTemplateColumn>
6278
</DataGrid.Columns>
79+
<DataGrid.InputBindings>
80+
<KeyBinding
81+
Key="C"
82+
Modifiers="Ctrl"
83+
Command="{Binding CopyCommand}"
84+
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
85+
</DataGrid.InputBindings>
6386
</DataGrid>
6487
</GroupBox>
6588

@@ -80,18 +103,43 @@
80103
ItemsSource="{Binding ResponseHeaders}"
81104
AutoGenerateColumns="False"
82105
IsReadOnly="True"
83-
HeadersVisibility="None">
106+
HeadersVisibility="None"
107+
ScrollViewer.CanContentScroll="False"
108+
ScrollViewer.VerticalScrollBarVisibility="Disabled"
109+
PreviewMouseWheel="DataGrid_PreviewMouseWheel">
84110
<DataGrid.Columns>
85-
<DataGridTextColumn
111+
<DataGridTemplateColumn
86112
Header="Key"
87113
Width="auto"
88-
MinWidth="70"
89-
Binding="{Binding Key}"/>
90-
<DataGridTextColumn
91-
Header="Value"
92-
Width="*"
93-
Binding="{Binding Value}"/>
114+
MaxWidth="70">
115+
<DataGridTemplateColumn.CellTemplate>
116+
<DataTemplate>
117+
<TextBlock
118+
Text="{Binding Key}"
119+
TextWrapping="Wrap"
120+
FontWeight="Bold"/>
121+
</DataTemplate>
122+
</DataGridTemplateColumn.CellTemplate>
123+
</DataGridTemplateColumn>
124+
<DataGridTemplateColumn
125+
Header="Key"
126+
Width="*">
127+
<DataGridTemplateColumn.CellTemplate>
128+
<DataTemplate>
129+
<TextBlock
130+
Text="{Binding Value}"
131+
TextWrapping="Wrap"/>
132+
</DataTemplate>
133+
</DataGridTemplateColumn.CellTemplate>
134+
</DataGridTemplateColumn>
94135
</DataGrid.Columns>
136+
<DataGrid.InputBindings>
137+
<KeyBinding
138+
Key="C"
139+
Modifiers="Ctrl"
140+
Command="{Binding CopyCommand}"
141+
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
142+
</DataGrid.InputBindings>
95143
</DataGrid>
96144
</GroupBox>
97145

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Windows;
1+
using System.Windows;
72
using System.Windows.Controls;
8-
using System.Windows.Data;
9-
using System.Windows.Documents;
103
using System.Windows.Input;
114
using System.Windows.Media;
12-
using System.Windows.Media.Imaging;
13-
using System.Windows.Navigation;
14-
using System.Windows.Shapes;
155

166
namespace Diol.Wpf.Core.Views
177
{
@@ -24,5 +14,31 @@ public AspnetDetail()
2414
{
2515
InitializeComponent();
2616
}
17+
18+
private void DataGrid_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
19+
{
20+
var scrollViewer = FindParent<ScrollViewer>((DependencyObject)sender);
21+
if (scrollViewer != null)
22+
{
23+
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - e.Delta);
24+
e.Handled = true;
25+
}
26+
}
27+
28+
private static T FindParent<T>(DependencyObject child) where T : DependencyObject
29+
{
30+
DependencyObject parentObject = VisualTreeHelper.GetParent(child);
31+
if (parentObject == null) return null;
32+
33+
T parent = parentObject as T;
34+
if (parent != null)
35+
{
36+
return parent;
37+
}
38+
else
39+
{
40+
return FindParent<T>(parentObject);
41+
}
42+
}
2743
}
2844
}

source/Diol/src/Diol.Wpf.Core/Views/EntityFrameworkComponent.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
<GridSplitter
2525
Grid.Column="1"
2626
Width="5"
27-
HorizontalAlignment="Stretch"/>
27+
HorizontalAlignment="Stretch"
28+
IsEnabled="False"/>
2829

2930
<local:EntityFrameworkDetail Grid.Column="2" />
3031
</Grid>

source/Diol/src/Diol.Wpf.Core/Views/HttpComponent.xaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
x:Name="cd_detail"
1919
Width="{Binding DetailWidth}" />
2020
</Grid.ColumnDefinitions>
21-
21+
2222
<local:HttpMaster Grid.Column="0"/>
23-
23+
2424
<GridSplitter
2525
Grid.Column="1"
2626
Width="5"
27-
HorizontalAlignment="Stretch"/>
27+
HorizontalAlignment="Stretch"
28+
IsEnabled="False"/>
2829

29-
<local:HttpDetail Grid.Column="2" />
30+
<local:HttpDetail Grid.Column="2"/>
3031

3132
</Grid>
3233
</UserControl>

0 commit comments

Comments
 (0)