1- using System . Windows ;
1+ using System ;
2+ using System . IO ;
3+ using System . Windows ;
24using System . Windows . Controls ;
35using System . Windows . Input ;
6+ using Flow . Launcher . ViewModel ;
47
58namespace Flow . Launcher
69{
@@ -24,7 +27,7 @@ private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
2427
2528 private void OnMouseEnter ( object sender , MouseEventArgs e )
2629 {
27- lock ( _lock )
30+ lock ( _lock )
2831 {
2932 curItem = ( ListBoxItem ) sender ;
3033 var p = e . GetPosition ( ( IInputElement ) sender ) ;
@@ -34,7 +37,7 @@ private void OnMouseEnter(object sender, MouseEventArgs e)
3437
3538 private void OnMouseMove ( object sender , MouseEventArgs e )
3639 {
37- lock ( _lock )
40+ lock ( _lock )
3841 {
3942 var p = e . GetPosition ( ( IInputElement ) sender ) ;
4043 if ( _lastpos != p )
@@ -46,13 +49,59 @@ private void OnMouseMove(object sender, MouseEventArgs e)
4649
4750 private void ListBox_PreviewMouseDown ( object sender , MouseButtonEventArgs e )
4851 {
49- lock ( _lock )
52+ lock ( _lock )
5053 {
5154 if ( curItem != null )
5255 {
5356 curItem . IsSelected = true ;
5457 }
5558 }
5659 }
60+
61+
62+ private Point start ;
63+ private string path ;
64+ private string query ;
65+
66+ private void ResultList_PreviewMouseLeftButtonDown ( object sender , MouseButtonEventArgs e )
67+ {
68+ if ( Mouse . DirectlyOver is not FrameworkElement { DataContext : ResultViewModel result } )
69+ return ;
70+
71+ path = result . Result . CopyText ;
72+ query = result . Result . OriginQuery . RawQuery ;
73+ start = e . GetPosition ( null ) ;
74+ }
75+
76+ private void ResultList_MouseMove ( object sender , MouseEventArgs e )
77+ {
78+ if ( e . LeftButton != MouseButtonState . Pressed )
79+ {
80+ start = default ;
81+ path = string . Empty ;
82+ query = string . Empty ;
83+ return ;
84+ }
85+
86+ if ( ! File . Exists ( path ) && ! Directory . Exists ( path ) )
87+ return ;
88+
89+ Point mousePosition = e . GetPosition ( null ) ;
90+ Vector diff = this . start - mousePosition ;
91+
92+ if ( Math . Abs ( diff . X ) < SystemParameters . MinimumHorizontalDragDistance
93+ || Math . Abs ( diff . Y ) < SystemParameters . MinimumVerticalDragDistance )
94+ return ;
95+
96+ var data = new DataObject ( DataFormats . FileDrop , new [ ]
97+ {
98+ path
99+ } ) ;
100+ DragDrop . DoDragDrop ( ( DependencyObject ) sender , data , DragDropEffects . Move | DragDropEffects . Copy ) ;
101+
102+ App . API . ChangeQuery ( query , true ) ;
103+
104+ e . Handled = true ;
105+ }
57106 }
58107}
0 commit comments