Changeset 17147 for stable


Ignore:
Timestamp:
07/22/19 14:12:15 (4 months ago)
Author:
abeham
Message:

#3010: merged to stable (17009, 17126)

Location:
stable
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Core

  • stable/HeuristicLab.Core.Views

  • stable/HeuristicLab.Core.Views/3.3/CheckedItemCollectionView.cs

    r17097 r17147  
    3434  [Content(typeof(ReadOnlyCheckedItemCollection<>), true)]
    3535  public partial class CheckedItemCollectionView<T> : ItemCollectionView<T> where T : class, IItem {
     36    private bool suppressCheckedEvents;
     37
    3638    public new ICheckedItemCollection<T> Content {
    3739      get { return (ICheckedItemCollection<T>)base.Content; }
     
    8284      if (doubleClick) {
    8385        e.NewValue = e.CurrentValue;
    84         doubleClick = false;
    8586      } else {
     87        bool check = e.NewValue == CheckState.Checked;
    8688        var checkedItem = (T)itemsListView.Items[e.Index].Tag;
    87         bool check = e.NewValue == CheckState.Checked;
    88         if (Content.ItemChecked(checkedItem) != check) {
    89           if (!ReadOnly && !Locked) Content.SetItemCheckedState(checkedItem, check);
    90           else e.NewValue = e.CurrentValue;
    91         }
     89        if (Content.ItemChecked(checkedItem) == check) return;
     90
     91        suppressCheckedEvents = true;
     92        try {
     93          if (itemsListView.SelectedIndices.Count > 1
     94            && itemsListView.SelectedIndices.Contains(e.Index)) {
     95            if (!ReadOnly && !Locked) Content.SetItemCheckedState(itemsListView.SelectedItems.Cast<ListViewItem>().Select(x => (T)x.Tag), check);
     96            else e.NewValue = e.CurrentValue;
     97          } else {
     98            if (!ReadOnly && !Locked) Content.SetItemCheckedState(checkedItem, check);
     99            else e.NewValue = e.CurrentValue;
     100          }
     101        } finally { suppressCheckedEvents = false; }
    92102      }
    93103    }
    94     protected void itemsListView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
    95       if (e.Clicks > 1)
    96         doubleClick = true;
     104    protected void itemsListView_MouseDown(object sender, MouseEventArgs e) {
     105      doubleClick = e.Clicks > 1;
    97106    }
    98107    #endregion
     
    103112        Invoke(new CollectionItemsChangedEventHandler<T>(Content_CheckedItemsChanged), sender, e);
    104113      else {
    105         UpdateCheckedItemState(e.Items);
     114        if (!suppressCheckedEvents) UpdateCheckedItemState(e.Items);
    106115        SetNumberOfCheckItems();
    107116      }
     
    130139
    131140    private void UpdateCheckedItemState(IEnumerable<T> items) {
    132       foreach (T item in items) {
    133         foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) {
    134           var isChecked = Content.ItemChecked(item);
    135           if (listViewItem.Checked != isChecked)
    136             listViewItem.Checked = isChecked;
     141      itemsListView.BeginUpdate();
     142      try {
     143        foreach (T item in items) {
     144          foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) {
     145            var isChecked = Content.ItemChecked(item);
     146            if (listViewItem.Checked != isChecked)
     147              listViewItem.Checked = isChecked;
     148          }
    137149        }
    138       }
     150      } finally { itemsListView.EndUpdate(); itemsListView.Refresh(); }
    139151    }
    140152  }
  • stable/HeuristicLab.Core.Views/3.3/CheckedItemListView.cs

    r17097 r17147  
    3737  [Content(typeof(ReadOnlyCheckedItemList<>), true)]
    3838  public partial class CheckedItemListView<T> : ItemListView<T> where T : class, IItem {
     39    private bool suppressCheckedEvents;
     40
    3941    public new ICheckedItemList<T> Content {
    4042      get { return (ICheckedItemList<T>)base.Content; }
     
    8486      if (doubleClick) {
    8587        e.NewValue = e.CurrentValue;
    86         doubleClick = false;
    8788      } else {
    88         var checkedItem = (T)itemsListView.Items[e.Index].Tag;
    8989        bool check = e.NewValue == CheckState.Checked;
    90         if (Content.ItemChecked(checkedItem) != check) {
    91           if (!ReadOnly && !Locked) Content.SetItemCheckedState(checkedItem, check);
    92           else e.NewValue = e.CurrentValue;
    93         }
     90        if (Content.ItemChecked(e.Index) == check) return;
     91
     92        suppressCheckedEvents = true;
     93        try {
     94          if (itemsListView.SelectedIndices.Count > 1
     95            && itemsListView.SelectedIndices.Contains(e.Index)) {
     96            if (!ReadOnly && !Locked) Content.SetItemCheckedState(itemsListView.SelectedIndices.Cast<int>(), check);
     97            else e.NewValue = e.CurrentValue;
     98          } else {
     99            var checkedItem = (T)itemsListView.Items[e.Index].Tag;
     100            if (!ReadOnly && !Locked) Content.SetItemCheckedState(checkedItem, check);
     101            else e.NewValue = e.CurrentValue;
     102          }
     103        } finally { suppressCheckedEvents = false; }
    94104      }
    95105    }
    96106
    97107    protected void itemsListView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
    98       if (e.Clicks > 1)
    99         doubleClick = true;
     108      doubleClick = e.Clicks > 1;
    100109    }
    101110
     
    139148        Invoke(new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CheckedItemsChanged), sender, e);
    140149      else {
    141         UpdateCheckedItemState(e.Items);
     150        if (!suppressCheckedEvents) UpdateCheckedItemState(e.Items);
    142151        SetNumberOfCheckItems();
    143152      }
     
    175184
    176185    private void UpdateCheckedItemState(IEnumerable<IndexedItem<T>> items) {
    177       foreach (var item in items) {
    178         var isChecked = Content.ItemChecked(item.Value);
    179         if (itemsListView.Items[item.Index].Checked != isChecked)
    180           itemsListView.Items[item.Index].Checked = isChecked;
    181       }
     186      itemsListView.BeginUpdate();
     187      try {
     188        foreach (var item in items) {
     189          var isChecked = Content.ItemChecked(item.Value);
     190          if (itemsListView.Items[item.Index].Checked != isChecked)
     191            itemsListView.Items[item.Index].Checked = isChecked;
     192        }
     193      } finally { itemsListView.EndUpdate(); itemsListView.Refresh(); }
    182194    }
    183195  }
  • stable/HeuristicLab.Core/3.3/Collections/CheckedItemCollection.cs

    r17097 r17147  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Collections;
    2627using HeuristicLab.Common;
    27 using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Core {
     
    108108
    109109    /// <summary>
     110    /// Sets the checked state of <paramref name="items"/> to <paramref name="checkedState"/>.
     111    /// </summary>
     112    /// <param name="items">The items to set the checked state for.</param>
     113    /// <param name="checkedState">The new checked state of <paramref name="item"/></param>
     114    public void SetItemCheckedState(IEnumerable<T> items, bool checkedState) {
     115      var changed = new List<T>();
     116      foreach (var item in items) {
     117        if (!this.checkedState.TryGetValue(item, out bool currentState)) throw new ArgumentException();
     118        if (currentState != checkedState) {
     119          this.checkedState[item] = checkedState;
     120          changed.Add(item);
     121        }
     122      }
     123      if (changed.Count > 0) OnCheckedItemsChanged(changed);
     124    }
     125
     126    /// <summary>
    110127    /// Adds a new <paramref name="item"/> with the given <paramref name="checkedState"/>.
    111128    /// </summary>
  • stable/HeuristicLab.Core/3.3/Collections/CheckedItemList.cs

    r17097 r17147  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Collections;
    2627using HeuristicLab.Common;
    27 using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Core {
     
    111111    /// Sets the checked state of <paramref name="item"/> to <paramref name="checkedState"/>.
    112112    /// </summary>
     113    /// <remarks>
     114    /// This method is slower than <see cref="SetItemCheckedState(int, bool)"/>.
     115    /// </remarks>
    113116    /// <param name="item">The item to set the checked state for.</param>
    114117    /// <param name="checkedState">The new checked state of <paramref name="item"/></param>
    115118    public void SetItemCheckedState(T item, bool checkedState) {
    116       if (!this.checkedState.ContainsKey(item)) throw new ArgumentException();
    117       if (this.checkedState[item] != checkedState) {
    118         this.checkedState[item] = checkedState;
    119         OnCheckedItemsChanged(new IndexedItem<T>[] { new IndexedItem<T>(IndexOf(item), item) });
    120       }
     119      SetItemCheckedState(IndexOf(item), checkedState);
     120    }
     121
     122    /// <summary>
     123    /// Sets the checked state of <paramref name="items"/> to <paramref name="checkedState"/>.
     124    /// </summary>
     125    /// <remarks>
     126    /// This method is slower than <see cref="SetItemCheckedState(IEnumerable{int}, bool)"/>.
     127    /// </remarks>
     128    /// <param name="items">The items to set the checked state for.</param>
     129    /// <param name="checkedState">The new checked state of <paramref name="item"/></param>
     130    public void SetItemCheckedState(IEnumerable<T> items, bool checkedState) {
     131      var changed = new List<IndexedItem<T>>();
     132      foreach (var item in items) {
     133        if (!this.checkedState.TryGetValue(item, out bool currentState)) throw new ArgumentException();
     134        if (currentState != checkedState) {
     135          this.checkedState[item] = checkedState;
     136          changed.Add(new IndexedItem<T>(IndexOf(item), item));
     137        }
     138      }
     139      if (changed.Count > 0) OnCheckedItemsChanged(changed);
    121140    }
    122141
     
    127146    /// <param name="checkedState">The new checked state of the item.</param>
    128147    public void SetItemCheckedState(int itemIndex, bool checkedState) {
    129       SetItemCheckedState(this[itemIndex], checkedState);
     148      var item = list[itemIndex];
     149      if (!this.checkedState.TryGetValue(item, out bool currentState)) throw new ArgumentException();
     150      if (currentState != checkedState) {
     151        this.checkedState[item] = checkedState;
     152        OnCheckedItemsChanged(new IndexedItem<T>[] { new IndexedItem<T>(itemIndex, item) });
     153      }
     154    }
     155
     156    /// <summary>
     157    /// Sets the checked state of all <paramref name="itemIndices"/> to <paramref name="checkedState"/>.
     158    /// </summary>
     159    /// <param name="itemIndices">The indices of all items to set the checked state for.</param>
     160    /// <param name="checkedState">The new checked state of the item.</param>
     161    public void SetItemCheckedState(IEnumerable<int> itemIndices, bool checkedState) {
     162      var changed = new List<IndexedItem<T>>();
     163      foreach (var index in itemIndices) {
     164        var item = list[index];
     165        if (!this.checkedState.TryGetValue(item, out bool currentState)) throw new ArgumentException();
     166        if (currentState != checkedState) {
     167          this.checkedState[item] = checkedState;
     168          changed.Add(new IndexedItem<T>(index, item));
     169        }
     170      }
     171      if (changed.Count > 0) OnCheckedItemsChanged(changed);
    130172    }
    131173
  • stable/HeuristicLab.Core/3.3/Collections/ReadOnlyCheckedItemCollection.cs

    r17097 r17147  
    2222using System;
    2323using System.Collections.Generic;
     24using HEAL.Attic;
    2425using HeuristicLab.Collections;
    2526using HeuristicLab.Common;
    26 using HEAL.Attic;
    2727
    2828namespace HeuristicLab.Core {
     
    7575    }
    7676
     77    public void SetItemCheckedState(IEnumerable<T> items, bool checkedState) {
     78      CheckedItemCollection.SetItemCheckedState(items, checkedState);
     79    }
     80
    7781    public void Add(T item, bool checkedState) {
    7882      throw new NotSupportedException();
  • stable/HeuristicLab.Core/3.3/Collections/ReadOnlyCheckedItemList.cs

    r17097 r17147  
    2222using System;
    2323using System.Collections.Generic;
     24using HEAL.Attic;
    2425using HeuristicLab.Collections;
    2526using HeuristicLab.Common;
    26 using HEAL.Attic;
    2727
    2828namespace HeuristicLab.Core {
     
    7272    }
    7373
     74    public bool ItemChecked(int itemIndex) {
     75      return CheckedItemList.ItemChecked(itemIndex);
     76    }
     77
    7478    public void SetItemCheckedState(T item, bool checkedState) {
    7579      CheckedItemList.SetItemCheckedState(item, checkedState);
     80    }
     81
     82    public void SetItemCheckedState(IEnumerable<T> items, bool checkedState) {
     83      CheckedItemList.SetItemCheckedState(items, checkedState);
     84    }
     85
     86    public void SetItemCheckedState(int itemIndex, bool checkedState) {
     87      CheckedItemList.SetItemCheckedState(itemIndex, checkedState);
     88    }
     89
     90    public void SetItemCheckedState(IEnumerable<int> itemIndices, bool checkedState) {
     91      CheckedItemList.SetItemCheckedState(itemIndices, checkedState);
    7692    }
    7793
  • stable/HeuristicLab.Core/3.3/Interfaces/ICheckedItemCollection.cs

    r17097 r17147  
    2121
    2222using System.Collections.Generic;
     23using HEAL.Attic;
    2324using HeuristicLab.Collections;
    24 using HEAL.Attic;
    2525
    2626namespace HeuristicLab.Core {
     
    3131    bool ItemChecked(T item);
    3232    void SetItemCheckedState(T item, bool checkedState);
     33    void SetItemCheckedState(IEnumerable<T> item, bool checkedState);
    3334    void Add(T item, bool checkedState);
    3435  }
  • stable/HeuristicLab.Core/3.3/Interfaces/ICheckedItemList.cs

    r17097 r17147  
    2121
    2222using System.Collections.Generic;
     23using HEAL.Attic;
    2324using HeuristicLab.Collections;
    24 using HEAL.Attic;
    2525
    2626namespace HeuristicLab.Core {
     
    3030    IEnumerable<IndexedItem<T>> CheckedItems { get; }
    3131    bool ItemChecked(T item);
     32    bool ItemChecked(int itemIndex);
    3233    void SetItemCheckedState(T item, bool checkedState);
     34    void SetItemCheckedState(IEnumerable<T> items, bool checkedState);
     35    void SetItemCheckedState(int itemIndex, bool checkedState);
     36    void SetItemCheckedState(IEnumerable<int> itemIndices, bool checkedState);
    3337    void Add(T item, bool checkedState);
    3438    void Insert(int index, T item, bool checkedState);
Note: See TracChangeset for help on using the changeset viewer.