-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
重写右侧页面刷新相关操作并把它们挪到右侧页面的vb文件里 使用 Loader 作为唯一标识符 Fix #4556 对 UI 设计的修改:把下载任务失败后的错误提示从 TextBlock 改成了 MyHint
- Loading branch information
Showing
8 changed files
with
280 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<local:MyCard x:Class="MyDlEntry" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:PCL"> | ||
<local:MyIconButton x:Name="BtnCancel" Logo="F1 M2,0 L0,2 8,10 0,18 2,20 10,12 18,20 20,18 12,10 20,2 18,0 10,8 2,0Z" | ||
Height="20" Margin="0 10 10 0" LogoScale="1.1" HorizontalAlignment="Right" VerticalAlignment="Top" /> | ||
<ListBox x:Name="TaskListBox" ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:MyDlEntry}, Path=TaskEntries}" | ||
Background="Transparent" BorderThickness="0" IsHitTestVisible="False" Margin="14 40 15 10"> | ||
<ListBox.ItemTemplate> | ||
<DataTemplate> | ||
<Grid MinHeight="26"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="50" /> | ||
<ColumnDefinition /> | ||
</Grid.ColumnDefinitions> | ||
<ContentPresenter Grid.Column="0" Content="{Binding LoaderState, Converter={StaticResource DlStateConverter}}" /> | ||
<TextBlock Grid.Column="1" Text="{Binding Descreption, Mode=OneWay}" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" /> | ||
</Grid> | ||
</DataTemplate> | ||
</ListBox.ItemTemplate> | ||
</ListBox> | ||
<local:MyHint x:Name="ExceptionHint" Visibility="Collapsed" ToolTip="单击复制错误详情" Margin="14 40 15 10" /> | ||
</local:MyCard> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
Imports System.Collections.ObjectModel | ||
Imports System.ComponentModel | ||
|
||
Public Class MyDlEntry | ||
Inherits MyCard | ||
|
||
''' <summary> | ||
''' 卡片中每一条子下载任务的数据模型,将Loader作为唯一标识符 | ||
''' </summary> | ||
Public Class MyDlTaskEntry | ||
Implements INotifyPropertyChanged | ||
|
||
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged | ||
|
||
Public Sub New(Loader As LoaderBase) | ||
Me.Loader = Loader | ||
_LoaderState = Loader.State | ||
_Progress = Loader.Progress | ||
_Descreption = Loader.Name | ||
End Sub | ||
|
||
''' <summary> | ||
''' 检查值有无改变以及通知前端 | ||
''' </summary> | ||
Public Sub SyncValuesToUI() | ||
If (Not Loader.State = _LoaderState) Then | ||
_LoaderState = Loader.State | ||
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("LoaderState")) | ||
End If | ||
If (Not Loader.Progress = _Progress) Then | ||
_Progress = Loader.Progress | ||
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("PercentStr")) | ||
End If | ||
End Sub | ||
|
||
Public Loader As LoaderBase | ||
|
||
Private _LoaderState As LoadState | ||
Public ReadOnly Property LoaderState As LoadState | ||
Get | ||
Return _LoaderState | ||
End Get | ||
End Property | ||
|
||
Private _Progress As Double | ||
Public ReadOnly Property PercentStr As String | ||
Get | ||
Return Math.Floor(_Progress * 100) & "%" | ||
End Get | ||
End Property | ||
|
||
Private _Descreption As String | ||
Public ReadOnly Property Descreption As String | ||
Get | ||
Return _Descreption | ||
End Get | ||
End Property | ||
End Class | ||
|
||
''' <summary> | ||
''' TaskListBox的数据源 | ||
''' </summary> | ||
Public ReadOnly Property TaskEntries As New ObservableCollection(Of MyDlTaskEntry) | ||
|
||
Public Loader As LoaderBase | ||
|
||
''' <summary> | ||
''' 获取所有子下载任务 | ||
''' </summary> | ||
Private ReadOnly Property SubDlTasks As List(Of LoaderBase) | ||
Get | ||
Return CType(Loader, Object).GetLoaderList() | ||
End Get | ||
End Property | ||
|
||
Private _Failed As Boolean | ||
''' <summary> | ||
''' 是否已经失败,值发生改变时切换显示内容 | ||
''' </summary> | ||
Private Property Failed | ||
Get | ||
Return _Failed | ||
End Get | ||
Set(value) | ||
If value = _Failed Then Exit Property | ||
_Failed = value | ||
If value Then | ||
ExceptionHint.Text = GetExceptionDetail(Loader.Error) | ||
ExceptionHint.Visibility = Visibility.Visible | ||
TaskListBox.Visibility = Visibility.Collapsed | ||
Else '应该不会进到这个case里 | ||
ExceptionHint.Visibility = Visibility.Collapsed | ||
TaskListBox.Visibility = Visibility.Visible | ||
End If | ||
End Set | ||
End Property | ||
|
||
Public Sub New(Loader As LoaderBase) | ||
InitializeComponent() | ||
Me.Loader = Loader | ||
Title = Loader.Name | ||
RefreshSubTasks() | ||
End Sub | ||
|
||
''' <summary> | ||
''' 同步前端状态(是否已失败、初次调用时添加子任务显示条目、刷新子任务显示条目的信息) | ||
''' </summary> | ||
Public Sub RefreshSubTasks() | ||
If Failed Then Exit Sub | ||
Try | ||
If Loader.State = LoadState.Failed Then | ||
Failed = True | ||
Else | ||
For Each DlTask As LoaderBase In SubDlTasks | ||
Dim TaskEntry = TaskEntries.FirstOrDefault(Function(t) t.Loader Is DlTask) | ||
If TaskEntry Is Nothing Then '除了第一次调用之外不会进入这个case,因为LoaderCombo的子加载任务不会增加 | ||
TaskEntries.Add(New MyDlTaskEntry(DlTask)) | ||
Else | ||
TaskEntry.SyncValuesToUI() | ||
End If | ||
Next | ||
End If | ||
Catch ex As Exception | ||
Log(ex, "刷新下载管理显示失败", LogLevel.Feedback) | ||
End Try | ||
End Sub | ||
|
||
''' <summary> | ||
''' 点击失败提示卡片之后复制错误信息到剪贴板 | ||
''' </summary> | ||
Private Sub CopyExceptionDetail(sender As MyHint, e As EventArgs) Handles ExceptionHint.MouseLeftButtonDown | ||
ClipboardSet(sender.Text, False) | ||
Hint("已复制错误详情!", HintType.Finish) | ||
End Sub | ||
|
||
''' <summary> | ||
''' 点击取消按钮之后播放关闭动画、中止Loader | ||
''' </summary> | ||
Private Sub Cancel(sender As MyIconButton, e As EventArgs) Handles BtnCancel.Click | ||
AniDispose(sender, False) | ||
AniDispose(Me, True, Sub() FrmSpeedRight?.TryReturnToHome()) | ||
RunInThread(Sub() Loader.Abort()) | ||
LoaderTaskbar.Remove(Loader) | ||
End Sub | ||
|
||
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.