Skip to content

Commit 3dfc4d1

Browse files
committed
Adds ability to edit Display Name in the watched folders list by double-clicking. Closes #487
1 parent b0b7258 commit 3dfc4d1

File tree

4 files changed

+99
-36
lines changed

4 files changed

+99
-36
lines changed

CompactGUI.Watcher/WatchedFolder.vb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Public Class WatchedFolder : Inherits ObservableObject
1717
Public Property CompressionLevel As Core.WOFCompressionAlgorithm
1818
<JsonIgnore>
1919
Public Property IsWorking As Boolean
20+
<JsonIgnore>
21+
Public Property IsEditing As Boolean = False
22+
2023
Public ReadOnly Property DecayPercentage As Decimal
2124
Get
2225
If LastCompressedSize = 0 Then Return 1

CompactGUI/ViewModels/WatcherViewModel.vb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Public Class WatcherViewModel : Inherits ObservableObject
1515
Public Property RefreshWatchedCommand As AsyncRelayCommand = New AsyncRelayCommand(AddressOf RefreshWatchedAsync)
1616
Public Property ManuallyAddFolderToWatcherCommand As AsyncRelayCommand = New AsyncRelayCommand(AddressOf ManuallyAddFolderToWatcher)
1717

18+
19+
1820
Public Sub New(watcher As Watcher.Watcher)
1921
Me.Watcher = watcher
2022
End Sub

CompactGUI/Views/Components/FolderWatcherCard.xaml

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
d:DataContext="{d:DesignInstance Type=local:WatcherViewModel}"
1212
d:DesignHeight="500" d:DesignWidth="800"
1313
mc:Ignorable="d">
14-
<Grid VerticalAlignment="Stretch" Margin="30 10 30 0">
14+
<Grid Margin="30,10,30,0" VerticalAlignment="Stretch">
1515

1616
<Grid.Resources>
1717
<CollectionViewSource x:Key="Src" Source="{Binding Watcher.WatchedFolders}">
@@ -33,7 +33,8 @@
3333

3434
<TextBlock Text="Watched folders"
3535
Grid.Row="0"
36-
FontSize="26" VerticalAlignment="Top"
36+
VerticalAlignment="Top"
37+
FontSize="26"
3738
Foreground="{StaticResource CardForeground}"
3839
Visibility="Visible" />
3940

@@ -52,63 +53,73 @@
5253

5354

5455

55-
<TextBlock Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Center"
56-
FontSize="20" Foreground="{StaticResource CardForegroundDisabled}">
56+
<TextBlock Grid.Row="1"
57+
HorizontalAlignment="Left" VerticalAlignment="Center"
58+
FontSize="20"
59+
Foreground="{StaticResource CardForegroundDisabled}">
5760
<Run Text="{Binding Watcher.TotalSaved, Mode=OneWay, Converter={StaticResource BytesToReadableConverter}}" d:Text="51.8GB" />
5861
<Run Text="saved" />
5962
</TextBlock>
6063

61-
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0 0 3 0" >
62-
<Grid Width="45" Height="25" VerticalAlignment="Center" >
64+
<StackPanel Grid.Row="1"
65+
Margin="0,0,3,0" HorizontalAlignment="Right" VerticalAlignment="Center"
66+
Orientation="Horizontal">
67+
<Grid Width="45" Height="25"
68+
VerticalAlignment="Center">
6369
<ui:Button Background="Transparent" BorderThickness="0"
64-
Command="{Binding RefreshWatchedCommand}"
65-
Visibility="{Binding RefreshWatchedCommand.IsRunning, Converter={StaticResource BooleanToInverseVisibilityConverter}}">
70+
Command="{Binding RefreshWatchedCommand}"
71+
Visibility="{Binding RefreshWatchedCommand.IsRunning, Converter={StaticResource BooleanToInverseVisibilityConverter}}">
6672

