Skip to content

Commit

Permalink
Added file drag and drop support
Browse files Browse the repository at this point in the history
  • Loading branch information
CPKreu committed May 21, 2021
1 parent de41d9a commit ebb1f87
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
34 changes: 17 additions & 17 deletions PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,7 @@ public void OpenAny()
Open((object)null);
}

private void Owner_OnStartupEvent(object sender, System.EventArgs e)
{
var lastArg = Environment.GetCommandLineArgs().Last();
if (Importer.IsSupportedFile(lastArg) && File.Exists(lastArg))
{
Open(lastArg);
}
else
{
if (IPreferences.Current.GetPreference("ShowStartupWindow", true))
{
OpenHelloTherePopup();
}
}
}

private void Open(string path)
public void Open(string path)
{
try
{
Expand All @@ -203,6 +187,22 @@ private void Open(string path)
}
}

private void Owner_OnStartupEvent(object sender, System.EventArgs e)
{
var lastArg = Environment.GetCommandLineArgs().Last();
if (Importer.IsSupportedFile(lastArg) && File.Exists(lastArg))
{
Open(lastArg);
}
else
{
if (IPreferences.Current.GetPreference("ShowStartupWindow", true))
{
OpenHelloTherePopup();
}
}
}

private void Open(object property)
{
OpenFileDialog dialog = new OpenFileDialog
Expand Down
3 changes: 2 additions & 1 deletion PixiEditor/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
xmlns:avalonDockTheme="clr-namespace:PixiEditor.Styles.AvalonDock" d:DataContext="{d:DesignInstance Type=vm:ViewModelMain}" xmlns:dataHolders="clr-namespace:PixiEditor.Models.DataHolders"
mc:Ignorable="d" WindowStyle="None" Initialized="MainWindow_Initialized"
Title="PixiEditor" Name="mainWindow" Height="1000" Width="1600" Background="{StaticResource MainColor}"
WindowStartupLocation="CenterScreen" WindowState="Maximized">
WindowStartupLocation="CenterScreen" WindowState="Maximized"
AllowDrop="True" Drop="MainWindow_Drop">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="32"
ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
Expand Down
10 changes: 10 additions & 0 deletions PixiEditor/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,15 @@ private void MainWindow_Initialized(object sender, EventArgs e)
{
AppDomain.CurrentDomain.UnhandledException += (sender, e) => Helpers.CrashHelper.SaveCrashInfo((Exception)e.ExceptionObject);
}

private void MainWindow_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

DataContext.FileSubViewModel.Open(files[0]);
}
}
}
}

0 comments on commit ebb1f87

Please sign in to comment.