Skip to content

Commit

Permalink
Updated to ReSharper 2016.1
Browse files Browse the repository at this point in the history
  • Loading branch information
citizenmatt committed Apr 21, 2016
1 parent 58ac1fd commit bd3c305
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 136 deletions.
6 changes: 3 additions & 3 deletions install/CitizenMatt.PreviewTab.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
<metadata>
<id>CitizenMatt.PreviewTab</id>
<title>Preview Tab Behaviour for ReSharper 10</title>
<version>1.4.1</version>
<version>1.5.0</version>
<authors>Matt Ellis</authors>
<owners>Matt Ellis</owners>
<description>Open files in Visual Studio's preview tab</description>
<releaseNotes>&#8226; Support for ReSharper 10</releaseNotes>
<releaseNotes>&#8226; Support for ReSharper 2016.1</releaseNotes>
<projectUrl>https://github.com/citizenmatt/resharper-preview-tab</projectUrl>
<licenseUrl>https://raw.github.com/citizenmatt/resharper-preview-tab/master/license.txt</licenseUrl>
<iconUrl>https://raw.github.com/citizenmatt/resharper-preview-tab/master/icon.png</iconUrl>
<copyright>Copyright 2014-2015 Matt Ellis</copyright>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<dependencies>
<dependency id="Wave" version="[4.0]" />
<dependency id="Wave" version="[5.0]" />
</dependencies>
<tags>resharper preview previewtab editor visualstudio</tags>
</metadata>
Expand Down
83 changes: 19 additions & 64 deletions src/resharper-preview-tab/PreviewTabEditorManager.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,6 +15,7 @@
*/

