From 8e7455fc88a1d7904ebd399c17c56a07e4cc796c Mon Sep 17 00:00:00 2001 From: Kirill Osenkov Date: Wed, 5 Dec 2018 15:56:21 -0800 Subject: Update more files and bump version to 15.2.4-pre. --- .../Impl/Commanding/EditorCommandHandlerService.cs | 2 +- src/Text/Impl/EditorOperations/EditorOperations.cs | 1 + src/Text/Util/TextUIUtil/BaseProxyService.cs | 35 +++++++++++++++++++ .../TextUIUtil/DefaultUIThreadOperationExecutor.cs | 24 +++++++++---- .../Util/TextUIUtil/UIThreadOperationExecutor.cs | 39 ++++++++-------------- 5 files changed, 68 insertions(+), 33 deletions(-) create mode 100644 src/Text/Util/TextUIUtil/BaseProxyService.cs (limited to 'src/Text') diff --git a/src/Text/Impl/Commanding/EditorCommandHandlerService.cs b/src/Text/Impl/Commanding/EditorCommandHandlerService.cs index c9730e7..e057ea9 100644 --- a/src/Text/Impl/Commanding/EditorCommandHandlerService.cs +++ b/src/Text/Impl/Commanding/EditorCommandHandlerService.cs @@ -478,7 +478,7 @@ namespace Microsoft.VisualStudio.UI.Text.Commanding.Implementation public int CancelAfter => _state.IsExecutingTypingCommand ? - _textView.Options.GetOptionValue(DefaultOptions.MaximumTypingLatencyOptionId) : + _textView.Options.GetOptionValue("MaximumTypingLatency") : Timeout.Infinite; public bool ShouldCancel() diff --git a/src/Text/Impl/EditorOperations/EditorOperations.cs b/src/Text/Impl/EditorOperations/EditorOperations.cs index 4672260..4cd00e0 100644 --- a/src/Text/Impl/EditorOperations/EditorOperations.cs +++ b/src/Text/Impl/EditorOperations/EditorOperations.cs @@ -25,6 +25,7 @@ namespace Microsoft.VisualStudio.Text.Operations.Implementation using Microsoft.VisualStudio.Utilities; using Microsoft.VisualStudio.Text.Outlining; using Microsoft.VisualStudio.Text.Tagging; + using Microsoft.VisualStudio.Text.Utilities; #if WINDOWS using Microsoft.VisualStudio.Language.Intellisense.Utilities; #endif diff --git a/src/Text/Util/TextUIUtil/BaseProxyService.cs b/src/Text/Util/TextUIUtil/BaseProxyService.cs new file mode 100644 index 0000000..0062990 --- /dev/null +++ b/src/Text/Util/TextUIUtil/BaseProxyService.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.Composition; + +namespace Microsoft.VisualStudio.Utilities +{ + /// + /// A proxy service for exposing best implementation to the MEF composition. + /// + internal abstract class BaseProxyService where T : class + { + protected abstract IEnumerable> UnorderedImplementations { get; set; } + + private T bestImpl; + + protected virtual T BestImplementation + { + get + { + if (this.bestImpl == null) + { + var orderedImpls = Orderer.Order(UnorderedImplementations); + if (orderedImpls.Count == 0) + { + throw new ImportCardinalityMismatchException($"Expected to import at least one export of {typeof(T).FullName}, but got none."); + } + + this.bestImpl = orderedImpls[0].Value; + } + + return this.bestImpl; + } + } + } +} \ No newline at end of file diff --git a/src/Text/Util/TextUIUtil/DefaultUIThreadOperationExecutor.cs b/src/Text/Util/TextUIUtil/DefaultUIThreadOperationExecutor.cs index e022a1c..c6c349d 100644 --- a/src/Text/Util/TextUIUtil/DefaultUIThreadOperationExecutor.cs +++ b/src/Text/Util/TextUIUtil/DefaultUIThreadOperationExecutor.cs @@ -7,14 +7,24 @@ namespace Microsoft.VisualStudio.UI.Text.Commanding.Implementation [Name("default")] internal class DefaultUIThreadOperationExecutor : IUIThreadOperationExecutor { - public IUIThreadOperationContext BeginExecute(string title, string description, bool allowCancel, bool showProgress) + public IUIThreadOperationContext BeginExecute(string title, string defaultDescription, bool allowCancellation, bool showProgress) { - return new DefaultUIThreadOperationContext(allowCancel, description); + return BeginExecute(new UIThreadOperationExecutionOptions(title, defaultDescription, allowCancellation, showProgress)); } - public UIThreadOperationStatus Execute(string title, string description, bool allowCancel, bool showProgress, Action action) + public IUIThreadOperationContext BeginExecute(UIThreadOperationExecutionOptions executionOptions) { - var context = new DefaultUIThreadOperationContext(allowCancel, description); + return new DefaultUIThreadOperationContext(executionOptions.AllowCancellation, executionOptions.DefaultDescription); + } + + public UIThreadOperationStatus Execute(string title, string defaultDescription, bool allowCancellation, bool showProgress, Action action) + { + return Execute(new UIThreadOperationExecutionOptions(title, defaultDescription, allowCancellation, showProgress), action); + } + + public UIThreadOperationStatus Execute(UIThreadOperationExecutionOptions executionOptions, Action action) + { + var context = new DefaultUIThreadOperationContext(executionOptions.AllowCancellation, executionOptions.DefaultDescription); action(context); return UIThreadOperationStatus.Completed; } @@ -22,9 +32,9 @@ namespace Microsoft.VisualStudio.UI.Text.Commanding.Implementation internal class DefaultUIThreadOperationContext : AbstractUIThreadOperationContext { - public DefaultUIThreadOperationContext(bool allowCancellation, string description) - : base(allowCancellation, description) + public DefaultUIThreadOperationContext(bool allowCancellation, string defaultDescription) + : base(allowCancellation, defaultDescription) { } } -} +} \ No newline at end of file diff --git a/src/Text/Util/TextUIUtil/UIThreadOperationExecutor.cs b/src/Text/Util/TextUIUtil/UIThreadOperationExecutor.cs index e1a92bf..592c814 100644 --- a/src/Text/Util/TextUIUtil/UIThreadOperationExecutor.cs +++ b/src/Text/Util/TextUIUtil/UIThreadOperationExecutor.cs @@ -3,43 +3,32 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using Microsoft.VisualStudio.Utilities; -namespace Microsoft.VisualStudio.UI.Text.Commanding.Implementation +namespace Microsoft.VisualStudio.Text.Utilities { [Export(typeof(IUIThreadOperationExecutor))] - internal class UIThreadOperationExecutor : IUIThreadOperationExecutor + internal class UIThreadOperationExecutor : BaseProxyService, IUIThreadOperationExecutor { [ImportImplementations(typeof(IUIThreadOperationExecutor))] - private IEnumerable> _unorderedImplementations; + protected override IEnumerable> UnorderedImplementations { get; set; } - private IUIThreadOperationExecutor _bestImpl; - - private IUIThreadOperationExecutor BestImplementation + public IUIThreadOperationContext BeginExecute(string title, string defaultDescription, bool allowCancellation, bool showProgress) { - get - { - if (_bestImpl == null) - { - var orderedImpls = Orderer.Order(_unorderedImplementations); - if (orderedImpls.Count == 0) - { - throw new ImportCardinalityMismatchException($"Expected to import at least one export of {typeof(IUIThreadOperationExecutor).FullName}, but got none."); - } - - _bestImpl = orderedImpls[0].Value; - } + return BestImplementation.BeginExecute(title, defaultDescription, allowCancellation, showProgress); + } - return _bestImpl; - } + public IUIThreadOperationContext BeginExecute(UIThreadOperationExecutionOptions executionOptions) + { + return BestImplementation.BeginExecute(executionOptions); } - public IUIThreadOperationContext BeginExecute(string title, string description, bool allowCancel, bool showProgress) + public UIThreadOperationStatus Execute(string title, string defaultDescription, bool allowCancellation, bool showProgress, Action action) { - return BestImplementation.BeginExecute(title, description, allowCancel, showProgress); + return BestImplementation.Execute(title, defaultDescription, allowCancellation, showProgress, action); } - public UIThreadOperationStatus Execute(string title, string description, bool allowCancel, bool showProgress, Action action) + public UIThreadOperationStatus Execute(UIThreadOperationExecutionOptions executionOptions, Action action) { - return BestImplementation.Execute(title, description, allowCancel, showProgress, action); + return BestImplementation.Execute(executionOptions, action); } } -} +} \ No newline at end of file -- cgit v1.2.3