6773
<ui:FontIcon FontFamily="Segoe Fluent Icons, Segoe MDL2 Assets" FontSize="14"
68-
Glyph="&#xE9F3;" />
74+
Glyph="&#xE9F3;" />
6975
<ui:Button.ToolTip>
7076
<ToolTip ToolTipService.InitialShowDelay="100">
7177
<TextBlock Text="Re-analyse all watched folders"
72-
FontSize="12" Foreground="#FFBFC7CE" TextWrapping="NoWrap" />
78+
FontSize="12" Foreground="#FFBFC7CE" TextWrapping="NoWrap" />
7379
</ToolTip>
7480
</ui:Button.ToolTip>
7581
</ui:Button>
76-
<ui:ProgressRing Width="18" Height="18" Margin="-15 0 0 0 "
77-
Foreground="#FFBFC7CE" IsIndeterminate="True"
78-
Visibility="{Binding RefreshWatchedCommand.IsRunning, Converter={StaticResource BoolToVisConverter}}" />
82+
<ui:ProgressRing Width="18" Height="18"
83+
Margin="-15,0,0,0"
84+
Foreground="#FFBFC7CE" IsIndeterminate="True"
85+
Visibility="{Binding RefreshWatchedCommand.IsRunning, Converter={StaticResource BoolToVisConverter}}" />
7986
</Grid>
80-
8187

82-
<TextBlock VerticalAlignment="Center" Margin="0 -2 0 0" Text="{Binding Watcher.LastAnalysed, StringFormat=Last analysed {0}, Converter={StaticResource RelativeDateConverter}}"
83-
84-
d:Text="Last analysed: just now" FontSize="14" Foreground="#FFBFC7CE" />
88+
89+
<TextBlock Text="{Binding Watcher.LastAnalysed, StringFormat=Last analysed {0}, Converter={StaticResource RelativeDateConverter}}"
90+
Margin="0,-2,0,0" VerticalAlignment="Center"
91+
d:Text="Last analysed: just now" FontSize="14" Foreground="#FFBFC7CE" />
8592
</StackPanel>
8693

8794

88-
<Separator Height="1" Grid.Row="2" VerticalAlignment="Bottom"/>
95+
<Separator Grid.Row="2"
96+
Height="1"
97+
VerticalAlignment="Bottom" />
8998

9099

91-
<ListView x:Name="UiWatcherListView" Grid.Row="3" Margin="-10 0 -20 0" Padding="0 0 10 0"
92-
HorizontalAlignment="Stretch"
100+
<ListView x:Name="UiWatcherListView"
101+
Grid.Row="3"
102+
Margin="-10,0,-20,0" Padding="0,0,10,0" HorizontalAlignment="Stretch"
93103
d:ItemsSource="{Binding Source={StaticResource Dtd}}"
94-
Background="Transparent" BorderThickness="0"
95-
ItemsSource="{Binding Source={StaticResource Src}}"
96-
ScrollViewer.VerticalScrollBarVisibility="Visible">
104+
Background="Transparent" BorderThickness="0"
105+
ItemsSource="{Binding Source={StaticResource Src}}"
106+
ScrollViewer.VerticalScrollBarVisibility="Visible">
97107

98108
<ListView.ItemContainerStyle>
99109
<Style TargetType="ListViewItem">
100110
<Setter Property="Margin" Value="0,0,0,0" />
101111
<Setter Property="Background" Value="Transparent" />
102112
<Setter Property="BorderBrush" Value="Transparent" />
103113
<Setter Property="VerticalContentAlignment" Value="Center" />
104-
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
114+
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
105115
<Setter Property="Template">
106116
<Setter.Value>
107117
<ControlTemplate TargetType="{x:Type ListViewItem}">
108-
<Border Name="Border" CornerRadius="5"
118+
<Border Name="Border"
109119
Background="{TemplateBinding Background}"
110120
BorderBrush="{TemplateBinding BorderBrush}"
111-
BorderThickness="{TemplateBinding BorderThickness}">
121+
BorderThickness="{TemplateBinding BorderThickness}"
122+
CornerRadius="5">
112123
<ContentPresenter Content="{TemplateBinding Content}"
113124
Margin="{TemplateBinding Padding}"
114125
d:Content="{TemplateBinding Content}"
@@ -136,11 +147,11 @@
136147
MouseDown="ToggleBorderHeight" MouseEnter="ToggleBorderHeight">
137148

138149

