diff --git a/WinAlfred/PluginLoader/PythonPluginWrapper.cs b/WinAlfred/PluginLoader/PythonPluginWrapper.cs index f87550aad9..bb82e02b87 100644 --- a/WinAlfred/PluginLoader/PythonPluginWrapper.cs +++ b/WinAlfred/PluginLoader/PythonPluginWrapper.cs @@ -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 Query(Query query) { - string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""),"query",query.RawQuery)); - List o = JsonConvert.DeserializeObject>(s); - List r = new List(); - 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 o = JsonConvert.DeserializeObject>(s); + List r = new List(); + 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() diff --git a/WinAlfred/ResultPanel.xaml b/WinAlfred/ResultPanel.xaml index 125ab2c053..30f273803a 100644 --- a/WinAlfred/ResultPanel.xaml +++ b/WinAlfred/ResultPanel.xaml @@ -5,7 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> - + diff --git a/WinAlfred/ResultPanel.xaml.cs b/WinAlfred/ResultPanel.xaml.cs index 6f6d5d3b81..9c59fa1dd4 100644 --- a/WinAlfred/ResultPanel.xaml.cs +++ b/WinAlfred/ResultPanel.xaml.cs @@ -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); + } } }