Skip to content

Commit f5bcadd

Browse files
Requested Changes
1 parent 917c62a commit f5bcadd

File tree

5 files changed

+46
-12
lines changed

5 files changed

+46
-12
lines changed

src/Files.App/Helpers/ColorHelpers.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using CommunityToolkit.WinUI.Helpers;
12
using System;
23
using Windows.UI;
34

@@ -36,5 +37,20 @@ public static uint ToUint(this Color c)
3637
{
3738
return (uint)(((c.A << 24) | (c.R << 16) | (c.G << 8) | c.B) & 0xffffffffL);
3839
}
40+
41+
/// <summary>
42+
/// Generates a random color and returns its Hex
43+
/// </summary>
44+
/// <returns></returns>
45+
public static string RandomColor()
46+
{
47+
var color = Color.FromArgb(
48+
255,
49+
(byte)Random.Shared.Next(0, 256),
50+
(byte)Random.Shared.Next(0, 256),
51+
(byte)Random.Shared.Next(0, 256));
52+
53+
return color.ToHex();
54+
}
3955
}
4056
}

src/Files.App/ServicesImplementation/Settings/FileTagsSettingsService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Files.App.Extensions;
2+
using Files.App.Helpers;
23
using Files.App.Serialization;
34
using Files.App.Serialization.Implementation;
45
using Files.Backend.Services.Settings;
@@ -78,7 +79,7 @@ public void CreateNewTag()
7879
{
7980
var newTag = new TagViewModel(
8081
"NewTag",
81-
"#9EA3A1",
82+
ColorHelpers.RandomColor(),
8283
Guid.NewGuid().ToString());
8384

8485
var oldTags = FileTagList.ToList();

src/Files.App/ViewModels/SettingsViewModels/AdvancedViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public class AdvancedViewModel : ObservableObject
4343

4444
public ICommand AddTagCommand { get; }
4545

46-
public ICommand EditTagCommand { get; }
47-
4846
public ICommand DeleteTagCommand { get; }
4947

48+
public ICommand EditTagCommand { get; set; }
49+
5050
public ObservableCollection<TagViewModel> Tags { get; set; }
5151

5252
private int selectedTagIndex = -1;

src/Files.App/Views/SettingsPages/Advanced.xaml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@
160160
Command="{x:Bind ViewModel.AddTagCommand, Mode=OneWay}"
161161
Icon="Add"
162162
Label="{helpers:ResourceString Name=Add}" />
163+
<AppBarButton
164+
Command="{x:Bind ViewModel.EditTagCommand}"
165+
Icon="Edit"
166+
IsEnabled="{x:Bind ViewModel.AreTagsCommandEnabled, Mode=OneWay}"
167+
Label="{helpers:ResourceString Name=Edit}" />
163168
<AppBarButton
164169
Command="{x:Bind ViewModel.DeleteTagCommand}"
165170
Icon="Delete"
@@ -204,22 +209,31 @@
204209
<SolidColorBrush x:Key="TextControlBackgroundFocused" Color="{ThemeResource SolidBackgroundFillColorSecondary}" />
205210
</TextBox.Resources>
206211
</TextBox>
207-
<Ellipse
212+
<Button
208213
Grid.Column="2"
209-
Width="24"
210-
Height="24"
211-
Margin="0,8"
212-
Fill="{x:Bind Color}">
213-
<Ellipse.ContextFlyout>
214+
Padding="0"
215+
AutomationProperties.Name="{helpers:ResourceString Name=TagColor}">
216+
<StackPanel Orientation="Horizontal">
217+
<Border
218+
Width="24"
219+
Height="24"
220+
Margin="4"
221+
Background="{x:Bind Color}"
222+
CornerRadius="4" />
223+
<FontIcon
224+
Margin="8,4,10,4"
225+
FontSize="12"
226+
Glyph="&#xE019;" />
227+
</StackPanel>
228+
<Button.Flyout>
214229
<Flyout>
215230
<controls:ColorPicker
216-
Grid.Column="2"
217231
ColorChanged="ColorPicker_ColorChanged"
218232
IsAlphaEnabled="True"
219233
IsColorSpectrumVisible="False" />
220234
</Flyout>
221-
</Ellipse.ContextFlyout>
222-
</Ellipse>
235+
</Button.Flyout>
236+
</Button>
223237
</Grid>
224238
</DataTemplate>
225239
</ListView.ItemTemplate>

src/Files.App/Views/SettingsPages/Advanced.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using CommunityToolkit.Mvvm.Input;
12
using CommunityToolkit.WinUI.UI;
23
using Files.Backend.ViewModels.FileTags;
34
using Microsoft.UI.Xaml;
@@ -26,6 +27,8 @@ public Advanced()
2627
{
2728
InitializeComponent();
2829

30+
ViewModel.EditTagCommand = new RelayCommand(StartRenameTag);
31+
2932
tapDebounceTimer = DispatcherQueue.CreateTimer();
3033
}
3134

0 commit comments

Comments
 (0)