Skip to content

Commit bf91ef1

Browse files
committed
Watchlist changes
- added space saved on hover - added tooltip for folder path
1 parent 7080d5b commit bf91ef1

File tree

5 files changed

+85
-7
lines changed

5 files changed

+85
-7
lines changed

CompactGUI.Watcher/WatchedFolder.vb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Public Class WatchedFolder : Inherits ObservableObject
2424
End Get
2525
End Property
2626

27+
Public ReadOnly Property SavedSpace As Long
28+
Get
29+
Return LastUncompressedSize - LastCompressedSize
30+
End Get
31+
End Property
32+
2733
Public Sub RefreshProperties()
2834
For Each prop In Me.GetType.GetProperties
2935
Me.OnPropertyChanged(prop.Name)

CompactGUI/Components/Converters/Converters.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
<local:NonZeroToVisConverter x:Key="NonZeroToVisConverter" />
1818
<local:WindowScalingConverter x:Key="WindowScalingConverter"/>
1919
<local:BooleanToInverseVisibilityConverter x:Key="BooleanToInverseVisibilityConverter" />
20-
20+
<local:TokenisedFolderPathConverter x:Key="TokenisedFolderPathConverter" />
21+
2122
</ResourceDictionary>

CompactGUI/Components/Converters/IValueConverters.vb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@ Public Class BytesToReadableConverter : Implements IValueConverter
2323
If value = 0 Then Return "0" & suf(0)
2424
Dim bytes As Long = Math.Abs(value)
2525
Dim place As Integer = CInt(Math.Floor(Math.Log(bytes, 1024)))
26-
Dim num As Double = Math.Round(bytes / Math.Pow(1024, place), 1)
26+
27+
Dim roundingPrecision As Integer = 1
28+
If parameter IsNot Nothing AndAlso Integer.TryParse(parameter.ToString(), roundingPrecision) Then
29+
roundingPrecision = Math.Max(0, roundingPrecision)
30+
'We want to round to 1 decimal place if the value is in the GB range or higher
31+
If Array.IndexOf(suf, suf(place)) > 2 AndAlso roundingPrecision = 0 Then
32+
roundingPrecision = 1
33+
End If
34+
End If
35+
36+
Dim num As Double = Math.Round(bytes / Math.Pow(1024, place), roundingPrecision)
2737

2838
Return (Math.Sign(value) * num).ToString() & suf(place)
2939
End Function
@@ -47,6 +57,20 @@ Public Class StrippedFolderPathConverter : Implements IValueConverter
4757
End Class
4858

4959

