forked from files-community/Files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenameAction.cs
71 lines (60 loc) · 1.86 KB
/
RenameAction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) Files Community
// Licensed under the MIT License.
namespace Files.App.Actions
{
internal sealed partial class RenameAction : ObservableObject, IAction
{
private readonly IContentPageContext context;
public string Label
=> Strings.Rename.GetLocalizedResource();
public string Description
=> Strings.RenameDescription.GetLocalizedResource();
public HotKey HotKey
=> new(Keys.F2);
public RichGlyph Glyph
=> new(themedIconStyle: "App.ThemedIcons.Rename");
public bool IsExecutable =>
context.ShellPage is not null &&
IsPageTypeValid() &&
context.ShellPage.SlimContentPage is not null &&
context.HasSelection;
public RenameAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();
context.PropertyChanged += Context_PropertyChanged;
}
public async Task ExecuteAsync(object? parameter = null)
{
if (context.SelectedItems.Count > 1)
{
var viewModel = new BulkRenameDialogViewModel();
var dialogService = Ioc.Default.GetRequiredService<IDialogService>();
var result = await dialogService.ShowDialogAsync(viewModel);
}
else
{
context.ShellPage?.SlimContentPage?.ItemManipulationModel.StartRenameItem();
}
}
private bool IsPageTypeValid()
{
return
context.PageType != ContentPageTypes.None &&
context.PageType != ContentPageTypes.Home &&
context.PageType != ContentPageTypes.RecycleBin &&
context.PageType != ContentPageTypes.ZipFolder;
}
private void Context_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.ShellPage):
case nameof(IContentPageContext.PageType):
case nameof(IContentPageContext.HasSelection):
case nameof(IContentPageContext.SelectedItems):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}