mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
@@ -41,8 +41,8 @@
|
|||||||
Style="{DynamicResource PendingLineStyle}" Visibility="{Binding ProgressBarVisibility, Mode=TwoWay}"
|
Style="{DynamicResource PendingLineStyle}" Visibility="{Binding ProgressBarVisibility, Mode=TwoWay}"
|
||||||
Y1="0" Y2="0" X2="100" Height="2" Width="752" StrokeThickness="1">
|
Y1="0" Y2="0" X2="100" Height="2" Width="752" StrokeThickness="1">
|
||||||
</Line>
|
</Line>
|
||||||
<ContentControl Content="{Binding Results}" Visibility="{Binding ResultListBoxVisibility}" />
|
<ContentControl Name="Results" Content="{Binding Results}" Visibility="{Binding ResultListBoxVisibility}" />
|
||||||
<ContentControl Content="{Binding ContextMenu}" Visibility="{Binding ContextMenuVisibility}" />
|
<ContentControl Name ="ContextMenu" Content="{Binding ContextMenu}" Visibility="{Binding ContextMenuVisibility}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
</Window>
|
</Window>
|
||||||
@@ -333,15 +333,6 @@ namespace Wox
|
|||||||
var vm = DataContext as MainViewModel;
|
var vm = DataContext as MainViewModel;
|
||||||
if (vm != null)
|
if (vm != null)
|
||||||
{
|
{
|
||||||
if (vm.ContextMenuVisibility.IsVisible())
|
|
||||||
{
|
|
||||||
vm.ContextMenu.SelectResult(result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vm.Results.SelectResult(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.ChangedButton == MouseButton.Left)
|
if (e.ChangedButton == MouseButton.Left)
|
||||||
{
|
{
|
||||||
vm.OpenResultCommand.Execute(null);
|
vm.OpenResultCommand.Execute(null);
|
||||||
|
|||||||
@@ -7,11 +7,16 @@
|
|||||||
xmlns:vm="clr-namespace:Wox.ViewModel"
|
xmlns:vm="clr-namespace:Wox.ViewModel"
|
||||||
mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="100"
|
mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="100"
|
||||||
d:DataContext="{d:DesignInstance vm:ResultsViewModel}"
|
d:DataContext="{d:DesignInstance vm:ResultsViewModel}"
|
||||||
MaxHeight="{Binding MaxHeight}" SelectedItem="{Binding SelectedResult}"
|
MaxHeight="{Binding MaxHeight}"
|
||||||
|
SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"
|
||||||
|
SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}"
|
||||||
HorizontalContentAlignment="Stretch" ItemsSource="{Binding Results}" Margin="{Binding Margin}"
|
HorizontalContentAlignment="Stretch" ItemsSource="{Binding Results}" Margin="{Binding Margin}"
|
||||||
Style="{DynamicResource BaseListboxStyle}" SelectionChanged="lbResults_SelectionChanged" Focusable="False"
|
Style="{DynamicResource BaseListboxStyle}" Focusable="False"
|
||||||
KeyboardNavigation.DirectionalNavigation="Cycle" SelectionMode="Single"
|
KeyboardNavigation.DirectionalNavigation="Cycle" SelectionMode="Single"
|
||||||
VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard">
|
VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard"
|
||||||
|
SelectionChanged="OnSelectionChanged"
|
||||||
|
IsSynchronizedWithCurrentItem="True">
|
||||||
|
<!--IsSynchronizedWithCurrentItem: http://stackoverflow.com/a/7833798/2833083-->
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<DataTemplate.DataType>
|
<DataTemplate.DataType>
|
||||||
@@ -65,6 +70,7 @@
|
|||||||
<!--http://stackoverflow.com/questions/16819577/setting-background-color-or-wpf-4-0-listbox-windows-8/#16820062-->
|
<!--http://stackoverflow.com/questions/16819577/setting-background-color-or-wpf-4-0-listbox-windows-8/#16820062-->
|
||||||
<ListBox.ItemContainerStyle>
|
<ListBox.ItemContainerStyle>
|
||||||
<Style TargetType="{x:Type ListBoxItem}">
|
<Style TargetType="{x:Type ListBoxItem}">
|
||||||
|
<EventSetter Event="MouseEnter" Handler="OnMouseEnter"></EventSetter>
|
||||||
<Setter Property="Height" Value="50" />
|
<Setter Property="Height" Value="50" />
|
||||||
<Setter Property="Margin" Value="0" />
|
<Setter Property="Margin" Value="0" />
|
||||||
<Setter Property="Padding" Value="0"/>
|
<Setter Property="Padding" Value="0"/>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Linq;
|
|||||||
using System.Runtime.Remoting.Contexts;
|
using System.Runtime.Remoting.Contexts;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.ViewModel;
|
using Wox.ViewModel;
|
||||||
|
|
||||||
@@ -13,10 +14,10 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
public void AddResults(List<Result> newRawResults)
|
public void AddResults(List<Result> newRawResults)
|
||||||
{
|
{
|
||||||
var vm = DataContext as ResultsViewModel;
|
var vm = (ResultsViewModel) DataContext;
|
||||||
var newResults = newRawResults.Select(r => new ResultViewModel(r)).ToList();
|
var newResults = newRawResults.Select(r => new ResultViewModel(r)).ToList();
|
||||||
vm.Results.Update(newResults);
|
vm.Results.Update(newResults);
|
||||||
vm.SelectedResult = vm.Results[0];
|
vm.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ namespace Wox
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lbResults_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.AddedItems.Count > 0 && e.AddedItems[0] != null)
|
if (e.AddedItems.Count > 0 && e.AddedItems[0] != null)
|
||||||
{
|
{
|
||||||
@@ -33,5 +34,9 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnMouseEnter(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
((ListBoxItem) sender).IsSelected = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,30 +167,33 @@ namespace Wox.ViewModel
|
|||||||
Process.Start("http://doc.getwox.com");
|
Process.Start("http://doc.getwox.com");
|
||||||
});
|
});
|
||||||
|
|
||||||
OpenResultCommand = new RelayCommand(o =>
|
OpenResultCommand = new RelayCommand(index =>
|
||||||
{
|
{
|
||||||
var results = ContextMenuVisibility.IsVisible() ? ContextMenu : Results;
|
var results = ContextMenuVisibility.IsVisible() ? ContextMenu : Results;
|
||||||
|
|
||||||
if (o != null)
|
if (index != null)
|
||||||
{
|
{
|
||||||
var index = int.Parse(o.ToString());
|
results.SelectedIndex = int.Parse(index.ToString());
|
||||||
results.SelectResult(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = results.SelectedResult.RawResult;
|
var result = results.SelectedItem?.RawResult;
|
||||||
bool hideWindow = result.Action(new ActionContext
|
if (result != null) // SelectedItem returns null if selection is empty.
|
||||||
{
|
{
|
||||||
SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
|
bool hideWindow = result.Action(new ActionContext
|
||||||
});
|
{
|
||||||
if (hideWindow)
|
SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
|
||||||
{
|
});
|
||||||
MainWindowVisibility = Visibility.Collapsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ContextMenuVisibility.IsVisible())
|
if (hideWindow)
|
||||||
{
|
{
|
||||||
_userSelectedRecord.Add(result);
|
MainWindowVisibility = Visibility.Collapsed;
|
||||||
_queryHistory.Add(result.OriginQuery.RawQuery);
|
}
|
||||||
|
|
||||||
|
if (!ContextMenuVisibility.IsVisible())
|
||||||
|
{
|
||||||
|
_userSelectedRecord.Add(result);
|
||||||
|
_queryHistory.Add(result.OriginQuery.RawQuery);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -198,19 +201,23 @@ namespace Wox.ViewModel
|
|||||||
{
|
{
|
||||||
if (!ContextMenuVisibility.IsVisible())
|
if (!ContextMenuVisibility.IsVisible())
|
||||||
{
|
{
|
||||||
var result = Results.SelectedResult.RawResult;
|
var result = Results.SelectedItem?.RawResult;
|
||||||
var id = result.PluginID;
|
|
||||||
|
|
||||||
var menus = PluginManager.GetContextMenusForPlugin(result);
|
if (result != null) // SelectedItem returns null if selection is empty.
|
||||||
menus.Add(ContextMenuTopMost(result));
|
|
||||||
menus.Add(ContextMenuPluginInfo(id));
|
|
||||||
|
|
||||||
ContextMenu.Clear();
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
{
|
||||||
ContextMenu.AddResults(menus, id);
|
var id = result.PluginID;
|
||||||
}, _updateToken);
|
|
||||||
ContextMenuVisibility = Visibility.Visible;
|
var menus = PluginManager.GetContextMenusForPlugin(result);
|
||||||
|
menus.Add(ContextMenuTopMost(result));
|
||||||
|
menus.Add(ContextMenuPluginInfo(id));
|
||||||
|
|
||||||
|
ContextMenu.Clear();
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
ContextMenu.AddResults(menus, id);
|
||||||
|
}, _updateToken);
|
||||||
|
ContextMenuVisibility = Visibility.Visible;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
using Wox.Core.UserSettings;
|
using Wox.Core.UserSettings;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.Storage;
|
|
||||||
|
|
||||||
namespace Wox.ViewModel
|
namespace Wox.ViewModel
|
||||||
{
|
{
|
||||||
@@ -17,7 +15,7 @@ namespace Wox.ViewModel
|
|||||||
{
|
{
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
|
|
||||||
private ResultViewModel _selectedResult;
|
private int _selectedIndex;
|
||||||
public ResultCollection Results { get; }
|
public ResultCollection Results { get; }
|
||||||
private Thickness _margin;
|
private Thickness _margin;
|
||||||
|
|
||||||
@@ -38,35 +36,17 @@ namespace Wox.ViewModel
|
|||||||
|
|
||||||
public int MaxHeight => _settings.MaxResultsToShow * 50;
|
public int MaxHeight => _settings.MaxResultsToShow * 50;
|
||||||
|
|
||||||
public ResultViewModel SelectedResult
|
public int SelectedIndex
|
||||||
{
|
{
|
||||||
get
|
get { return _selectedIndex; }
|
||||||
{
|
|
||||||
return _selectedResult;
|
|
||||||
}
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value != null)
|
_selectedIndex = value;
|
||||||
{
|
|
||||||
if (_selectedResult != null)
|
|
||||||
{
|
|
||||||
_selectedResult.IsSelected = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_selectedResult = value;
|
|
||||||
|
|
||||||
if (_selectedResult != null)
|
|
||||||
{
|
|
||||||
_selectedResult.IsSelected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
OnPropertyChanged();
|
OnPropertyChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResultViewModel SelectedItem { get; set; }
|
||||||
public Thickness Margin
|
public Thickness Margin
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -98,76 +78,44 @@ namespace Wox.ViewModel
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int NewIndex(int i)
|
||||||
|
{
|
||||||
|
var n = Results.Count;
|
||||||
|
if (n > 0)
|
||||||
|
{
|
||||||
|
i = (n + i) % n;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// SelectedIndex returns -1 if selection is empty.
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
|
||||||
public void SelectResult(int index)
|
|
||||||
{
|
|
||||||
if (index <= Results.Count - 1)
|
|
||||||
{
|
|
||||||
SelectedResult = Results[index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SelectResult(ResultViewModel result)
|
|
||||||
{
|
|
||||||
int i = Results.IndexOf(result);
|
|
||||||
SelectResult(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SelectNextResult()
|
public void SelectNextResult()
|
||||||
{
|
{
|
||||||
if (Results.Count > 0 && SelectedResult != null)
|
SelectedIndex = NewIndex(SelectedIndex + 1);
|
||||||
{
|
|
||||||
var index = Results.IndexOf(SelectedResult);
|
|
||||||
if (index == Results.Count - 1)
|
|
||||||
{
|
|
||||||
index = -1;
|
|
||||||
}
|
|
||||||
SelectedResult = Results.ElementAt(index + 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectPrevResult()
|
public void SelectPrevResult()
|
||||||
{
|
{
|
||||||
if (Results.Count > 0 && SelectedResult != null)
|
SelectedIndex = NewIndex(SelectedIndex - 1);
|
||||||
{
|
|
||||||
var index = Results.IndexOf(SelectedResult);
|
|
||||||
if (index == 0)
|
|
||||||
{
|
|
||||||
index = Results.Count;
|
|
||||||
}
|
|
||||||
SelectedResult = Results.ElementAt(index - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectNextPage()
|
public void SelectNextPage()
|
||||||
{
|
{
|
||||||
if (Results.Count > 0 && SelectedResult != null)
|
SelectedIndex = NewIndex(SelectedIndex + _settings.MaxResultsToShow);
|
||||||
{
|
|
||||||
var index = Results.IndexOf(SelectedResult);
|
|
||||||
index += 5;
|
|
||||||
if (index > Results.Count - 1)
|
|
||||||
{
|
|
||||||
index = Results.Count - 1;
|
|
||||||
}
|
|
||||||
SelectedResult = Results.ElementAt(index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectPrevPage()
|
public void SelectPrevPage()
|
||||||
{
|
{
|
||||||
if (Results.Count > 0 && SelectedResult != null)
|
SelectedIndex = NewIndex(SelectedIndex - _settings.MaxResultsToShow);
|
||||||
{
|
|
||||||
var index = Results.IndexOf(SelectedResult);
|
|
||||||
index -= 5;
|
|
||||||
if (index < 0)
|
|
||||||
{
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
SelectedResult = Results.ElementAt(index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
@@ -239,7 +187,7 @@ namespace Wox.ViewModel
|
|||||||
if (Results.Count > 0)
|
if (Results.Count > 0)
|
||||||
{
|
{
|
||||||
Margin = new Thickness { Top = 8 };
|
Margin = new Thickness { Top = 8 };
|
||||||
SelectedResult = Results[0];
|
SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -314,6 +262,8 @@ namespace Wox.ViewModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ResultViewModel this[int selectedIndex] => Results[selectedIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user