Skip to content

Commit 19001a4

Browse files
committed
Add Drag Test Code
1 parent 05044ae commit 19001a4

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

Flow.Launcher/MainWindow.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@
264264
<flowlauncher:ResultListBox
265265
x:Name="ResultListBox"
266266
DataContext="{Binding Results}"
267-
PreviewMouseDown="OnPreviewMouseButtonDown" />
267+
MouseMove="FileView_MouseMove"
268+
PreviewMouseLeftButtonDown="FileView_PreviewMouseLeftButtonDown"
269+
PreviewMouseLeftButtonUp="OnPreviewMouseButtonDown" />
268270
</ContentControl>
269271
</Border>
270272
<Border Style="{DynamicResource WindowRadius}">

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.ComponentModel;
33
using System.Threading.Tasks;
44
using System.Windows;
@@ -20,6 +20,9 @@
2020
using System.Windows.Media;
2121
using Flow.Launcher.Infrastructure.Hotkey;
2222
using Flow.Launcher.Plugin.SharedCommands;
23+
using System.Text;
24+
using DataObject = System.Windows.DataObject;
25+
using System.Diagnostics;
2326

2427
namespace Flow.Launcher
2528
{
@@ -383,6 +386,52 @@ private void OnPreviewDragOver(object sender, DragEventArgs e)
383386
e.Handled = true;
384387
}
385388

389+
private Point start;
390+
391+
private void FileView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
392+
{
393+
this.start = e.GetPosition(null);
394+
}
395+
396+
private void FileView_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
397+
{
398+
Point mpos = e.GetPosition(null);
399+
Vector diff = this.start - mpos;
400+
401+
if (e.LeftButton == MouseButtonState.Pressed &&
402+
Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance &&
403+
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
404+
{
405+
406+
if (this.ResultListBox.SelectedItems.Count == 0)
407+
{
408+
return;
409+
}
410+
411+
var r = (ResultListBox)sender;
412+
var d = (DependencyObject)e.OriginalSource;
413+
var item = ItemsControl.ContainerFromElement(r, d) as ListBoxItem;
414+
var result = (ResultViewModel)item?.DataContext;
415+
Console.WriteLine("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
416+
Console.WriteLine("result");
417+
418+
// right about here you get the file urls of the selected items.
419+
// should be quite easy, if not, ask.
420+
//string[] files = "asdf.txt";
421+
422+
string path = @"D:\test.png";
423+
string[] files = { path };
424+
var data = new DataObject(System.Windows.DataFormats.FileDrop, files);
425+
data.SetData(System.Windows.DataFormats.Text, files[0]);
426+
DragDrop.DoDragDrop(this, data, System.Windows.DragDropEffects.Copy);
427+
e.Handled = true;
428+
// string dataFormat = System.Windows.DataFormats.FileDrop;
429+
//System.Windows.DataObject dataObject = new System.Windows.DataObject(dataFormat, files);
430+
//DragDrop.DoDragDrop(this.ResultListBox, dataObject, System.Windows.DragDropEffects.Copy);
431+
}
432+
}
433+
434+
386435
private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs e)
387436
{
388437
_viewModel.Hide();
@@ -556,4 +605,4 @@ public void InitializeColorScheme()
556605
}
557606
}
558607
}
559-
}
608+
}

0 commit comments

Comments
 (0)