fix some small UI issue

This commit is contained in:
qianlifeng 2014-02-20 21:46:23 +08:00
parent 5a3669cbe7
commit 18ee6ecf80
8 changed files with 63 additions and 177 deletions

View File

@ -28,6 +28,8 @@ namespace Wox
private NotifyIcon notifyIcon;
Storyboard progressBarStoryboard = new Storyboard();
private bool queryHasReturn = false;
private static object locker = new object();
private static List<Result> waitShowResultList = new List<Result>();
private KeyboardListener keyboardListener = new KeyboardListener();
private bool WinRStroked = false;
@ -51,12 +53,7 @@ namespace Wox
SetTheme(CommonStorage.Instance.UserSetting.Theme = "Default");
}
this.Closing += MainWindow_Closing;
}
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
Plugins.Init();
}
private void WakeupApp()
@ -203,8 +200,7 @@ namespace Wox
Left = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2;
Top = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 3;
WakeupApp();
Plugins.Init();
//WakeupApp();
keyboardListener.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
}
@ -293,13 +289,22 @@ namespace Wox
{
if (o.AutoAjustScore) o.Score += CommonStorage.Instance.UserSelectedRecords.GetSelectedCount(o);
});
resultCtrl.Dispatcher.Invoke(new Action(() =>
lock(locker)
{
waitShowResultList.AddRange(list);
}
Dispatcher.DelayInvoke("ShowResult", k => resultCtrl.Dispatcher.Invoke(new Action(() =>
{
var t1 = Environment.TickCount;
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).ToList();
List<Result> l = waitShowResultList.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).ToList();
waitShowResultList.Clear();
resultCtrl.AddResults(l);
Debug.WriteLine("Time:" + (Environment.TickCount - t1) + " Count:" + l.Count);
}));
})), TimeSpan.FromMilliseconds(50));
}
}
@ -327,6 +332,7 @@ namespace Wox
public void CloseApp()
{
notifyIcon.Visible = false;
Close();
Environment.Exit(0);
}

View File

@ -1,26 +0,0 @@
<UserControl x:Class="Wox.ResultItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignWidth="400"
x:Name="resultItemControl"
Style="{DynamicResource ItemStyle}"
Height="50">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5" Cursor="Hand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32"></ColumnDefinition>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image x:Name="imgIco" Width="32" Height="32" HorizontalAlignment="Left" ></Image>
<Grid Margin="5 0 5 0" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition x:Name="SubTitleRowDefinition"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Style="{DynamicResource ItemTitleStyle}" VerticalAlignment="Center" x:Name="tbTitle">Title</TextBlock>
<TextBlock Style="{DynamicResource ItemSubTitleStyle}" Grid.Row="1" x:Name="tbSubTitle">sub title</TextBlock>
</Grid>
</Grid>
</UserControl>

View File

