Databinding for hotkey tab

part of #660
This commit is contained in:
bao-qian 2016-05-22 20:50:06 +01:00
parent 2256183422
commit cb56b98222
7 changed files with 66 additions and 68 deletions

View File

@ -1,7 +1,9 @@
using System;
using PropertyChanged;
namespace Wox.Core.UserSettings
{
[ImplementPropertyChanged]
public class CustomPluginHotkey
{
public string Hotkey { get; set; }

View File

@ -1,10 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using PropertyChanged;
using Wox.Core.Plugin;
using Wox.Plugin;
namespace Wox.Core.UserSettings
{
[ImplementPropertyChanged]
public class PluginsSettings
{
public string PythonDirectory { get; set; }

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using Newtonsoft.Json;
using PropertyChanged;
@ -31,7 +32,7 @@ namespace Wox.Core.UserSettings
// Order defaults to 0 or -1, so 1 will let this property appear last
[JsonProperty(Order = 1)]
public PluginsSettings PluginSettings { get; set; } = new PluginsSettings();
public List<CustomPluginHotkey> CustomPluginHotkeys { get; set; } = new List<CustomPluginHotkey>();
public ObservableCollection<CustomPluginHotkey> CustomPluginHotkeys { get; set; } = new ObservableCollection<CustomPluginHotkey>();
[Obsolete]
public double Opacity { get; set; } = 1;

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using NHotkey;
@ -41,7 +42,7 @@ namespace Wox
if (_settings.CustomPluginHotkeys == null)
{
_settings.CustomPluginHotkeys = new List<CustomPluginHotkey>();
_settings.CustomPluginHotkeys = new ObservableCollection<CustomPluginHotkey>();
}
var pluginHotkey = new CustomPluginHotkey
@ -78,7 +79,6 @@ namespace Wox
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
}
_settingWidow.ReloadCustomPluginHotkeyView();
Close();
}

View File

@ -3,6 +3,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wox="clr-namespace:Wox"
xmlns:s="clr-namespace:Wox.Core.UserSettings;assembly=Wox.Core"
xmlns:vm="clr-namespace:Wox.ViewModel"
x:Class="Wox.SettingWindow"
mc:Ignorable="d"
@ -237,56 +238,51 @@
</ComboBox>
</StackPanel>
</StackPanel>
</Grid>
</Grid>
</TabItem>
<TabItem Header="{DynamicResource hotkey}" Selector.Selected="OnHotkeyTabSelected">
<TabItem Header="{DynamicResource hotkey}">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition />
<RowDefinition Height="50" />
<RowDefinition Height="35" />
<RowDefinition Height="20"/>
<RowDefinition Height="400"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center">
<StackPanel Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center" Height="24" Margin="0,4,0,3">
<TextBlock VerticalAlignment="Center" Margin="0 0 10 0" Text="{DynamicResource woxHotkey}" />
<wox:HotkeyControl x:Name="HotkeyControl" />
<wox:HotkeyControl x:Name="HotkeyControl" HotkeyChanged="OnHotkeyChanged" Loaded="OnHotkeyControlLoaded" />
</StackPanel>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center" Grid.Row="0" Margin="0 0 10 0"
Text="{DynamicResource customQueryHotkey}" />
<ListView x:Name="CustomHotkies" Margin="0 5 0 0" Grid.Row="1">
<TextBlock VerticalAlignment="Center" Grid.Row="1" Margin="0,3,10,2"
Text="{DynamicResource customQueryHotkey}"/>
<ListView ItemsSource="{Binding Settings.CustomPluginHotkeys}"
SelectedItem="{Binding SelectedCustomPluginHotkey}"
Margin="0 5 0 0" Grid.Row="2">
<ListView.View>
<GridView>
<GridViewColumn Header="{DynamicResource hotkey}" Width="180">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Hotkey}" />
<DataTemplate DataType="s:CustomPluginHotkey">
<TextBlock Text="{Binding Hotkey}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="{DynamicResource actionKeywords}" Width="500">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ActionKeywords}" />
<DataTemplate DataType="s:CustomPluginHotkey">
<TextBlock Text="{Binding ActionKeyword}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
<StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Click="BtnDeleteCustomHotkey_OnClick" Width="100"
<StackPanel Grid.Row="3" HorizontalAlignment="Right" VerticalAlignment="Bottom" Orientation="Horizontal" Height="40" Width="360">
<Button Click="OnDeleteCustomHotkeyClick" Width="100"
Margin="10" Content="{DynamicResource delete}" />
<Button Click="BtnEditCustomHotkey_OnClick" Width="100" Margin="10"
<Button Click="OnnEditCustomHotkeyClick" Width="100" Margin="10"
Content="{DynamicResource edit}" />
<Button Click="BtnAddCustomeHotkey_OnClick" Width="100" Margin="10"
<Button Click="OnAddCustomeHotkeyClick" Width="100" Margin="10"
Content="{DynamicResource add}" />
</StackPanel>
</Grid>

View File

@ -154,13 +154,18 @@ namespace Wox
#region Hotkey
void ctlHotkey_OnHotkeyChanged(object sender, EventArgs e)
private void OnHotkeyControlLoaded(object sender, RoutedEventArgs e)
{
HotkeyControl.SetHotkey(_viewModel.Settings.Hotkey, false);
}
void OnHotkeyChanged(object sender, EventArgs e)
{
if (HotkeyControl.CurrentHotkeyAvailable)
{
SetHotkey(HotkeyControl.CurrentHotkey, delegate
{
if (!System.Windows.Application.Current.MainWindow.IsVisible)
if (!Application.Current.MainWindow.IsVisible)
{
_api.ShowApp();
}
@ -197,16 +202,9 @@ namespace Wox
}
}
public void OnHotkeyTabSelected(object sender, RoutedEventArgs e)
private void OnDeleteCustomHotkeyClick(object sender, RoutedEventArgs e)
{
HotkeyControl.HotkeyChanged += ctlHotkey_OnHotkeyChanged;
HotkeyControl.SetHotkey(_settings.Hotkey, false);
CustomHotkies.ItemsSource = _settings.CustomPluginHotkeys;
}
private void BtnDeleteCustomHotkey_OnClick(object sender, RoutedEventArgs e)
{
CustomPluginHotkey item = CustomHotkies.SelectedItem as CustomPluginHotkey;
var item = _viewModel.SelectedCustomPluginHotkey;
if (item == null)
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
@ -221,14 +219,13 @@ namespace Wox
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
_settings.CustomPluginHotkeys.Remove(item);
CustomHotkies.Items.Refresh();
RemoveHotkey(item.Hotkey);
}
}
private void BtnEditCustomHotkey_OnClick(object sender, RoutedEventArgs e)
private void OnnEditCustomHotkeyClick(object sender, RoutedEventArgs e)
{
CustomPluginHotkey item = CustomHotkies.SelectedItem as CustomPluginHotkey;
var item = _viewModel.SelectedCustomPluginHotkey;
if (item != null)
{
CustomQueryHotkeySetting window = new CustomQueryHotkeySetting(this, _settings);
@ -241,16 +238,11 @@ namespace Wox
}
}
private void BtnAddCustomeHotkey_OnClick(object sender, RoutedEventArgs e)
private void OnAddCustomeHotkeyClick(object sender, RoutedEventArgs e)
{
new CustomQueryHotkeySetting(this, _settings).ShowDialog();
}
public void ReloadCustomPluginHotkeyView()
{
CustomHotkies.Items.Refresh();
}
#endregion
#region Theme
@ -433,5 +425,6 @@ namespace Wox
e.Handled = true;
}
}
}

View File

@ -276,6 +276,10 @@ namespace Wox.ViewModel
}
#endregion
#region hotkey
public CustomPluginHotkey SelectedCustomPluginHotkey {get;set;}
#endregion
public SettingWindowViewModel()
{