/// <summary> /// Creates an instance of <see cref="TablesViewModel"/> /// </summary> public TablesViewModel(Compendium compendium, TableSearchService tableSearchService, TableSearchInput tableSearchInput, StringService stringService, DialogService dialogService, XMLImporter xmlImporter, DocumentService documentService, DataManager dataManager) { _compendium = compendium; _tableSearchService = tableSearchService; _tableSearchInput = tableSearchInput; _stringService = stringService; _dialogService = dialogService; _xmlImporter = xmlImporter; _documentService = documentService; _dataManager = dataManager; _selectTableCommand = new RelayCommand(obj => true, obj => SelectTable(obj as ListItemViewModel <RandomTableModel>)); _editTableCommand = new RelayCommand(obj => true, obj => EditTable(obj as RandomTableViewModel)); _exportTableCommand = new RelayCommand(obj => true, obj => ExportTable(obj as RandomTableViewModel)); _cancelEditTableCommand = new RelayCommand(obj => true, obj => CancelEditTable()); _saveEditTableCommand = new RelayCommand(obj => HasUnsavedChanges, obj => SaveEditTable()); _resetFiltersCommand = new RelayCommand(obj => true, obj => InitializeSearch()); _addCommand = new RelayCommand(obj => true, obj => Add()); _copyCommand = new RelayCommand(obj => _selectedTable != null, obj => Copy()); _deleteCommand = new RelayCommand(obj => _selectedTable != null, obj => Delete()); _importCommand = new RelayCommand(obj => true, obj => Import()); _selectNextCommand = new RelayCommand(obj => true, obj => SelectNext()); _selectPreviousCommand = new RelayCommand(obj => true, obj => SelectPrevious()); Search(); }
/// <summary> /// True if the search input applies to the model /// </summary> public bool SearchInputApplies(TableSearchInput searchInput, RandomTableModel randomTableModel) { return(HasSearchText(randomTableModel, searchInput.SearchText) && HasTag(randomTableModel, searchInput.Tag.Key)); }
/// <summary> /// Searches for random tables matching the search input /// </summary> public List <RandomTableModel> Search(TableSearchInput searchInput) { return(Sort(_compendium.Tables.Where(x => SearchInputApplies(searchInput, x)), searchInput.SortOption.Key)); }