/// <summary> /// Creates an instance of <see cref="SpellsViewModel"/> /// </summary> public SpellsViewModel(Compendium compendium, SpellSearchService spellSearchService, SpellSearchInput spellSearchInput, StringService stringService, DialogService dialogService, XMLImporter xmlImporter, XMLExporter xmlExporter, DocumentService documentService) { _compendium = compendium; _spellSearchService = spellSearchService; _spellSearchInput = spellSearchInput; _stringService = stringService; _dialogService = dialogService; _xmlImporter = xmlImporter; _xmlExporter = xmlExporter; _documentService = documentService; _selectSpellCommand = new RelayCommand(obj => true, obj => SelectSpell(obj as SpellListItemViewModel)); _editSpellCommand = new RelayCommand(obj => true, obj => EditSpell(obj as SpellViewModel)); _exportSpellCommand = new RelayCommand(obj => true, obj => ExportSpell(obj as SpellViewModel)); _cancelEditSpellCommand = new RelayCommand(obj => true, obj => CancelEditSpell()); _saveEditSpellCommand = new RelayCommand(obj => HasUnsavedChanges, obj => SaveEditSpell()); _resetFiltersCommand = new RelayCommand(obj => true, obj => InitializeSearch()); _addCommand = new RelayCommand(obj => true, obj => Add()); _copyCommand = new RelayCommand(obj => _selectedSpell != null, obj => Copy()); _deleteCommand = new RelayCommand(obj => _selectedSpell != null, obj => Delete()); _importCommand = new RelayCommand(obj => true, obj => Import()); _selectNextCommand = new RelayCommand(obj => true, obj => SelectNext()); _selectPreviousCommand = new RelayCommand(obj => true, obj => SelectPrevious()); InitializeSearch(); }
/// <summary> /// True if the search applies to the model /// </summary> public bool SearchInputApplies(SpellSearchInput searchInput, SpellModel spellModel) { return(HasSearchText(spellModel, searchInput.SearchText) && IsLevel(spellModel, searchInput.Level.Key) && IsSchool(spellModel, searchInput.School.Key) && HasClass(spellModel, searchInput.Class.Key) && MatchesConcentration(spellModel, searchInput.Concentration.Key) && MatchesRitual(spellModel, searchInput.Ritual.Key)); }
/// <summary> /// Creates an instance of <see cref="SpellSearchViewModel"/> /// </summary> public SpellSearchViewModel(Compendium compendium, SpellSearchService spellSearchService, SpellSearchInput spellSearchInput, StringService stringService, DialogService dialogService) { _compendium = compendium; _spellSearchService = spellSearchService; _spellSearchInput = spellSearchInput; _stringService = stringService; _dialogService = dialogService; _selectSpellCommand = new RelayCommand(obj => true, obj => SelectSpell(obj as SpellListItemViewModel)); _resetFiltersCommand = new RelayCommand(obj => true, obj => InitializeSearch()); _acceptCommand = new RelayCommand(obj => true, obj => OnAccept()); _rejectCommand = new RelayCommand(obj => true, obj => OnReject()); Search(); }
/// <summary> /// Searches the compendium for spells matching the search input /// </summary> public List <SpellModel> Search(SpellSearchInput searchInput) { return(Sort(_compendium.Spells.Where(x => SearchInputApplies(searchInput, x)), searchInput.SortOption.Key)); }