Skip to content

Commit

Permalink
fix UI
Browse files Browse the repository at this point in the history
  • Loading branch information
OlzhabaevSh committed Aug 9, 2024
1 parent 75e1a5b commit e6f486c
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 63 deletions.
27 changes: 27 additions & 0 deletions source/Diol/src/Diol.Wpf.Core/Services/RelayCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Windows.Input;

namespace Diol.Wpf.Core.Services
{
public class RelayCommand : ICommand
{
private readonly Action<object> _execute;
private readonly Func<object, bool> _canExecute;

public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
_canExecute = canExecute;
}

public bool CanExecute(object parameter) => _canExecute?.Invoke(parameter) ?? true;

public void Execute(object parameter) => _execute(parameter);

public event EventHandler CanExecuteChanged
{
add => CommandManager.RequerySuggested += value;
remove => CommandManager.RequerySuggested -= value;
}
}
}
22 changes: 22 additions & 0 deletions source/Diol/src/Diol.Wpf.Core/ViewModels/AspnetDetailViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using Diol.Wpf.Core.Features.Aspnetcores;
using Diol.Wpf.Core.Features.Shared;
using Diol.Wpf.Core.Services;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Diol.Wpf.Core.ViewModels
{
Expand Down Expand Up @@ -88,6 +93,8 @@ public string ResponseBodyAsString
public ObservableCollection<KeyValuePair<string, string>> ResponseHeaders { get; set; } =
new ObservableCollection<KeyValuePair<string, string>>();

public ICommand CopyCommand { get; }

/// <summary>
/// Initializes a new instance of the <see cref="AspnetDetailViewModel"/> class.
/// </summary>
Expand All @@ -107,6 +114,8 @@ public AspnetDetailViewModel(
this.eventAggregator
.GetEvent<ClearDataEvent>()
.Subscribe(HandleClearDataEvent, ThreadOption.UIThread);

this.CopyCommand = new RelayCommand(CopySelectedData);
}

private DelegateCommand _closeCommand = null;
Expand Down Expand Up @@ -172,5 +181,18 @@ private void HandleClearDataEvent(string obj)
this.ResponseHeaders.Clear();
this.ResponseBodyAsString = string.Empty;
}

private void CopySelectedData(object parameter)
{
if (parameter is DataGrid dataGrid && dataGrid.SelectedItems != null)
{
var sb = new StringBuilder();
foreach (var item in dataGrid.SelectedItems)
{
sb.AppendLine(item.ToString());
}
Clipboard.SetText(sb.ToString());
}
}
}
}
22 changes: 22 additions & 0 deletions source/Diol/src/Diol.Wpf.Core/ViewModels/HttpDetailViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using Diol.Share.Features.Httpclients;
using Diol.Wpf.Core.Features.Https;
using Diol.Wpf.Core.Features.Shared;
using Diol.Wpf.Core.Services;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

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

public ICommand CopyCommand { get; }

/// <summary>
/// Initializes a new instance of the <see cref="HttpDetailViewModel"/> class.
/// </summary>
Expand All @@ -68,6 +75,8 @@ public HttpDetailViewModel(
this.eventAggregator
.GetEvent<ClearDataEvent>()
.Subscribe(HandleClearDataEvent, ThreadOption.UIThread);

this.CopyCommand = new RelayCommand(CopySelectedData);
}

private DelegateCommand _closeCommand = null;
Expand Down Expand Up @@ -123,5 +132,18 @@ private void HandleHttpItemSelectedEvent(string obj)
}
}
}

private void CopySelectedData(object parameter)
{
if (parameter is DataGrid dataGrid && dataGrid.SelectedItems != null)
{
var sb = new StringBuilder();
foreach (var item in dataGrid.SelectedItems)
{
sb.AppendLine(item.ToString());
}
Clipboard.SetText(sb.ToString());
}
}
}
}
3 changes: 2 additions & 1 deletion source/Diol/src/Diol.Wpf.Core/Views/AspnetComponent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<GridSplitter
Grid.Column="1"
Width="5"
HorizontalAlignment="Stretch"/>
HorizontalAlignment="Stretch"
IsEnabled="False"/>

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

