Skip to content

Commit

Permalink
Add recently opened directories to the taskbar jumplist (#1331)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaiganeshKumaran committed Jul 12, 2020
1 parent 5a8f9f1 commit cefbdb5
Show file tree
Hide file tree
Showing 22 changed files with 189 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Files/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Files.Filesystem;
using Files.Interacts;
using Files.View_Models;
using Files.Helpers;
using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
Expand Down Expand Up @@ -56,8 +57,8 @@ public static IShellPage CurrentInstance
public static ObservableCollection<WSLDistroItem> linuxDistroItems = new ObservableCollection<WSLDistroItem>();
public static SettingsViewModel AppSettings { get; set; }
public static InteractionViewModel InteractionViewModel { get; set; }
public static JumpListManager JumpList { get; } = new JumpListManager();
public static SidebarPinnedController SidebarPinnedController { get; set; }

private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

public App()
Expand Down
Binary file added Files/Assets/FolderIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<Compile Include="Helpers\DialogDisplayHelper.cs" />
<Compile Include="Helpers\DispatcherHelper.cs" />
<Compile Include="Helpers\ItemsDataTemplateSelector.cs" />
<Compile Include="Helpers\JumpListManager.cs" />
<Compile Include="Helpers\NativeDirectoryChangesHelper.cs" />
<Compile Include="Helpers\NativeFindStorageItemHelper.cs" />
<Compile Include="Helpers\NaturalStringComparer.cs" />
Expand Down Expand Up @@ -304,6 +305,7 @@
<Content Include="Assets\Files UWP Beta Icon.png" />
<Content Include="Assets\Files UWP Icon.png" />
<Content Include="Assets\FilesHome.png" />
<Content Include="Assets\FolderIcon.png" />
<Content Include="Assets\FolderIcon.svg" />
<Content Include="Assets\FolderIconLarge.svg" />
<Content Include="Assets\LargeTile.scale-100.png" />
Expand Down
114 changes: 114 additions & 0 deletions Files/Helpers/JumpListManager.cs
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();
}
}
}
}
7 changes: 7 additions & 0 deletions Files/Interacts/Interaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ public async Task<bool> RenameFileItem(ListedItem item, string oldName, string n
var folder = await ItemViewModel.GetFolderFromPathAsync(item.ItemPath);

await folder.RenameAsync(newName, NameCollisionOption.GenerateUniqueName);

App.JumpList.RemoveFolder(folder.Path);
}
else
{
Expand All @@ -815,6 +817,8 @@ public async Task<bool> RenameFileItem(ListedItem item, string oldName, string n
var folder = await ItemViewModel.GetFolderFromPathAsync(item.ItemPath);

await folder.RenameAsync(newName, NameCollisionOption.ReplaceExisting);

App.JumpList.RemoveFolder(folder.Path);
}
else
{
Expand Down Expand Up @@ -888,6 +892,9 @@ public async Task<StorageFolder> MoveDirectoryAsync(StorageFolder SourceFolder,
{
await MoveDirectoryAsync(folderinSourceDir, DestinationFolder, folderinSourceDir.Name);
}

App.JumpList.RemoveFolder(SourceFolder.Path);

return createdRoot;
}

Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.de-DE.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,10 @@
<source>File system:</source>
<target state="needs-review-translation" state-qualifier="tm-suggestion">Dateisystem:</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.es-ES.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,10 @@
<source>Moving files to Recycle Bin</source>
<target state="translated">Moviendo archivos a la papelera de reciclaje</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.fr-FR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,10 @@
<source>File system:</source>
<target state="needs-review-translation" state-qualifier="tm-suggestion">Système de fichiers</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.he-IL.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,10 @@
<source>File system:</source>
<target state="translated" state-qualifier="tm-suggestion">מערכת קבצים:</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
5 changes: 5 additions & 0 deletions Files/MultilingualResources/Files.it-IT.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,11 @@
<source>Moving files to Recycle Bin</source>
<target state="new">Moving files to Recycle Bin</target>
</trans-unit>

<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.ja-JP.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,10 @@
<source>File system:</source>
<target state="needs-review-translation" state-qualifier="tm-suggestion">ファイル システム</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.nl-NL.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,10 @@
<source>File system:</source>
<target state="needs-review-translation" state-qualifier="tm-suggestion">Bestandssysteem</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.pl-PL.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,10 @@
<source>File system:</source>
<target state="needs-review-translation" state-qualifier="tm-suggestion">System plików</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,10 @@
<source>Status</source>
<target state="new">Status</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.ru-RU.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,10 @@
<source>Moving files to Recycle Bin</source>
<target state="translated">Перемещение файлов в Корзину</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.ta.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,10 @@
<source>File system:</source>
<target state="needs-review-translation" state-qualifier="tm-suggestion">கோப்பு முறைமை:</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.tr-TR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,10 @@
<source>Moving files to Recycle Bin</source>
<target state="new">Moving files to Recycle Bin</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.uk-UA.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,10 @@
<source>File system:</source>
<target state="translated">Файлова система:</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,10 @@
<source>File system:</source>
<target state="translated">文件系统:</target>
</trans-unit>
<trans-unit id="JumpListRecentGroupHeader" translate="yes" xml:space="preserve">
<source>Recent</source>
<target state="new">Recent</target>
</trans-unit>
<trans-unit id="SettingsPreferencesAppLanguage.Text" translate="yes" xml:space="preserve">
<source>App Language</source>
<target state="new">App Language</target>
Expand Down
3 changes: 3 additions & 0 deletions Files/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,9 @@
<data name="PropertiesDriveFileSystem.Text" xml:space="preserve">
<value>File system:</value>
</data>
<data name="JumpListRecentGroupHeader" xml:space="preserve">
<value>Recent</value>
</data>
<data name="SettingsPreferencesAppLanguage.Text" xml:space="preserve">
<value>App Language</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions Files/View Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public async Task SetWorkingDirectory(string value)
return;
}

App.JumpList.AddFolderToJumpList(value);

INavigationControlItem item = null;
List<INavigationControlItem> sidebarItems = App.sideBarItems.Where(x => !string.IsNullOrWhiteSpace(x.Path)).ToList();

Expand Down Expand Up @@ -1199,6 +1201,7 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
{
IsFolderEmptyTextDisplayed = true;
}
App.JumpList.RemoveFolder(item.ItemPath);
UpdateDirectoryInfo();
});
Expand Down
2 changes: 1 addition & 1 deletion Files/View Models/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,4 @@ public TValue Get<TValue>(TValue defaultValue, [CallerMemberName] string propert

private delegate bool TryParseDelegate<TValue>(string inValue, out TValue parsedValue);
}
}
}

0 comments on commit cefbdb5

Please sign in to comment.