summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorsr55 <[email protected]>2015-03-14 17:34:12 +0000
committersr55 <[email protected]>2015-03-14 17:34:12 +0000
commitabcbdbca5fc445a4eac9024a41d803cd4e62f9ab (patch)
tree90df520abab7c3fc0848a98b082081ec665fdaa3 /win
parent0b14b5646566aa90026466dd7c4b3430dec7c093 (diff)
WinGui: Fixed the temp Property Changed Base Impl.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6987 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
-rw-r--r--win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj2
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/Execute.cs136
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/Interfaces/INotifyPropertyChangedEx.cs37
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs92
-rw-r--r--win/CS/HandBrakeWPF/Services/PrePostActionService.cs2
-rw-r--r--win/CS/HandBrakeWPF/Services/QueueProcessor.cs1
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs1
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs2
8 files changed, 244 insertions, 29 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
index a507cfdc8..e84331529 100644
--- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
+++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
@@ -190,7 +190,9 @@
<Compile Include="Services\Scan\EventArgs\ScanProgressEventArgs.cs" />
<Compile Include="Utilities\Converters.cs" />
<Compile Include="Utilities\EnumHelper.cs" />
+ <Compile Include="Utilities\Execute.cs" />
<Compile Include="Utilities\ExtensionMethods.cs" />
+ <Compile Include="Utilities\Interfaces\INotifyPropertyChangedEx.cs" />
<Compile Include="Utilities\PropertyChangedBase.cs" />
<Compile Include="Utilities\SystemInfo.cs" />
<Compile Include="Utilities\VersionHelper.cs" />
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/Execute.cs b/win/CS/HandBrake.ApplicationServices/Utilities/Execute.cs
new file mode 100644
index 000000000..7f5889891
--- /dev/null
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/Execute.cs
@@ -0,0 +1,136 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright company="HandBrake Project (http://handbrake.fr)" file="Execute.cs">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Enables easy marshalling of code to the UI thread.
+// Borrowed from Caliburn Micro.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Utilities
+{
+ using System;
+ using System.ComponentModel;
+ using System.Diagnostics;
+ using System.Threading.Tasks;
+ using System.Windows;
+ using System.Windows.Threading;
+
+ /// <summary>
+ /// Enables easy marshalling of code to the UI thread.
+ /// </summary>
+ public static class Execute
+ {
+ private static System.Action<System.Action> executor = (System.Action<System.Action>)(action => action());
+ private static Dispatcher dispatcher;
+ private static bool? inDesignMode;
+
+ /// <summary>
+ /// Indicates whether or not the framework is in design-time mode.
+ /// </summary>
+ public static bool InDesignMode
+ {
+ get
+ {
+ if (!Execute.inDesignMode.HasValue)
+ {
+ Execute.inDesignMode = new bool?((bool)DependencyPropertyDescriptor.FromProperty(DesignerProperties.IsInDesignModeProperty, typeof(FrameworkElement)).Metadata.DefaultValue);
+ if (!Execute.inDesignMode.GetValueOrDefault(false) && Process.GetCurrentProcess().ProcessName.StartsWith("devenv", StringComparison.Ordinal))
+ Execute.inDesignMode = new bool?(true);
+ }
+ return Execute.inDesignMode.GetValueOrDefault(false);
+ }
+ }
+
+ /// <summary>
+ /// Initializes the framework using the current dispatcher.
+ /// </summary>
+ public static void InitializeWithDispatcher()
+ {
+ Execute.dispatcher = Dispatcher.CurrentDispatcher;
+ Execute.executor = (System.Action<System.Action>)null;
+ }
+
+ /// <summary>
+ /// Resets the executor to use a non-dispatcher-based action executor.
+ /// </summary>
+ public static void ResetWithoutDispatcher()
+ {
+ executor = (System.Action<System.Action>)(action => action());
+ dispatcher = (Dispatcher)null;
+ }
+
+ /// <summary>
+ /// Sets a custom UI thread marshaller.
+ /// </summary>
+ /// <param name="marshaller">The marshaller.</param>
+ [Obsolete]
+ public static void SetUIThreadMarshaller(System.Action<System.Action> marshaller)
+ {
+ Execute.executor = marshaller;
+ Execute.dispatcher = (Dispatcher)null;
+ }
+
+ private static void ValidateDispatcher()
+ {
+ if (Execute.dispatcher == null)
+ throw new InvalidOperationException("Not initialized with dispatcher.");
+ }
+
+ /// <summary>
+ /// Executes the action on the UI thread asynchronously.
+ /// </summary>
+ /// <param name="action">The action to execute.</param>
+ public static void BeginOnUIThread(this System.Action action)
+ {
+ Execute.ValidateDispatcher();
+ Execute.dispatcher.BeginInvoke((Delegate)action);
+ }
+
+ /// <summary>
+ /// Executes the action on the UI thread asynchronously.
+ /// </summary>
+ /// <param name="action">The action to execute.</param>
+ public static Task OnUIThreadAsync(this System.Action action)
+ {
+ Execute.ValidateDispatcher();
+ TaskCompletionSource<object> taskSource = new TaskCompletionSource<object>();
+ System.Action action1 = (System.Action)(() =>
+ {
+ try
+ {
+ action();
+ taskSource.SetResult((object)null);
+ }
+ catch (Exception ex)
+ {
+ taskSource.SetException(ex);
+ }
+ });
+ Execute.dispatcher.BeginInvoke((Delegate)action1);
+ return (Task)taskSource.Task;
+ }
+
+ private static bool CheckAccess()
+ {
+ if (Execute.dispatcher != null)
+ return Execute.dispatcher.CheckAccess();
+ return true;
+ }
+
+ /// <summary>
+ /// Executes the action on the UI thread.
+ /// </summary>
+ /// <param name="action">The action to execute.</param>
+ public static void OnUIThread(this System.Action action)
+ {
+ if (Execute.executor != null)
+ Execute.executor(action);
+ else if (Execute.CheckAccess())
+ action();
+ else
+ Execute.OnUIThreadAsync(action).Wait();
+ }
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/Interfaces/INotifyPropertyChangedEx.cs b/win/CS/HandBrake.ApplicationServices/Utilities/Interfaces/INotifyPropertyChangedEx.cs
new file mode 100644
index 000000000..add37626b
--- /dev/null
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/Interfaces/INotifyPropertyChangedEx.cs
@@ -0,0 +1,37 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="INotifyPropertyChangedEx.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Extends <see cref="T:System.ComponentModel.INotifyPropertyChanged" /> such that the change event can be raised by external parties.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Utilities.Interfaces
+{
+ using System.ComponentModel;
+
+ /// <summary>
+ /// Extends <see cref="T:System.ComponentModel.INotifyPropertyChanged"/> such that the change event can be raised by external parties.
+ /// </summary>
+ public interface INotifyPropertyChangedEx : INotifyPropertyChanged
+ {
+ /// <summary>
+ /// Enables/Disables property change notification.
+ /// </summary>
+ bool IsNotifying { get; set; }
+
+ /// <summary>
+ /// Notifies subscribers of the property change.
+ /// </summary>
+ /// <param name="propertyName">
+ /// Name of the property.
+ /// </param>
+ void NotifyOfPropertyChange(string propertyName);
+
+ /// <summary>
+ /// Raises a change notification indicating that all bindings should be refreshed.
+ /// </summary>
+ void Refresh();
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs b/win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs
index 9809def57..b5de5dd22 100644
--- a/win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/PropertyChangedBase.cs
@@ -1,10 +1,10 @@
// --------------------------------------------------------------------------------------------------------------------
-// <copyright file="PropertyChangedBase.cs" company="HandBrake Project (http://handbrake.fr)">
+// <copyright company="HandBrake Project (http://handbrake.fr)" file="PropertyChangedBase.cs">
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
// A base class that implements the infrastructure for property change notification and automatically performs UI thread marshalling.
-// This class is a modified version of the caliburn micro
+// Borrowed from Caliburn Micro
// </summary>
// --------------------------------------------------------------------------------------------------------------------
@@ -15,72 +15,106 @@ namespace HandBrake.ApplicationServices.Utilities
using System.Linq.Expressions;
using System.Runtime.Serialization;
+ using HandBrake.ApplicationServices.Utilities.Interfaces;
+
/// <summary>
- /// Property Changed Base implimentation.
+ /// A base class that implements the infrastructure for property change notification and automatically performs UI thread marshalling.
/// </summary>
- [DataContract]
- public class PropertyChangedBase : INotifyPropertyChanged
+ [Serializable]
+ public class PropertyChangedBase : INotifyPropertyChangedEx, INotifyPropertyChanged
{
+ [NonSerialized]
+ private bool isNotifying;
+
/// <summary>
- /// Creates an instance of <see cref = "PropertyChangedBase" />.
+ /// Enables/Disables property change notification.
/// </summary>
- public PropertyChangedBase()
+ [Browsable(false)]
+ public bool IsNotifying
{
- IsNotifying = true;
+ get
+ {
+ return this.isNotifying;
+ }
+ set
+ {
+ this.isNotifying = value;
+ }
}
/// <summary>
/// Occurs when a property value changes.
/// </summary>
- public event PropertyChangedEventHandler PropertyChanged = delegate { };
+ public event PropertyChangedEventHandler PropertyChanged = (param0, param1) => { };
/// <summary>
- /// Enables/Disables property change notification.
+ /// Creates an instance of <see cref="T:HandBrake.ApplicationServices.Utilities.PropertyChangedBase"/>.
/// </summary>
- public bool IsNotifying { get; set; }
+ public PropertyChangedBase()
+ {
+ this.IsNotifying = true;
+ }
/// <summary>
/// Raises a change notification indicating that all bindings should be refreshed.
/// </summary>
- public virtual void Refresh()
+ public void Refresh()
{
- NotifyOfPropertyChange(string.Empty);
+ this.NotifyOfPropertyChange(string.Empty);
}
/// <summary>
/// Notifies subscribers of the property change.
/// </summary>
- /// <param name = "propertyName">Name of the property.</param>
- public virtual void NotifyOfPropertyChange(string propertyName = null)
+ /// <param name="propertyName">Name of the property.</param>
+ public virtual void NotifyOfPropertyChange(string propertyName)
{
- if (IsNotifying)
- {
- OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
- }
+ if (!this.IsNotifying)
+ return;
+ Execute.OnUIThread((System.Action)(() => this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName))));
}
/// <summary>
/// Notifies subscribers of the property change.
/// </summary>
- /// <typeparam name = "TProperty">The type of the property.</typeparam>
- /// <param name = "property">The property expression.</param>
+ /// <typeparam name="TProperty">The type of the property.</typeparam><param name="property">The property expression.</param>
public void NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>> property)
{
- NotifyOfPropertyChange(property.GetMemberInfo().Name);
+ this.NotifyOfPropertyChange(ExtensionMethods.GetMemberInfo((Expression)property).Name);
}
/// <summary>
- /// Raises the <see cref="PropertyChanged" /> event directly.
+ /// Raises the <see cref="E:PropertyChanged"/> event directly.
/// </summary>
- /// <param name="e">The <see cref="PropertyChangedEventArgs"/> instance containing the event data.</param>
+ /// <param name="e">The <see cref="T:System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
protected void OnPropertyChanged(PropertyChangedEventArgs e)
{
- var handler = PropertyChanged;
- if (handler != null)
- {
- handler(this, e);
- }
+ PropertyChangedEventHandler changedEventHandler = this.PropertyChanged;
+ if (changedEventHandler == null)
+ return;
+ changedEventHandler((object)this, e);
+ }
+
+ /// <summary>
+ /// Called when the object is deserialized.
+ /// </summary>
+ /// <param name="c">The streaming context.</param>
+ [OnDeserialized]
+ public void OnDeserialized(StreamingContext c)
+ {
+ this.IsNotifying = true;
+ }
+
+ /// <summary>
+ /// Used to indicate whether or not the IsNotifying property is serialized to Xml.
+ /// </summary>
+ /// <returns>
+ /// Whether or not to serialize the IsNotifying property. The default is false.
+ /// </returns>
+ public virtual bool ShouldSerializeIsNotifying()
+ {
+ return false;
}
}
}
diff --git a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
index b8501b999..5bb8ca0ad 100644
--- a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
+++ b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
@@ -22,6 +22,8 @@ namespace HandBrakeWPF.Services
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.ViewModels.Interfaces;
+ using Execute = Caliburn.Micro.Execute;
+
/// <summary>
/// The when done service.
/// </summary>
diff --git a/win/CS/HandBrakeWPF/Services/QueueProcessor.cs b/win/CS/HandBrakeWPF/Services/QueueProcessor.cs
index a6dfe83c4..0507f7307 100644
--- a/win/CS/HandBrakeWPF/Services/QueueProcessor.cs
+++ b/win/CS/HandBrakeWPF/Services/QueueProcessor.cs
@@ -24,6 +24,7 @@ namespace HandBrakeWPF.Services
using HandBrake.ApplicationServices.Services.Encode.Interfaces;
using HandBrake.ApplicationServices.Utilities;
+ using Execute = Caliburn.Micro.Execute;
using IQueueProcessor = HandBrakeWPF.Services.Interfaces.IQueueProcessor;
using QueueCompletedEventArgs = HandBrakeWPF.EventArgs.QueueCompletedEventArgs;
using QueueProgressEventArgs = HandBrakeWPF.EventArgs.QueueProgressEventArgs;
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
index 88aa0c9e9..c35d6d7de 100644
--- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -52,6 +52,7 @@ namespace HandBrakeWPF.ViewModels
using Ookii.Dialogs.Wpf;
+ using Execute = Caliburn.Micro.Execute;
using IQueueProcessor = HandBrakeWPF.Services.Interfaces.IQueueProcessor;
/// <summary>
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
index 31841a335..2e73657cb 100644
--- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
@@ -28,6 +28,8 @@ namespace HandBrakeWPF.ViewModels
using Ookii.Dialogs.Wpf;
+ using Execute = Caliburn.Micro.Execute;
+
/// <summary>
/// The Options View Model
/// </summary>