Skip to content
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

Code Quality: Enforced centralized Strings class in viewmodels #16939

Closed
wants to merge 1 commit into from
Closed
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 @@ -33,8 +33,8 @@ public async Task AddItemsToListAsync(IEnumerable<ShellNewEntry> itemTypes)

AddItemsList.Add(new()
{
Header = "Folder".ToLocalized(),
SubHeader = "AddDialogListFolderSubHeader".ToLocalized(),
Header = Strings.Folder.ToLocalized(),
SubHeader = Strings.AddDialogListFolderSubHeader.ToLocalized(),
Glyph = "\xE838",
IsItemEnabled = true,
ItemResult = new()
Expand All @@ -45,8 +45,8 @@ public async Task AddItemsToListAsync(IEnumerable<ShellNewEntry> itemTypes)

AddItemsList.Add(new()
{
Header = "File".ToLocalized(),
SubHeader = "AddDialogListFileSubHeader".ToLocalized(),
Header = Strings.File.ToLocalized(),
SubHeader = Strings.AddDialogListFileSubHeader.ToLocalized(),
Glyph = "\xE8A5",
IsItemEnabled = true,
ItemResult = new()
Expand All @@ -58,8 +58,8 @@ public async Task AddItemsToListAsync(IEnumerable<ShellNewEntry> itemTypes)

AddItemsList.Add(new()
{
Header = "Shortcut".ToLocalized(),
SubHeader = "AddDialogListShortcutSubHeader".ToLocalized(),
Header = Strings.Shortcut.ToLocalized(),
SubHeader = Strings.AddDialogListShortcutSubHeader.ToLocalized(),
Glyph = "\uE71B",
IsItemEnabled = true,
ItemResult = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,48 +149,48 @@ public static FileSystemDialogViewModel GetDialogViewModel(FileSystemDialogMode

if (dialogMode.ConflictsExist)
{
titleText = "ConflictingItemsDialogTitle".GetLocalizedFormatResource(totalCount);
titleText = Strings.ConflictingItemsDialogTitle.GetLocalizedFormatResource(totalCount);

descriptionText = nonConflictingItems.Count > 0
? "ConflictingItemsDialogSubtitleConflictsNonConflicts".GetLocalizedFormatResource(conflictingItems.Count, nonConflictingItems.Count)
: "ConflictingItemsDialogSubtitleConflicts".GetLocalizedFormatResource(conflictingItems.Count);
? Strings.ConflictingItemsDialogSubtitleConflictsNonConflicts.GetLocalizedFormatResource(conflictingItems.Count, nonConflictingItems.Count)
: Strings.ConflictingItemsDialogSubtitleConflicts.GetLocalizedFormatResource(conflictingItems.Count);

primaryButtonText = "ConflictingItemsDialogPrimaryButtonText".ToLocalized();
secondaryButtonText = "Cancel".ToLocalized();
primaryButtonText = Strings.ConflictingItemsDialogPrimaryButtonText.ToLocalized();
secondaryButtonText = Strings.Cancel.ToLocalized();
}
else
{
switch (operationType)
{
case FilesystemOperationType.Copy:
{
titleText = "CopyItemsDialogTitle".GetLocalizedFormatResource(totalCount);
titleText = Strings.CopyItemsDialogTitle.GetLocalizedFormatResource(totalCount);

descriptionText = "CopyItemsDialogSubtitle".GetLocalizedFormatResource(totalCount);
primaryButtonText = "Copy".ToLocalized();
secondaryButtonText = "Cancel".ToLocalized();
descriptionText = Strings.CopyItemsDialogSubtitle.GetLocalizedFormatResource(totalCount);
primaryButtonText = Strings.Copy.ToLocalized();
secondaryButtonText = Strings.Cancel.ToLocalized();

break;
}

case FilesystemOperationType.Move:
{
titleText = "MoveItemsDialogTitle".GetLocalizedFormatResource(totalCount);
titleText = Strings.MoveItemsDialogTitle.GetLocalizedFormatResource(totalCount);

descriptionText = "MoveItemsDialogSubtitle".GetLocalizedFormatResource(totalCount);
primaryButtonText = "MoveItemsDialogPrimaryButtonText".ToLocalized();
secondaryButtonText = "Cancel".ToLocalized();
descriptionText = Strings.MoveItemsDialogSubtitle.GetLocalizedFormatResource(totalCount);
primaryButtonText = Strings.MoveItemsDialogPrimaryButtonText.ToLocalized();
secondaryButtonText = Strings.Cancel.ToLocalized();

break;
}

case FilesystemOperationType.Delete:
{
titleText = "DeleteItemsDialogTitle".GetLocalizedFormatResource(totalCount);
titleText = Strings.DeleteItemsDialogTitle.GetLocalizedFormatResource(totalCount);

descriptionText = "DeleteItemsDialogSubtitle".GetLocalizedFormatResource(totalCount);
primaryButtonText = "Delete".ToLocalized();
secondaryButtonText = "Cancel".ToLocalized();
descriptionText = Strings.DeleteItemsDialogSubtitle.GetLocalizedFormatResource(totalCount);
primaryButtonText = Strings.Delete.ToLocalized();
secondaryButtonText = Strings.Cancel.ToLocalized();

isInDeleteMode = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed partial class ReorderSidebarItemsDialogViewModel : ObservableObjec
{
private readonly IQuickAccessService quickAccessService = Ioc.Default.GetRequiredService<IQuickAccessService>();

public string HeaderText = "ReorderSidebarItemsDialogText".GetLocalizedResource();
public string HeaderText = Strings.ReorderSidebarItemsDialogText.GetLocalizedResource();
public ICommand PrimaryButtonCommand { get; private set; }

public ObservableCollection<LocationItem> SidebarPinnedFolderItems = new(App.QuickAccessManager.Model._PinnedFolderItems
Expand Down
14 changes: 7 additions & 7 deletions src/Files.App/ViewModels/Layouts/BaseLayoutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,23 @@ public async Task DragOverAsync(DragEventArgs e)
e.DragUIOverride.IsCaptionVisible = true;
if (pwd.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
e.DragUIOverride.Caption = string.Format(Strings.MoveToFolderCaptionText.GetLocalizedResource(), folderName);
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
}
else if (e.Modifiers.HasFlag(DragDropModifiers.Alt) || e.Modifiers.HasFlag(DragDropModifiers.Control | DragDropModifiers.Shift))
{
e.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), folderName);
e.DragUIOverride.Caption = string.Format(Strings.LinkToFolderCaptionText.GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Link;
}
else if (e.Modifiers.HasFlag(DragDropModifiers.Control))
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
e.DragUIOverride.Caption = string.Format(Strings.CopyToFolderCaptionText.GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
}
else if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
e.DragUIOverride.Caption = string.Format(Strings.MoveToFolderCaptionText.GetLocalizedResource(), folderName);
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
}
Expand All @@ -150,18 +150,18 @@ x.Item is ZipStorageFile ||
x.Item is ZipStorageFolder) ||
ZipStorageFolder.IsZipPath(pwd))
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
e.DragUIOverride.Caption = string.Format(Strings.CopyToFolderCaptionText.GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
}
else if (draggedItems.AreItemsInSameDrive(_associatedInstance.ShellViewModel.WorkingDirectory))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
e.DragUIOverride.Caption = string.Format(Strings.MoveToFolderCaptionText.GetLocalizedResource(), folderName);
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
}
else
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
e.DragUIOverride.Caption = string.Format(Strings.CopyToFolderCaptionText.GetLocalizedResource(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ViewModels/Properties/BasePropertiesPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)

string[] extensions =
[
"BitmapFiles".GetLocalizedResource(), "*.bmp",
Strings.BitmapFiles.GetLocalizedResource(), "*.bmp",
"JPEG", "*.jpg;*.jpeg",
"PNG", "*.png",
];
Expand Down
24 changes: 12 additions & 12 deletions src/Files.App/ViewModels/Properties/CompatibilityViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,26 @@ public CompatibilityViewModel(ListedItem item)

CompatibilityOptions = WindowsCompatibilityService.GetCompatibilityOptionsForPath(ItemPath);

CompatibilityModes.Add(WindowsCompatModeKind.None, "None".GetLocalizedResource());
CompatibilityModes.Add(WindowsCompatModeKind.None, Strings.None.GetLocalizedResource());
CompatibilityModes.Add(WindowsCompatModeKind.WindowsVista, "Windows Vista");
CompatibilityModes.Add(WindowsCompatModeKind.WindowsVistaSP1, "Windows Vista (Service Pack 1)");
CompatibilityModes.Add(WindowsCompatModeKind.WindowsVistaSP2, "Windows Vista (Service Pack 2)");
CompatibilityModes.Add(WindowsCompatModeKind.Windows7, "Windows 7");
CompatibilityModes.Add(WindowsCompatModeKind.Windows8, "Windows 8");

ReducedColorModes.Add(WindowsCompatReducedColorModeKind.None, "CompatibilityNoReducedColor".GetLocalizedResource());
ReducedColorModes.Add(WindowsCompatReducedColorModeKind.Color8Bit, "CompatibilityReducedColorModeColor8bit".GetLocalizedResource());
ReducedColorModes.Add(WindowsCompatReducedColorModeKind.Color16Bit, "CompatibilityReducedColorModeColor16bit".GetLocalizedResource());
ReducedColorModes.Add(WindowsCompatReducedColorModeKind.None, Strings.CompatibilityNoReducedColor.GetLocalizedResource());
ReducedColorModes.Add(WindowsCompatReducedColorModeKind.Color8Bit, Strings.CompatibilityReducedColorModeColor8bit.GetLocalizedResource());
ReducedColorModes.Add(WindowsCompatReducedColorModeKind.Color16Bit, Strings.CompatibilityReducedColorModeColor16bit.GetLocalizedResource());

HighDpiOptions.Add(WindowsCompatDPIOptionKind.None, "CompatibilityDoNotAdjustDPI".GetLocalizedResource());
HighDpiOptions.Add(WindowsCompatDPIOptionKind.UseDPIOnLogin, "CompatibilityOnWindowsLogin".GetLocalizedResource());
HighDpiOptions.Add(WindowsCompatDPIOptionKind.UseDPIOnProgramStart, "CompatibilityOnProgramStart".GetLocalizedResource());
HighDpiOptions.Add(WindowsCompatDPIOptionKind.None, Strings.CompatibilityDoNotAdjustDPI.GetLocalizedResource());
HighDpiOptions.Add(WindowsCompatDPIOptionKind.UseDPIOnLogin, Strings.CompatibilityOnWindowsLogin.GetLocalizedResource());
HighDpiOptions.Add(WindowsCompatDPIOptionKind.UseDPIOnProgramStart, Strings.CompatibilityOnProgramStart.GetLocalizedResource());

HighDpiOverrides.Add(WindowsCompatDpiOverrideKind.None, "CompatibilityDoNotOverrideDPI".GetLocalizedResource());
HighDpiOverrides.Add(WindowsCompatDpiOverrideKind.Advanced, "Advanced".GetLocalizedResource());
HighDpiOverrides.Add(WindowsCompatDpiOverrideKind.Application, "Application".GetLocalizedResource());
HighDpiOverrides.Add(WindowsCompatDpiOverrideKind.System, "System".GetLocalizedResource());
HighDpiOverrides.Add(WindowsCompatDpiOverrideKind.SystemAdvanced, "CompatibilitySystemEnhanced".GetLocalizedResource());
HighDpiOverrides.Add(WindowsCompatDpiOverrideKind.None, Strings.CompatibilityDoNotOverrideDPI.GetLocalizedResource());
HighDpiOverrides.Add(WindowsCompatDpiOverrideKind.Advanced, Strings.Advanced.GetLocalizedResource());
HighDpiOverrides.Add(WindowsCompatDpiOverrideKind.Application, Strings.Application.GetLocalizedResource());
HighDpiOverrides.Add(WindowsCompatDpiOverrideKind.System, Strings.System.GetLocalizedResource());
HighDpiOverrides.Add(WindowsCompatDpiOverrideKind.SystemAdvanced, Strings.CompatibilitySystemEnhanced.GetLocalizedResource());

RunTroubleshooterCommand = new AsyncRelayCommand(ExecuteRunTroubleshooterCommand);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/ViewModels/Properties/HashesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void ToggleIsEnabled(string? algorithm)
// Don't calculate hashes for online files
if (_item.SyncStatusUI.SyncStatus is CloudDriveSyncStatus.FileOnline or CloudDriveSyncStatus.FolderOnline)
{
hashInfoItem.HashValue = "CalculationOnlineFileHashError".GetLocalizedResource();
hashInfoItem.HashValue = Strings.CalculationOnlineFileHashError.GetLocalizedResource();
return;
}

Expand Down Expand Up @@ -106,11 +106,11 @@ private void ToggleIsEnabled(string? algorithm)
catch (IOException)
{
// File is currently open
hashInfoItem.HashValue = "CalculationErrorFileIsOpen".GetLocalizedResource();
hashInfoItem.HashValue = Strings.CalculationErrorFileIsOpen.GetLocalizedResource();
}
catch (Exception)
{
hashInfoItem.HashValue = "CalculationError".GetLocalizedResource();
hashInfoItem.HashValue = Strings.CalculationError.GetLocalizedResource();
}
finally
{
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/ViewModels/Properties/Items/BaseProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ await Dispatcher.EnqueueOrInvokeAsync(() =>
public void SetItemsCountString()
{
ViewModel.FilesAndFoldersCountString = ViewModel.LocationsCount > 0
? "PropertiesFilesAndFoldersAndLocationsCount".GetLocalizedFormatResource(ViewModel.FilesCount, ViewModel.FoldersCount, ViewModel.LocationsCount)
: "PropertiesFilesAndFoldersCountString".GetLocalizedFormatResource(ViewModel.FilesCount, ViewModel.FoldersCount);
? Strings.PropertiesFilesAndFoldersAndLocationsCount.GetLocalizedFormatResource(ViewModel.FilesCount, ViewModel.FoldersCount, ViewModel.LocationsCount)
: Strings.PropertiesFilesAndFoldersCountString.GetLocalizedFormatResource(ViewModel.FilesCount, ViewModel.FoldersCount);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public async Task GetSystemFilePropertiesAsync()
else if (props.Where(x => x.Property == prop.Property).Any(x => !Equals(x.Value, prop.Value)))
{
// Has multiple values
prop.Value = prop.IsReadOnly ? "MultipleValues".GetLocalizedResource() : null;
prop.PlaceholderText = "MultipleValues".GetLocalizedResource();
prop.Value = prop.IsReadOnly ? Strings.MultipleValues.GetLocalizedResource() : null;
prop.PlaceholderText = Strings.MultipleValues.GetLocalizedResource();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ public sealed override void GetBaseProperties()

if (List.All(x => x.ItemType.Equals(List.First().ItemType)))
{
ViewModel.ItemType = string.Format("PropertiesDriveItemTypesEquals".GetLocalizedResource(), List.First().ItemType);
ViewModel.ItemType = string.Format(Strings.PropertiesDriveItemTypesEquals.GetLocalizedResource(), List.First().ItemType);
}
else
{
ViewModel.ItemType = "PropertiesDriveItemTypeDifferent".GetLocalizedResource();
ViewModel.ItemType = Strings.PropertiesDriveItemTypeDifferent.GetLocalizedResource();
}

var itemsPath = List.Select(Item => (Item as RecycleBinItem)?.ItemOriginalFolder ??
(Path.IsPathRooted(Item.ItemPath) ? Path.GetDirectoryName(Item.ItemPath) : Item.ItemPath));

if (itemsPath.Distinct().Count() == 1)
ViewModel.ItemLocation = string.Format("PropertiesCombinedItemLocation".GetLocalizedResource(), itemsPath.First());
ViewModel.ItemLocation = string.Format(Strings.PropertiesCombinedItemLocation.GetLocalizedResource(), itemsPath.First());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/ViewModels/Properties/Items/FileProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public override void GetBaseProperties()
FileExtensionHelpers.IsExecutableFile(shortcutItem.TargetPath) ||
FileExtensionHelpers.IsMsiFile(shortcutItem.TargetPath);

ViewModel.ShortcutItemType = isApplication ? "Application".GetLocalizedResource() :
Item.IsLinkItem ? "PropertiesShortcutTypeLink".GetLocalizedResource() : "File".GetLocalizedResource();
ViewModel.ShortcutItemType = isApplication ? Strings.Application.GetLocalizedResource() :
Item.IsLinkItem ? Strings.PropertiesShortcutTypeLink.GetLocalizedResource() : Strings.File.GetLocalizedResource();
ViewModel.ShortcutItemPath = shortcutItem.TargetPath;
ViewModel.IsShortcutItemPathReadOnly = shortcutItem.IsSymLink;
ViewModel.ShortcutItemWorkingDir = shortcutItem.WorkingDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override void GetBaseProperties()
if (Item.IsShortcut)
{
var shortcutItem = (ShortcutItem)Item;
ViewModel.ShortcutItemType = "Folder".GetLocalizedResource();
ViewModel.ShortcutItemType = Strings.Folder.GetLocalizedResource();
ViewModel.ShortcutItemPath = shortcutItem.TargetPath;
ViewModel.IsShortcutItemPathReadOnly = false;
ViewModel.ShortcutItemWorkingDir = shortcutItem.WorkingDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public async override Task GetSpecialPropertiesAsync()
}
else
{
ViewModel.FilesAndFoldersCountString = "LibraryNoLocations/Text".GetLocalizedResource();
ViewModel.FilesAndFoldersCountString = Strings.LibraryNoLocations_Text.GetLocalizedResource();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ private void LoadAccessControlEntry()
if (error is WIN32_ERROR.ERROR_ACCESS_DENIED)
{
ErrorMessage =
"SecurityRequireReadPermissions".GetLocalizedResource() +
Strings.SecurityRequireReadPermissions.GetLocalizedResource() +
"\r\n\r\n" +
"SecuritySuggestToTakeOwnership".GetLocalizedResource();
Strings.SecuritySuggestToTakeOwnership.GetLocalizedResource();
}
else
{
ErrorMessage =
"SecurityUnableToDisplayPermissions".GetLocalizedResource() +
Strings.SecurityUnableToDisplayPermissions.GetLocalizedResource() +
"\r\n\r\n" +
error.ToString();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/ViewModels/Properties/SecurityViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ SelectedAccessControlEntry is not null &&

public string SelectedItemHeaderText =>
SelectedAccessControlEntry is null
? "Permissions".GetLocalizedResource()
: string.Format("SecurityPermissionsHeaderText".GetLocalizedResource(), SelectedAccessControlEntry?.Principal.DisplayName);
? Strings.Permissions.GetLocalizedResource()
: string.Format(Strings.SecurityPermissionsHeaderText.GetLocalizedResource(), SelectedAccessControlEntry?.Principal.DisplayName);

private AccessControlList _AccessControlList;
public AccessControlList AccessControlList
Expand Down Expand Up @@ -98,8 +98,8 @@ public SecurityViewModel(PropertiesPageNavigationParameter parameter)
{
DisplayElements = false;
ErrorMessage = error is WIN32_ERROR.ERROR_ACCESS_DENIED
? "SecurityRequireReadPermissions".GetLocalizedResource() + "\r\n" + "SecurityClickAdvancedPermissions".GetLocalizedResource()
: "SecurityUnableToDisplayPermissions".GetLocalizedResource();
? Strings.SecurityRequireReadPermissions.GetLocalizedResource() + "\r\n" + Strings.SecurityClickAdvancedPermissions.GetLocalizedResource()
: Strings.SecurityUnableToDisplayPermissions.GetLocalizedResource();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ViewModels/Settings/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed partial class AboutViewModel : ObservableObject
// Properties

public string Version
=> string.Format($"{"SettingsAboutVersionTitle".GetLocalizedResource()} {AppVersion.Major}.{AppVersion.Minor}.{AppVersion.Build}.{AppVersion.Revision}");
=> string.Format($"{Strings.SettingsAboutVersionTitle.GetLocalizedResource()} {AppVersion.Major}.{AppVersion.Minor}.{AppVersion.Build}.{AppVersion.Revision}");

public string AppName
=> Package.Current.DisplayName;
Expand Down
Loading
Loading