using System;
using System.Threading;
using JetBrains.DataFlow;
using JetBrains.DocumentManagers;
using JetBrains.DocumentModel.Transactions;
Expand All @@ -24,25 +25,18 @@
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;

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,
Expand All @@ -52,85 +46,46 @@ 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)
{
// 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
{
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));
}
}
}
5 changes: 3 additions & 2 deletions src/resharper-preview-tab/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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")]
2 changes: 1 addition & 1 deletion src/resharper-preview-tab/ZoneMarker.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
54 changes: 29 additions & 25 deletions src/resharper-preview-tab/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,45 @@
<packages>
<package id="Antlr2.Runtime" version="2.7.7.02" targetFramework="net45" />
<package id="Antlr2.Tools" version="2.7.6.4" targetFramework="net45" />
<package id="AsyncBridge.JetBrains" version="0.1.1.0" targetFramework="net45" />
<package id="DotNetZip.Reduced" version="1.9.1.8" targetFramework="net45" />
<package id="JetBrains.Annotations" version="10.0.0" targetFramework="net45" />
<package id="JetBrains.Build.Platform.Tasks.ThemedIconsPacker" version="2.0.20150812.0" targetFramework="net45" developmentDependency="true" />
<package id="JetBrains.ExternalAnnotations" version="10.0.15" targetFramework="net45" />
<package id="JetBrains.Annotations" version="10.1.4" targetFramework="net45" />
<package id="JetBrains.Build.Platform.Tasks.ThemedIconsPacker" version="2.0.20151217.1" targetFramework="net45" developmentDependency="true" />
<package id="JetBrains.ExternalAnnotations" version="10.1.8" targetFramework="net45" />
<package id="JetBrains.Mono.Posix" version="0.1" targetFramework="net45" />
<package id="JetBrains.Platform.Core.Ide" version="104.0.20151101.164845" targetFramework="net45" />
<package id="JetBrains.Platform.Core.Shell" version="104.0.20151101.164331" targetFramework="net45" />
<package id="JetBrains.Platform.Core.Text" version="104.0.20151101.164845" targetFramework="net45" />
<package id="JetBrains.Platform.Installer" version="104.0.20151101.164845" targetFramework="net45" />
<package id="JetBrains.Platform.Interop.dotMemoryUnit.Interop" version="104.0.20151101.164845" targetFramework="net45" />
<package id="JetBrains.Platform.Core.Ide" version="105.0.20160414.153405" targetFramework="net45" />
<package id="JetBrains.Platform.Core.Shell" version="105.0.20160414.95726" targetFramework="net45" />
<package id="JetBrains.Platform.Core.Text" version="105.0.20160414.153405" targetFramework="net45" />
<package id="JetBrains.Platform.Installer" version="105.0.20160414.153405" targetFramework="net45" />
<package id="JetBrains.Platform.Interop.dotMemoryUnit.Interop" version="105.0.20160414.153405" targetFramework="net45" />
<package id="JetBrains.Platform.Lib.DevExpress" version="2.0.20150224.0" targetFramework="net45" />
<package id="JetBrains.Platform.Lib.Microsoft.Deployment.Compression.Cab" version="2.0.20140304.0" targetFramework="net45" />
<package id="JetBrains.Platform.Lib.Microsoft.Deployment.WindowsInstaller" version="2.0.20140821.0" targetFramework="net45" />
<package id="JetBrains.Platform.Lib.System.Windows.Interactivity" version="2.0.20140318.0" targetFramework="net45" />
<package id="JetBrains.Platform.Lib.VisualStudio.AnyVs.ShellInterop.PrivateBuild" version="2.0.20140304.0" targetFramework="net45" />
<package id="JetBrains.Platform.Lib.WpfContrib" version="2.0.20150225.0" targetFramework="net45" />
<package id="JetBrains.Platform.Symbols" version="104.0.20151101.164845" targetFramework="net45" />
<package id="JetBrains.Platform.Tests.Framework" version="104.0.20151101.164845" targetFramework="net45" />
<package id="JetBrains.Platform.VisualStudio" version="104.0.20151101.164845" targetFramework="net45" />
<package id="JetBrains.Psi.Features.Core" version="104.0.20151101.185700" targetFramework="net45" />
<package id="JetBrains.Psi.Features.Cpp.src" version="104.0.20151101.190744" targetFramework="net45" />
<package id="JetBrains.Psi.Features.SolutionBuilder" version="104.0.20151101.185700" targetFramework="net45" />
<package id="JetBrains.Psi.Features.src" version="104.0.20151101.185700" targetFramework="net45" />
<package id="JetBrains.Psi.Features.Tasks" version="104.0.20151101.185700" targetFramework="net45" />
<package id="JetBrains.Psi.Features.test.Framework" version="104.0.20151101.185700" targetFramework="net45" />
<package id="JetBrains.Psi.Features.UnitTesting" version="104.0.20151101.185700" targetFramework="net45" />
<package id="JetBrains.Psi.Features.VisualStudio" version="104.0.20151101.185700" targetFramework="net45" />
<package id="JetBrains.ReSharper.SDK" version="10.0.20151101.194233" targetFramework="net45" developmentDependency="true" />
<package id="JetBrains.ReSharper.SDK.Internal" version="104.0.20151101.194233" targetFramework="net45" />
<package id="JetBrains.Platform.Symbols" version="105.0.20160414.153405" targetFramework="net45" />
<package id="JetBrains.Platform.Tests.Framework" version="105.0.20160414.153405" targetFramework="net45" />
<package id="JetBrains.Platform.VisualStudio" version="105.0.20160414.153405" targetFramework="net45" />
<package id="JetBrains.Psi.Features.Core" version="105.0.20160414.153845" targetFramework="net45" />
<package id="JetBrains.Psi.Features.Cpp.Src" version="105.0.20160414.155000" targetFramework="net45" />
<package id="JetBrains.Psi.Features.SolutionBuilder" version="105.0.20160414.153845" targetFramework="net45" />
<package id="JetBrains.Psi.Features.src" version="105.0.20160414.153845" targetFramework="net45" />
<package id="JetBrains.Psi.Features.Tasks" version="105.0.20160414.153845" targetFramework="net45" />
<package id="JetBrains.Psi.Features.test.Framework" version="105.0.20160414.153845" targetFramework="net45" />
<package id="JetBrains.Psi.Features.UnitTesting" version="105.0.20160414.153845" targetFramework="net45" />
<package id="JetBrains.Psi.Features.VisualStudio" version="105.0.20160414.153845" targetFramework="net45" />
<package id="JetBrains.ReSharper.SDK" version="2016.1.20160414.161610" targetFramework="net45" developmentDependency="true" />
<package id="JetBrains.ReSharper.SDK.Internal" version="105.0.20160414.161610" targetFramework="net45" />
<package id="JetBrains.WinDbg.SymStore" version="10.0.10586.20151201" targetFramework="net45" developmentDependency="true" />
<package id="Microsoft.VC100.CRT.JetBrains" version="10.00.40219.2" targetFramework="net45" />
<package id="Microsoft.VC120.CRT.JetBrains" version="12.0.21005.2" targetFramework="net45" />
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net45" />
<package id="Newtonsoft35.Json" version="7.0.1" targetFramework="net45" />
<package id="NuGet.Core" version="2.8.6" targetFramework="net45" />
<package id="NuGet.Core" version="2.10.1" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnit.ReSharperRunner2" version="2.6.408" targetFramework="net45" />
<package id="NUnit.ReSharperRunner3" version="3.0.11" targetFramework="net45" />
<package id="NUnit.ReSharperRunner3" version="3.0.12" targetFramework="net45" />
<package id="NVelocity" version="1.0.3" targetFramework="net45" />
<package id="SharpZipLib.JetBrains.Stripped" version="0.86.20150204.1" targetFramework="net45" />
<package id="Sprache.JetBrains" version="2.0.0.44" targetFramework="net45" />
Expand All @@ -56,8 +58,10 @@
<package id="VSSDK.Shell.Interop.9" version="9.0.4" targetFramework="net45" />
<package id="VSSDK.TextManager.Interop" version="7.0.4" targetFramework="net45" />
<package id="VSSDK.TextManager.Interop.8" version="8.0.4" targetFramework="net45" />
<package id="Wave" version="4.0.0.0" targetFramework="net45" />
<package id="WinDbg.SymStore" version="8.1.20130822.1833" targetFramework="net45" developmentDependency="true" />
<package id="Wave" version="5.0.0.0" targetFramework="net45" />
<package id="Windows7APICodePack.JetBrains.Stripped" version="1.1.20150225.0" targetFramework="net45" />
<package id="xmlrpcnet" version="2.5.0" targetFramework="net45" />
<package id="xunit.abstractions.JetBrains" version="2.0.0" targetFramework="net45" />
<package id="xunit.JetBrains" version="1.9.2" targetFramework="net45" />
<package id="xunit.runner.utility.JetBrains" version="2.2.0" targetFramework="net45" />
</packages>
Loading

0 comments on commit bd3c305

Please sign in to comment.