OSDN Git Service

DetailsListView.RefreshItemsメソッドを追加
authorKimura Youichi <kim.upsilon@bucyou.net>
Mon, 25 Apr 2022 15:00:57 +0000 (00:00 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Mon, 25 Apr 2022 17:25:35 +0000 (02:25 +0900)
OpenTween/DetailsListView.cs
OpenTween/TimelineListViewCache.cs

index ae45be8..a1df119 100644 (file)
@@ -116,41 +116,19 @@ namespace OpenTween.OpenTweenCustomControl
             this.OnSelectedIndexChanged(EventArgs.Empty);
         }
 
-        public void ChangeItemBackColor(ListViewItem item, Color backColor)
+        public void RefreshItem(int index)
         {
-            if (item.BackColor == backColor)
-                return;
-
-            item.BackColor = backColor;
-
-            var index = item.Index;
-            if (index != -1)
-                this.RefreshItemsRange(index, index);
-        }
-
-        public void ChangeItemForeColor(ListViewItem item, Color foreColor)
-        {
-            if (item.ForeColor == foreColor)
-                return;
-
-            item.ForeColor = foreColor;
-
-            var index = item.Index;
-            if (index != -1)
-                this.RefreshItemsRange(index, index);
+            this.ValidateAll();
+            this.RefreshItemsRange(index, index);
         }
 
-        public void ChangeItemFontAndColor(ListViewItem item, Color foreColor, Font fnt)
+        public void RefreshItems(IEnumerable<int> indices)
         {
-            if (item.ForeColor == foreColor && item.Font.Equals(fnt))
-                return;
-
-            item.ForeColor = foreColor;
-            item.Font = fnt;
+            var chunks = MyCommon.ToRangeChunk(indices);
+            this.ValidateAll();
 
-            var index = item.Index;
-            if (index != -1)
-                this.RefreshItemsRange(index, index);
+            foreach (var (start, end) in chunks)
+                this.RefreshItemsRange(start, end);
         }
 
         private void RefreshItemsRange(int start, int end)
@@ -158,7 +136,6 @@ namespace OpenTween.OpenTweenCustomControl
             try
             {
                 this.redrawRange = (start, end);
-                this.ValidateAll();
                 this.RedrawItems(start, end, invalidateOnly: false);
             }
             finally
index c82fed7..168f844 100644 (file)
@@ -206,19 +206,18 @@ namespace OpenTween
             var fnt = this.GetFont(this.DetermineFont(post));
             var cl = this.GetForeColor(this.DetermineForeColor(post));
 
+            var index = item.Index;
+            if (index != -1)
+                this.listView.Update();
+
             if (item.SubItems[5].Text != star)
                 item.SubItems[5].Text = star;
 
-            if (item.Index == -1)
-            {
-                item.ForeColor = cl;
-                item.Font = fnt;
-            }
-            else
-            {
-                this.listView.Update();
-                this.listView.ChangeItemFontAndColor(item, cl, fnt);
-            }
+            item.ForeColor = cl;
+            item.Font = fnt;
+
+            if (index != -1)
+                this.listView.RefreshItem(index);
         }
 
         public void ColorizeList()
@@ -240,7 +239,8 @@ namespace OpenTween
             {
                 var post = this.tab[index];
                 var backColor = this.JudgeColor(basePost, post);
-                this.listView.ChangeItemBackColor(listViewItem, backColor);
+                listViewItem.BackColor = backColor;
+                this.listView.RefreshItem(index);
             }
         }
 
@@ -252,10 +252,14 @@ namespace OpenTween
             if (basePost == null)
                 return;
 
-            if (item.Index == -1)
-                item.BackColor = this.JudgeColor(basePost, post);
-            else
-                this.listView.ChangeItemBackColor(item, this.JudgeColor(basePost, post));
+            var index = item.Index;
+            if (index != -1)
+                this.listView.Update();
+
+            item.BackColor = this.JudgeColor(basePost, post);
+
+            if (index != -1)
+                this.listView.RefreshItem(index);
         }
 
         internal Color JudgeColor(PostClass basePost, PostClass targetPost)