More data bindings (MaxResultsToShow + ActivatedTimes)

This commit is contained in:
bao-qian
2016-05-23 22:08:13 +01:00
parent 762de84f34
commit e1131dcf3d
15 changed files with 62 additions and 52 deletions

View File

@@ -38,6 +38,7 @@
<Private>True</Private>
</Reference>
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,10 +1,8 @@
using System;
using PropertyChanged;
using Wox.Plugin;
namespace Wox.Core.UserSettings
{
[ImplementPropertyChanged]
public class CustomPluginHotkey
public class CustomPluginHotkey : BaseModel
{
public string Hotkey { get; set; }
public string ActionKeyword { get; set; }

View File

@@ -1,13 +1,9 @@
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 class PluginsSettings : BaseModel
{
public string PythonDirectory { get; set; }
public Dictionary<string, Plugin> Plugins { get; set; } = new Dictionary<string, Plugin>();

View File

@@ -3,12 +3,11 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using Newtonsoft.Json;
using PropertyChanged;
using Wox.Plugin;
namespace Wox.Core.UserSettings
{
[ImplementPropertyChanged]
public class Settings
public class Settings : BaseModel
{
public string Hotkey { get; set; } = "Alt + Space";
public string Language { get; set; } = "en";
@@ -55,6 +54,7 @@ namespace Wox.Core.UserSettings
public int ProxyPort { get; set; }
public string ProxyUserName { get; set; }
public string ProxyPassword { get; set; }
}
[Obsolete]

View File

@@ -3,7 +3,6 @@ using System.IO;
using NLog;
using NLog.Config;
using NLog.Targets;
using Wox.Infrastructure.Exception;
namespace Wox.Infrastructure.Logger
{

19
Wox.Plugin/BaseModel.cs Normal file
View File

@@ -0,0 +1,19 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
using PropertyChanged;
namespace Wox.Plugin
{
[ImplementPropertyChanged]
public class BaseModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -5,9 +5,8 @@ using Newtonsoft.Json;
using PropertyChanged;
namespace Wox.Plugin
{
[ImplementPropertyChanged]
[JsonObject(MemberSerialization.OptOut)]
public class PluginMetadata
public class PluginMetadata : BaseModel
{
private string _pluginDirectory;
public string ID { get; set; }

View File

@@ -60,6 +60,7 @@
<Link>Properties\SolutionAssemblyInfo.cs</Link>
</Compile>
<Compile Include="AllowedLanguage.cs" />
<Compile Include="BaseModel.cs" />
<Compile Include="EventHandler.cs" />
<Compile Include="Feature.cs" />
<Compile Include="Features\IContextMenu.cs" />

View File

@@ -349,7 +349,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" Text="{Binding ActivatedTimes}" />
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" Text="{Binding ActivatedTimes, Mode=OneWay}" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="{DynamicResource website}" />
<TextBlock Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left">
<Hyperlink NavigateUri="{Binding Github, Mode=OneWay}" RequestNavigate="OnRequestNavigate">

View File

@@ -1,21 +1,9 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
namespace Wox.ViewModel
{
public class BaseViewModel : INotifyPropertyChanged
{
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
//todo rename file
public class RelayCommand : ICommand
{

View File

@@ -20,7 +20,7 @@ using Wox.Storage;
namespace Wox.ViewModel
{
public class MainViewModel : BaseViewModel, ISavable
public class MainViewModel : BaseModel, ISavable
{
#region Private Fields
@@ -231,15 +231,15 @@ namespace Wox.ViewModel
}
private void InitializeResultListBox()
{
Results = new ResultsViewModel(_settings.MaxResultsToShow);
{
Results = new ResultsViewModel(_settings);
ResultListBoxVisibility = Visibility.Collapsed;
}
private void InitializeContextMenu()
{
ContextMenu = new ResultsViewModel(_settings.MaxResultsToShow);
ContextMenu = new ResultsViewModel(_settings);
ContextMenuVisibility = Visibility.Collapsed;
}

View File

@@ -1,14 +1,12 @@
using System.Windows;
using System.Windows.Media;
using Wox.Plugin;
using PropertyChanged;
using Wox.Core.Resource;
using Wox.Infrastructure.Image;
namespace Wox.ViewModel
{
[ImplementPropertyChanged]
public class PluginViewModel
public class PluginViewModel : BaseModel
{
public PluginPair PluginPair { get; set; }
public PluginMetadata Metadata { get; set; }

View File

@@ -7,7 +7,7 @@ using Wox.Plugin;
namespace Wox.ViewModel
{
public class ResultViewModel : BaseViewModel
public class ResultViewModel : BaseModel
{
#region Private Fields

View File

@@ -6,10 +6,11 @@ using System.Windows;
using System.Windows.Data;
using Wox.Core.UserSettings;
using Wox.Plugin;
using PropertyChanged;
namespace Wox.ViewModel
{
public class ResultsViewModel : BaseViewModel
public class ResultsViewModel : BaseModel
{
#region Private Fields
@@ -19,16 +20,24 @@ namespace Wox.ViewModel
private readonly object _addResultsLock = new object();
private readonly object _collectionLock = new object();
public int MaxResults = 6;
private readonly Settings _settings;
private int MaxResults => _settings?.MaxResultsToShow ?? 6;
public ResultsViewModel()
{
Results = new ResultCollection();
BindingOperations.EnableCollectionSynchronization(Results, _collectionLock);
}
public ResultsViewModel(int maxResults) : this()
public ResultsViewModel(Settings settings) : this()
{
MaxResults = maxResults;
_settings = settings;
_settings.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(_settings.MaxResultsToShow))
{
OnPropertyChanged(nameof(MaxHeight));
}
};
}
#endregion

View File

@@ -4,10 +4,8 @@ using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using PropertyChanged;
using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Core.UserSettings;
@@ -15,12 +13,10 @@ using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using static System.String;
namespace Wox.ViewModel
{
[ImplementPropertyChanged]
public class SettingWindowViewModel
public class SettingWindowViewModel : BaseModel
{
private readonly JsonStrorage<Settings> _storage;
@@ -28,6 +24,13 @@ namespace Wox.ViewModel
{
_storage = new JsonStrorage<Settings>();
Settings = _storage.Load();
Settings.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(Settings.ActivateTimes))
{
OnPropertyChanged(nameof(ActivatedTimes));
}
};
}
public Settings Settings { get; set; }
@@ -63,7 +66,7 @@ namespace Wox.ViewModel
var d2 = settings[b.Metadata.ID].Disabled;
if (d1 == d2)
{
return Compare(a.Metadata.Name, b.Metadata.Name, StringComparison.CurrentCulture);
return string.Compare(a.Metadata.Name, b.Metadata.Name, StringComparison.CurrentCulture);
}
else
{
@@ -145,7 +148,7 @@ namespace Wox.ViewModel
bitmap.BeginInit();
bitmap.StreamSource = memStream;
bitmap.EndInit();
var brush = new ImageBrush(bitmap) {Stretch = Stretch.UniformToFill};
var brush = new ImageBrush(bitmap) { Stretch = Stretch.UniformToFill };
return brush;
}
else
@@ -194,7 +197,7 @@ namespace Wox.ViewModel
SubTitle = "Please star it!"
}
};
var vm = new ResultsViewModel(6);
var vm = new ResultsViewModel();
vm.AddResults(results, "PREVIEW");
return vm;
}
@@ -303,15 +306,14 @@ namespace Wox.ViewModel
public static string Github => Constant.Github;
public static string ReleaseNotes => @"https://github.com/Wox-launcher/Wox/releases/latest";
public static string Version => Constant.Version;
public string ActivatedTimes
=> Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
public string ActivatedTimes => string.Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
private string _newVersionTips;
public string NewVersionTips
{
get { return _newVersionTips; }
set
{
_newVersionTips = Format(_translater.GetTranslation("newVersionTips"), value);
_newVersionTips = string.Format(_translater.GetTranslation("newVersionTips"), value);
NewVersionTipsVisibility = Visibility.Visible;
}
}