@ -1,105 +0,0 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Wox.Annotations;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Plugin;
using Brush = System.Windows.Media.Brush;
namespace Wox
{
public partial class ResultItem : UserControl, INotifyPropertyChanged
{
private bool selected;
public Result Result { get; private set; }
public bool Selected
{
get
{
return selected;
}
set
{
selected = value;
OnPropertyChanged("Selected");
}
}
public ResultItem(Result result)
{
InitializeComponent();
Result = result;
tbTitle.Text = result.Title;
tbSubTitle.Text = result.SubTitle;
if (string.IsNullOrEmpty(result.SubTitle))
{
SubTitleRowDefinition.Height = new GridLength(0);
}
string path = string.Empty;
if (!string.IsNullOrEmpty(result.IcoPath) && result.IcoPath.Contains(":\\") && File.Exists(result.IcoPath))
{
path = result.IcoPath;
}
else if (!string.IsNullOrEmpty(result.IcoPath) && File.Exists(result.PluginDirectory + result.IcoPath))
{
path = result.PluginDirectory + result.IcoPath;
}
if (!string.IsNullOrEmpty(path))
{
if (path.ToLower().EndsWith(".exe") || path.ToLower().EndsWith(".lnk"))
{
imgIco.Source = GetIcon(path);
}
else
{
imgIco.Source = new BitmapImage(new Uri(path));
}
}
AddHandler(MouseLeftButtonUpEvent, new RoutedEventHandler((o, e) =>
{
if (Result.Action != null)
Result.Action(new ActionContext()
{
SpecialKeyState = new KeyboardListener().CheckModifiers()
});
CommonStorage.Instance.UserSelectedRecords.Add(result);
if (!result.DontHideWoxAfterSelect)
{
App.Window.HideApp();
}
e.Handled = true;
}));
}
private static ImageSource GetIcon(string fileName)
{
Icon icon = Icon.ExtractAssociatedIcon(fileName);
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
icon.Handle,
new Int32Rect(0, 0, icon.Width, icon.Height),
BitmapSizeOptions.FromEmptyOptions());
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@ -10,13 +10,13 @@
<wox:ImagePathConverter x:Key="ImagePathConverter"/>
</UserControl.Resources>
<Grid>
<ListBox x:Name="lbResults" ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Hidden" SelectionChanged ="lbResults_SelectionChanged" Focusable="False" KeyboardNavigation.DirectionalNavigation="Cycle" SelectionMode="Single" BorderBrush="Transparent" Background="Transparent" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling">
<Grid x:Name="gridContainer">
<ListBox x:Name="lbResults" Style="{DynamicResource listboxStyle}" SelectionChanged ="lbResults_SelectionChanged" Focusable="False" KeyboardNavigation.DirectionalNavigation="Cycle" SelectionMode="Single" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling">
<ListBox.Resources>
<!--SelectedItem with focus-->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#4F6180"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{DynamicResource ResultItemHighlightBackgroundColor}"/>
<!--SelectedItem without focus-->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#4F6180"/>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="{DynamicResource ResultItemHighlightBackgroundColor}"/>
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>

View File

@ -1,9 +1,8 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using Wox.Helper;
using Wox.Plugin;
using Point = System.Windows.Point;
namespace Wox
{
@ -23,6 +22,7 @@ namespace Wox
int position = GetInsertLocation(result.Score);
lbResults.Items.Insert(position, result);
}
gridContainer.Margin = lbResults.Items.Count > 0 ? new Thickness { Top = 8 } : new Thickness { Top = 0 };
lbResults.UpdateLayout();
SelectFirst();
}
@ -119,6 +119,7 @@ namespace Wox
public void Clear()
{
lbResults.Items.Clear();
gridContainer.Margin = new Thickness { Top = 0 };
}
private void lbResults_SelectionChanged(object sender, SelectionChangedEventArgs e)

View File

@ -33,13 +33,25 @@
<Style x:Key="ItemSubTitleStyle" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="#D9D9D4" />
</Style>
<Style x:Key="ItemStyle" TargetType="{x:Type UserControl}">
<Setter Property="Background" Value="Transparent" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Selected}" Value="true">
<Setter Property="Background" Value="#4F6180" />
</DataTrigger>
</Style.Triggers>
<Color x:Key="ResultItemHighlightBackgroundColor">#4F6180</Color>
<Style x:Key="listboxStyle" TargetType="{x:Type ListBox}">
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer Focusable="false" Template="{DynamicResource ScrollViewerControlTemplate}">
<StackPanel IsItemsHost="True" />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- ScrollViewer Style -->

View File

@ -23,32 +23,37 @@
<Setter Property="Stroke" Value="Blue"></Setter>
</Style>
<Color x:Key="ResultItemHighlightBackgroundColor">#543BFD</Color>
<!-- Item Style -->
<Style x:Key="ItemTitleStyle" TargetType="{x:Type TextBlock}" >
<Setter Property="Foreground" Value="#141411"></Setter>
<Setter Property="FontSize" Value="16"></Setter>
<Setter Property="FontWeight" Value="Medium"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=resultItemControl, Path=Selected}" Value="true">
<Setter Property="Foreground" Value="#F6F6FF"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="ItemSubTitleStyle" TargetType="{x:Type TextBlock}" >
<Setter Property="Foreground" Value="#B3B2B0"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=resultItemControl, Path=Selected}" Value="true">
<Setter Property="Foreground" Value="#F6F6FF"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="ItemStyle" TargetType="{x:Type UserControl}" >
<Setter Property="Background" Value="Transparent"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Selected}" Value="true">
<Setter Property="Background" Value="#543BFD"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="listboxStyle" TargetType="{x:Type ListBox}">
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer Focusable="false" Template="{DynamicResource ScrollViewerControlTemplate}">
<StackPanel IsItemsHost="True" />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- ScrollViewer Style -->

View File

@ -138,9 +138,6 @@
<Compile Include="ResultPanel.xaml.cs">
<DependentUpon>ResultPanel.xaml</DependentUpon>
</Compile>
<Compile Include="ResultItem.xaml.cs">
<DependentUpon>ResultItem.xaml</DependentUpon>
</Compile>
<Compile Include="SettingWindow.xaml.cs">
<DependentUpon>SettingWindow.xaml</DependentUpon>
</Compile>
@ -168,10 +165,6 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ResultItem.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SettingWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>