diff --git a/GUI/MainWindow.xaml b/GUI/MainWindow.xaml index 0db0295e..9416b88f 100644 --- a/GUI/MainWindow.xaml +++ b/GUI/MainWindow.xaml @@ -8,6 +8,7 @@ Title="GARbro" MinHeight="250" ResizeMode="CanResizeWithGrip" Loaded="WindowLoaded" KeyDown="WindowKeyDown" + AllowDrop="True" Drop="OnDropEvent" Top="{Binding Source={x:Static p:Settings.Default}, Path=winTop, Mode=TwoWay}" Left="{Binding Source={x:Static p:Settings.Default}, Path=winLeft, Mode=TwoWay}" Height="{Binding Source={x:Static p:Settings.Default}, Path=winHeight, Mode=TwoWay}" diff --git a/GUI/MainWindow.xaml.cs b/GUI/MainWindow.xaml.cs index ee5280fd..303994cc 100644 --- a/GUI/MainWindow.xaml.cs +++ b/GUI/MainWindow.xaml.cs @@ -798,19 +798,9 @@ namespace GARbro.GUI private void OpenFile (string filename) { - if (filename == CurrentPath || string.IsNullOrEmpty (filename)) - return; try { - if (File.Exists (filename)) - VFS.FullPath = new string[] { filename, "" }; - else - VFS.FullPath = new string[] { filename }; - var vm = new DirectoryViewModel (VFS.FullPath, VFS.GetFiles(), VFS.IsVirtual); - PushViewModel (vm); - if (null != VFS.CurrentArchive) - SetStatusText (VFS.CurrentArchive.Description); - lv_SelectItem (0); + OpenFileOrDir (filename); } catch (OperationCanceledException X) { @@ -822,6 +812,21 @@ namespace GARbro.GUI } } + private void OpenFileOrDir (string filename) + { + if (filename == CurrentPath || string.IsNullOrEmpty (filename)) + return; + if (File.Exists (filename)) + VFS.FullPath = new string[] { filename, "" }; + else + VFS.FullPath = new string[] { filename }; + var vm = new DirectoryViewModel (VFS.FullPath, VFS.GetFiles(), VFS.IsVirtual); + PushViewModel (vm); + if (null != VFS.CurrentArchive) + SetStatusText (VFS.CurrentArchive.Description); + lv_SelectItem (0); + } + private void OpenRecentExec (object control, ExecutedRoutedEventArgs e) { string filename = e.Parameter as string; @@ -1336,6 +1341,36 @@ namespace GARbro.GUI else item.Visibility = Visibility.Visible; } + + private void OnDropEvent (object sender, DragEventArgs e) + { + try + { + if (!e.Data.GetDataPresent (DataFormats.FileDrop)) + return; + var files = (string[])e.Data.GetData (DataFormats.FileDrop); + if (!files.Any()) + return; + var filename = files.First(); + try + { + OpenFileOrDir (filename); + } + catch (Exception X) + { + VFS.FullPath = new string[] { Path.GetDirectoryName (filename) }; + var vm = new DirectoryViewModel (VFS.FullPath, VFS.GetFiles(), VFS.IsVirtual); + PushViewModel (vm); + filename = Path.GetFileName (filename); + lv_SelectItem (filename); + SetStatusText (string.Format("{0}: {1}", filename, X.Message)); + } + } + catch (Exception X) + { + Trace.WriteLine (X.Message, "Drop event failed"); + } + } } public class SortModeToBooleanConverter : IValueConverter