Jump to the selected item when refreshing the server list

https://github.com/2dust/v2rayN/issues/6800
This commit is contained in:
2dust 2025-02-26 16:36:36 +08:00
parent 6d6894591c
commit a18ae5582b
3 changed files with 64 additions and 16 deletions

View file

@ -247,7 +247,10 @@ namespace v2rayN.Desktop.Views
case EViewAction.AddServerViaClipboard: case EViewAction.AddServerViaClipboard:
var clipboardData = await AvaUtils.GetClipboardData(this); var clipboardData = await AvaUtils.GetClipboardData(this);
ViewModel?.AddServerViaClipboardAsync(clipboardData); if (ViewModel != null)
{
await ViewModel.AddServerViaClipboardAsync(clipboardData);
}
break; break;
case EViewAction.AdjustMainLvColWidth: case EViewAction.AdjustMainLvColWidth:
@ -294,7 +297,10 @@ namespace v2rayN.Desktop.Views
break; break;
case WindowCloseReason.ApplicationShutdown or WindowCloseReason.OSShutdown: case WindowCloseReason.ApplicationShutdown or WindowCloseReason.OSShutdown:
await ViewModel?.MyAppExitAsync(true); if (ViewModel != null)
{
await ViewModel.MyAppExitAsync(true);
}
break; break;
} }
@ -309,7 +315,10 @@ namespace v2rayN.Desktop.Views
{ {
case Key.V: case Key.V:
var clipboardData = await AvaUtils.GetClipboardData(this); var clipboardData = await AvaUtils.GetClipboardData(this);
ViewModel?.AddServerViaClipboardAsync(clipboardData); if (ViewModel != null)
{
await ViewModel.AddServerViaClipboardAsync(clipboardData);
}
break; break;
case Key.S: case Key.S:
@ -358,7 +367,11 @@ namespace v2rayN.Desktop.Views
{ {
return; return;
} }
await ViewModel?.ScanImageResult(fileName);
if (ViewModel != null)
{
await ViewModel.ScanImageResult(fileName);
}
} }
private void MenuCheckUpdate_Click(object? sender, RoutedEventArgs e) private void MenuCheckUpdate_Click(object? sender, RoutedEventArgs e)
@ -382,8 +395,10 @@ namespace v2rayN.Desktop.Views
_blCloseByUser = true; _blCloseByUser = true;
StorageUI(); StorageUI();
if (ViewModel != null)
await ViewModel?.MyAppExitAsync(false); {
await ViewModel.MyAppExitAsync(false);
}
} }
#endregion Event #endregion Event

View file

@ -102,11 +102,16 @@ namespace v2rayN.Desktop.Views
private async void LstProfiles_Sorting(object? sender, DataGridColumnEventArgs e) private async void LstProfiles_Sorting(object? sender, DataGridColumnEventArgs e)
{ {
e.Handled = true; e.Handled = true;
await ViewModel?.SortServer(e.Column.Tag.ToString());
if (ViewModel != null && e.Column?.Tag?.ToString() != null)
{
await ViewModel.SortServer(e.Column.Tag.ToString());
}
e.Handled = false; e.Handled = false;
} }
//#region Event #region Event
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj) private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
{ {
@ -179,7 +184,9 @@ namespace v2rayN.Desktop.Views
case EViewAction.DispatcherRefreshServersBiz: case EViewAction.DispatcherRefreshServersBiz:
Dispatcher.UIThread.Post(() => Dispatcher.UIThread.Post(() =>
ViewModel?.RefreshServersBiz(), {
_ = RefreshServersBiz();
},
DispatcherPriority.Default); DispatcherPriority.Default);
break; break;
} }
@ -198,6 +205,19 @@ namespace v2rayN.Desktop.Views
await DialogHost.Show(dialog); await DialogHost.Show(dialog);
} }
public async Task RefreshServersBiz()
{
if (ViewModel != null)
{
await ViewModel.RefreshServersBiz();
}
if (lstProfiles.SelectedIndex > 0)
{
lstProfiles.ScrollIntoView(lstProfiles.SelectedItem, null);
}
}
private void lstProfiles_SelectionChanged(object? sender, SelectionChangedEventArgs e) private void lstProfiles_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{ {
ViewModel.SelectedProfiles = lstProfiles.SelectedItems.Cast<ProfileItemModel>().ToList(); ViewModel.SelectedProfiles = lstProfiles.SelectedItems.Cast<ProfileItemModel>().ToList();
@ -333,9 +353,9 @@ namespace v2rayN.Desktop.Views
} }
} }
//#endregion Event #endregion Event
//#region UI #region UI
private void RestoreUI() private void RestoreUI()
{ {
@ -388,9 +408,9 @@ namespace v2rayN.Desktop.Views
_config.UiItem.MainColumnItem = lvColumnItem; _config.UiItem.MainColumnItem = lvColumnItem;
} }
//#endregion UI #endregion UI
//#region Drag and Drop #region Drag and Drop
//private Point startPoint = new(); //private Point startPoint = new();
//private int startIndex = -1; //private int startIndex = -1;
@ -480,6 +500,6 @@ namespace v2rayN.Desktop.Views
// } // }
//} //}
//#endregion Drag and Drop #endregion Drag and Drop
} }
} }

View file

@ -166,7 +166,7 @@ namespace v2rayN.Views
case EViewAction.DispatcherRefreshServersBiz: case EViewAction.DispatcherRefreshServersBiz:
Application.Current?.Dispatcher.Invoke((() => Application.Current?.Dispatcher.Invoke((() =>
{ {
ViewModel?.RefreshServersBiz(); _ = RefreshServersBiz();
}), DispatcherPriority.Normal); }), DispatcherPriority.Normal);
break; break;
} }
@ -186,6 +186,19 @@ namespace v2rayN.Views
await DialogHost.Show(dialog, "RootDialog"); await DialogHost.Show(dialog, "RootDialog");
} }
public async Task RefreshServersBiz()
{
if (ViewModel != null)
{
await ViewModel.RefreshServersBiz();
}
if (lstProfiles.SelectedIndex > 0)
{
lstProfiles.ScrollIntoView(lstProfiles.SelectedItem, null);
}
}
private void lstProfiles_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) private void lstProfiles_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{ {
ViewModel.SelectedProfiles = lstProfiles.SelectedItems.Cast<ProfileItemModel>().ToList(); ViewModel.SelectedProfiles = lstProfiles.SelectedItems.Cast<ProfileItemModel>().ToList();