Skip to content

Commit

Permalink
Allow drag and drop to file opener
Browse files Browse the repository at this point in the history
  • Loading branch information
dogzz9445 committed Jul 16, 2024
1 parent 4fcefcb commit c3ce65c
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 25 deletions.
25 changes: 24 additions & 1 deletion Corathing.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{9DC8
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Corathing.Dashboards.WPF.Sample", "src\Samples\Corathing.Dashboards.WPF.Sample\Corathing.Dashboards.WPF.Sample.csproj", "{CA61CC63-9DDE-4614-9288-1E1EFACB3FF7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Corathing.Contracts.Utils.UnitTests", "src\Shared\Corathing.Contracts.Utils.UnitTests\Corathing.Contracts.Utils.UnitTests.csproj", "{CB963293-F6CE-4685-B33E-8AE41948EB83}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Corathing.Contracts.Utils.UnitTests", "src\Shared\Corathing.Contracts.Utils.UnitTests\Corathing.Contracts.Utils.UnitTests.csproj", "{CB963293-F6CE-4685-B33E-8AE41948EB83}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Corathing.UI", "src\Shared\Corathing.UI\Corathing.UI.csproj", "{7995D746-109F-4438-8D5A-E897216AB867}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -377,6 +379,26 @@ Global
{CB963293-F6CE-4685-B33E-8AE41948EB83}.Release|x64.Build.0 = Release|Any CPU
{CB963293-F6CE-4685-B33E-8AE41948EB83}.Release|x86.ActiveCfg = Release|Any CPU
{CB963293-F6CE-4685-B33E-8AE41948EB83}.Release|x86.Build.0 = Release|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Debug|ARM.ActiveCfg = Debug|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Debug|ARM.Build.0 = Debug|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Debug|ARM64.Build.0 = Debug|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Debug|x64.ActiveCfg = Debug|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Debug|x64.Build.0 = Debug|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Debug|x86.ActiveCfg = Debug|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Debug|x86.Build.0 = Debug|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Release|Any CPU.Build.0 = Release|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Release|ARM.ActiveCfg = Release|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Release|ARM.Build.0 = Release|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Release|ARM64.ActiveCfg = Release|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Release|ARM64.Build.0 = Release|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Release|x64.ActiveCfg = Release|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Release|x64.Build.0 = Release|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Release|x86.ActiveCfg = Release|Any CPU
{7995D746-109F-4438-8D5A-E897216AB867}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -395,6 +417,7 @@ Global
{A9AE0DA4-AFE4-4D9A-A123-FA242BFA0C0C} = {5BF1289A-1427-4306-B2E1-51E0770B6B75}
{55A4F80C-E7CB-48E6-A34D-BACBD470E0D4} = {5BF1289A-1427-4306-B2E1-51E0770B6B75}
{CA61CC63-9DDE-4614-9288-1E1EFACB3FF7} = {9DC8886B-D4A5-43C1-9004-1EC87AA69E7C}
{7995D746-109F-4438-8D5A-E897216AB867} = {89CC8AAB-466A-47B6-98B9-93EB379F55A7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FC027A8C-0C58-494B-BE76-F403F0336A74}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace Corathing.Dashboards.WPF.Converters;
/// <seealso cref="System.Windows.Data.IValueConverter" />
public class NullToVisibilityConverter : IValueConverter
{
#region Public Methods

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value == null ? Visibility.Collapsed : Visibility.Visible;
Expand All @@ -23,6 +21,4 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
{
throw new NotImplementedException();
}

#endregion Public Methods
}
11 changes: 8 additions & 3 deletions src/Shared/Corathing.UI.WPF/Corathing.UI.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
<PackageReference Include="MahApps.Metro" Version="2.4.10" />
<PackageReference Include="MahApps.Metro.IconPacks" Version="5.0.0" />
<PackageReference Include="Material.Icons.WPF" Version="2.1.10" />
<PackageReference Include="MaterialDesignThemes" Version="5.0.0" />
<PackageReference Include="MaterialDesignThemes.MahApps" Version="1.0.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="MaterialDesignThemes" Version="5.1.0" />
<PackageReference Include="MaterialDesignThemes.MahApps" Version="3.1.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.122" />
<PackageReference Include="PixiEditor.ColorPicker" Version="3.4.1" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="WPF-UI" Version="3.0.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Corathing.UI\Corathing.UI.csproj" />
</ItemGroup>

<ItemGroup>
<Resource Include="Fonts\NotoSansKR-Black.ttf" />
<Resource Include="Fonts\NotoSansKR-Bold.ttf" />
Expand Down
13 changes: 13 additions & 0 deletions src/Shared/Corathing.UI/Corathing.UI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Svg" Version="3.4.7" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Corathing.Widgets.Basics.DataSources.FileStorages;

public abstract class AbstractFileStorageDataSourceContext
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Corathing.Widgets.Basics.DataSources.FileStorages;

[EntryCoraDataSource(
dataSourceType: typeof(FileStorageDataSourceContext),
dataSourceType: typeof(LocalFileStorageDataSourceContext),
name: "Executable App",
description: "Execute an executable app with the selected files.",
defaultTitle: "DefaultApp"
Expand All @@ -23,6 +23,6 @@ namespace Corathing.Widgets.Basics.DataSources.FileStorages;
[EntryCoraDataSourceName(ApplicationLanguage.ko_KR, "실행 앱")]
[EntryCoraDataSourceDescription(ApplicationLanguage.en_US, "Execute an executable app with the selected files")]
[EntryCoraDataSourceDescription(ApplicationLanguage.ko_KR, "실행 앱을 통해 선택된 파일들을 실행")]
public class FileStorageDataSourceContext : DataSourceContext
public class LocalFileStorageDataSourceContext : DataSourceContext
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace Corathing.Widgets.Basics.DataSources.FileStorages;

public partial class FileStorageDataSourceSelector : DataSourceSelector<FileStorageDataSourceContext>
public partial class LocalFileStorageDataSourceSelector : DataSourceSelector<LocalFileStorageDataSourceContext>
{
public FileStorageDataSourceSelector(IServiceProvider services, Guid? guid = null) : base(services, guid)
public LocalFileStorageDataSourceSelector(IServiceProvider services, Guid? guid = null) : base(services, guid)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@

<!-- File Opener Widget -->
<DataTemplate DataType="{x:Type local:FileOpenerWidgetContext}">
<Button Style="{DynamicResource CoraWidgetEditModeButtonWithEvent}"
Command="{Binding ExecuteCommand}">
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ui:SymbolIcon Symbol="{Binding Icon}">
<i:Interaction.Behaviors>
<behaviors:SymbolIconScaleFontBehavior />
</i:Interaction.Behaviors>
</ui:SymbolIcon>
</Grid>
</Button>
<local:FileOpenerWidget />
</DataTemplate>

<!-- File Opener Settings View -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public enum FileOpenType
Folders,
}

public enum IconSourceType
{
System,
Svg,
Image,
}

public class FileOpenerOption
{
public FileOpenType OpenType { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<UserControl x:Class="Corathing.Widgets.Basics.Widgets.FileOpeners.FileOpenerWidget"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:local="clr-namespace:Corathing.Widgets.Basics.Widgets.FileOpeners"
xmlns:behaviors="clr-namespace:Corathing.UI.WPF.Behaviors;assembly=Corathing.UI.WPF"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:localizations="clr-namespace:Corathing.Widgets.Basics.Behaviors"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:FileOpenerWidgetContext,
IsDesignTimeCreatable=False}">
<UserControl.Resources>
<local:FileOpenTypeFileToVisibleConverter x:Key="FileOpenTypeFileToVisibleConverter" />
<local:FileOpenTypeFolderToVisibleConverter x:Key="FileOpenTypeFolderToVisibleConverter" />
</UserControl.Resources>

<Grid>
<Button AllowDrop="True"
DragEnter="Button_DragEnter"
DragOver="Button_FileOrFolder_PreviewDragOver"
PreviewDrop="Button_FileOrFolder_PreviewDrop"
DragLeave="Button_FileOrFolder_PreviewDragLeave"
Command="{Binding ExecuteCommand}">
<Button.Style>
<Style BasedOn="{StaticResource ButtonNoStyle}"
TargetType="{x:Type Button}">
<Setter Property="Background"
Value="{DynamicResource ControlBackground}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}">
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ui:SymbolIcon Symbol="{Binding Icon}">
<i:Interaction.Behaviors>
<behaviors:SymbolIconScaleFontBehavior />
</i:Interaction.Behaviors>
</ui:SymbolIcon>

<!-- FIXME: 수정 피료 -->
<!--<Image Source="{Binding ImageIcon}" />-->



<!--<Path Fill="#FFE812" Data="M256 236c0 11.046-8.954 20-20 20H20c-11.046 0-20-8.954-20-20V20C0 8.954 8.954 0 20 0h216c11.046 0 20 8.954 20 20v216z" />
<Path Fill="Black" Data="M128 36C70.562 36 24 72.713 24 118c0 29.279 19.466 54.97 48.748 69.477-1.593 5.494-10.237 35.344-10.581 37.689 0 0-.207 1.762.934 2.434s2.483.15 2.483.15c3.272-.457 37.943-24.811 43.944-29.04 5.995.849 12.168 1.29 18.472 1.29 57.438 0 104-36.712 104-82 0-45.287-46.562-82-104-82z" />
<Path Data="M70.5 146.625c-3.309 0-6-2.57-6-5.73V105.25h-9.362c-3.247 0-5.888-2.636-5.888-5.875s2.642-5.875 5.888-5.875h30.724c3.247 0 5.888 2.636 5.888 5.875s-2.642 5.875-5.888 5.875H76.5v35.645c0 3.16-2.691 5.73-6 5.73zM123.112 146.547c-2.502 0-4.416-1.016-4.993-2.65l-2.971-7.778-18.296-.001-2.973 7.783c-.575 1.631-2.488 2.646-4.99 2.646a9.155 9.155 0 0 1-3.814-.828c-1.654-.763-3.244-2.861-1.422-8.52l14.352-37.776c1.011-2.873 4.082-5.833 7.99-5.922 3.919.088 6.99 3.049 8.003 5.928l14.346 37.759c1.826 5.672.236 7.771-1.418 8.532a9.176 9.176 0 0 1-3.814.827c-.001 0 0 0 0 0zm-11.119-21.056L106 108.466l-5.993 17.025h11.986zM138 145.75c-3.171 0-5.75-2.468-5.75-5.5V99.5c0-3.309 2.748-6 6.125-6s6.125 2.691 6.125 6v35.25h12.75c3.171 0 5.75 2.468 5.75 5.5s-2.579 5.5-5.75 5.5H138zM171.334 146.547c-3.309 0-6-2.691-6-6V99.5c0-3.309 2.691-6 6-6s6 2.691 6 6v12.896l16.74-16.74c.861-.861 2.044-1.335 3.328-1.335 1.498 0 3.002.646 4.129 1.772 1.051 1.05 1.678 2.401 1.764 3.804.087 1.415-.384 2.712-1.324 3.653l-13.673 13.671 14.769 19.566a5.951 5.951 0 0 1 1.152 4.445 5.956 5.956 0 0 1-2.328 3.957 5.94 5.94 0 0 1-3.609 1.211 5.953 5.953 0 0 1-4.793-2.385l-14.071-18.644-2.082 2.082v13.091a6.01 6.01 0 0 1-6.002 6.003z"
Fill="#FFE812" />-->

<ContentPresenter />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
Value="True" />
<Condition Binding="{Binding DataContext.EditMode, RelativeSource={RelativeSource AncestorType={x:Type local:FileOpenerWidget}}}"
Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Background"
Value="{DynamicResource ControlBackgroundHover}" />
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}"
Value="True" />
<Condition Binding="{Binding DataContext.EditMode, RelativeSource={RelativeSource AncestorType={x:Type local:FileOpenerWidget}}}"
Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Background"
Value="{DynamicResource ControlBackgroundPressed}" />
</MultiDataTrigger>

<DataTrigger Binding="{Binding IsDraggingOver, RelativeSource={RelativeSource AncestorType={x:Type local:FileOpenerWidget}}}"
Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Background="{TemplateBinding Background}"
Focusable="False">
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Center"
Focusable="False"
Background="{TemplateBinding Background}"
Text="Dropping..." />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Microsoft.CodeAnalysis;
using Wpf.Ui.Controls;

using static System.Windows.Forms.AxHost;

using DataFormats = System.Windows.DataFormats;
using UserControl = System.Windows.Controls.UserControl;

namespace Corathing.Widgets.Basics.Widgets.FileOpeners;

/// <summary>
/// Interaction logic for FileOpenerWidget.xaml
/// </summary>
public partial class FileOpenerWidget : UserControl
{
/// <summary>Identifies the <see cref="Symbol"/> dependency property.</summary>
public static readonly DependencyProperty SymbolProperty = DependencyProperty.Register(
nameof(Symbol),
typeof(SymbolRegular),
typeof(FileOpenerWidget),
new PropertyMetadata(SymbolRegular.Empty)
);

/// <summary>
/// Gets or sets displayed <see cref="SymbolRegular"/>.
/// </summary>
public SymbolRegular Symbol
{
get => (SymbolRegular)GetValue(SymbolProperty);
set => SetValue(SymbolProperty, value);
}

/// <summary>
/// The edit mode property
/// </summary>
public static readonly DependencyProperty IsDraggingOverProperty = DependencyProperty.Register(
nameof(IsDraggingOver),
typeof(bool),
typeof(FileOpenerWidget),
new PropertyMetadata(false, (d, e) => ((FileOpenerWidget)d).DragOverEnabler()));

/// <summary>
/// Gets or sets a value indicating whether the dashboard is in [edit mode].
/// </summary>
/// <value><c>true</c> if [edit mode]; otherwise, <c>false</c>.</value>
public bool IsDraggingOver
{
get => (bool)GetValue(IsDraggingOverProperty);
set => SetValue(IsDraggingOverProperty, value);
}

bool _isDraggingLeaveProgress = false;

public FileOpenerWidget()
{
InitializeComponent();
}

public void DragOverEnabler()
{

}

private void Button_FileOrFolder_PreviewDrop(object sender, System.Windows.DragEventArgs e)
{
if (DataContext is not FileOpenerWidgetContext context)
return;

_isDraggingLeaveProgress = false;
IsDraggingOver = false;

context.OnDrop(e);
}


private void Button_FileOrFolder_PreviewDragOver(object sender, System.Windows.DragEventArgs e)
{
_isDraggingLeaveProgress = false;
if (e.Data == null)
return;

if (!e.Data.GetDataPresent(DataFormats.FileDrop))
return;

if (e.Data.GetData(DataFormats.FileDrop) == null)
return;

IsDraggingOver = true;
}

private void Button_FileOrFolder_PreviewDragLeave(object sender, System.Windows.DragEventArgs e)
{
_isDraggingLeaveProgress = true;
Dispatcher.BeginInvoke(new Action(() =>
{
if (_isDraggingLeaveProgress) IsDraggingOver = false;
}));
}

private void Button_DragEnter(object sender, System.Windows.DragEventArgs e)
{
_isDraggingLeaveProgress = false;
}
}
Loading

0 comments on commit c3ce65c

Please sign in to comment.