Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions Files/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ sealed partial class App : Application

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

public static SecondaryTileHelper SecondaryTileHelper { get; private set; } = new SecondaryTileHelper();

public static class AppData
{
// Get the extensions that are available for this host.
Expand Down
Binary file added Files/Assets/tile-0-250x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Files/Assets/tile-0-300x300.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions Files/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,8 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
{
UnloadMenuFlyoutItemByName("SidebarPinItem");
UnloadMenuFlyoutItemByName("SidebarUnpinItem");
UnloadMenuFlyoutItemByName("PinItemToStart");
UnloadMenuFlyoutItemByName("UnpinItemFromStart");
UnloadMenuFlyoutItemByName("OpenInNewTab");
UnloadMenuFlyoutItemByName("OpenInNewWindowItem");
UnloadMenuFlyoutItemByName("OpenInNewPane");
Expand Down Expand Up @@ -742,6 +744,7 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
if (SelectedItems.Any(x => x.IsShortcutItem))
{
UnloadMenuFlyoutItemByName("SidebarPinItem");
UnloadMenuFlyoutItemByName("PinItemToStart");
UnloadMenuFlyoutItemByName("CreateShortcut");
}
else if (SelectedItems.Count == 1)
Expand Down Expand Up @@ -772,6 +775,17 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
LoadMenuFlyoutItemByName("SidebarPinItem");
UnloadMenuFlyoutItemByName("SidebarUnpinItem");
}

if (selectedItems.All(x => x.IsItemPinnedToStart))
{
UnloadMenuFlyoutItemByName("PinItemToStart");
LoadMenuFlyoutItemByName("UnpinItemFromStart");
}
else
{
LoadMenuFlyoutItemByName("PinItemToStart");
UnloadMenuFlyoutItemByName("UnpinItemFromStart");
}
}

if (SelectedItems.Count <= 5 && SelectedItems.Count > 0)
Expand All @@ -796,6 +810,13 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
{
UnloadMenuFlyoutItemByName("OpenInNewPane");
}

//Shift key is not held, remove extras here
if(!Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down))
{
UnloadMenuFlyoutItemByName("PinItemToStart");
UnloadMenuFlyoutItemByName("UnpinItemFromStart");
}
}

//check the file extension of the selected item
Expand Down Expand Up @@ -1083,6 +1104,21 @@ public void BaseLayout_PointerWheelChanged(object sender, PointerRoutedEventArgs
}
}

public async void PinItemToStart_Click(object sender, RoutedEventArgs e)
{
foreach (ListedItem listedItem in SelectedItems)
{
await App.SecondaryTileHelper.TryPinFolderAsync(listedItem.ItemPath, listedItem.ItemName);
}
}
public async void UnpinItemFromStart_Click(object sender, RoutedEventArgs e)
{
foreach (ListedItem listedItem in SelectedItems)
{
await App.SecondaryTileHelper.UnpinFromStartAsync(listedItem.ItemPath);
}
}

public abstract void Dispose();
}
}
3 changes: 3 additions & 0 deletions Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
<Compile Include="Interacts\BaseLayoutCommandsViewModel.cs" />
<Compile Include="Interacts\IBaseLayoutCommandImplementationModel.cs" />
<Compile Include="Interacts\IStatusCenterActions.cs" />
<Compile Include="Helpers\SecondaryTileHelper.cs" />
<Compile Include="UserControls\FilePreviews\BasicPreview.xaml.cs">
<DependentUpon>BasicPreview.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -619,6 +620,8 @@
<Content Include="Assets\StoreLogo.scale-200_contrast-white.png" />
<Content Include="Assets\StoreLogo.scale-400_contrast-black.png" />
<Content Include="Assets\StoreLogo.scale-400_contrast-white.png" />
<Content Include="Assets\tile-0-250x250.png" />
<Content Include="Assets\tile-0-300x300.png" />
<Content Include="Assets\Wide310x150Logo.scale-100_contrast-black.png" />
<Content Include="Assets\Wide310x150Logo.scale-100_contrast-white.png" />
<Content Include="Assets\Wide310x150Logo.scale-125_contrast-black.png" />
Expand Down
2 changes: 2 additions & 0 deletions Files/Filesystem/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public BitmapImage FileImage
}
}

public bool IsItemPinnedToStart => App.SecondaryTileHelper.CheckFolderPinned(ItemPath);

private BitmapImage iconOverlay;

[JsonIgnore]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ private static async Task<ListedItem> AddFolderAsync(StorageFolder folder, Stora
LoadUnknownTypeGlyph = false,
FileSize = null,
FileSizeBytes = 0
//FolderTooltipText = tooltipString,
};
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ CancellationToken cancellationToken
LoadUnknownTypeGlyph = false,
FileSize = null,
FileSizeBytes = 0,
ContainsFilesOrFolders = FolderHelpers.CheckForFilesFolders(itemPath),
//FolderTooltipText = tooltipString,
ContainsFilesOrFolders = FolderHelpers.CheckForFilesFolders(itemPath)
};
}

