Add web search feature & some UI changes.

This commit is contained in:
qianlifeng
2014-01-29 22:44:57 +08:00
parent 9f22a6d26d
commit fa3ae62254
31 changed files with 340 additions and 86 deletions

View File

@@ -1,85 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading;
using Newtonsoft.Json;
using Wox.Models;
namespace Wox.Helper
{
[Serializable]
public class CommonStorage
{
private static string configPath = Directory.GetCurrentDirectory() + "\\data.json";
private static object locker = new object();
private static CommonStorage storage;
public UserSetting UserSetting { get; set; }
public UserSelectedRecords UserSelectedRecords { get; set; }
private CommonStorage()
{
//default setting
UserSetting = new UserSetting
{
Theme = "Default",
ReplaceWinR = true,
WebSearches = new List<WebSearch>()
};
UserSelectedRecords = new UserSelectedRecords();
}
public void Save()
{
lock (locker)
{
//json is a good choise, readable and flexiable
string json = JsonConvert.SerializeObject(storage, Formatting.Indented);
File.WriteAllText(configPath, json);
}
}
private static void Load()
{
if (!File.Exists(configPath))
{
File.Create(configPath).Close();
}
string json = File.ReadAllText(configPath);
if (!string.IsNullOrEmpty(json))
{
try
{
storage = JsonConvert.DeserializeObject<CommonStorage>(json);
}
catch (Exception e)
{
//on-op, keep default storage
}
}
}
public static CommonStorage Instance
{
get
{
if (storage == null)
{
lock (locker)
{
if (storage == null)
{
storage = new CommonStorage();
Load();
}
}
}
return storage;
}
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -12,6 +12,7 @@ using System.Windows.Input;
using System.Windows.Media.Animation;
using Wox.Commands;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Plugin;
using Wox.PluginLoader;
using Application = System.Windows.Application;

View File

@@ -1,47 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using Wox.Helper;
using Wox.Plugin;
namespace Wox.Models
{
[Serializable]
public class UserSelectedRecords
{
private static int hasAddedCount = 0;
public Dictionary<string,int> Records = new Dictionary<string, int>();
public void Add(Result result)
{
if (Records.ContainsKey(result.ToString()))
{
Records[result.ToString()] += 1;
}
else
{
Records.Add(result.ToString(), 1);
}
//hasAddedCount++;
//if (hasAddedCount == 10)
//{
// hasAddedCount = 0;
//}
CommonStorage.Instance.Save();
}
public int GetSelectedCount(Result result)
{
if (Records.ContainsKey(result.ToString()))
{
return Records[result.ToString()];
}
return 0;
}
}
}

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.Models
{
public class UserSetting
{
public string Theme { get; set; }
public bool ReplaceWinR { get; set; }
public List<WebSearch> WebSearches { get; set; }
}
}

View File

@@ -1,10 +0,0 @@
namespace Wox.Models
{
public class WebSearch
{
public string Keyword { get; set; }
public string IconPath { get; set; }
public string Website { get; set; }
public string Enabled { get; set; }
}
}

View File

@@ -15,12 +15,12 @@
<ColumnDefinition Width="73.064"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image x:Name="imgIco" Width="32" Height="32" HorizontalAlignment="Left" ></Image>
<Grid HorizontalAlignment="Stretch" Margin="5 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
<Grid Margin="5 0 0 0" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="23"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition x:Name="SubTitleRowDefinition"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Style="{DynamicResource ItemTitleStyle}" x:Name="tbTitle">Title</TextBlock>
<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>
<DockPanel Grid.Column="2" Visibility="Hidden">

View File

@@ -9,6 +9,7 @@ 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;
@@ -16,7 +17,6 @@ namespace Wox
{
public partial class ResultItem : UserControl, INotifyPropertyChanged
{
private bool selected;
public Result Result { get; private set; }
@@ -55,6 +55,10 @@ namespace Wox
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))
{

View File

@@ -26,28 +26,28 @@
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
</Grid.RowDefinitions>
<ListView Grid.Row="0">
<ListView x:Name="webSearchView" Grid.Row="0">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Keyword" Width="180">
<GridViewColumn Header="ActionWord" Width="180">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=OPERATOR}"></TextBlock>
<TextBlock Text="{Binding Path=ActionWord}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Website" Width="500">
<GridViewColumn Header="Url" Width="500">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=DDATE}"></TextBlock>
<TextBlock Text="{Binding Path=Url}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Enable" Width="50" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=CONTENT}"></TextBlock>
<TextBlock Text="{Binding Path=Enabled}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Wox.Helper;
using Wox.Infrastructure;
namespace Wox
{
@@ -38,6 +39,7 @@ namespace Wox
themeComboBox.SelectedItem = CommonStorage.Instance.UserSetting.Theme;
cbReplaceWinR.IsChecked = CommonStorage.Instance.UserSetting.ReplaceWinR;
webSearchView.ItemsSource = CommonStorage.Instance.UserSetting.WebSearches;
}
private List<string> LoadAvailableThemes()

View File

@@ -4,45 +4,30 @@
Icon="Images\app.png"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Title="WebSearchSetting" Height="400" Width="674.766">
Title="WebSearchSetting" Height="300" Width="674.766">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Search URL:</TextBlock>
<TextBox Margin="10" Grid.Row="0" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
<TextBlock Margin="10 0 10 0" Foreground="Gray" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1" TextWrapping="Wrap" HorizontalAlignment="Left">Perform a search on a website and copy the result URL. Replace your search term with {query} in curly brackets</TextBlock>
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Title:</TextBlock>
<TextBox x:Name="tbTitle" Margin="10" Grid.Row="0" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
<TextBlock Margin="10" FontSize="14" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Title:</TextBlock>
<TextBox Margin="10" Grid.Row="2" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
<TextBlock Margin="10 0 10 0" Foreground="Gray" VerticalAlignment="Top" Grid.Row="3" Grid.Column="1" TextWrapping="Wrap" HorizontalAlignment="Left">What to show in the Wox. The search query is automatically appended for clarity.</TextBlock>
<TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">URL:</TextBlock>
<TextBox x:Name="tbUrl" Margin="10" Grid.Row="1" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
<TextBlock Margin="10" FontSize="14" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Keyword:</TextBlock>
<TextBox Margin="10" Grid.Row="4" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
<TextBlock Margin="10 0 10 0" Foreground="Gray" VerticalAlignment="Top" Grid.Row="5" Grid.Column="1" TextWrapping="Wrap" HorizontalAlignment="Left">What you type to use this shortcut.</TextBlock>
<TextBlock Margin="10" FontSize="14" Grid.Row="6" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Validation:</TextBlock>
<StackPanel Grid.Row="6" Grid.Column="1" VerticalAlignment="Center" Orientation="Horizontal">
<TextBox Margin="10" Width="400" HorizontalAlignment="Left"></TextBox>
<Button x:Name="btnValidation" Width="60" Height="24">Test</Button>
</StackPanel>
<TextBlock Margin="10 0 10 0" Foreground="Gray" VerticalAlignment="Top" Grid.Row="7" Grid.Column="1" TextWrapping="Wrap" HorizontalAlignment="Left">Type some text and click test to check it works.</TextBlock>
<TextBlock Margin="10" FontSize="14" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">ActionWord:</TextBlock>
<TextBox x:Name="tbActionword" Margin="10" Grid.Row="2" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="8" Grid.Column="1">
<Button x:Name="btnCancel" Click="BtnCancel_OnClick" Margin="10 0 10 0" Width="80" Height="25">Cancel</Button>
<Button Margin="10 0 10 0" Width="80" Height="25">Add</Button>
<Button x:Name="btnAdd" Margin="10 0 10 0" Width="80" Height="25" Click="btnAdd_OnClick">Add</Button>
</StackPanel>
</Grid>
</Window>

View File

@@ -10,6 +10,9 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.UserSettings;
namespace Wox
{
@@ -24,5 +27,45 @@ namespace Wox
{
Close();
}
private void btnAdd_OnClick(object sender, RoutedEventArgs e)
{
string title = tbTitle.Text;
if (string.IsNullOrEmpty(title))
{
MessageBox.Show("Please input Title field");
return;
}
string url = tbUrl.Text;
if (string.IsNullOrEmpty(url))
{
MessageBox.Show("Please input URL field");
return;
}
string action = tbActionword.Text;
if (string.IsNullOrEmpty(action))
{
MessageBox.Show("Please input ActionWord field");
return;
}
if (CommonStorage.Instance.UserSetting.WebSearches.Exists(o => o.ActionWord == action))
{
MessageBox.Show("ActionWord has existed, please input a new one.");
return;
}
CommonStorage.Instance.UserSetting.WebSearches.Add(new WebSearch()
{
ActionWord = action,
Enabled = true,
IconPath="",
Url = url,
Title = title
});
CommonStorage.Instance.Save();
MessageBox.Show("Succeed!");
}
}
}