60+
Public Class TokenisedFolderPathConverter : Implements IValueConverter
61+
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
62+
If value Is Nothing Then Return Nothing
63+
Dim Str = CType(value, String)
64+
Dim formattedString = Str.Replace("\"c, " 🢒 ")
65+
Return formattedString
66+
End Function
67+
68+
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
69+
Throw New NotImplementedException()
70+
End Function
71+
End Class
72+
73+
5074
Public Class RelativeDateConverter : Implements IValueConverter
5175
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
5276
Dim dt = CType(value, DateTime)

CompactGUI/Views/Components/FolderWatcherCard.xaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
<Button VerticalAlignment="Top" Content="Add To Watchlist" Background="#A26B8399" Foreground="White" HorizontalAlignment="Right" Margin="0,-26,10,0" Command="{Binding ManuallyAddFolderToWatcherCommand}" />
3333

34-
<ui:ListView x:Name="uiWatcherListView" ScrollViewer.VerticalScrollBarVisibility="Hidden" Margin="-20,60,-20,0" Padding="10,0,10,0" ItemsSource="{Binding Source = {StaticResource src}}" d:ItemsSource="{Binding Source = {StaticResource dtd}}" KeyboardNavigation.TabNavigation="None" ui:ScrollViewerHelper.AutoHideScrollBars="False">
34+
<ui:ListView x:Name="uiWatcherListView" Margin="-20,60,-20,0" Padding="10,0,10,0" ItemsSource="{Binding Source = {StaticResource src}}" d:ItemsSource="{Binding Source = {StaticResource dtd}}" KeyboardNavigation.TabNavigation="None" ui:ScrollViewerHelper.AutoHideScrollBars="True" >
3535
<ui:ListView.Background>
3636
<LinearGradientBrush StartPoint="0.5, 0" EndPoint="0.5, 1">
3737
<GradientStop Color="#00000000" Offset="0"/>
@@ -93,9 +93,15 @@
9393
<TextBlock Text="{Binding CompressionLevel, Converter={StaticResource CompressionLevelAbbreviatedConverter}}" d:Text="fds" FontSize="11" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#FFF" FontWeight="SemiBold" />
9494
</Border>
9595

96-
<TextBlock Width="220" Text="{Binding Folder}" TextTrimming="CharacterEllipsis" FontSize="12" Foreground="#80FFFFFF" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="50,20,0,0"/>
97-
<TextBlock Text="{Binding DecayPercentage, StringFormat={}{0}% decayed, Mode=OneWay, Converter={StaticResource DecimalToPercentageConverter}}" FontSize="12" Foreground="#FFBFC7CE" VerticalAlignment="Top" Margin="0,-2,30,0" HorizontalAlignment="Right"/>
98-
96+
<TextBlock Width="220" Text="{Binding Folder, Converter={StaticResource TokenisedFolderPathConverter}}" TextTrimming="CharacterEllipsis" FontSize="12" Foreground="#80FFFFFF" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="50,20,0,0">
97+
<TextBlock.ToolTip >
98+
<ToolTip Background="#304257" Placement="RelativePoint" >
99+
<TextBlock Text="{Binding Folder, Converter={StaticResource TokenisedFolderPathConverter}}" TextWrapping="NoWrap" Foreground="#FFBFC7CE" FontSize="12"/>
100+
</ToolTip>
101+
</TextBlock.ToolTip>
102+
</TextBlock>
103+
<TextBlock x:Name="DecayedText" Text="{Binding DecayPercentage, StringFormat={}{0}% decayed, Mode=OneWay, Converter={StaticResource DecimalToPercentageConverter}}" FontSize="12" Foreground="#FFBFC7CE" VerticalAlignment="Top" Margin="0,-2,30,0" HorizontalAlignment="Right" d:Text="7% decayed"/>
104+
<TextBlock x:Name="SavedText" Visibility="Collapsed" Text="{Binding SavedSpace, StringFormat={}{0} saved, Mode=OneWay, Converter={StaticResource BytesToReadableConverter}, ConverterParameter=0}" FontSize="12" Foreground="#FFBFC7CE" VerticalAlignment="Top" Margin="0,-2,30,0" HorizontalAlignment="Right" d:Text="39GB saved"/>
99105
<ui:ProgressBar Height="6" Width="108" CornerRadius="3" Value="{Binding DecayPercentage, Mode=OneWay, Converter={StaticResource DecimalToPercentageConverter}, ConverterParameter='I'}" Foreground="{Binding DecayPercentage, Converter={StaticResource ProgressBarColorConverter}}" Background="#808B9FB3" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,25,30,0" >
100106
<ui:ProgressBar.Effect>
101107
<DropShadowEffect Direction="-135" Opacity="0.2" ShadowDepth="3" BlurRadius="4"/>
@@ -114,6 +120,9 @@
114120
<TextBlock FontSize="12" Foreground="#FF8B9FB3" Text="last modified:" Margin="0,0,27,0"/>
115121
<TextBlock FontSize="12" Foreground="#FF8B9FB3" Text="{Binding LastSystemModifiedDate, Converter={StaticResource RelativeDateConverter}}" d:Text="fds"/>
116122
</StackPanel>
123+
124+
125+
117126
<Button HorizontalAlignment="Right" Command="{Binding ElementName=uiWatcherListView, Path=DataContext.RemoveWatcherCommand}" CommandParameter="{Binding}" Background="#DD6B6B" Foreground="White">
118127
<ui:FontIcon Glyph="&#xE74D;" FontSize="14"/>
119128
</Button>

CompactGUI/Views/Components/FolderWatcherCard.xaml.vb

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,26 @@ Public Class FolderWatcherCard : Inherits UserControl
88
Dim border As Border = DirectCast(sender, Border)
99
Dim newHeight As Double = If(border.Height = 100, 50, 100)
1010

11+
Dim childSavedText = FindChild(Of TextBlock)(border, "SavedText")
12+
Dim childDecayedText = FindChild(Of TextBlock)(border, "DecayedText")
13+
14+
Dim previousBorderChildSavedText = FindChild(Of TextBlock)(currentlyExpandedBorder, "SavedText")
15+
Dim previousBorderChildDecayedText = FindChild(Of TextBlock)(currentlyExpandedBorder, "DecayedText")
16+
1117
If currentlyExpandedBorder Is border AndAlso border.Height = 100 AndAlso TypeOf (e) IsNot MouseButtonEventArgs Then
1218
' Do nothing, keep it expanded
1319
Return
1420
End If
1521

1622
If currentlyExpandedBorder IsNot Nothing AndAlso currentlyExpandedBorder IsNot border Then
1723
AnimateBorderHeight(currentlyExpandedBorder, 50)
18-
End If
24+
previousBorderChildSavedText.Visibility = Visibility.Collapsed
25+
previousBorderChildDecayedText.Visibility = Visibility.Visible
1926

27+
End If
2028
AnimateBorderHeight(border, newHeight)
29+
childSavedText.Visibility = If(newHeight = 100, Visibility.Visible, Visibility.Collapsed)
30+
childDecayedText.Visibility = If(newHeight = 100, Visibility.Collapsed, Visibility.Visible)
2131
currentlyExpandedBorder = If(newHeight = 100, border, Nothing)
2232
End Sub
2333

@@ -35,4 +45,32 @@ Public Class FolderWatcherCard : Inherits UserControl
3545
storyboard.Begin()
3646
End Sub
3747

48+
Public Shared Function FindChild(Of T As DependencyObject)(parent As DependencyObject, childName As String) As T
49+
If parent Is Nothing Then Return Nothing
50+
Dim foundChild As T = Nothing
51+
Dim childrenCount As Integer = VisualTreeHelper.GetChildrenCount(parent)
52+
For i As Integer = 0 To childrenCount - 1
53+
Dim child As DependencyObject = VisualTreeHelper.GetChild(parent, i)
54+
Dim childType As T = TryCast(child, T)
55+
If childType Is Nothing Then
56+
' The child is not of the request type, so recurse down the tree
57+
foundChild = FindChild(Of T)(child, childName)
58+
If foundChild IsNot Nothing Then Exit For
59+
ElseIf Not String.IsNullOrEmpty(childName) Then
60+
Dim frameworkElement As FrameworkElement = TryCast(child, FrameworkElement)
61+
' If the child has the correct name and type
62+
If frameworkElement IsNot Nothing AndAlso frameworkElement.Name = childName Then
63+
foundChild = DirectCast(child, T)
64+
Exit For
65+
End If
66+
Else
67+
' Child is of the requested type but has no name, return it
68+
foundChild = DirectCast(child, T)
69+
Exit For
70+
End If
71+
Next
72+
Return foundChild
73+
End Function
74+
75+
3876
End Class

0 commit comments

Comments
 (0)