Group rename
This commit is contained in:
@@ -180,12 +180,15 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
|
|
||||||
private async Task Rename(RenameCommand command)
|
private async Task Rename(RenameCommand command)
|
||||||
{
|
{
|
||||||
|
List<ItemToMove> itemsToMove = new();
|
||||||
if ((_markedItems?.Collection?.Count ?? 0) > 0)
|
if ((_markedItems?.Collection?.Count ?? 0) > 0)
|
||||||
{
|
{
|
||||||
BehaviorSubject<string> templateRegexValue = new(string.Empty);
|
BehaviorSubject<string> templateRegexValue = new(string.Empty);
|
||||||
BehaviorSubject<string> newNameSchemaValue = new(string.Empty);
|
BehaviorSubject<string> newNameSchemaValue = new(string.Empty);
|
||||||
|
|
||||||
var itemPreviews = _markedItems!.Collection!
|
var itemsToRename = new List<FullName>(_markedItems!.Collection!);
|
||||||
|
|
||||||
|
var itemPreviews = itemsToRename
|
||||||
.Select(item =>
|
.Select(item =>
|
||||||
{
|
{
|
||||||
var originalName = item.GetName();
|
var originalName = item.GetName();
|
||||||
@@ -238,7 +241,102 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
|| string.IsNullOrWhiteSpace(newNameSchema)) return new List<ItemNamePart> {new(originalName)};
|
|| string.IsNullOrWhiteSpace(newNameSchema)) return new List<ItemNamePart> {new(originalName)};
|
||||||
|
|
||||||
var regex = new Regex(templateRegex);
|
var regex = new Regex(templateRegex);
|
||||||
var match = regex.Match(originalName);
|
var itemNameParts = GetItemNameParts(regex, originalName, newNameSchema);
|
||||||
|
|
||||||
|
return itemNameParts.ToList();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return new List<ItemNamePart> {new(originalName)};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var preview = new DoubleTextPreview
|
||||||
|
{
|
||||||
|
Text1 = decoratedOriginalName,
|
||||||
|
Text2 = text2
|
||||||
|
};
|
||||||
|
return preview;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
DoubleTextListPreview doubleTextListPreview = new();
|
||||||
|
doubleTextListPreview.Items.AddRange(itemPreviews);
|
||||||
|
|
||||||
|
var templateRegex = new TextInputElement("Template regex", string.Empty,
|
||||||
|
s => templateRegexValue.OnNext(s!));
|
||||||
|
var newNameSchema = new TextInputElement("New name schema", string.Empty,
|
||||||
|
s => newNameSchemaValue.OnNext(s!));
|
||||||
|
|
||||||
|
var success = await _userCommunicationService.ReadInputs(
|
||||||
|
new[] {templateRegex, newNameSchema},
|
||||||
|
new[] {doubleTextListPreview}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
if (templateRegex.Value is null)
|
||||||
|
{
|
||||||
|
//TODO messagebox
|
||||||
|
}
|
||||||
|
else if (newNameSchema.Value is null)
|
||||||
|
{
|
||||||
|
//TODO messagebox
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var regex = new Regex(templateRegex.Value);
|
||||||
|
var itemsToMoveWithPath = itemsToRename
|
||||||
|
.Select(item =>
|
||||||
|
(
|
||||||
|
OriginalFullName: item,
|
||||||
|
NewName:
|
||||||
|
item.GetParent()!.GetChild(
|
||||||
|
string.Join(
|
||||||
|
"",
|
||||||
|
GetItemNameParts(regex, item.GetName(), newNameSchema.Value)
|
||||||
|
.Select(i => i.Text)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.Select(i => new ItemToMove(i.OriginalFullName, i.NewName));
|
||||||
|
|
||||||
|
itemsToMove.AddRange(itemsToMoveWithPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_currentSelectedItem?.BaseItem?.FullName is null) return;
|
||||||
|
|
||||||
|
var item = await _timelessContentProvider.GetItemByFullNameAsync(_currentSelectedItem.BaseItem.FullName, PointInTime.Present);
|
||||||
|
|
||||||
|
if (item is null) return;
|
||||||
|
|
||||||
|
var renameInput = new TextInputElement("New name", item.Name);
|
||||||
|
|
||||||
|
if (await _userCommunicationService.ReadInputs(renameInput))
|
||||||
|
{
|
||||||
|
//TODO: should check these null forgivings...
|
||||||
|
var newPath = item.FullName!.GetParent()!.GetChild(renameInput.Value!);
|
||||||
|
itemsToMove.Add(new ItemToMove(item.FullName, newPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemsToMove.Count > 0)
|
||||||
|
{
|
||||||
|
//TODO: name collision, probably on the input window at the new template name
|
||||||
|
//TODO: check if the name changed
|
||||||
|
var moveCommandFactory = _serviceProvider.GetRequiredService<MoveCommandFactory>();
|
||||||
|
var moveCommand = moveCommandFactory.GenerateCommand(itemsToMove);
|
||||||
|
await AddCommand(moveCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
static IEnumerable<ItemNamePart> GetItemNameParts(Regex templateRegex, string originalName, string newNameSchema)
|
||||||
|
{
|
||||||
|
var match = templateRegex.Match(originalName);
|
||||||
if (!match.Success) return new List<ItemNamePart> {new(originalName)};
|
if (!match.Success) return new List<ItemNamePart> {new(originalName)};
|
||||||
|
|
||||||
var matchGroups = match.Groups;
|
var matchGroups = match.Groups;
|
||||||
@@ -266,56 +364,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
: new ItemNamePart(namePart, false)
|
: new ItemNamePart(namePart, false)
|
||||||
);
|
);
|
||||||
|
|
||||||
return itemNameParts.ToList();
|
return itemNameParts;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return new List<ItemNamePart> {new(originalName)};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
var preview = new DoubleTextPreview
|
|
||||||
{
|
|
||||||
Text1 = decoratedOriginalName,
|
|
||||||
Text2 = text2
|
|
||||||
};
|
|
||||||
return preview;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
DoubleTextListPreview doubleTextListPreview = new();
|
|
||||||
doubleTextListPreview.Items.AddRange(itemPreviews);
|
|
||||||
|
|
||||||
var templateRegex = new TextInputElement("Template regex", string.Empty,
|
|
||||||
s => templateRegexValue.OnNext(s!));
|
|
||||||
var newNameSchema = new TextInputElement("New name schema", string.Empty,
|
|
||||||
s => newNameSchemaValue.OnNext(s!));
|
|
||||||
await _userCommunicationService.ReadInputs(
|
|
||||||
new[] {templateRegex, newNameSchema},
|
|
||||||
new[] {doubleTextListPreview}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
List<ItemToMove> itemsToMove = new();
|
|
||||||
if (_currentSelectedItem?.BaseItem?.FullName is null) return;
|
|
||||||
|
|
||||||
var item = await _timelessContentProvider.GetItemByFullNameAsync(_currentSelectedItem.BaseItem.FullName, PointInTime.Present);
|
|
||||||
|
|
||||||
if (item is null) return;
|
|
||||||
|
|
||||||
var renameInput = new TextInputElement("New name", item.Name);
|
|
||||||
|
|
||||||
await _userCommunicationService.ReadInputs(renameInput);
|
|
||||||
|
|
||||||
//TODO: should check these...
|
|
||||||
var newPath = item.FullName!.GetParent()!.GetChild(renameInput.Value!);
|
|
||||||
itemsToMove.Add(new ItemToMove(item.FullName, newPath));
|
|
||||||
|
|
||||||
var moveCommandFactory = _serviceProvider.GetRequiredService<MoveCommandFactory>();
|
|
||||||
var moveCommand = moveCommandFactory.GenerateCommand(itemsToMove);
|
|
||||||
await AddCommand(moveCommand);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user