Skip to content

Feature: Added support for reordering tags #11306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public FileTagsSettingsService()
public IList<TagViewModel> FileTagList
{
get => Get<List<TagViewModel>>(DefaultFileTags);
set => Set(value);
set
{
Set(value);
OnTagsUpdated.Invoke(this, EventArgs.Empty);
}
}

public TagViewModel GetTagById(string uid)
Expand Down Expand Up @@ -86,7 +90,6 @@ public void CreateNewTag(string newTagName, string color)
var oldTags = FileTagList.ToList();
oldTags.Add(newTag);
FileTagList = oldTags;
OnTagsUpdated.Invoke(this, EventArgs.Empty);
}

public void EditTag(string uid, string name, string color)
Expand All @@ -102,7 +105,6 @@ public void EditTag(string uid, string name, string color)
oldTags.RemoveAt(index);
oldTags.Insert(index, tag);
FileTagList = oldTags;
OnTagsUpdated.Invoke(this, EventArgs.Empty);
}

public void DeleteTag(string uid)
Expand All @@ -115,8 +117,6 @@ public void DeleteTag(string uid)
oldTags.RemoveAt(index);
FileTagList = oldTags;
UntagAllFiles(uid);

OnTagsUpdated.Invoke(this, EventArgs.Empty);
}

public override bool ImportSettings(object import)
Expand Down
36 changes: 35 additions & 1 deletion src/Files.App/ViewModels/SettingsViewModels/AdvancedViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
using Files.Backend.Services.Settings;
using Files.Backend.ViewModels.FileTags;
using Files.Shared.Extensions;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Win32;
using SevenZip;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
Expand All @@ -34,6 +34,10 @@ public class AdvancedViewModel : ObservableObject

private readonly IFileTagsSettingsService fileTagsSettingsService = Ioc.Default.GetRequiredService<IFileTagsSettingsService>();

private bool isBulkOperation = true;

private bool isDragStarting = true;

public ICommand SetAsDefaultExplorerCommand { get; }
public ICommand SetAsOpenFileDialogCommand { get; }
public ICommand ExportSettingsCommand { get; }
Expand Down Expand Up @@ -64,7 +68,28 @@ public AdvancedViewModel()
CancelNewTagCommand = new RelayCommand(DoCancelNewTag);

Tags = new ObservableCollection<ListedTagViewModel>();
Tags.CollectionChanged += Tags_CollectionChanged;
fileTagsSettingsService.FileTagList?.ForEach(tag => Tags.Add(new ListedTagViewModel(tag)));

isBulkOperation = false;
}

private void Tags_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (isBulkOperation)
return;

// Reaordering ListView has no events, but its collection is updated twice,
// first to remove the selected item, and second to add the item at the selected position.
if (isDragStarting)
{
isDragStarting = false;
return;
}

isDragStarting = true;

fileTagsSettingsService.FileTagList = Tags.Select(tagVM => tagVM.Tag).ToList();
}

private async Task OpenSettingsJson()
Expand Down Expand Up @@ -329,8 +354,11 @@ private void DoSaveNewTag()
IsCreatingNewTag = false;

fileTagsSettingsService.CreateNewTag(NewTag.Name, NewTag.Color);

isBulkOperation = true;
Tags.Clear();
fileTagsSettingsService.FileTagList?.ForEach(tag => Tags.Add(new ListedTagViewModel(tag)));
isBulkOperation = false;
}

private void DoCancelNewTag()
Expand All @@ -341,13 +369,19 @@ private void DoCancelNewTag()
public void EditExistingTag(ListedTagViewModel item, string newName, string color)
{
fileTagsSettingsService.EditTag(item.Tag.Uid, newName, color);

isBulkOperation = true;
Tags.Clear();
fileTagsSettingsService.FileTagList?.ForEach(tag => Tags.Add(new ListedTagViewModel(tag)));
isBulkOperation = false;
}

public void DeleteExistingTag(ListedTagViewModel item)
{
isBulkOperation = true;
Tags.Remove(item);
isBulkOperation = false;

fileTagsSettingsService.DeleteTag(item.Tag.Uid);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Views/SettingsPages/Advanced.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,11 @@
MaxHeight="300"
Padding="12"
HorizontalAlignment="Stretch"
AllowDrop="True"
CanReorderItems="True"
IsItemClickEnabled="True"
ItemsSource="{x:Bind ViewModel.Tags, Mode=TwoWay}"
ReorderMode="Enabled"
SelectionMode="None">
<ListView.ItemTemplate>
<DataTemplate xmlns:vm="using:Files.Backend.ViewModels.FileTags" x:DataType="vm:ListedTagViewModel">
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/SettingsPages/Advanced.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private bool IsNameValid(string name)
string.IsNullOrWhiteSpace(name) ||
name.StartsWith('.') ||
name.EndsWith('.') ||
ViewModel.Tags.Any(tag => name == tag.Tag.Name)
(name != editingTag.Tag.Name && ViewModel.Tags.Any(tag => name == tag.Tag.Name))
);
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Files.InteractionTests/Tests/FolderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void CreateFolderTest()
action.SendKeys(Keys.Enter).Perform();

// Wait for folder to be created
Thread.Sleep(1000);
Thread.Sleep(2000);

// Check for accessibility issues in the file area
AxeHelper.AssertNoAccessibilityErrors();
Expand All @@ -85,7 +85,7 @@ private void RenameFolderTest()
action.SendKeys(Keys.Enter).Perform();

// Wait for the folder to be renamed
Thread.Sleep(1000);
Thread.Sleep(2000);
}

/// <summary>
Expand All @@ -97,13 +97,13 @@ private void CopyPasteFolderTest()
TestHelper.InvokeButtonById("InnerNavigationToolbarCopyButton");

// Wait for folder to be copied
Thread.Sleep(1000);
Thread.Sleep(2000);

// Click the "paste" button on the toolbar
TestHelper.InvokeButtonById("InnerNavigationToolbarPasteButton");

// Wait for folder to be pasted
Thread.Sleep(1000);
Thread.Sleep(2000);
}

/// <summary>
Expand All @@ -116,7 +116,7 @@ private void DeleteFolderTest()
TestHelper.InvokeButtonById("Delete");

// Wait for prompt to show
Thread.Sleep(1000);
Thread.Sleep(2000);

// Check for accessibility issues in the confirm delete prompt
AxeHelper.AssertNoAccessibilityErrors();
Expand All @@ -131,7 +131,7 @@ private void DeleteFolderTest()
TestHelper.InvokeButtonById("Delete");

// Wait for prompt to show
Thread.Sleep(1000);
Thread.Sleep(2000);

// Check for accessibility issues in the confirm delete prompt
AxeHelper.AssertNoAccessibilityErrors();
Expand All @@ -141,7 +141,7 @@ private void DeleteFolderTest()
action.SendKeys(Keys.Enter).Perform();

// Wait for items to finish being deleted
Thread.Sleep(1000);
Thread.Sleep(2000);
}
}
}