-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recently opened directories to the taskbar jumplist (#1331)
- Loading branch information
1 parent
5a8f9f1
commit cefbdb5
Showing
22 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Windows.UI.StartScreen; | ||
using Windows.Storage; | ||
using Files.Common; | ||
|
||
namespace Files.Helpers | ||
{ | ||
public sealed class JumpListManager | ||
{ | ||
private JumpList _instance = null; | ||
private List<string> JumpListItemPaths { get; set; } | ||
public JumpListManager() | ||
{ | ||
Initialize(); | ||
} | ||
|
||
private async void Initialize() | ||
{ | ||
if (JumpList.IsSupported()) | ||
{ | ||
_instance = await JumpList.LoadCurrentAsync(); | ||
|
||
// Disable automatic jumplist. It doesn't work with Files UWP. | ||
_instance.SystemGroupKind = JumpListSystemGroupKind.None; | ||
JumpListItemPaths = _instance.Items.Select(item => item.Arguments).ToList(); | ||
} | ||
} | ||
|
||
public async void AddFolderToJumpList(string path) | ||
{ | ||
await AddFolder(path); | ||
await _instance?.SaveAsync(); | ||
} | ||
|
||
private Task AddFolder(string path) | ||
{ | ||
if (!JumpListItemPaths.Contains(path) && _instance != null) | ||
{ | ||
string displayName; | ||
if (path.Equals(App.AppSettings.DesktopPath, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
displayName = "ms-resource:///Resources/SidebarDesktop"; | ||
} | ||
else if (path.Equals(App.AppSettings.DownloadsPath, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
displayName = "ms-resource:///Resources/SidebarDownloads"; | ||
} | ||
else if (path.Equals(App.AppSettings.DocumentsPath, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
displayName = "ms-resource:///Resources/SidebarDocuments"; | ||
} | ||
else if (path.Equals(App.AppSettings.PicturesPath, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
displayName = "ms-resource:///Resources/SidebarPictures"; | ||
} | ||
else if (path.Equals(App.AppSettings.MusicPath, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
displayName = "ms-resource:///Resources/SidebarMusic"; | ||
} | ||
else if (path.Equals(App.AppSettings.VideosPath, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
displayName = "ms-resource:///Resources/SidebarVideos"; | ||
} | ||
else if (path.Equals(App.AppSettings.RecycleBinPath, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
var localSettings = ApplicationData.Current.LocalSettings; | ||
displayName = localSettings.Values.Get("RecycleBin_Title", "Recycle Bin"); | ||
} | ||
else | ||
{ | ||
displayName = Path.GetFileName(path); | ||
} | ||
|
||
var jumplistItem = JumpListItem.CreateWithArguments(path, displayName); | ||
jumplistItem.Description = jumplistItem.Arguments; | ||
jumplistItem.GroupName = "ms-resource:///Resources/JumpListRecentGroupHeader"; | ||
jumplistItem.Logo = new Uri("ms-appx:///Assets/FolderIcon.png"); | ||
_instance.Items.Add(jumplistItem); | ||
JumpListItemPaths.Add(path); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public async void RemoveFolder(string path) | ||
{ | ||
if (JumpListItemPaths.Contains(path)) | ||
{ | ||
JumpListItemPaths.Remove(path); | ||
await UpdateAsync(); | ||
} | ||
} | ||
|
||
private async Task UpdateAsync() | ||
{ | ||
if (_instance != null) | ||
{ | ||
// Clear all items to avoid localization issues | ||
_instance?.Items.Clear(); | ||
|
||
foreach (string path in JumpListItemPaths) | ||
{ | ||
await AddFolder(path); | ||
} | ||
|
||
await _instance.SaveAsync(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters