增加导入后自动选中最后一项

This commit is contained in:
ww-rm
2025-09-08 21:50:11 +08:00
parent 13ef873650
commit 415df555c7
2 changed files with 34 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ using SpineViewer.ViewModels.Exporters;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text;
@@ -45,6 +46,11 @@ namespace SpineViewer.ViewModels.MainWindow
_customFFmpegExporterViewModel = new(_vmMain);
}
/// <summary>
/// 请求选中项发生变化
/// </summary>
public event NotifyCollectionChangedEventHandler? RequestSelectionChanging;
/// <summary>
/// 单帧导出 ViewModel
/// </summary>
@@ -489,6 +495,19 @@ namespace SpineViewer.ViewModels.MainWindow
{
var sp = new SpineObjectModel(skelPath, atlasPath);
lock (_spineObjectModels.Lock) _spineObjectModels.Add(sp);
if (Application.Current.Dispatcher.CheckAccess())
{
RequestSelectionChanging?.Invoke(this, new(NotifyCollectionChangedAction.Reset));
RequestSelectionChanging?.Invoke(this, new(NotifyCollectionChangedAction.Add, sp));
}
else
{
Application.Current.Dispatcher.Invoke(() =>
{
RequestSelectionChanging?.Invoke(this, new(NotifyCollectionChangedAction.Reset));
RequestSelectionChanging?.Invoke(this, new(NotifyCollectionChangedAction.Add, sp));
});
}
return true;
}
catch (Exception ex)
@@ -505,6 +524,19 @@ namespace SpineViewer.ViewModels.MainWindow
{
var sp = new SpineObjectModel(cfg);
lock (_spineObjectModels.Lock) _spineObjectModels.Add(sp);
if (Application.Current.Dispatcher.CheckAccess())
{
RequestSelectionChanging?.Invoke(this, new(NotifyCollectionChangedAction.Reset));
RequestSelectionChanging?.Invoke(this, new(NotifyCollectionChangedAction.Add, sp));
}
else
{
Application.Current.Dispatcher.Invoke(() =>
{
RequestSelectionChanging?.Invoke(this, new(NotifyCollectionChangedAction.Reset));
RequestSelectionChanging?.Invoke(this, new(NotifyCollectionChangedAction.Add, sp));
});
}
return true;
}
catch (Exception ex)

View File

@@ -30,7 +30,7 @@ namespace SpineViewer.Views;
public partial class MainWindow : Window
{
/// <summary>
/// 布局文件保存路径
/// 上一次状态文件保存路径
/// </summary>
public static readonly string LastStateFilePath = Path.Combine(Path.GetDirectoryName(Environment.ProcessPath), "laststate.json");
@@ -46,8 +46,8 @@ public partial class MainWindow : Window
InitializeLogConfiguration();
_vm = new (_renderPanel);
DataContext = _vm;
_vm.SpineObjectListViewModel.RequestSelectionChanging += SpinesListView_RequestSelectionChanging;
_vm.SFMLRendererViewModel.RequestSelectionChanging += SpinesListView_RequestSelectionChanging;
Loaded += MainWindow_Loaded;
Closed += MainWindow_Closed;
}