Skip to content

Commit

Permalink
fix some bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanthinker committed Jul 21, 2019
1 parent e6ae182 commit 6a8fa8d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
36 changes: 30 additions & 6 deletions src/Log2Window/Log/LoggerItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ internal LogMessageItem AddLogMessage(LogMessage logMsg)
public static void TryEnsureVisibleForSuitableItems(ListView logListView)
{
try
{
{
if (lastEnsureVisibleTime > DateTime.Now) //PC time may changed by user.
lastEnsureVisibleTime = DateTime.Now - EnsureVisiblePeroid - EnsureVisiblePeroid; //let EnsureVisible trigger at once.

Expand All @@ -321,6 +321,7 @@ public static void TryEnsureVisibleForSuitableItems(ListView logListView)
{
lock (LogManager.Instance.dataLocker)
{
var islogListViewFocused = logListView.Focused;
LogManager.Instance.DequeueMoreThanMaxCount();

if (LogManager.Instance.PauseRefreshNewMessages)
Expand All @@ -334,6 +335,7 @@ public static void TryEnsureVisibleForSuitableItems(ListView logListView)
// 因此使用SetRedraw(false)强制不更新此窗体. 当所有的设置结束后再显示窗口的最后状态.
MainForm.Instance.SetRedraw(false);


try
{
for (int i = 0; i < 10; i++)//最多重试10次. 其实第一次抛出异常的时候, VirtualListSize 的值已经设置成功了. 第二次的时候, 因为 if 判断就已经相等了, 其实就不会出错了.
Expand All @@ -342,6 +344,8 @@ public static void TryEnsureVisibleForSuitableItems(ListView logListView)
{
if (logListView.VirtualListSize != LogManager.Instance._dataSource.Count)
{
logListView.Hide(); //当选中的行不再可视范围内时, 修改 VirtualListSize 会导致画面抖动. 即时设置了 MainForm.Instance.SetRedraw(false); 也无法解决, 因此这里先隐藏.

Utils.log.Debug("set VirtualListSize in TryEnsureVisibleForSuitableItems");
logListView.VirtualListSize = LogManager.Instance._dataSource.Count;
needEnsureVisible = true;
Expand Down Expand Up @@ -376,7 +380,7 @@ public static void TryEnsureVisibleForSuitableItems(ListView logListView)

//如果当前界面包含选中的元素(没被条件过滤掉了), 后面才有必要让窗口强行刷新到 index 位置.
if (LogManager.Instance._dataSource[index].Message.ArrivedId == LogManager.Instance.manulSelectedArrivedId)
{
{
needEnsureVisible = true;
}
}
Expand Down Expand Up @@ -409,15 +413,29 @@ public static void TryEnsureVisibleForSuitableItems(ListView logListView)
try
{
LogManager.Instance.inSetSelectedIndicesByCode = true;
logListView.SelectedIndices.Clear();
logListView.SelectedIndices.Add(index);
if (logListView.SelectedIndices.Count == 1 && logListView.SelectedIndices[0] == index)
{
//如果索引没变, 没必要再设置, 会触发index change事件.
// do nothing
}
else
{
logListView.SelectedIndices.Clear();
logListView.SelectedIndices.Add(index);
}

}
finally
{
LogManager.Instance.inSetSelectedIndicesByCode = false;
}

logListView.EnsureVisible(index);
if (thisArrivedId != lastEnsureVisibleArrivedId
|| LogManager.Instance.manulSelectedArrivedId == 0 //未选中任何行, 需要定位到最后一行
)
{
logListView.EnsureVisible(index);
}
//logListView.Refresh();

MainForm.Instance.RefreshTitle();
Expand All @@ -437,7 +455,13 @@ public static void TryEnsureVisibleForSuitableItems(ListView logListView)
}
finally
{
MainForm.Instance.SetRedraw(true);
logListView.Show();
if (islogListViewFocused)
{
logListView.Focus();
}

MainForm.Instance.SetRedraw(true);
}
}
}));
Expand Down
1 change: 1 addition & 0 deletions src/Log2Window/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,7 @@ public void ReBindListViewFromAllLogMessageItems(bool needDeleteMessages = false
}

this.RefreshTitle();
logListView.Focus();
//}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/TestLog4net/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ static void DoLog(string cmd)
_log.Info(i);
}
}
if (cmd.ToLower() == "b3")
{
for (int i = 0; i < 10000; i++)
{
_log.Info(i);
Thread.Sleep(100);
}
}
if (cmd.ToLower() == "b2")
{
string data = File.ReadAllText(@"d:\Projects\github\Log2Window\src\TestLog4net\testDatas.txt");
Expand Down

0 comments on commit 6a8fa8d

Please sign in to comment.