private void _textBox_TextChanged(object sender, TextChangedEventArgs e) { try { if (!_tab.ItemsEventsDisabled) { DisplayableProperty <TKey, TValue> .ApplyCommand(_tab, _attribute, _textBox.Text); } try { byte[] data = _tab.ProjectDatabase.MetaGrf.GetDataBuffered(EncodingService.FromAnyToDisplayEncoding(GrfPath.Combine(_grfPath1, _textBox.Text.ExpandString()) + _ext)); if (data != null) { WpfUtilities.TextBoxOk(_textBox); _wrapper1.Image = ImageProvider.GetImage(data, _ext); _wrapper1.Image.MakePinkTransparent(); _imageResource.Tag = _textBox.Text; _imageResource.Source = _wrapper1.Image.Cast <BitmapSource>(); } else { WpfUtilities.TextBoxError(_textBox); _wrapper1.Image = null; _imageResource.Source = null; } } catch (ArgumentException) { WpfUtilities.TextBoxError(_textBox); _wrapper1.Image = null; _imageResource.Source = null; } try { byte[] data2 = _tab.ProjectDatabase.MetaGrf.GetDataBuffered(EncodingService.FromAnyToDisplayEncoding(GrfPath.Combine(_grfPath2, _textBox.Text.ExpandString()) + _ext)); if (data2 != null) { _wrapper2.Image = ImageProvider.GetImage(data2, _ext); _wrapper2.Image.MakePinkTransparent(); _imagePreview.Tag = _textBox.Text; _imagePreview.Source = _wrapper2.Image.Cast <BitmapSource>(); //_imagePreview.Source.Freeze(); } else { _wrapper2.Image = null; _imagePreview.Source = null; } } catch (ArgumentException) { _wrapper2.Image = null; _imagePreview.Source = null; } } catch (Exception err) { ErrorHandler.HandleException(err); } }
private void _update() { if (!_boxEventsEnabled) { return; } try { _boxEventsEnabled = false; string hexJob = JobList.GetHexJob(_boxes.Where(p => p.IsChecked == true).Select(p => (Job)p.Tag).ToList()); _preview.Text = hexJob; _updateClassPreview(); WpfUtilities.TextBoxOk(_preview); } finally { _boxEventsEnabled = true; } }
private void _preview_TextChanged(object sender, TextChangedEventArgs e) { if (!_boxEventsEnabled) { return; } try { _boxEventsEnabled = false; int value; try { value = Convert.ToInt32(_preview.Text, 16); WpfUtilities.TextBoxOk(_preview); } catch { WpfUtilities.TextBoxError(_preview); return; } foreach (CheckBox box in _boxes) { Job job = (Job)box.Tag; if ((job.Id & value) == job.Id) { box.IsChecked = true; } else { box.IsChecked = false; } } _updateClassPreview(); } finally { _boxEventsEnabled = true; } }
private void _update() { if (!_boxEventsEnabled) { return; } try { _boxEventsEnabled = false; string hexJob; if (_cbJobMode.SelectedIndex == 1) { hexJob = JobList.GetNegativeHexJob(_boxes.Where(p => p.IsChecked == true).Select(p => (Job)p.Tag).ToList()); } else { hexJob = JobList.GetHexJob(_boxes.Where(p => p.IsChecked == true).Select(p => (Job)p.Tag).ToList()); } if (_previewEventsEnabled) { _preview.Text = hexJob; } _updateClassPreview(); WpfUtilities.TextBoxOk(_preview); _checkAllEnabled = false; _cbSelectAll.IsChecked = _boxes.All(p => p.IsEnabled && p.IsChecked == true); _checkAllEnabled = true; OnValueChanged(); } finally { _boxEventsEnabled = true; } }
private void _preview_TextChanged(object sender, TextChangedEventArgs e) { if (!_boxEventsEnabled) { return; } if (!_previewEventsEnabled) { return; } try { _boxEventsEnabled = false; _previewEventsEnabled = false; int value; try { value = Convert.ToInt32(_preview.Text, 16); WpfUtilities.TextBoxOk(_preview); } catch { WpfUtilities.TextBoxError(_preview); return; } if (value < 0) { value ^= -1; foreach (CheckBox box in _boxes) { Job job = (Job)box.Tag; if (!box.IsEnabled) { box.IsChecked = false; continue; } if ((job.Id & value) == job.Id) { box.IsChecked = true; } else { box.IsChecked = false; } } _cbJobMode.SelectedIndex = 1; } else { foreach (CheckBox box in _boxes) { Job job = (Job)box.Tag; if (!box.IsEnabled) { box.IsChecked = false; continue; } if ((job.Id & value) == job.Id) { box.IsChecked = true; } else { box.IsChecked = false; } } _cbJobMode.SelectedIndex = 0; } } finally { _boxEventsEnabled = true; _update(); _previewEventsEnabled = true; } }
private void _filterInternal(string currentSearch) { lock (_filterLock) { IsFiltering = true; try { if (currentSearch != _searchItemsFilter) { return; } if (_items == null) { return; } List <TValue> allItems; if (SubsetCondition != null) { allItems = _table.FastItems.Where(p => SubsetCondition(p)).ToList(); } else { allItems = _table.FastItems; } if (SetupImageDataGetter != null) { allItems.Where(p => p.GetImageData == null).ToList().ForEach(p => SetupImageDataGetter(p)); } List <string> search = _getSearch(currentSearch); if (allItems.Count == 0) { _items.Dispatch(r => r.ItemsSource = new RangeObservableCollection <TValue>(new List <TValue>())); WpfUtilities.TextBoxOk(_tbSearchItems); OnFilterFinished(new List <TValue>()); return; } WpfUtilities.TextBoxProcessing(_tbSearchItems); if (!_searchFirstTimeSet) { _entryComparer = new DatabaseItemSorter <TValue>(_settings.AttributeList); _entryComparer.SetSort(_settings.AttId.AttributeName, ListSortDirection.Ascending); _searchFirstTimeSet = true; } _items.Dispatch(p => _entryComparer.SetSort(WpfUtils.GetLastGetSearchAccessor(_items), WpfUtils.GetLastSortDirection(_items))); if (search.Count == 0 && !_attributes.Where(p => p.DataType.BaseType == typeof(Enum)).Any(p => _itemsSearchSettings[p]) && !_itemsSearchSettings[GSearchSettings.TupleAdded] && !_itemsSearchSettings[GSearchSettings.TupleModified] && !_itemsSearchSettings[GSearchSettings.TupleRange]) { allItems = allItems.OrderBy(p => p, _entryComparer).ToList(); _items.Dispatch(r => r.ItemsSource = new RangeObservableCollection <TValue>(allItems)); WpfUtilities.TextBoxOk(_tbSearchItems); OnFilterFinished(allItems); return; } if (currentSearch != _searchItemsFilter) { return; } string predicateSearch = _tbItemsRange.Dispatch(() => _tbItemsRange.Text); bool isWiden = _itemsSearchSettings.Get(GSearchSettings.Mode) == "0"; List <Func <TValue, string, bool> > generalPredicates = (from attribute in _attributes where attribute != null let attributeCopy = attribute where _itemsSearchSettings[attributeCopy] where attribute.DataType.BaseType != typeof(Enum) select new Func <TValue, string, bool>((p, s) => p.GetValue <string>(attributeCopy).IndexOf(s, StringComparison.OrdinalIgnoreCase) != -1)).ToList(); bool isAttributeRestricted = false; if (search.Any(p => p.StartsWith("[", StringComparison.Ordinal) && p.EndsWith("]", StringComparison.Ordinal))) { generalPredicates.Clear(); for (int index = 0; index < search.Count; index++) { string se = search[index]; int ival; if (se.StartsWith("[", StringComparison.Ordinal) && se.EndsWith("]", StringComparison.Ordinal)) { se = se.Substring(1, se.Length - 2); se = se.Replace("_", " "); var att = _settings.AttributeList.Attributes.FirstOrDefault(p => p.DisplayName.IndexOf(se, 0, StringComparison.OrdinalIgnoreCase) > -1); if (Int32.TryParse(se, out ival) || att != null) { if (ival < _settings.AttributeList.Attributes.Count) { DbAttribute attribute = att ?? _settings.AttributeList.Attributes[ival]; isAttributeRestricted = true; //generalPredicates.Add(new Func<TValue, string, bool>((p, s) => p.GetValue<string>(attribute).IndexOf(s, StringComparison.OrdinalIgnoreCase) != -1)); string nextSearch = index + 1 < search.Count ? search[index + 1] : ""; generalPredicates.Add(new Func <TValue, string, bool>((p, s) => String.Compare(p.GetValue <string>(attribute), nextSearch, StringComparison.OrdinalIgnoreCase) == 0)); } search.RemoveAt(index); index--; } } } } List <DbAttribute> enumAttributes = _attributes.Where(p => p.DataType.BaseType == typeof(Enum) && _itemsSearchSettings[p]).ToList(); bool hasTuplePredicates = _itemsSearchSettings[GSearchSettings.TupleAdded] || _itemsSearchSettings[GSearchSettings.TupleModified] || _itemsSearchSettings[GSearchSettings.TupleRange] || enumAttributes.Any(); Func <TValue, bool> tuplePredicate = null; if (hasTuplePredicates) { tuplePredicate = _getTuplePredicates(enumAttributes, predicateSearch); } if (currentSearch != _searchItemsFilter) { return; } List <TValue> result = _getResults(search, isAttributeRestricted, generalPredicates, allItems, tuplePredicate, isWiden); if (currentSearch != _searchItemsFilter) { WpfUtilities.TextBoxOk(_tbSearchItems); return; } _items.Dispatch(r => r.ItemsSource = new RangeObservableCollection <TValue>(result)); WpfUtilities.TextBoxOk(_tbSearchItems); OnFilterFinished(result); } catch { WpfUtilities.TextBoxOk(_tbSearchItems); } finally { IsFiltering = false; } } }