Expand Down
73 changes: 73 additions & 0 deletions Files/Helpers/SecondaryTileHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Files.Filesystem;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Svg;
using Microsoft.Graphics.Canvas.Text;
using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Storage;
using Windows.UI;
using Windows.UI.Notifications;
using Windows.UI.StartScreen;
using TileSize = Windows.UI.StartScreen.TileSize;

namespace Files.Helpers
{
public class SecondaryTileHelper
{
public bool CheckFolderPinned(string path)
{
return SecondaryTile.Exists(GetTileID(path));
}

/// <summary>
/// Gets a tile-id to be used from a folder path
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
private string GetTileID(string path)
{
// Remove symbols because windows doesn't like them in the ID, and will blow up
return $"folder-{new string(path.Where(c => char.IsLetterOrDigit(c)).ToArray())}";
}

public async Task<bool> TryPinFolderAsync(string path, string name)
{
var result = false;
try
{
Uri Path150x150 = new Uri("ms-appx:///Assets/tile-0-300x300.png");
Uri Path71x71 = new Uri("ms-appx:///Assets/tile-0-250x250.png");

SecondaryTile tile = new SecondaryTile(
GetTileID(path),
name,
path,
Path150x150,
TileSize.Square150x150);

tile.VisualElements.Square71x71Logo = Path71x71;
tile.VisualElements.ShowNameOnSquare150x150Logo = true;
result = await tile.RequestCreateAsync();
}
catch (Exception e)
{
Debug.WriteLine(GetTileID(path));
Debug.WriteLine(e.ToString());
}

return result;
}

public async Task<bool> UnpinFromStartAsync(string path)
{
return await StartScreenManager.GetDefault().TryRemoveSecondaryTileAsync(GetTileID(path));
}
}
}
9 changes: 8 additions & 1 deletion Files/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1944,4 +1944,11 @@
<data name="FullTrustStatusTeachingTip.Title" xml:space="preserve">
<value>Administrator</value>
</data>
</root>
<data name="PinItemToStart.Text" xml:space="preserve">
<value>Pin to the Start Menu</value>
</data>
<data name="UnpinItemFromStart.Text" xml:space="preserve">
<value>Unpin from the Start Menu</value>
</data>

</root>
1 change: 1 addition & 0 deletions Files/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows.Input;
Expand Down
4 changes: 2 additions & 2 deletions Files/ViewModels/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ await DialogDisplayHelper.ShowDialogAsync(
ItemPath = string.IsNullOrEmpty(rootFolder.Path) ? storageFolderForGivenPath.Path : rootFolder.Path,
LoadUnknownTypeGlyph = false,
FileSize = null,
FileSizeBytes = 0
FileSizeBytes = 0,
};
if (DateTimeOffset.TryParse(extraProps["System.DateCreated"] as string, out var dateCreated))
{
Expand Down Expand Up @@ -1223,7 +1223,7 @@ await DialogDisplayHelper.ShowDialogAsync(
ItemPath = path,
LoadUnknownTypeGlyph = false,
FileSize = null,
FileSizeBytes = 0
FileSizeBytes = 0,
};
if (!cacheOnly)
{
Expand Down
20 changes: 20 additions & 0 deletions Files/Views/LayoutModes/GenericFileBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,26 @@
<FontIcon Glyph="&#xE77A;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="PinItemToStart"
x:Uid="PinItemToStart"
x:Load="False"
Click="PinItemToStart_Click"
Text="Pin to the Start Menu">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE840;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="UnpinItemFromStart"
x:Uid="UnpinItemFromStart"
x:Load="False"
Click="UnpinItemFromStart_Click"
Text="Unpin from the Start Menu">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE77A;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="PropertiesItem"
x:Uid="BaseLayoutItemContextFlyoutProperties"
Expand Down
20 changes: 20 additions & 0 deletions Files/Views/LayoutModes/GridViewBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,26 @@
<FontIcon Glyph="&#xE77A;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="PinItemToStart"
x:Uid="PinItemToStart"
x:Load="False"
Click="PinItemToStart_Click"
Text="Pin to the Start Menu">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE840;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="UnpinItemFromStart"
x:Uid="UnpinItemFromStart"
x:Load="False"
Click="UnpinItemFromStart_Click"
Text="Unpin from the Start Menu">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE77A;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="PropertiesItem"
x:Uid="BaseLayoutItemContextFlyoutProperties"
Expand Down