Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
MouseDoubleClick="MouseDoubleClickItem"
SelectedItem="{Binding Settings.SelectedSearchSource}"
SizeChanged="ListView_SizeChanged"
PreviewMouseLeftButtonDown="ListView_PreviewMouseLeftButtonDown"
PreviewMouseMove="ListView_PreviewMouseMove"
AllowDrop="True"
Drop="ListView_Drop"
Style="{StaticResource {x:Static GridView.GridViewStyleKey}}">
<ListView.View>
<GridView>
Expand All @@ -68,7 +72,7 @@
</GridViewColumn.CellTemplate>
</GridViewColumn>

<!-- Margin="0 6" is a workaround to set this TextBlock to vertially center -->

Check warning on line 75 in Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml

View workflow job for this annotation

GitHub Actions / Check Spelling

`vertially` is not a recognized word. (unrecognized-spelling)
<GridViewColumn Width="135" Header="{DynamicResource flowlauncher_plugin_websearch_action_keyword}">
<GridViewColumn.CellTemplate>
<DataTemplate>
Expand Down Expand Up @@ -102,7 +106,7 @@
</GridViewColumn.CellTemplate>
</GridViewColumn>

<!-- CheckBox is vertially center by default -->

Check warning on line 109 in Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml

View workflow job for this annotation

GitHub Actions / Check Spelling

`vertially` is not a recognized word. (unrecognized-spelling)
<GridViewColumn Width="123" Header="{DynamicResource flowlauncher_plugin_websearch_private_mode_label}">
<GridViewColumn.CellTemplate>
<DataTemplate>
Expand Down
79 changes: 77 additions & 2 deletions Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Windows;
using System.Windows.Controls;
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;

namespace Flow.Launcher.Plugin.WebSearch
{
Expand All @@ -12,6 +15,7 @@
{
private readonly Settings _settings;
private readonly PluginInitContext _context;
private Point _dragStartPoint;

public SettingsControl(PluginInitContext context, SettingsViewModel viewModel)
{
Expand Down Expand Up @@ -163,5 +167,76 @@
gView.Columns[3].Width = workingWidth * col4;
gView.Columns[4].Width = workingWidth * col5;
}

private void ListView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_dragStartPoint = e.GetPosition(null);
}

private void ListView_PreviewMouseMove(object sender, MouseEventArgs e)
{
Point mousePos = e.GetPosition(null);
Vector diff = _dragStartPoint - mousePos;

if (e.LeftButton == MouseButtonState.Pressed &&
(Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
{
ListView listView = sender as ListView;
ListViewItem listViewItem = FindAncestor<ListViewItem>((DependencyObject)e.OriginalSource);

if (listViewItem == null) return;

SearchSource item = (SearchSource)listView.ItemContainerGenerator.ItemFromContainer(listViewItem);
if (item == null) return;

DragDrop.DoDragDrop(listViewItem, item, DragDropEffects.Move);
}
}

private void ListView_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(SearchSource)))
{
SearchSource droppedData = e.Data.GetData(typeof(SearchSource)) as SearchSource;
ListView listView = sender as ListView;
var target = GetNearestContainer(e.OriginalSource);

if (target == null)
return;

SearchSource targetData = (SearchSource)listView.ItemContainerGenerator.ItemFromContainer(target);

var items = _settings.SearchSources;
int removedIdx = items.IndexOf(droppedData);
int targetIdx = items.IndexOf(targetData);

Check warning on line 212 in Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Idx` is not a recognized word. (unrecognized-spelling)

if (removedIdx == targetIdx)

Check warning on line 214 in Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Idx` is not a recognized word. (unrecognized-spelling)

Check warning on line 214 in Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Idx` is not a recognized word. (unrecognized-spelling)
return;

items.RemoveAt(removedIdx);

Check warning on line 217 in Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Idx` is not a recognized word. (unrecognized-spelling)
items.Insert(targetIdx, droppedData);
}
}

private ListViewItem GetNearestContainer(object source)
{
var element = source as UIElement;
while (element != null && !(element is ListViewItem))
element = VisualTreeHelper.GetParent(element) as UIElement;

return element as ListViewItem;
}

private static T FindAncestor<T>(DependencyObject current) where T : DependencyObject
{
while (current != null)
{
if (current is T)
return (T)current;
current = VisualTreeHelper.GetParent(current);
}
return null;
}
}
}
Loading