|
100 | 100 | Filter = FilterType.All
|
101 | 101 | SearchBox.Text = "" '这会触发结果刷新,所以需要在 ModItems 更新之后,详见 #3124 的视频
|
102 | 102 | RefreshUI()
|
| 103 | + SetSortMethod(SortMethod.FileName) |
103 | 104 | Catch ex As Exception
|
104 | 105 | Log(ex, "加载 Mod 列表 UI 失败", LogLevel.Feedback)
|
105 | 106 | End Try
|
|
109 | 110 | Dim NewItem As New MyLocalModItem With {.SnapsToDevicePixels = True, .Entry = Entry,
|
110 | 111 | .ButtonHandler = AddressOf McModContent, .Checked = SelectedMods.Contains(Entry.RawFileName)}
|
111 | 112 | AddHandler Entry.OnCompUpdate, AddressOf NewItem.Refresh
|
| 113 | + 'AddHandler Entry.OnCompUpdate, Sub() RunInUi(Sub() DoSort()) |
112 | 114 | NewItem.Refresh()
|
113 | 115 | AniControlEnabled -= 1
|
114 | 116 | Return NewItem
|
@@ -486,10 +488,103 @@ Install:
|
486 | 488 | Private Sub ChangeFilter(sender As MyRadioButton, raiseByMouse As Boolean) Handles BtnFilterAll.Check, BtnFilterCanUpdate.Check, BtnFilterDisabled.Check, BtnFilterEnabled.Check, BtnFilterError.Check
|
487 | 489 | Filter = sender.Tag
|
488 | 490 | RefreshUI()
|
| 491 | + DoSort() |
489 | 492 | End Sub
|
490 | 493 |
|
491 | 494 | #End Region
|
492 | 495 |
|
| 496 | +#Region "排序" |
| 497 | + Private CurrentSortMethod As SortMethod = SortMethod.FileName |
| 498 | + |
| 499 | + Private Sub SetSortMethod(Target As SortMethod) |
| 500 | + CurrentSortMethod = Target |
| 501 | + BtnSort.Text = $"排序:{GetSortName(Target)}" |
| 502 | + RefreshUI() |
| 503 | + DoSort() |
| 504 | + End Sub |
| 505 | + |
| 506 | + Private Enum SortMethod |
| 507 | + FileName |
| 508 | + ModName |
| 509 | + TagNums |
| 510 | + CreateTime |
| 511 | + End Enum |
| 512 | + |
| 513 | + Private Function GetSortName(Method As SortMethod) As String |
| 514 | + Select Case Method |
| 515 | + Case SortMethod.FileName : Return "文件名" |
| 516 | + Case SortMethod.ModName : Return "模组名称" |
| 517 | + Case SortMethod.TagNums : Return "标签数量" |
| 518 | + Case SortMethod.CreateTime : Return "加入时间" |
| 519 | + End Select |
| 520 | + Return "" |
| 521 | + End Function |
| 522 | + |
| 523 | + Private Sub BtnSortClick(sender As Object, e As RouteEventArgs) Handles BtnSort.Click |
| 524 | + Dim Body As New ContextMenu |
| 525 | + For Each i As SortMethod In [Enum].GetValues(GetType(SortMethod)) |
| 526 | + Dim Item As New MyMenuItem |
| 527 | + Item.Header = GetSortName(i) |
| 528 | + AddHandler Item.Click, Sub() |
| 529 | + SetSortMethod(i) |
| 530 | + End Sub |
| 531 | + Body.Items.Add(Item) |
| 532 | + Next |
| 533 | + Body.PlacementTarget = sender |
| 534 | + Body.Placement = Primitives.PlacementMode.Bottom |
| 535 | + Body.IsOpen = True |
| 536 | + End Sub |
| 537 | + |
| 538 | + Private ReadOnly SortLock As New Object |
| 539 | + Private Sub DoSort() |
| 540 | + SyncLock SortLock |
| 541 | + If PanList Is Nothing Then Exit Sub |
| 542 | + Dim Length As Integer = PanList.Children.Count |
| 543 | + Dim MS = GetSortMethod(CurrentSortMethod) |
| 544 | + For i As Integer = 0 To Length - 1 |
| 545 | + For j As Integer = 0 To Length - i - 2 |
| 546 | + Dim Comp1 As MyLocalModItem = PanList.Children(j) |
| 547 | + Dim Comp2 As MyLocalModItem = PanList.Children(j + 1) |
| 548 | + |
| 549 | + If CurrentSortMethod = SortMethod.TagNums AndAlso (Comp1.Entry.Comp Is Nothing OrElse Comp2.Entry.Comp Is Nothing) Then |
| 550 | + Continue For |
| 551 | + End If |
| 552 | + If MS(Comp2.Entry, Comp1.Entry) Then |
| 553 | + ' 交换元素 |
| 554 | + Dim temp1 As MyLocalModItem = PanList.Children(j) |
| 555 | + Dim temp2 As MyLocalModItem = PanList.Children(j + 1) |
| 556 | + PanList.Children.Remove(temp1) |
| 557 | + PanList.Children.Remove(temp2) |
| 558 | + PanList.Children.Insert(j, temp2) |
| 559 | + PanList.Children.Insert(j + 1, temp1) |
| 560 | + End If |
| 561 | + Next |
| 562 | + Next |
| 563 | + End SyncLock |
| 564 | + End Sub |
| 565 | + |
| 566 | + Private Function GetSortMethod(Method As SortMethod) As Func(Of McMod, McMod, Boolean) |
| 567 | + Select Case Method |
| 568 | + Case SortMethod.FileName |
| 569 | + Return Function(a As McMod, b As McMod) As Boolean |
| 570 | + Return StrComp(a.FileName, b.FileName) < 0 |
| 571 | + End Function |
| 572 | + Case SortMethod.ModName |
| 573 | + Return Function(a As McMod, b As McMod) As Boolean |
| 574 | + Return StrComp(a.Name, b.Name) < 0 |
| 575 | + End Function |
| 576 | + Case SortMethod.TagNums |
| 577 | + Return Function(a As McMod, b As McMod) As Boolean |
| 578 | + Return a.Comp.Tags.Count > b.Comp.Tags.Count |
| 579 | + End Function |
| 580 | + Case SortMethod.CreateTime |
| 581 | + Return Function(a As McMod, b As McMod) As Boolean |
| 582 | + Return (New FileInfo(a.Path)).CreationTime > (New FileInfo(b.Path)).CreationTime |
| 583 | + End Function |
| 584 | + End Select |
| 585 | + End Function |
| 586 | +#End Region |
| 587 | + |
493 | 588 | #Region "下边栏"
|
494 | 589 |
|
495 | 590 | '启用 / 禁用
|
|
0 commit comments