Skip to content

Commit bca3b4b

Browse files
authored
Localize tab headers from desktop.ini / Support user level folder name localization for tabs. (#3319)
1 parent 3f8a4cd commit bca3b4b

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

Files/Views/MainPage.xaml.cs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Files.Common;
2+
using Files.Enums;
23
using Files.Filesystem;
34
using Files.Helpers;
45
using Files.UserControls.MultitaskingControl;
@@ -250,17 +251,14 @@ public static async Task AddNewTabByPathAsync(Type type, string path, int atInde
250251
NavigationArg = path
251252
};
252253
tabItem.Control.ContentChanged += Control_ContentChanged;
253-
await SetSelectedTabInfoAsync(tabItem, path);
254+
await UpdateTabInfo(tabItem, path);
254255
AppInstances.Insert(atIndex == -1 ? AppInstances.Count : atIndex, tabItem);
255256
}
256257

257-
private static async Task SetSelectedTabInfoAsync(TabItem selectedTabItem, string currentPath, string tabHeader = null)
258+
private static async Task<(string tabLocationHeader, Microsoft.UI.Xaml.Controls.IconSource tabIcon)> GetSelectedTabInfoAsync(string currentPath)
258259
{
259-
selectedTabItem.AllowStorageItemDrop = true;
260-
261260
string tabLocationHeader;
262261
Microsoft.UI.Xaml.Controls.FontIconSource fontIconSource = new Microsoft.UI.Xaml.Controls.FontIconSource();
263-
Microsoft.UI.Xaml.Controls.IconSource tabIcon;
264262
fontIconSource.FontFamily = App.Current.Resources["FluentUIGlyphs"] as FontFamily;
265263

266264
if (currentPath == null || currentPath == "SidebarSettings/Text".GetLocalized())
@@ -332,7 +330,7 @@ private static async Task SetSelectedTabInfoAsync(TabItem selectedTabItem, strin
332330

333331
if (matchingDrive != null)
334332
{
335-
//Go through types and set the icon according to type
333+
// Go through types and set the icon according to type
336334
string type = GetDriveTypeIcon(matchingDrive);
337335
if (!string.IsNullOrWhiteSpace(type))
338336
{
@@ -359,15 +357,20 @@ private static async Task SetSelectedTabInfoAsync(TabItem selectedTabItem, strin
359357
{
360358
fontIconSource.Glyph = "\xea55"; //Folder icon
361359
tabLocationHeader = currentPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Split('\\', StringSplitOptions.RemoveEmptyEntries).Last();
360+
361+
FilesystemResult<StorageFolderWithPath> rootItem = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(currentPath));
362+
if (rootItem)
363+
{
364+
StorageFolder currentFolder = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(currentPath, rootItem));
365+
if (currentFolder != null && !string.IsNullOrEmpty(currentFolder.DisplayName))
366+
{
367+
tabLocationHeader = currentFolder.DisplayName;
368+
}
369+
}
362370
}
363371
}
364-
if (tabHeader != null)
365-
{
366-
tabLocationHeader = tabHeader;
367-
}
368-
tabIcon = fontIconSource;
369-
selectedTabItem.Header = tabLocationHeader;
370-
selectedTabItem.IconSource = tabIcon;
372+
373+
return (tabLocationHeader, fontIconSource);
371374
}
372375

373376
private static async void Control_ContentChanged(object sender, TabItemArguments e)
@@ -382,22 +385,24 @@ private static async void Control_ContentChanged(object sender, TabItemArguments
382385

383386
private static async Task UpdateTabInfo(TabItem tabItem, object navigationArg)
384387
{
388+
tabItem.AllowStorageItemDrop = true;
385389
if (navigationArg is PaneNavigationArguments paneArgs)
386390
{
387-
var leftHeader = !string.IsNullOrEmpty(paneArgs.LeftPaneNavPathParam) ? new DirectoryInfo(paneArgs.LeftPaneNavPathParam).Name : null;
388-
var rightHeader = !string.IsNullOrEmpty(paneArgs.RightPaneNavPathParam) ? new DirectoryInfo(paneArgs.RightPaneNavPathParam).Name : null;
389-
if (leftHeader != null && rightHeader != null)
391+
if (!string.IsNullOrEmpty(paneArgs.LeftPaneNavPathParam) && !string.IsNullOrEmpty(paneArgs.RightPaneNavPathParam))
390392
{
391-
await SetSelectedTabInfoAsync(tabItem, paneArgs.LeftPaneNavPathParam, $"{leftHeader} | {rightHeader}");
393+
var leftTabInfo = await GetSelectedTabInfoAsync(paneArgs.LeftPaneNavPathParam);
394+
var rightTabInfo = await GetSelectedTabInfoAsync(paneArgs.RightPaneNavPathParam);
395+
tabItem.Header = $"{leftTabInfo.tabLocationHeader} | {rightTabInfo.tabLocationHeader}";
396+
tabItem.IconSource = leftTabInfo.tabIcon;
392397
}
393398
else
394399
{
395-
await SetSelectedTabInfoAsync(tabItem, paneArgs.LeftPaneNavPathParam);
400+
(tabItem.Header, tabItem.IconSource) = await GetSelectedTabInfoAsync(paneArgs.LeftPaneNavPathParam);
396401
}
397402
}
398403
else if (navigationArg is string pathArgs)
399404
{
400-
await SetSelectedTabInfoAsync(tabItem, pathArgs);
405+
(tabItem.Header, tabItem.IconSource) = await GetSelectedTabInfoAsync(pathArgs);
401406
}
402407
}
403408

0 commit comments

Comments
 (0)