mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 23:19:13 +08:00
Fix scroll issues
This commit is contained in:
parent
ece5cc7dd5
commit
bdf77b2782
@ -11,7 +11,7 @@ namespace WinAlfred.PluginLoader
|
||||
private PluginMetadata metadata;
|
||||
|
||||
[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)]
|
||||
private extern static void InitPythonEnv();
|
||||
|
||||
@ -22,16 +22,25 @@ namespace WinAlfred.PluginLoader
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""),"query",query.RawQuery));
|
||||
List<PythonResult> o = JsonConvert.DeserializeObject<List<PythonResult>>(s);
|
||||
List<Result> r = new List<Result>();
|
||||
foreach (PythonResult pythonResult in o)
|
||||
try
|
||||
{
|
||||
PythonResult ps = pythonResult;
|
||||
ps.Action = () => ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""),ps.ActionName,ps.ActionPara);
|
||||
r.Add(ps);
|
||||
string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), "query", query.RawQuery));
|
||||
List<PythonResult> o = JsonConvert.DeserializeObject<List<PythonResult>>(s);
|
||||
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()
|
||||
|
@ -5,7 +5,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<ScrollViewer MaxHeight="300" VerticalScrollBarVisibility="Auto">
|
||||
<ScrollViewer x:Name="sv" MaxHeight="300" VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel x:Name="pnlContainer">
|
||||
|
||||
</StackPanel>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using WinAlfred.Plugin;
|
||||
|
||||
@ -89,9 +90,54 @@ namespace WinAlfred
|
||||
{
|
||||
if (pnlContainer.Children.Count > 0)
|
||||
{
|
||||
int oldIndex = GetCurrentSelectedResultIndex();
|
||||
|
||||
UnSelectAll();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user