Expand Down
84 changes: 66 additions & 18 deletions source/Diol/src/Diol.Wpf.Core/Views/AspnetDetail.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
Command="{Binding CloseCommand}"
FontFamily="Segoe UI Symbol"
Content="&#xE10A;" />

<GroupBox
Header="General">
<StackPanel>
Expand All @@ -41,25 +40,49 @@
IsReadOnly="True" />
</StackPanel>
</GroupBox>

<GroupBox
Header="Request headers">
<DataGrid
ItemsSource="{Binding RequestHeaders}"
AutoGenerateColumns="False"
IsReadOnly="True"
HeadersVisibility="None">
HeadersVisibility="None"
ScrollViewer.CanContentScroll="False"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
PreviewMouseWheel="DataGrid_PreviewMouseWheel">
<DataGrid.Columns>
<DataGridTextColumn
<DataGridTemplateColumn
Header="Key"
Width="auto"
MinWidth="70"
Binding="{Binding Key}"/>
<DataGridTextColumn
Header="Value"
Width="*"
Binding="{Binding Value}"/>
MaxWidth="70">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
Text="{Binding Key}"
TextWrapping="Wrap"
FontWeight="Bold"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
Header="Key"
Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
Text="{Binding Value}"
TextWrapping="Wrap"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
<DataGrid.InputBindings>
<KeyBinding
Key="C"
Modifiers="Ctrl"
Command="{Binding CopyCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
</DataGrid.InputBindings>
</DataGrid>
</GroupBox>

Expand All @@ -80,18 +103,43 @@
ItemsSource="{Binding ResponseHeaders}"
AutoGenerateColumns="False"
IsReadOnly="True"
HeadersVisibility="None">
HeadersVisibility="None"
ScrollViewer.CanContentScroll="False"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
PreviewMouseWheel="DataGrid_PreviewMouseWheel">
<DataGrid.Columns>
<DataGridTextColumn
<DataGridTemplateColumn
Header="Key"
Width="auto"
MinWidth="70"
Binding="{Binding Key}"/>
<DataGridTextColumn
Header="Value"
Width="*"
Binding="{Binding Value}"/>
MaxWidth="70">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
Text="{Binding Key}"
TextWrapping="Wrap"
FontWeight="Bold"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
Header="Key"
Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
Text="{Binding Value}"
TextWrapping="Wrap"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
<DataGrid.InputBindings>
<KeyBinding
Key="C"
Modifiers="Ctrl"
Command="{Binding CopyCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
</DataGrid.InputBindings>
</DataGrid>
</GroupBox>

Expand Down
38 changes: 27 additions & 11 deletions source/Diol/src/Diol.Wpf.Core/Views/AspnetDetail.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Diol.Wpf.Core.Views
{
Expand All @@ -24,5 +14,31 @@ public AspnetDetail()
{
InitializeComponent();
}

private void DataGrid_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
var scrollViewer = FindParent<ScrollViewer>((DependencyObject)sender);
if (scrollViewer != null)
{
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - e.Delta);
e.Handled = true;
}
}

private static T FindParent<T>(DependencyObject child) where T : DependencyObject
{
DependencyObject parentObject = VisualTreeHelper.GetParent(child);
if (parentObject == null) return null;

T parent = parentObject as T;
if (parent != null)
{
return parent;
}
else
{
return FindParent<T>(parentObject);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<GridSplitter
Grid.Column="1"
Width="5"
HorizontalAlignment="Stretch"/>
HorizontalAlignment="Stretch"
IsEnabled="False"/>

<local:EntityFrameworkDetail Grid.Column="2" />
</Grid>
Expand Down
9 changes: 5 additions & 4 deletions source/Diol/src/Diol.Wpf.Core/Views/HttpComponent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
x:Name="cd_detail"
Width="{Binding DetailWidth}" />
</Grid.ColumnDefinitions>

<local:HttpMaster Grid.Column="0"/>

<GridSplitter
Grid.Column="1"
Width="5"
HorizontalAlignment="Stretch"/>
HorizontalAlignment="Stretch"
IsEnabled="False"/>

<local:HttpDetail Grid.Column="2" />
<local:HttpDetail Grid.Column="2"/>

</Grid>
</UserControl>
Loading

0 comments on commit e6f486c

Please sign in to comment.