private void UpdateSortedListView(MaskDescriptorComparer.SortType sortType) { if (this.listViewCannedMasks.IsHandleCreated) { MaskDescriptor maskDex = null; if (this.listViewCannedMasks.SelectedItems.Count > 0) { int num = this.listViewCannedMasks.SelectedIndices[0]; maskDex = this.maskDescriptors[num]; } this.maskDescriptors.RemoveAt(this.maskDescriptors.Count - 1); this.maskDescriptors.Sort(new MaskDescriptorComparer(sortType, this.listViewSortOrder)); System.Design.UnsafeNativeMethods.SendMessage(this.listViewCannedMasks.Handle, 11, false, 0); try { this.listViewCannedMasks.Items.Clear(); string str = System.Design.SR.GetString("MaskDescriptorValidatingTypeNone"); foreach (MaskDescriptor descriptor2 in this.maskDescriptors) { string str2 = (descriptor2.ValidatingType != null) ? descriptor2.ValidatingType.Name : str; MaskedTextProvider provider = new MaskedTextProvider(descriptor2.Mask, descriptor2.Culture); provider.Add(descriptor2.Sample); string str3 = provider.ToString(false, true); this.listViewCannedMasks.Items.Add(new ListViewItem(new string[] { descriptor2.Name, str3, str2 })); } this.maskDescriptors.Add(this.customMaskDescriptor); this.listViewCannedMasks.Items.Add(new ListViewItem(new string[] { this.customMaskDescriptor.Name, "", str })); if (maskDex != null) { this.SetSelectedMaskDescriptor(maskDex); } } finally { System.Design.UnsafeNativeMethods.SendMessage(this.listViewCannedMasks.Handle, 11, true, 0); this.listViewCannedMasks.Invalidate(); } } }
/// <summary> /// Sorts the maskDescriptors and the list view items. /// </summary> private void UpdateSortedListView(MaskDescriptorComparer.SortType sortType) { if (!_listViewCannedMasks.IsHandleCreated) { return; } MaskDescriptor selectedMaskDex = null; // Save current selected entry to restore it after sorting. if (_listViewCannedMasks.SelectedItems.Count > 0) { int selectedIndex = _listViewCannedMasks.SelectedIndices[0]; selectedMaskDex = _maskDescriptors[selectedIndex]; } // Custom mask descriptor should always be the last entry - remove it before sorting array. _maskDescriptors.RemoveAt(_maskDescriptors.Count - 1); // Sort MaskDescriptor collection. _maskDescriptors.Sort(new MaskDescriptorComparer(sortType, _listViewSortOrder)); // Since we need to pre-process each item before inserting it in the ListView, it is better to remove all items // from it first and then add the sorted ones back (no replace). Stop redrawing while we change the list. User32.SendMessageW(_listViewCannedMasks, User32.WM.SETREDRAW, (nint)BOOL.FALSE); try { _listViewCannedMasks.Items.Clear(); string nullEntry = SR.MaskDescriptorValidatingTypeNone; foreach (MaskDescriptor maskDescriptor in _maskDescriptors) { string validatingType = maskDescriptor.ValidatingType != null ? maskDescriptor.ValidatingType.Name : nullEntry; // Make sure the sample displays literals. MaskedTextProvider mtp = new MaskedTextProvider(maskDescriptor.Mask, maskDescriptor.Culture); bool success = mtp.Add(maskDescriptor.Sample); Debug.Assert(success, "BadBad: Could not add MaskDescriptor.Sample even it was validated, something is wrong!"); // Don't include prompt. string sample = mtp.ToString(false, true); _listViewCannedMasks.Items.Add(new ListViewItem(new string[] { maskDescriptor.Name, sample, validatingType })); } // Add the custom mask descriptor as the last entry. _maskDescriptors.Add(_customMaskDescriptor); _listViewCannedMasks.Items.Add(new ListViewItem(new string[] { _customMaskDescriptor.Name, "", nullEntry })); if (selectedMaskDex != null) { SetSelectedMaskDescriptor(selectedMaskDex); } } finally { // Resume redraw. User32.SendMessageW(_listViewCannedMasks, User32.WM.SETREDRAW, (nint)BOOL.TRUE); _listViewCannedMasks.Invalidate(); } }
/// <summary> /// Sorts the maskDescriptors and the list view items. /// </summary> private void UpdateSortedListView(MaskDescriptorComparer.SortType sortType) { if (!_listViewCannedMasks.IsHandleCreated) { return; } MaskDescriptor selectedMaskDex = null; // Save current selected entry to restore it after sorting. if (_listViewCannedMasks.SelectedItems.Count > 0) { int selectedIndex = _listViewCannedMasks.SelectedIndices[0]; selectedMaskDex = _maskDescriptors[selectedIndex]; } // Custom mask descriptor should always be the last entry - remove it before sorting array. _maskDescriptors.RemoveAt(_maskDescriptors.Count - 1); // Sort MaskDescriptor collection. _maskDescriptors.Sort(new MaskDescriptorComparer(sortType, _listViewSortOrder)); // Sorting the ListView items forces handle recreation, since we have the items sorted and know what item to select // it is better for us to replace the items ourselves. This way also avoids problems with the selected item and // the custom entry not getting properly added. // this.listViewCannedMasks.Sort(); // Since we need to pre-process each item before inserting it in the ListView, it is better to remove all items // from it first and then add the sorted ones back (no replace). Stop redrawing while we change the list. UnsafeNativeMethods.SendMessage(_listViewCannedMasks.Handle, Interop.WindowMessages.WM_SETREDRAW, false, /* unused = */ 0); try { _listViewCannedMasks.Items.Clear(); string nullEntry = SR.MaskDescriptorValidatingTypeNone; foreach (MaskDescriptor maskDescriptor in _maskDescriptors) { string validatingType = maskDescriptor.ValidatingType != null ? maskDescriptor.ValidatingType.Name : nullEntry; // Make sure the sample displays literals. MaskedTextProvider mtp = new MaskedTextProvider(maskDescriptor.Mask, maskDescriptor.Culture); bool success = mtp.Add(maskDescriptor.Sample); Debug.Assert(success, "BadBad: Could not add MaskDescriptor.Sample even it was validated, something is wrong!"); // Don't include prompt. string sample = mtp.ToString(false, true); _listViewCannedMasks.Items.Add(new ListViewItem(new string[] { maskDescriptor.Name, sample, validatingType })); } // Add the custom mask descriptor as the last entry. _maskDescriptors.Add(_customMaskDescriptor); _listViewCannedMasks.Items.Add(new ListViewItem(new string[] { _customMaskDescriptor.Name, "", nullEntry })); if (selectedMaskDex != null) { SetSelectedMaskDescriptor(selectedMaskDex); } } finally { // Resume redraw. UnsafeNativeMethods.SendMessage(_listViewCannedMasks.Handle, Interop.WindowMessages.WM_SETREDRAW, true, /* unused = */ 0); _listViewCannedMasks.Invalidate(); } }