• R/O
  • HTTP
  • SSH
  • HTTPS

open-tween: Commit

開発に使用するリポジトリ


Commit MetaInfo

Revision39a3c86501fcc5a2e2585d727159dde5fd9c68af (tree)
Time2020-03-13 04:13:52
AuthorKimura Youichi <kim.upsilon@bucy...>
CommiterKimura Youichi

Log Message

発言一覧の選択状態を更新する際に選択範囲の差分のみ反映する

Change Summary

Incremental Difference

--- a/OpenTween/DetailsListView.cs
+++ b/OpenTween/DetailsListView.cs
@@ -70,15 +70,39 @@ namespace OpenTween.OpenTweenCustomControl
7070
7171 public void SelectItems(int[] indices)
7272 {
73- foreach (var index in indices)
74- {
75- if (index < 0 || index >= this.VirtualListSize)
76- throw new ArgumentOutOfRangeException(nameof(indices));
73+ var listSize = this.VirtualListSize;
74+ if (indices.Any(x => x < 0 || x >= listSize))
75+ throw new ArgumentOutOfRangeException(nameof(indices));
7776
78- NativeMethods.SelectItem(this, index);
77+ if (indices.Length == 0)
78+ {
79+ this.SelectedIndices.Clear();
7980 }
81+ else if (indices.Length == 1)
82+ {
83+ this.SelectedIndices.Clear();
84+ this.SelectedIndices.Add(indices[0]);
85+ }
86+ else
87+ {
88+ var currentSelectedIndices = this.SelectedIndices.Cast<int>().ToArray();
89+ var selectIndices = indices.Except(currentSelectedIndices).ToArray();
90+ var deselectIndices = currentSelectedIndices.Except(indices).ToArray();
8091
81- this.OnSelectedIndexChanged(EventArgs.Empty);
92+ if (selectIndices.Length + deselectIndices.Length > currentSelectedIndices.Length)
93+ {
94+ // Clearして選択し直した方が早い場合
95+ this.SelectedIndices.Clear();
96+ selectIndices = indices;
97+ deselectIndices = Array.Empty<int>();
98+ }
99+
100+ foreach (var index in selectIndices)
101+ NativeMethods.SelectItem(this, index, selected: true);
102+
103+ foreach (var index in deselectIndices)
104+ NativeMethods.SelectItem(this, index, selected: false);
105+ }
82106 }
83107
84108 public void SelectAllItems()
--- a/OpenTween/NativeMethods.cs
+++ b/OpenTween/NativeMethods.cs
@@ -121,6 +121,7 @@ namespace OpenTween
121121 [Flags]
122122 private enum LVIS : uint
123123 {
124+ None = 0,
124125 SELECTED = 0x02,
125126 }
126127
@@ -130,13 +131,13 @@ namespace OpenTween
130131 /// <param name="listView">対象となる ListView</param>
131132 /// <param name="index">選択するアイテムのインデックス</param>
132133 /// <returns>成功した場合は true、それ以外の場合は false</returns>
133- public static bool SelectItem(ListView listView, int index)
134+ public static bool SelectItem(ListView listView, int index, bool selected = true)
134135 {
135136 // LVM_SETITEMSTATE では stateMask, state 以外のメンバーは無視される
136137 var lvitem = new LVITEM
137138 {
138139 stateMask = LVIS.SELECTED,
139- state = LVIS.SELECTED,
140+ state = selected ? LVIS.SELECTED : LVIS.None,
140141 };
141142
142143 var ret = (int)SendMessage(listView.Handle, SendMessageType.LVM_SETITEMSTATE, (IntPtr)index, ref lvitem);
--- a/OpenTween/Tween.cs
+++ b/OpenTween/Tween.cs
@@ -9552,11 +9552,6 @@ namespace OpenTween
95529552
95539553 if (Index != null)
95549554 {
9555- do
9556- {
9557- LView.SelectedIndices.Clear();
9558- }
9559- while (LView.SelectedIndices.Count > 0);
95609555 LView.SelectItems(Index);
95619556 }
95629557 if (selectionMarkIndex > -1 && LView.VirtualListSize > selectionMarkIndex)
Show on old repository browser