diff --git a/install/CitizenMatt.PreviewTab.nuspec b/install/CitizenMatt.PreviewTab.nuspec index 2b8308e..cd40c90 100644 --- a/install/CitizenMatt.PreviewTab.nuspec +++ b/install/CitizenMatt.PreviewTab.nuspec @@ -3,18 +3,18 @@ CitizenMatt.PreviewTab Preview Tab Behaviour for ReSharper 10 - 1.4.1 + 1.5.0 Matt Ellis Matt Ellis Open files in Visual Studio's preview tab - • Support for ReSharper 10 + • Support for ReSharper 2016.1 https://github.com/citizenmatt/resharper-preview-tab https://raw.github.com/citizenmatt/resharper-preview-tab/master/license.txt https://raw.github.com/citizenmatt/resharper-preview-tab/master/icon.png Copyright 2014-2015 Matt Ellis false - + resharper preview previewtab editor visualstudio diff --git a/src/resharper-preview-tab/PreviewTabEditorManager.cs b/src/resharper-preview-tab/PreviewTabEditorManager.cs index d0cf284..97c695f 100644 --- a/src/resharper-preview-tab/PreviewTabEditorManager.cs +++ b/src/resharper-preview-tab/PreviewTabEditorManager.cs @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2015 Matt Ellis + * Copyright 2012 - 2016 Matt Ellis * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ using System; +using System.Threading; using JetBrains.DataFlow; using JetBrains.DocumentManagers; using JetBrains.DocumentModel.Transactions; @@ -24,7 +25,6 @@ using JetBrains.TextControl; using JetBrains.Threading; using JetBrains.UI.WindowManagement; -using JetBrains.Util; using JetBrains.VsIntegration.DocumentModel; using JetBrains.VsIntegration.ProjectDocuments.Projects.Builder; using Microsoft.VisualStudio.Shell.Interop; @@ -32,17 +32,11 @@ namespace CitizenMatt.ReSharper.PreviewTab { [SolutionComponent] - public class PreviewTabEditorManager : EditorManagerSinceVs11, IEditorManager + public class PreviewTabEditorManager : EditorManagerSinceVs11 { - // Defined in Microsoft.VisualStudio.Shell.11.0.dll, but this saves us having to reference it - // (and reference Microsoft.VisualStudio.Shell.12.0.dll for VS2013) - private static readonly Guid NavigationReason = new Guid("8d57e022-9e44-4efd-8e4e-230284f86376"); - - private readonly IVsUIShellOpenDocument3 vsUiShellOpenDocument3; private readonly DocumentTransactionManager documentTransactionManager; private readonly IThreading threading; - private IVsNewDocumentStateContext newDocumentStateContext; - private Action doEnablePreviewTab; + private long previewTabRequests; public PreviewTabEditorManager(Lifetime lifetime, ProjectModelSynchronizer projectModelSynchronizer, IVsUIShellOpenDocument vsUiShellOpenDocument, @@ -52,14 +46,12 @@ public PreviewTabEditorManager(Lifetime lifetime, ProjectModelSynchronizer proje DocumentTransactionManager documentTransactionManager, IThreading threading) : base(lifetime, projectModelSynchronizer, vsUiShellOpenDocument, vsDocumentManagerSynchronization, - textControlManager, frameFocusHelper, documentManager) + textControlManager, frameFocusHelper, documentManager) { - // ReSharper disable once SuspiciousTypeConversion.Global - vsUiShellOpenDocument3 = vsUiShellOpenDocument as IVsUIShellOpenDocument3; this.documentTransactionManager = documentTransactionManager; this.threading = threading; - doEnablePreviewTab = DoEnablePreviewTab; + previewTabRequests = 0; } protected override bool OpenInProvisionTab(TabOptions tabOptions) @@ -67,27 +59,19 @@ protected override bool OpenInProvisionTab(TabOptions tabOptions) // If we're in a transaction, something's happening (e.g. opening files for a refactoring) // so don't force the preview tab. If we're not in a transaction, that just means someone's // navigating to the file, so yes, force the preview tab - return !IsInDocumentTransaction; - } - - protected override void EnablePreviewTab() - { - doEnablePreviewTab(); + return !HasCurrentPreviewTabRequest && !IsInDocumentTransaction; } - ITextControl IEditorManager.OpenProjectFile(IProjectFile projectFile, bool activate, FileView fileViewPrimary, - TabOptions tabOptions) + protected override IDisposable WithEnabledPreviewTab(bool openInPreviewTab) { - var textControl = base.OpenProjectFile(projectFile, activate, fileViewPrimary, tabOptions); - RestoreNewDocumentStateContext(); - return textControl; + var disposable = base.WithEnabledPreviewTab(openInPreviewTab); + AddPreviewTabRequest(); + return disposable; } - ITextControl IEditorManager.OpenFile(FileSystemPath fileName, bool activate, TabOptions tabOptions) + private bool HasCurrentPreviewTabRequest { - var textControl = base.OpenFile(fileName, activate, tabOptions); - RestoreNewDocumentStateContext(); - return textControl; + get { return Interlocked.Read(ref previewTabRequests) != 0; } } private bool IsInDocumentTransaction @@ -95,42 +79,13 @@ private bool IsInDocumentTransaction get { return documentTransactionManager.CurrentTransaction != null; } } - private void DoEnablePreviewTab() - { - if (vsUiShellOpenDocument3 == null) - return; - - SetNewDocumentState(); - DisablePreviewTabUntilIdle(); - } - - private void SetNewDocumentState() - { - newDocumentStateContext = vsUiShellOpenDocument3.SetNewDocumentState((uint) __VSNEWDOCUMENTSTATE.NDS_Provisional, - NavigationReason); - } - - // We can only open one document in the preview tab. Subsequent documents need to use normal tabs. - // Enqueue a re-enable command with the UI - once the UI is executing again, the preview tab has - // been shown, and it's fair game again. This fixes issues with multi-file templates - private void DisablePreviewTabUntilIdle() - { - doEnablePreviewTab = () => { }; - threading.ReentrancyGuard.Queue("reset preview tab", () => doEnablePreviewTab = DoEnablePreviewTab); - } - - // Make sure we restore the document state, or VS will try to open subsequent documents in the preview - // tab (ideally, this should happen in VsEditorManager, which calls SetNewDocumentState). Incidentally, - // I don't know why we don't need to reset this when using to open files one at a time, but we do need - // to use it when we try to open multiple files at once (e.g. multi-file templates). Perhaps the GC - // kicks in and frees the early object for us? Or there's a timeout? - private void RestoreNewDocumentStateContext() + // Prevent opening multiple documents in the preview tab at the same time. Wait until the UI has + // a chance to catch up. This fixes an issue with multi-file templates that want to open multiple + // documents at the same time - and we get an exception. + private void AddPreviewTabRequest() { - if (newDocumentStateContext != null) - { - newDocumentStateContext.Restore(); - newDocumentStateContext = null; - } + Interlocked.Increment(ref previewTabRequests); + threading.ReentrancyGuard.Queue("reset preview tab", () => Interlocked.Decrement(ref previewTabRequests)); } } } \ No newline at end of file diff --git a/src/resharper-preview-tab/Properties/AssemblyInfo.cs b/src/resharper-preview-tab/Properties/AssemblyInfo.cs index 228d22d..f850867 100644 --- a/src/resharper-preview-tab/Properties/AssemblyInfo.cs +++ b/src/resharper-preview-tab/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ /* + * Copyright 2012 - 2016 Matt Ellis * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +24,8 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Matt Ellis")] [assembly: AssemblyProduct("resharper-preview-tab")] -[assembly: AssemblyCopyright("Copyright © Matt Ellis, 2014")] +[assembly: AssemblyCopyright("Copyright © Matt Ellis, 2016")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -[assembly: AssemblyVersion("1.4.*")] +[assembly: AssemblyVersion("1.5.0.0")] diff --git a/src/resharper-preview-tab/ZoneMarker.cs b/src/resharper-preview-tab/ZoneMarker.cs index a6001b6..2702b58 100644 --- a/src/resharper-preview-tab/ZoneMarker.cs +++ b/src/resharper-preview-tab/ZoneMarker.cs @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2015 Matt Ellis + * Copyright 2012 - 2016 Matt Ellis * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/resharper-preview-tab/packages.config b/src/resharper-preview-tab/packages.config index 1a065e8..863d8cb 100644 --- a/src/resharper-preview-tab/packages.config +++ b/src/resharper-preview-tab/packages.config @@ -2,43 +2,45 @@ + - - - + + + - - - - - + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + - + - + @@ -56,8 +58,10 @@ - - + + + + \ No newline at end of file diff --git a/src/resharper-preview-tab/resharper-preview-tab.csproj b/src/resharper-preview-tab/resharper-preview-tab.csproj index 5db2c08..d5c993c 100644 --- a/src/resharper-preview-tab/resharper-preview-tab.csproj +++ b/src/resharper-preview-tab/resharper-preview-tab.csproj @@ -13,7 +13,7 @@ v4.5 512 - db7f1a6e + 0170b7fe true @@ -39,6 +39,10 @@ ..\packages\Antlr2.Runtime.2.7.7.02\lib\antlr.runtime.dll True + + ..\packages\AsyncBridge.JetBrains.0.1.1.0\lib\net40-Client\AsyncBridge.dll + True + ..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll True @@ -67,8 +71,8 @@ ..\packages\DotNetZip.Reduced.1.9.1.8\lib\net20\Ionic.Zip.Reduced.dll True - - ..\packages\JetBrains.Annotations.10.0.0\lib\net20\JetBrains.Annotations.dll + + ..\packages\JetBrains.Annotations.10.1.4\lib\net20\JetBrains.Annotations.dll True @@ -137,8 +141,8 @@ ..\packages\Newtonsoft35.Json.7.0.1\lib\net35\Newtonsoft.Json.dll True - - ..\packages\NuGet.Core.2.8.6\lib\net40-Client\NuGet.Core.dll + + ..\packages\NuGet.Core.2.10.1\lib\net40-Client\NuGet.Core.dll True @@ -175,6 +179,18 @@ ..\packages\JetBrains.Platform.Lib.WpfContrib.2.0.20150225.0\lib\Net\WpfContrib.dll True + + ..\packages\xunit.JetBrains.1.9.2\lib\net20\xunit.dll + True + + + ..\packages\xunit.abstractions.JetBrains.2.0.0\lib\net35\xunit.abstractions.dll + True + + + ..\packages\xunit.runner.utility.JetBrains.2.2.0\lib\net35\xunit.runner.utility.desktop.dll + True + @@ -185,47 +201,47 @@ - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + \ No newline at end of file