Skip to content

Commit

Permalink
Use gong-wpf-dragdrop for drag and drop reordering
Browse files Browse the repository at this point in the history
  • Loading branch information
bburky committed Sep 13, 2021
1 parent bb0ed1a commit fa68375
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
23 changes: 16 additions & 7 deletions Playlist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;

namespace Playlist
{
Expand All @@ -30,29 +31,37 @@ public override IEnumerable<SidebarItem> GetSidebarItems()
{
Title = "Playlist",
Type = SiderbarItemType.View,
Icon = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "icon.png"),
Icon = new TextBlock
{
Text = "\ueca6", // Circled play button
FontFamily = ResourceProvider.GetResource("FontIcoFont") as FontFamily,
},
Opened = () => { return playlistView; }
};
}
public override IEnumerable<GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
{
yield return new GameMenuItem
{
Description = "Add to Playlist",
Action = (itemArgs) =>
{
Description = "Add to playlist",
Action = (itemArgs) =>
foreach (Game game in args.Games)
{
foreach (Game game in args.Games)
{
playlistViewModel.PlaylistGames.AddMissing(game);
}
playlistViewModel.PlaylistGames.AddMissing(game);
}
}
};
}

public override Guid Id { get; } = Guid.Parse("b0313f81-2b86-4eba-9f24-1a727dedbd45");

public Playlist(IPlayniteAPI api) : base(api)
{
// Ensure the library loaded now, relative to the extension DLL.
// If the XAML trys to load it later it will incorrectly load it relative to Playnite's executable
Assembly.Load("GongSolutions.WPF.DragDrop");

playlistGames = new List<Game>();
settings = new PlaylistSettingsViewModel(this);
playniteApi = api;
Expand Down
3 changes: 3 additions & 0 deletions Playlist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="GongSolutions.WPF.DragDrop, Version=2.0.0.0, Culture=neutral, PublicKeyToken=91f1945125b7a587, processorArchitecture=MSIL">
<HintPath>packages\gong-wpf-dragdrop.2.4.1\lib\net462\GongSolutions.WPF.DragDrop.dll</HintPath>
</Reference>
<Reference Include="Playnite.SDK, Version=6.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\PlayniteSDK.6.0.0-preview3\lib\net462\Playnite.SDK.dll</HintPath>
</Reference>
Expand Down
29 changes: 14 additions & 15 deletions PlaylistView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,52 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dd="urn:gong-wpf-dragdrop"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="600">

<UserControl.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource BaseTextBlockStyle}" />
</UserControl.Resources>



<DockPanel>
<StackPanel Orientation="Horizontal" Margin="10,10,0,0" DockPanel.Dock="Top">
<TextBlock VerticalAlignment="Center" WindowChrome.IsHitTestVisibleInChrome="True">
<Hyperlink Command="{Binding NavigateBackCommand}">
<TextBlock Text="&#xea5c;" FontFamily="{DynamicResource FontIcoFont}"
FontSize="26" />
FontSize="26" />
</Hyperlink>
</TextBlock>
<TextBlock Text="Playlist" VerticalAlignment="Center"
Style="{StaticResource BaseTextBlockStyle}"
Margin="10,0,0,0" FontSize="18"/>
Style="{StaticResource BaseTextBlockStyle}"
Margin="10,0,0,0" FontSize="18"/>
</StackPanel>
<ListView
SelectedIndex="1"
Margin="5"
ItemsSource="{Binding PlaylistGames}"
AllowDrop="True">
<ListView.View>
AllowDrop="True"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True">
<ListView.View>
<GridView>
<GridViewColumn Header="" Width="65">
<GridViewColumn Header="" Width="55">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button
Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=DataContext.StartGameCommand}"
CommandParameter="{Binding .}"
Width="50" Height="40">
<TextBlock Text="&#xec74;" FontFamily="{DynamicResource FontIcoFont}"
FontSize="26" />
Width="40" Height="40" HorizontalAlignment="Right">
<TextBlock Text="&#xec74;" FontFamily="{DynamicResource FontIcoFont}" FontSize="18" />
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="" Width="50">
<GridViewColumn Header="" Width="55">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Stretch="Uniform" StretchDirection="DownOnly"
<Image Stretch="Uniform"
RenderOptions.BitmapScalingMode="Fant"
Height="32" Width="32" HorizontalAlignment="Center"
Height="40" Width="40" HorizontalAlignment="Center"
Source="{Binding Icon, Mode=OneWay, Converter={StaticResource ImageStringToImageConverterCached}}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
Expand Down
1 change: 1 addition & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="gong-wpf-dragdrop" version="2.4.1" targetFramework="net462" />
<package id="PlayniteSDK" version="6.0.0-preview3" targetFramework="net462" />
</packages>

0 comments on commit fa68375

Please sign in to comment.