View File

@@ -119,9 +119,6 @@
<Compile Include="Helper\DwmDropShadow.cs" />
<Compile Include="Helper\KeyboardHook.cs" />
<Compile Include="Helper\Log.cs" />
<Compile Include="Helper\CommonStorage.cs" />
<Compile Include="Models\UserSetting.cs" />
<Compile Include="Models\WebSearch.cs" />
<Compile Include="Helper\WoxException.cs" />
<Compile Include="Helper\KeyboardListener.cs" />
<Compile Include="Msg.xaml.cs">
@@ -140,7 +137,6 @@
<Compile Include="ResultItem.xaml.cs">
<DependentUpon>ResultItem.xaml</DependentUpon>
</Compile>
<Compile Include="Models\UserSelectedRecords.cs" />
<Compile Include="SettingWindow.xaml.cs">
<DependentUpon>SettingWindow.xaml</DependentUpon>
</Compile>
@@ -221,6 +217,10 @@
<Project>{097b4ac0-74e9-4c58-bcf8-c69746ec8271}</Project>
<Name>Python.Runtime</Name>
</ProjectReference>
<ProjectReference Include="..\Wox.Infrastructure\Wox.Infrastructure.csproj">
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
<Name>Wox.Infrastructure</Name>
</ProjectReference>
<ProjectReference Include="..\Wox.Plugin.System\Wox.Plugin.System.csproj">
<Project>{69ce0206-cb41-453d-88af-df86092ef9b8}</Project>
<Name>Wox.Plugin.System</Name>
@@ -277,7 +277,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup>
<PostBuildEvent>xcopy /Y $(ProjectDir)Images\*.* $(TargetDir)Images\
<PostBuildEvent>xcopy /Y /S $(ProjectDir)Images\*.* $(TargetDir)Images\
xcopy /Y $(ProjectDir)app.ico $(TargetDir)
xcopy /Y $(ProjectDir)Themes\*.* $(TargetDir)Themes\</PostBuildEvent>
</PropertyGroup>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 361 KiB

After

Width:  |  Height:  |  Size: 361 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 11 KiB