From 19001a459ee55391423d9c27335ce119b095d526 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 8 Sep 2022 16:09:57 +0900 Subject: [PATCH 01/11] Add Drag Test Code --- Flow.Launcher/MainWindow.xaml | 4 ++- Flow.Launcher/MainWindow.xaml.cs | 53 ++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 714fcc53fa1..957e942dc38 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -264,7 +264,9 @@ + MouseMove="FileView_MouseMove" + PreviewMouseLeftButtonDown="FileView_PreviewMouseLeftButtonDown" + PreviewMouseLeftButtonUp="OnPreviewMouseButtonDown" /> diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 2b7db38cff2..53928f2edd7 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using System.Threading.Tasks; using System.Windows; @@ -20,6 +20,9 @@ using System.Windows.Media; using Flow.Launcher.Infrastructure.Hotkey; using Flow.Launcher.Plugin.SharedCommands; +using System.Text; +using DataObject = System.Windows.DataObject; +using System.Diagnostics; namespace Flow.Launcher { @@ -383,6 +386,52 @@ private void OnPreviewDragOver(object sender, DragEventArgs e) e.Handled = true; } + private Point start; + + private void FileView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + this.start = e.GetPosition(null); + } + + private void FileView_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) + { + Point mpos = e.GetPosition(null); + Vector diff = this.start - mpos; + + if (e.LeftButton == MouseButtonState.Pressed && + Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance && + Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance) + { + + if (this.ResultListBox.SelectedItems.Count == 0) + { + return; + } + + var r = (ResultListBox)sender; + var d = (DependencyObject)e.OriginalSource; + var item = ItemsControl.ContainerFromElement(r, d) as ListBoxItem; + var result = (ResultViewModel)item?.DataContext; + Console.WriteLine("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + Console.WriteLine("result"); + + // right about here you get the file urls of the selected items. + // should be quite easy, if not, ask. + //string[] files = "asdf.txt"; + + string path = @"D:\test.png"; + string[] files = { path }; + var data = new DataObject(System.Windows.DataFormats.FileDrop, files); + data.SetData(System.Windows.DataFormats.Text, files[0]); + DragDrop.DoDragDrop(this, data, System.Windows.DragDropEffects.Copy); + e.Handled = true; + // string dataFormat = System.Windows.DataFormats.FileDrop; + //System.Windows.DataObject dataObject = new System.Windows.DataObject(dataFormat, files); + //DragDrop.DoDragDrop(this.ResultListBox, dataObject, System.Windows.DragDropEffects.Copy); + } + } + + private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs e) { _viewModel.Hide(); @@ -556,4 +605,4 @@ public void InitializeColorScheme() } } } -} \ No newline at end of file +} From 3e128e1a9a53c77c5ec5fdd3c712b89546bec65f Mon Sep 17 00:00:00 2001 From: DB p Date: Wed, 28 Sep 2022 15:06:14 +0900 Subject: [PATCH 02/11] Changed listitem to draggable --- Flow.Launcher/ResultListBox.xaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Flow.Launcher/ResultListBox.xaml b/Flow.Launcher/ResultListBox.xaml index 2c78f9babbf..d0a5247a585 100644 --- a/Flow.Launcher/ResultListBox.xaml +++ b/Flow.Launcher/ResultListBox.xaml @@ -120,6 +120,7 @@ x:Name="Title" VerticalAlignment="Center" DockPanel.Dock="Left" + IsHitTestVisible="False" Style="{DynamicResource ItemTitleStyle}" Text="{Binding Result.Title}" ToolTip="{Binding ShowTitleToolTip}"> @@ -133,6 +134,7 @@ From dde5a513d35b366eef9ab4c511f5d3b032b1ff69 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 29 Sep 2022 00:02:49 +0900 Subject: [PATCH 03/11] Adjust Drag and drop code --- Flow.Launcher/MainWindow.xaml.cs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 53928f2edd7..a35f35a4552 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -23,6 +23,8 @@ using System.Text; using DataObject = System.Windows.DataObject; using System.Diagnostics; +using Microsoft.AspNetCore.Http; +using System.IO; namespace Flow.Launcher { @@ -412,22 +414,19 @@ private void FileView_MouseMove(object sender, System.Windows.Input.MouseEventAr var d = (DependencyObject)e.OriginalSource; var item = ItemsControl.ContainerFromElement(r, d) as ListBoxItem; var result = (ResultViewModel)item?.DataContext; - Console.WriteLine("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); - Console.WriteLine("result"); - // right about here you get the file urls of the selected items. - // should be quite easy, if not, ask. - //string[] files = "asdf.txt"; - string path = @"D:\test.png"; + string copyText = string.IsNullOrEmpty(result.Result.CopyText) ? result.Result.SubTitle : result.Result.CopyText; + var isFile = File.Exists(copyText); + var isFolder = Directory.Exists(copyText); + + //string path = @"D:\test.png"; + string path = Convert.ToString(copyText); string[] files = { path }; var data = new DataObject(System.Windows.DataFormats.FileDrop, files); - data.SetData(System.Windows.DataFormats.Text, files[0]); - DragDrop.DoDragDrop(this, data, System.Windows.DragDropEffects.Copy); + //data.SetData(System.Windows.DataFormats.FileDrop, files[0]); + DragDrop.DoDragDrop(this.ResultListBox, data, System.Windows.DragDropEffects.Copy); e.Handled = true; - // string dataFormat = System.Windows.DataFormats.FileDrop; - //System.Windows.DataObject dataObject = new System.Windows.DataObject(dataFormat, files); - //DragDrop.DoDragDrop(this.ResultListBox, dataObject, System.Windows.DragDropEffects.Copy); } } From d0c281ef359d868dbfa372f5a506b2734a8847a4 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 29 Sep 2022 01:11:20 +0900 Subject: [PATCH 04/11] - Add "Move" - Adjust Function Name --- Flow.Launcher/MainWindow.xaml | 4 ++-- Flow.Launcher/MainWindow.xaml.cs | 36 +++++++++++++------------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 957e942dc38..f68934ebfdf 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -264,8 +264,8 @@ diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index a35f35a4552..6e1ff94b366 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -390,42 +390,34 @@ private void OnPreviewDragOver(object sender, DragEventArgs e) private Point start; - private void FileView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + private void ResultList_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { this.start = e.GetPosition(null); } - private void FileView_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) + private void ResultList_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { + if (this.ResultListBox.SelectedItems.Count == 0) + { + return; + } + Point mpos = e.GetPosition(null); Vector diff = this.start - mpos; + var r = (ResultListBox)sender; + var d = (DependencyObject)e.OriginalSource; + var item = ItemsControl.ContainerFromElement(r, d) as ListBoxItem; + var result = (ResultViewModel)item?.DataContext; + if (e.LeftButton == MouseButtonState.Pressed && Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance && Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance) { - - if (this.ResultListBox.SelectedItems.Count == 0) - { - return; - } - - var r = (ResultListBox)sender; - var d = (DependencyObject)e.OriginalSource; - var item = ItemsControl.ContainerFromElement(r, d) as ListBoxItem; - var result = (ResultViewModel)item?.DataContext; - - string copyText = string.IsNullOrEmpty(result.Result.CopyText) ? result.Result.SubTitle : result.Result.CopyText; - var isFile = File.Exists(copyText); - var isFolder = Directory.Exists(copyText); - - //string path = @"D:\test.png"; - string path = Convert.ToString(copyText); - string[] files = { path }; + string[] files = { copyText }; var data = new DataObject(System.Windows.DataFormats.FileDrop, files); - //data.SetData(System.Windows.DataFormats.FileDrop, files[0]); - DragDrop.DoDragDrop(this.ResultListBox, data, System.Windows.DragDropEffects.Copy); + DragDrop.DoDragDrop(this.ResultListBox, data, System.Windows.DragDropEffects.Copy | System.Windows.DragDropEffects.Move); e.Handled = true; } } From 74999006a5506676d0111caf8b0eeb83e294a542 Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 29 Sep 2022 18:04:15 +0900 Subject: [PATCH 05/11] Change the default drag action to copy (shift+drag to move) --- Flow.Launcher/MainWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 6e1ff94b366..10fadd59195 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -417,7 +417,7 @@ private void ResultList_MouseMove(object sender, System.Windows.Input.MouseEvent string copyText = string.IsNullOrEmpty(result.Result.CopyText) ? result.Result.SubTitle : result.Result.CopyText; string[] files = { copyText }; var data = new DataObject(System.Windows.DataFormats.FileDrop, files); - DragDrop.DoDragDrop(this.ResultListBox, data, System.Windows.DragDropEffects.Copy | System.Windows.DragDropEffects.Move); + DragDrop.DoDragDrop(this.ResultListBox, data, System.Windows.DragDropEffects.Move | System.Windows.DragDropEffects.Copy); e.Handled = true; } } From 4a15263a1ee974576c8c9ccafff3d837770cb85a Mon Sep 17 00:00:00 2001 From: DB p Date: Sat, 22 Oct 2022 11:25:26 +0900 Subject: [PATCH 06/11] Changed the Icon 'IsHitTestVisible' --- Flow.Launcher/ResultListBox.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/ResultListBox.xaml b/Flow.Launcher/ResultListBox.xaml index 3737a7ade01..869045526e6 100644 --- a/Flow.Launcher/ResultListBox.xaml +++ b/Flow.Launcher/ResultListBox.xaml @@ -84,7 +84,7 @@ x:Name="ImageIcon" Width="{Binding IconXY}" Height="{Binding IconXY}" - Margin="0,0,0,0" + Margin="0,0,0,0" IsHitTestVisible="False" HorizontalAlignment="Center" Source="{Binding Image, TargetNullValue={x:Null}}" Stretch="Uniform" From 234156b15371e4b70998ce5027753e58eb316e2b Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sun, 23 Oct 2022 18:04:25 -0400 Subject: [PATCH 07/11] Move code to ResultListBox to avoid extra children retrieval. Adjust the CopyText property to automatically return Subtitle is not specified --- Flow.Launcher.Plugin/Result.cs | 7 +++- Flow.Launcher/MainWindow.xaml | 2 - Flow.Launcher/MainWindow.xaml.cs | 35 ---------------- Flow.Launcher/ResultListBox.xaml | 7 +++- Flow.Launcher/ResultListBox.xaml.cs | 51 ++++++++++++++++++++++-- Flow.Launcher/ViewModel/MainViewModel.cs | 18 ++++----- 6 files changed, 66 insertions(+), 54 deletions(-) diff --git a/Flow.Launcher.Plugin/Result.cs b/Flow.Launcher.Plugin/Result.cs index 7633e34a70c..a1d3b83abf2 100644 --- a/Flow.Launcher.Plugin/Result.cs +++ b/Flow.Launcher.Plugin/Result.cs @@ -37,7 +37,11 @@ public class Result /// user's clipboard when Ctrl + C is pressed on a result. If the text is a file/directory path /// flow will copy the actual file/folder instead of just the path text. /// - public string CopyText { get; set; } = string.Empty; + public string CopyText + { + get => string.IsNullOrEmpty(_copyText) ? SubTitle : _copyText; + set => _copyText = value; + } /// /// This holds the text which can be provided by plugin to help Flow autocomplete text @@ -81,6 +85,7 @@ public string IcoPath /// Delegate to Get Image Source /// public IconDelegate Icon; + private string _copyText = string.Empty; /// /// Information for Glyph Icon (Prioritized than IcoPath/Icon if user enable Glyph Icons) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 006d394fe75..3e89ae5e035 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -288,8 +288,6 @@ diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index ac0393855b7..72fd97b3b7d 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -374,41 +374,6 @@ private void OnPreviewDragOver(object sender, DragEventArgs e) e.Handled = true; } - private Point start; - - private void ResultList_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - this.start = e.GetPosition(null); - } - - private void ResultList_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) - { - if (this.ResultListBox.SelectedItems.Count == 0) - { - return; - } - - Point mpos = e.GetPosition(null); - Vector diff = this.start - mpos; - - var r = (ResultListBox)sender; - var d = (DependencyObject)e.OriginalSource; - var item = ItemsControl.ContainerFromElement(r, d) as ListBoxItem; - var result = (ResultViewModel)item?.DataContext; - - if (e.LeftButton == MouseButtonState.Pressed && - Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance && - Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance) - { - string copyText = string.IsNullOrEmpty(result.Result.CopyText) ? result.Result.SubTitle : result.Result.CopyText; - string[] files = { copyText }; - var data = new DataObject(System.Windows.DataFormats.FileDrop, files); - DragDrop.DoDragDrop(this.ResultListBox, data, System.Windows.DragDropEffects.Move | System.Windows.DragDropEffects.Copy); - e.Handled = true; - } - } - - private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs e) { _viewModel.Hide(); diff --git a/Flow.Launcher/ResultListBox.xaml b/Flow.Launcher/ResultListBox.xaml index 869045526e6..1ece390d120 100644 --- a/Flow.Launcher/ResultListBox.xaml +++ b/Flow.Launcher/ResultListBox.xaml @@ -25,12 +25,15 @@ VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" Visibility="{Binding Visbility}" - mc:Ignorable="d"> + mc:Ignorable="d" + PreviewMouseMove="ResultList_MouseMove" + PreviewMouseLeftButtonDown="ResultList_PreviewMouseLeftButtonDown"> -