2014-02-21 18:59:47 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-01-06 14:45:08 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Remoting.Contexts;
|
2013-12-27 00:39:07 +08:00
|
|
|
|
using System.Windows;
|
2013-12-22 19:35:21 +08:00
|
|
|
|
using System.Windows.Controls;
|
2014-03-05 22:32:21 +08:00
|
|
|
|
using System.Windows.Input;
|
2014-02-28 23:21:01 +08:00
|
|
|
|
using System.Windows.Media;
|
2015-07-17 15:08:39 +08:00
|
|
|
|
using Wox.Core.UserSettings;
|
2015-11-07 11:50:26 +08:00
|
|
|
|
using Wox.Helper;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using Wox.Plugin;
|
2015-02-05 23:29:41 +08:00
|
|
|
|
using Wox.Storage;
|
2016-02-18 19:31:15 +08:00
|
|
|
|
using Wox.ViewModel;
|
2013-12-22 19:35:21 +08:00
|
|
|
|
|
2014-01-29 18:33:24 +08:00
|
|
|
|
namespace Wox
|
2013-12-22 19:35:21 +08:00
|
|
|
|
{
|
2015-11-07 05:30:38 +08:00
|
|
|
|
[Synchronization]
|
2013-12-22 19:35:21 +08:00
|
|
|
|
public partial class ResultPanel : UserControl
|
|
|
|
|
{
|
2015-02-03 18:32:16 +08:00
|
|
|
|
public event Action<Result, IDataObject, DragEventArgs> ItemDropEvent;
|
2014-03-05 22:32:21 +08:00
|
|
|
|
|
2015-11-08 04:48:18 +08:00
|
|
|
|
public void AddResults(List<Result> newResults, string resultId)
|
2013-12-22 19:35:21 +08:00
|
|
|
|
{
|
2016-02-12 17:20:46 +08:00
|
|
|
|
var vm = this.DataContext as ResultPanelViewModel;
|
|
|
|
|
vm.AddResults(newResults, resultId);
|
2014-01-04 20:26:13 +08:00
|
|
|
|
}
|
2016-02-18 19:31:15 +08:00
|
|
|
|
|
2014-01-04 20:26:13 +08:00
|
|
|
|
|
2015-02-09 00:13:08 +08:00
|
|
|
|
private void UpdateItemNumber()
|
|
|
|
|
{
|
2015-02-09 19:16:13 +08:00
|
|
|
|
//VirtualizingStackPanel virtualizingStackPanel = GetInnerStackPanel(lbResults);
|
|
|
|
|
//int index = 0;
|
|
|
|
|
//for (int i = (int)virtualizingStackPanel.VerticalOffset; i <= virtualizingStackPanel.VerticalOffset + virtualizingStackPanel.ViewportHeight; i++)
|
|
|
|
|
//{
|
|
|
|
|
// index++;
|
|
|
|
|
// ListBoxItem item = lbResults.ItemContainerGenerator.ContainerFromIndex(i) as ListBoxItem;
|
|
|
|
|
// if (item != null)
|
|
|
|
|
// {
|
|
|
|
|
// ContentPresenter myContentPresenter = FindVisualChild<ContentPresenter>(item);
|
|
|
|
|
// if (myContentPresenter != null)
|
|
|
|
|
// {
|
|
|
|
|
// DataTemplate dataTemplate = myContentPresenter.ContentTemplate;
|
|
|
|
|
// TextBlock tbItemNumber = (TextBlock)dataTemplate.FindName("tbItemNumber", myContentPresenter);
|
|
|
|
|
// tbItemNumber.Text = index.ToString();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2015-02-09 00:13:08 +08:00
|
|
|
|
}
|
2015-01-23 18:28:14 +08:00
|
|
|
|
|
2013-12-22 19:35:21 +08:00
|
|
|
|
public ResultPanel()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-02-19 22:50:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lbResults_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
{
|
2014-03-18 00:25:27 +08:00
|
|
|
|
if (e.AddedItems.Count > 0 && e.AddedItems[0] != null)
|
2014-02-19 22:50:15 +08:00
|
|
|
|
{
|
|
|
|
|
lbResults.ScrollIntoView(e.AddedItems[0]);
|
2016-01-06 14:31:17 +08:00
|
|
|
|
//Dispatcher.DelayInvoke("UpdateItemNumber", () =>
|
|
|
|
|
//{
|
|
|
|
|
//UpdateItemNumber();
|
|
|
|
|
//}, TimeSpan.FromMilliseconds(3));
|
2014-02-19 22:50:15 +08:00
|
|
|
|
}
|
2014-01-03 23:52:36 +08:00
|
|
|
|
}
|
2014-03-05 22:32:21 +08:00
|
|
|
|
|
2015-02-02 23:28:40 +08:00
|
|
|
|
private void ListBoxItem_OnDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var item = ItemsControl.ContainerFromElement(lbResults, e.OriginalSource as DependencyObject) as ListBoxItem;
|
|
|
|
|
if (item != null)
|
|
|
|
|
{
|
2016-02-18 19:31:15 +08:00
|
|
|
|
OnItemDropEvent(item.DataContext as ResultItemViewModel, e.Data, e);
|
2015-02-02 23:28:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 19:31:15 +08:00
|
|
|
|
protected virtual void OnItemDropEvent(ResultItemViewModel obj, IDataObject data, DragEventArgs e)
|
2015-02-02 23:28:40 +08:00
|
|
|
|
{
|
|
|
|
|
var handler = ItemDropEvent;
|
2016-02-18 19:31:15 +08:00
|
|
|
|
if (handler != null) handler(obj.RawResult, data, e);
|
2015-02-02 23:28:40 +08:00
|
|
|
|
}
|
2013-12-22 19:35:21 +08:00
|
|
|
|
}
|
2013-12-23 23:53:38 +08:00
|
|
|
|
}
|