mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Fix scroll issues
This commit is contained in:
@@ -11,7 +11,7 @@ namespace WinAlfred.PluginLoader
|
|||||||
private PluginMetadata metadata;
|
private PluginMetadata metadata;
|
||||||
|
|
||||||
[DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
private extern static IntPtr ExecPython(string directory, string file,string method,string para);
|
private extern static IntPtr ExecPython(string directory, string file, string method, string para);
|
||||||
[DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
[DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||||
private extern static void InitPythonEnv();
|
private extern static void InitPythonEnv();
|
||||||
|
|
||||||
@@ -22,16 +22,25 @@ namespace WinAlfred.PluginLoader
|
|||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""),"query",query.RawQuery));
|
try
|
||||||
List<PythonResult> o = JsonConvert.DeserializeObject<List<PythonResult>>(s);
|
|
||||||
List<Result> r = new List<Result>();
|
|
||||||
foreach (PythonResult pythonResult in o)
|
|
||||||
{
|
{
|
||||||
PythonResult ps = pythonResult;
|
string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), "query", query.RawQuery));
|
||||||
ps.Action = () => ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""),ps.ActionName,ps.ActionPara);
|
List<PythonResult> o = JsonConvert.DeserializeObject<List<PythonResult>>(s);
|
||||||
r.Add(ps);
|
List<Result> r = new List<Result>();
|
||||||
|
foreach (PythonResult pythonResult in o)
|
||||||
|
{
|
||||||
|
PythonResult ps = pythonResult;
|
||||||
|
ps.Action = () => ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), ps.ActionName, ps.ActionPara);
|
||||||
|
r.Add(ps);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
return r;
|
catch (Exception)
|
||||||
|
{
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="300" d:DesignWidth="300">
|
d:DesignHeight="300" d:DesignWidth="300">
|
||||||
<ScrollViewer MaxHeight="300" VerticalScrollBarVisibility="Auto">
|
<ScrollViewer x:Name="sv" MaxHeight="300" VerticalScrollBarVisibility="Auto">
|
||||||
<StackPanel x:Name="pnlContainer">
|
<StackPanel x:Name="pnlContainer">
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using WinAlfred.Plugin;
|
using WinAlfred.Plugin;
|
||||||
|
|
||||||
@@ -89,9 +90,54 @@ namespace WinAlfred
|
|||||||
{
|
{
|
||||||
if (pnlContainer.Children.Count > 0)
|
if (pnlContainer.Children.Count > 0)
|
||||||
{
|
{
|
||||||
|
int oldIndex = GetCurrentSelectedResultIndex();
|
||||||
|
|
||||||
UnSelectAll();
|
UnSelectAll();
|
||||||
var resultItemControl = pnlContainer.Children[index] as ResultItem;
|
var resultItemControl = pnlContainer.Children[index] as ResultItem;
|
||||||
if (resultItemControl != null) resultItemControl.Selected = true;
|
if (resultItemControl != null)
|
||||||
|
{
|
||||||
|
resultItemControl.Selected = true;
|
||||||
|
|
||||||
|
double scrollPosition = 0;
|
||||||
|
Point newItemBottomPoint = resultItemControl.TranslatePoint(new Point(0, resultItemControl.ActualHeight), pnlContainer);
|
||||||
|
if (index == 0)
|
||||||
|
{
|
||||||
|
sv.ScrollToTop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (index == pnlContainer.Children.Count - 1)
|
||||||
|
{
|
||||||
|
sv.ScrollToBottom();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index < oldIndex)
|
||||||
|
{
|
||||||
|
//move up and old item is at the top of the scroll view
|
||||||
|
if ( newItemBottomPoint.Y - sv.VerticalOffset == 0)
|
||||||
|
{
|
||||||
|
scrollPosition = sv.VerticalOffset - resultItemControl.ActualHeight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//move down and old item is at the bottom of scroll view
|
||||||
|
if (sv.ActualHeight + sv.VerticalOffset == newItemBottomPoint.Y - resultItemControl.ActualHeight)
|
||||||
|
{
|
||||||
|
scrollPosition = newItemBottomPoint.Y - sv.ActualHeight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sv.ScrollToVerticalOffset(scrollPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user