OSDN Git Service

TabModel.SelectedIndex プロパティを追加, TweenMain._curItemIndex フィールドを廃止
authorKimura Youichi <kim.upsilon@bucyou.net>
Sat, 20 Apr 2019 20:11:33 +0000 (05:11 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sun, 21 Apr 2019 17:12:33 +0000 (02:12 +0900)
OpenTween.Tests/Models/TabModelTest.cs
OpenTween/Models/TabModel.cs
OpenTween/Tween.cs

index f24bfaa..362fd2e 100644 (file)
@@ -54,6 +54,7 @@ namespace OpenTween.Models
             Assert.Equal(100L, tab.SelectedStatusId);
             Assert.Equal(new[] { posts[0], posts[2] }, tab.SelectedPosts);
             Assert.Equal(posts[0], tab.SelectedPost);
+            Assert.Equal(0, tab.SelectedIndex);
         }
 
         [Fact]
@@ -69,6 +70,7 @@ namespace OpenTween.Models
             Assert.Equal(-1L, tab.SelectedStatusId);
             Assert.Empty(tab.SelectedPosts);
             Assert.Null(tab.SelectedPost);
+            Assert.Equal(-1, tab.SelectedIndex);
         }
 
         [Fact]
index 5f1674e..e8c485d 100644 (file)
@@ -81,6 +81,15 @@ namespace OpenTween.Models
         public PostClass SelectedPost
             => this.selectedStatusIds.Select(x => this.Posts[x]).FirstOrDefault();
 
+        public int SelectedIndex
+        {
+            get
+            {
+                var statusId = this.SelectedStatusId;
+                return statusId != -1 ? this.IndexOf(statusId) : -1;
+            }
+        }
+
         private IndexedSortedSet<long> _ids = new IndexedSortedSet<long>();
         private ConcurrentQueue<TemporaryId> addQueue = new ConcurrentQueue<TemporaryId>();
         private ConcurrentQueue<long> removeQueue = new ConcurrentQueue<long>();
index 44470e8..0a09696 100644 (file)
@@ -250,7 +250,6 @@ namespace OpenTween
             }
         }
 
-        private int _curItemIndex;
         private bool _isColumnChanged = false;
 
         private const int MAX_WORKER_THREADS = 20;
@@ -1072,7 +1071,6 @@ namespace OpenTween
             }
 
             this._statuses.SelectTab(this.ListTab.SelectedTab.Text);
-            _curItemIndex = -1;
 
             MyCommon.TwitterApiInfo.AccessLimitUpdated += TwitterApiStatus_AccessLimitUpdated;
             Microsoft.Win32.SystemEvents.TimeChanged += SystemEvents_TimeChanged;
@@ -1934,15 +1932,15 @@ namespace OpenTween
             if (listView.SelectedIndices.Count != 1)
                 return;
 
-            _curItemIndex = listView.SelectedIndices[0];
-            if (_curItemIndex > listView.VirtualListSize - 1) return;
+            var index = listView.SelectedIndices[0];
+            if (index > listView.VirtualListSize - 1) return;
 
             this.PushSelectPostChain();
 
             var post = this.CurrentPost;
             this._statuses.SetReadAllTab(post.StatusId, read: true);
             //キャッシュの書き換え
-            ChangeCacheStyleRead(true, _curItemIndex);   //既読へ(フォント、文字色)
+            ChangeCacheStyleRead(true, index); // 既読へ(フォント、文字色)
 
             ColorizeList();
             _colorize = true;
@@ -3413,7 +3411,6 @@ namespace OpenTween
                     this.StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText3; // 失敗
 
                 this.PurgeListViewItemCache();
-                this._curItemIndex = -1;
 
                 foreach (var tabPage in this.ListTab.TabPages.Cast<TabPage>())
                 {
@@ -4288,11 +4285,7 @@ namespace OpenTween
                 _listCustom.SmallImageList = null;
                 _listCustom.ListViewItemSorter = null;
 
-                //キャッシュのクリア
-                if (this.CurrentTabPage.Equals(_tabPage))
-                {
-                    _curItemIndex = -1;
-                }
+                // キャッシュのクリア
                 this.PurgeListViewItemCache();
             }
 
@@ -4886,7 +4879,6 @@ namespace OpenTween
             using (ControlTransaction.Cursor(this, Cursors.WaitCursor))
             {
                 this.PurgeListViewItemCache();
-                this._curItemIndex = -1;
                 this._statuses.FilterAll();
 
                 foreach (TabPage tabPage in this.ListTab.TabPages)
@@ -6713,7 +6705,9 @@ namespace OpenTween
                     currentPost.InReplyToUser = post.InReplyToUser;
                     currentPost.IsReply = post.IsReply;
                     this.PurgeListViewItemCache();
-                    this.CurrentListView.RedrawItems(_curItemIndex, _curItemIndex, false);
+
+                    var index = curTabClass.SelectedIndex;
+                    this.CurrentListView.RedrawItems(index, index, false);
                 }
                 catch (WebApiException ex)
                 {
@@ -6819,7 +6813,8 @@ namespace OpenTween
                                 postList.RemoveAt(index);
                             }
                         }
-                        var post = postList.FirstOrDefault((pst) => { return pst.Tab == curTabClass && isForward ? pst.Index > _curItemIndex : pst.Index < _curItemIndex; });
+                        var currentIndex = this.CurrentTab.SelectedIndex;
+                        var post = postList.FirstOrDefault((pst) => { return pst.Tab == curTabClass && isForward ? pst.Index > currentIndex : pst.Index < currentIndex; });
                         if (post == null) post = postList.FirstOrDefault((pst) => { return pst.Tab != curTabClass; });
                         if (post == null) post = postList.First();
                         this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
@@ -8553,7 +8548,6 @@ namespace OpenTween
                 _anchorPost = null;
                 _anchorFlag = false;
                 this.PurgeListViewItemCache();
-                _curItemIndex = -1;
             }
             foreach (TabPage tb in ListTab.TabPages)
             {
@@ -9719,14 +9713,6 @@ namespace OpenTween
             this._statuses.SelectTab(_tab.Text);
 
             var listView = this.CurrentListView;
-            if (listView.SelectedIndices.Count > 0)
-            {
-                _curItemIndex = listView.SelectedIndices[0];
-            }
-            else
-            {
-                _curItemIndex = -1;
-            }
 
             _anchorPost = null;
             _anchorFlag = false;