mirror of
https://github.com/LorisYounger/VPet.ModMaker.git
synced 2024-08-30 18:22:21 +00:00
98 lines
2.9 KiB
C#
98 lines
2.9 KiB
C#
using HKW.HKWViewModels.SimpleObservable;
|
|
using LinePutScript.Localization.WPF;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using VPet.ModMaker.Models;
|
|
using VPet.ModMaker.Views.ModEdit.SelectTextEdit;
|
|
|
|
namespace VPet.ModMaker.ViewModels.ModEdit.SelectTextEdit;
|
|
|
|
public class SelectTextPageVM
|
|
{
|
|
#region Value
|
|
public ObservableValue<ObservableCollection<SelectTextModel>> ShowSelectTexts { get; } = new();
|
|
public ObservableCollection<SelectTextModel> SelectTexts => ModInfoModel.Current.SelectTexts;
|
|
public ObservableValue<string> Filter { get; } = new();
|
|
#endregion
|
|
#region Command
|
|
public ObservableCommand AddCommand { get; } = new();
|
|
public ObservableCommand<SelectTextModel> EditCommand { get; } = new();
|
|
public ObservableCommand<SelectTextModel> RemoveCommand { get; } = new();
|
|
#endregion
|
|
|
|
public SelectTextPageVM()
|
|
{
|
|
ShowSelectTexts.Value = SelectTexts;
|
|
Filter.ValueChanged += Filter_ValueChanged;
|
|
AddCommand.ExecuteEvent += Add;
|
|
EditCommand.ExecuteEvent += Edit;
|
|
RemoveCommand.ExecuteEvent += Remove;
|
|
}
|
|
|
|
private void Filter_ValueChanged(string value)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
ShowSelectTexts.Value = SelectTexts;
|
|
}
|
|
else
|
|
{
|
|
ShowSelectTexts.Value = new(
|
|
SelectTexts.Where(
|
|
m => m.Name.Value.Contains(value, StringComparison.OrdinalIgnoreCase)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
private void Add()
|
|
{
|
|
var window = new SelectTextEditWindow();
|
|
var vm = window.ViewModel;
|
|
window.ShowDialog();
|
|
if (window.IsCancel)
|
|
return;
|
|
SelectTexts.Add(vm.SelectText.Value);
|
|
}
|
|
|
|
public void Edit(SelectTextModel model)
|
|
{
|
|
var window = new SelectTextEditWindow();
|
|
var vm = window.ViewModel;
|
|
vm.OldSelectText = model;
|
|
var newLowTest = vm.SelectText.Value = new(model);
|
|
window.ShowDialog();
|
|
if (window.IsCancel)
|
|
return;
|
|
if (ShowSelectTexts.Value.Count == SelectTexts.Count)
|
|
{
|
|
SelectTexts[SelectTexts.IndexOf(model)] = newLowTest;
|
|
}
|
|
else
|
|
{
|
|
SelectTexts[SelectTexts.IndexOf(model)] = newLowTest;
|
|
ShowSelectTexts.Value[ShowSelectTexts.Value.IndexOf(model)] = newLowTest;
|
|
}
|
|
}
|
|
|
|
private void Remove(SelectTextModel model)
|
|
{
|
|
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
|
|
return;
|
|
if (ShowSelectTexts.Value.Count == SelectTexts.Count)
|
|
{
|
|
SelectTexts.Remove(model);
|
|
}
|
|
else
|
|
{
|
|
ShowSelectTexts.Value.Remove(model);
|
|
SelectTexts.Remove(model);
|
|
}
|
|
}
|
|
}
|