Fix ipinfo copy functionality (#10515)

* Fix ipinfo copy functionality

* Code clean

* Code clean
This commit is contained in:
DHR60
2026-11-03 11:43:06 +00:00
committed by GitHub
parent 281f5ee3c7
commit fe54a73d74
6 changed files with 27 additions and 156 deletions
@@ -1,5 +1,3 @@
using System.Security.Principal;
namespace ServiceLib.Handler;
public static class AutoStartupHandler
@@ -1,5 +1,3 @@
using System.Data;
namespace ServiceLib.Handler;
public static class ConfigHandler
@@ -1,4 +1,3 @@
using YamlDotNet.Core;
using YamlDotNet.RepresentationModel;
namespace ServiceLib.Services.CoreConfig;
@@ -1,4 +1,3 @@
using System.Text.Json;
using System.Xml;
using AvaloniaEdit.Highlighting;
using AvaloniaEdit.Highlighting.Xshd;
+11 -2
View File
@@ -353,10 +353,19 @@
Tag="IpInfo">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<SelectableTextBlock
<TextBlock
Margin="{StaticResource MarginLr8}"
VerticalAlignment="Center"
Text="{Binding Path=IpInfo, Mode=OneWay}" />
Text="{Binding Path=IpInfo, Mode=OneWay}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem
Click="CopyIpInfo_Click"
CommandParameter="{Binding IpInfo}"
Header="{x:Static resx:ResUI.menuEditCopy}" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
+16 -148
View File
@@ -23,16 +23,6 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
lstProfiles.SelectionChanged += lstProfiles_SelectionChanged;
lstProfiles.DoubleTapped += LstProfiles_DoubleTapped;
lstProfiles.Sorting += LstProfiles_Sorting;
//if (_config.UiItem.EnableDragDropSort)
//{
// lstProfiles.SetValue(DragDrop.AllowDropProperty, true);
// lstProfiles.AddHandler(PointerPressedEvent, LstProfiles_PointerPressed, RoutingStrategies.Bubble, true);
// lstProfiles.AddHandler(PointerMovedEvent, LstProfiles_PointerMoved, RoutingStrategies.Bubble, true);
// lstProfiles.AddHandler(PointerReleasedEvent, LstProfiles_PointerReleased, RoutingStrategies.Bubble, true);
// lstProfiles.AddHandler(DragDrop.DragOverEvent, LstProfiles_DragOver, RoutingStrategies.Bubble);
// lstProfiles.AddHandler(DragDrop.DropEvent, LstProfiles_Drop, RoutingStrategies.Bubble);
//}
this.WhenActivated(disposables =>
{
@@ -214,7 +204,7 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
}
}
private void LstProfiles_DoubleTapped(object? sender, Avalonia.Input.TappedEventArgs e)
private void LstProfiles_DoubleTapped(object? sender, TappedEventArgs e)
{
var source = e.Source as Border;
if (source?.Name == "HeaderBackground")
@@ -418,6 +408,21 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
}
}
private async void CopyIpInfo_Click(object? sender, RoutedEventArgs e)
{
try
{
if (sender is MenuItem { CommandParameter: string text } && !text.IsNullOrEmpty())
{
await AvaUtils.SetClipboardData(this, text);
}
}
catch
{
// Ignore
}
}
private void StorageUI()
{
try
@@ -446,143 +451,6 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
#endregion UI
//#region Drag and Drop
//private static readonly DataFormat<ProfileItemModel> LstProfilesRowFormat =
// DataFormat.CreateInProcessFormat<ProfileItemModel>("LstProfilesRow");
//private (Point, PointerPressedEventArgs)? _dragStartPoint;
//private void LstProfiles_PointerPressed(object? sender, PointerPressedEventArgs e)
//{
// var properties = e.GetCurrentPoint(this).Properties;
// if (properties.IsLeftButtonPressed)
// {
// _dragStartPoint = (e.GetPosition(this), e);
// }
//}
//private async void LstProfiles_PointerMoved(object? sender, PointerEventArgs e)
//{
// try
// {
// if (_dragStartPoint == null)
// {
// return;
// }
// var properties = e.GetCurrentPoint(this).Properties;
// if (!properties.IsLeftButtonPressed)
// {
// _dragStartPoint = null;
// return;
// }
// var currentPoint = e.GetPosition(this);
// var startPoint = _dragStartPoint.Value.Item1;
// var delta = startPoint - currentPoint;
// var threshold = new Vector(4, 4);
// if (!(Math.Abs(delta.X) >= threshold.X) && !(Math.Abs(delta.Y) >= threshold.Y))
// {
// return;
// }
// var dragStartEventArgs = _dragStartPoint.Value.Item2;
// _dragStartPoint = null;
// if (e.Source is not Visual visualSource)
// {
// return;
// }
// var row = visualSource.FindAncestorOfType<DataGridRow>(true);
// if (row?.DataContext == null)
// {
// return;
// }
// e.Handled = true;
// var dragData = new DataTransfer();
// var item = DataTransferItem.Create(LstProfilesRowFormat, row.DataContext as ProfileItemModel);
// dragData.Add(item);
// await DragDrop.DoDragDropAsync(dragStartEventArgs, dragData, DragDropEffects.Move);
// }
// catch
// {
// // Ignore
// }
//}
//private void LstProfiles_PointerReleased(object? sender, PointerReleasedEventArgs e)
//{
// _dragStartPoint = null;
//}
//private void LstProfiles_DragOver(object? sender, DragEventArgs e)
//{
// if (!e.DataTransfer.Contains(LstProfilesRowFormat))
// {
// e.DragEffects = DragDropEffects.None;
// return;
// }
// e.DragEffects = DragDropEffects.Move;
//}
//private void LstProfiles_Drop(object? sender, DragEventArgs e)
//{
// if (!e.DataTransfer.Contains(LstProfilesRowFormat))
// {
// return;
// }
// ProfileItemModel? sourceItem = null;
// foreach (var item in e.DataTransfer.Items)
// {
// if (!item.Formats.Contains(LstProfilesRowFormat))
// {
// continue;
// }
// if (item.TryGetRaw(LstProfilesRowFormat) is not ProfileItemModel model)
// {
// continue;
// }
// sourceItem = model;
// break;
// }
// if (sourceItem == null)
// {
// return;
// }
// if (e.Source is not Visual visualTarget)
// {
// return;
// }
// var targetRow = visualTarget.FindAncestorOfType<DataGridRow>(true);
// if (targetRow is not { DataContext: ProfileItemModel targetItem })
// {
// return;
// }
// if (ReferenceEquals(sourceItem, targetItem))
// {
// return;
// }
// if (lstProfiles.ItemsSource is not IList<ProfileItemModel> items)
// {
// return;
// }
// var oldIndex = items.IndexOf(sourceItem);
// var newIndex = items.IndexOf(targetItem);
// if (oldIndex >= 0 && newIndex >= 0)
// {
// ViewModel?.MoveServerTo(oldIndex, targetItem);
// }
//}
//#endregion Drag and Drop
private sealed class ProfileRowDropHandler(ProfilesViewModel viewModel) : IDataGridRowDropHandler
{
private readonly DataGridRowReorderHandler _reorderHandler = new();