123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using TranslateTool.Managers;
- using TranslateTool.Model;
- namespace TranslateTool.ViewModel
- {
- public class HandleRepaetItemPageViewModel:ViewModel
- {
- private readonly List<RepeatItem> _items;
- private readonly string _languageName;
- private readonly ClientManager _clientManager;
- private RepeatItem _repeatItem;
- private string _key;
- private List<string> _contents;
- private bool _isLastItem;
- private string _selectContent;
- private string _repeatMessage;
- public string RepeatMessage
- {
- get => _repeatMessage;
- set
- {
- if (_repeatMessage != value)
- {
- _repeatMessage = value;
- OnPropertyChanged(() => RepeatMessage);
- }
- }
- }
- public string SelectContent
- {
- get => _selectContent;
- set
- {
- if (_selectContent != value)
- {
- _selectContent = value;
- OnPropertyChanged(() => SelectContent);
- }
- }
- }
- public bool IsLastItem
- {
- get => _isLastItem;
- set
- {
- if (_isLastItem != value)
- {
- _isLastItem = value;
- OnPropertyChanged(() => IsLastItem);
- }
- }
- }
- public List<string> Contents
- {
- get => _contents;
- set
- {
- if (_contents != value)
- {
- _contents = value;
- SelectContent = string.Empty;
- OnPropertyChanged(() => Contents);
- }
- }
- }
- public string Key
- {
- get => _key;
- set
- {
- if (_key != value)
- {
- _key = value;
- OnPropertyChanged(() => Key);
- }
- }
- }
-
- public ButtonCommand NextCommand { get; }
- public ButtonCommand FinishCommand { get; }
- public HandleRepaetItemPageViewModel(string languageName, List<RepeatItem> repeatItems)
- {
- _clientManager = ClientManager.CreateInstance();
- _languageName = languageName;
- _items = repeatItems;
- NextCommand = new ButtonCommand(OnNext, "Next");
- FinishCommand = new ButtonCommand(OnFinish, "Finish");
- _repeatItem = repeatItems.First();
- Key = _repeatItem.Key;
- Contents = new List<string>(_repeatItem.Contents);
- RepeatMessage = $"有{_items.Count}条重复内容,请选择要使用的内容!";
- }
- private void OnFinish(object obj)
- {
- if (!string.IsNullOrEmpty(_selectContent))
- {
- _clientManager.UpdateItemValue(_languageName,_key,_selectContent);
- }
- OnClosedRequest();
- }
- private void OnNext(object obj)
- {
- if (!string.IsNullOrEmpty(_selectContent))
- {
- _clientManager.UpdateItemValue(_languageName, _key, _selectContent);
- }
- var index = _items.IndexOf(_repeatItem);
- if (index < _items.Count)
- {
- if (index == _items.Count - 2 )
- {
- IsLastItem = true;
- }
- _repeatItem = _items[index + 1];
-
- Key = _repeatItem.Key;
- Contents = new List<string>(_repeatItem.Contents);
- }
- }
- }
- }
|