139-
<Grid>
140-
141-
142-
143-
<Label >
150+
<Grid>
151+
152+
153+
154+
<Label>
144155
<StackPanel Orientation="Horizontal">
145156

146157
<ui:ProgressRing Width="15" Height="15"
@@ -159,10 +170,22 @@
159170
Margin="0,0,5,0"
160171
FontFamily="Segoe Fluent Icons, Segoe MDL2 Assets" Foreground="White"
161172
Visibility="{Binding IsSteamGame, Converter={StaticResource BooleanToInverseVisibilityConverter}}" />
162-
<TextBlock Text="{Binding DisplayName, Converter={StaticResource StrippedFolderPathConverter}}"
163-
MaxWidth="280"
164-
Margin="0,-2,0,0" VerticalAlignment="Top"
165-
FontSize="15" FontWeight="SemiBold" Foreground="White" TextTrimming="CharacterEllipsis" />
173+
<Grid>
174+
<TextBlock Text="{Binding DisplayName, Converter={StaticResource StrippedFolderPathConverter}}"
175+
MaxWidth="280" MinWidth="100"
176+
Margin="0,-2,0,0" VerticalAlignment="Top"
177+
FontSize="15" FontWeight="SemiBold" Foreground="White"
178+
MouseLeftButtonDown="DisplayNameTextBlock_MouseLeftButtonDown"
179+
TextTrimming="CharacterEllipsis"
180+
Visibility="{Binding IsEditing, Converter={StaticResource BooleanToInverseVisibilityConverter}}" />
181+
182+
<TextBox Text="{Binding DisplayName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
183+
MaxWidth="280" MinWidth="100"
184+
Margin="-3,-3,0,0" VerticalAlignment="Top" Padding="0"
185+
FontSize="15" FontWeight="SemiBold" Foreground="{StaticResource TextControlForeground}"
186+
KeyDown="DisplayNameTextBox_KeyDown" LostFocus="DisplayNameTextBox_LostFocus"
187+
Visibility="{Binding IsEditing, Converter={StaticResource BoolToVisConverter}}" />
188+
</Grid>
166189

167190
</StackPanel>
168191

@@ -268,7 +291,7 @@
268291

269292
</ListView>
270293

271-
294+
272295

273296
</Grid>
274297
</UserControl>

CompactGUI/Views/Components/FolderWatcherCard.xaml.vb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,40 @@ Public Class FolderWatcherCard : Inherits UserControl
7272
Return foundChild
7373
End Function
7474

75+
Private Sub DisplayNameTextBlock_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)
76+
If e.ClickCount = 2 Then
77+
Dim fe = TryCast(sender, FrameworkElement)
78+
If fe IsNot Nothing AndAlso fe.DataContext IsNot Nothing Then
79+
Dim vm = TryCast(fe.DataContext, Watcher.WatchedFolder)
80+
If vm IsNot Nothing Then
81+
vm.IsEditing = True
82+
End If
83+
End If
84+
End If
85+
End Sub
86+
87+
Private Sub DisplayNameTextBox_LostFocus(sender As Object, e As RoutedEventArgs)
88+
Dim fe = TryCast(sender, FrameworkElement)
89+
If fe IsNot Nothing AndAlso fe.DataContext IsNot Nothing Then
90+
Dim vm = TryCast(fe.DataContext, Watcher.WatchedFolder)
91+
If vm IsNot Nothing Then
92+
vm.IsEditing = False
93+
Application.GetService(Of Watcher.Watcher)().WriteToFile()
94+
End If
95+
End If
96+
End Sub
97+
98+
Private Sub DisplayNameTextBox_KeyDown(sender As Object, e As KeyEventArgs)
99+
If e.Key = Key.Enter Then
100+
Dim fe = TryCast(sender, FrameworkElement)
101+
If fe IsNot Nothing AndAlso fe.DataContext IsNot Nothing Then
102+
Dim vm = TryCast(fe.DataContext, Watcher.WatchedFolder)
103+
If vm IsNot Nothing Then
104+
vm.IsEditing = False
105+
Application.GetService(Of Watcher.Watcher)().WriteToFile()
106+
End If
107+
End If
108+
End If
109+
End Sub
75110

76111
End Class

0 commit comments

Comments
 (0)