├── VSTabPath
├── Key.snk
├── Resources
│ └── TabPathPackage.ico
├── Models
│ ├── ObservableModel.cs
│ ├── TabModel.cs
│ └── DisplayPathResolver.cs
├── source.extension.cs
├── VisualStudio.targets
├── VisualStudio.props
├── ViewModels
│ └── TabViewModel.cs
├── Properties
│ └── AssemblyInfo.cs
├── Views
│ └── DataTemplates.xaml
├── source.extension.vsixmanifest
├── TabPathViewElementFactory.cs
├── DelegatingViewElementFactory.cs
├── TabPathPackage.cs
├── TabTitleManager.cs
├── VSPackage.resx
└── VSTabPath.csproj
├── VSTabPath.Interop.Contracts
├── VSTabPath.Interop.Contracts.csproj
├── IDteInterop.cs
└── DteInteropResolver.cs
├── VSTabPath.sln.DotSettings
├── VSTabPath.Interop.X86
└── VSTabPath.Interop.X86.csproj
├── VSTabPath.Interop.X64
└── VSTabPath.Interop.X64.csproj
├── VSTabPath.Tests
├── Properties
│ └── AssemblyInfo.cs
├── VSTabPath.Tests.csproj
├── DisplayPathResolverTests_Solution.cs
└── DisplayPathResolverTests_NoSolution.cs
├── VSTabPath.Interop.Shared
├── VSTabPath.Interop.Shared.projitems
├── VSTabPath.Interop.Shared.shproj
└── DteInterop.cs
├── LICENSE
├── README.md
├── .gitattributes
├── VSTabPath.sln
└── .gitignore
/VSTabPath/Key.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DarkDaskin/VSTabPath/HEAD/VSTabPath/Key.snk
--------------------------------------------------------------------------------
/VSTabPath/Resources/TabPathPackage.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DarkDaskin/VSTabPath/HEAD/VSTabPath/Resources/TabPathPackage.ico
--------------------------------------------------------------------------------
/VSTabPath.Interop.Contracts/VSTabPath.Interop.Contracts.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net472
5 | True
6 | ..\VSTabPath\Key.snk
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/VSTabPath.Interop.Contracts/IDteInterop.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace VSTabPath.Interop.Contracts
4 | {
5 | public interface IDteInterop
6 | {
7 | string GetSolutionRootPath();
8 |
9 | event Action SolutionOpened;
10 | event Action SolutionRenamed;
11 | event Action SolutionClosed;
12 | }
13 | }
--------------------------------------------------------------------------------
/VSTabPath.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
--------------------------------------------------------------------------------
/VSTabPath/Models/ObservableModel.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using System.Runtime.CompilerServices;
3 | using JetBrains.Annotations;
4 |
5 | namespace VSTabPath.Models
6 | {
7 | public abstract class ObservableModel : INotifyPropertyChanged
8 | {
9 | public event PropertyChangedEventHandler PropertyChanged;
10 |
11 | [NotifyPropertyChangedInvocator]
12 | protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
13 | {
14 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/VSTabPath.Interop.X86/VSTabPath.Interop.X86.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net472
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/VSTabPath.Interop.X64/VSTabPath.Interop.X64.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net472
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/VSTabPath.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle("VSTabPath.Tests")]
6 | [assembly: AssemblyDescription("")]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany("")]
9 | [assembly: AssemblyProduct("VSTabPath.Tests")]
10 | [assembly: AssemblyCopyright("Copyright © 2019")]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: Guid("13611075-94b6-4ea9-b777-d56a83db16d6")]
17 |
18 | // [assembly: AssemblyVersion("1.0.*")]
19 | [assembly: AssemblyVersion("1.0.0.0")]
20 | [assembly: AssemblyFileVersion("1.0.0.0")]
21 |
--------------------------------------------------------------------------------
/VSTabPath.Interop.Shared/VSTabPath.Interop.Shared.projitems:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 | true
6 | 064a5ff7-b156-4165-9594-9867f5a5d382
7 |
8 |
9 | VSTabPath.Interop
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/VSTabPath/source.extension.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by VSIX Synchronizer
4 | //
5 | // ------------------------------------------------------------------------------
6 | namespace VSTabPath
7 | {
8 | internal sealed partial class Vsix
9 | {
10 | public const string Id = "VSTabPath.a8bf68de-eafb-40c2-bbb2-b8da07d67630";
11 | public const string Name = "TabPath";
12 | public const string Description = @"Shows file paths in tab titles.";
13 | public const string Language = "en-US";
14 | public const string Version = "1.3.0";
15 | public const string Author = "Dark Daskin";
16 | public const string Tags = "";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/VSTabPath.Interop.Contracts/DteInteropResolver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | namespace VSTabPath.Interop.Contracts
5 | {
6 | // Since VS 17.0, many interop types were moved to different assemblies, so code interacting with them
7 | // must have diferent references for different VS versions. Such code was moved to proxy assemblies.
8 | public static class DteInteropResolver
9 | {
10 | public static IDteInterop Interop { get; }
11 |
12 | static DteInteropResolver()
13 | {
14 | var assemblyName = Environment.Is64BitProcess ? "VSTabPath.Interop.X64" : "VSTabPath.Interop.X86";
15 | var assembly = Assembly.Load(assemblyName);
16 | var type = assembly.GetType("VSTabPath.Interop.DteInterop");
17 | Interop = (IDteInterop)Activator.CreateInstance(type);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/VSTabPath/VisualStudio.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | <_VisualStudioReference Include="@(Reference)" Condition="%(Reference->HasMetadata('IsVisualStudio')) == 'True'" />
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/VSTabPath.Interop.Shared/VSTabPath.Interop.Shared.shproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 064a5ff7-b156-4165-9594-9867f5a5d382
5 | 14.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Dark Daskin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/VSTabPath/VisualStudio.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 15.0
7 |
8 |
9 |
10 | <_VisualStudioVersionRange>[15.0,16.0)
11 | <_VisualStudioSdkVersion>15.0.26606
12 |
13 |
14 |
15 | <_VisualStudioVersionRange>[16.0,17.0)
16 | <_VisualStudioSdkVersion>16.0.28729
17 |
18 |
19 |
20 | <_VisualStudioVersionRange>[17.0,18.0)
21 | <_VisualStudioSdkVersion>17.0.32112.339
22 |
23 |
24 |
--------------------------------------------------------------------------------
/VSTabPath/ViewModels/TabViewModel.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using System.Windows;
3 | using Microsoft.VisualStudio.Platform.WindowManagement;
4 | using VSTabPath.Models;
5 |
6 | namespace VSTabPath.ViewModels
7 | {
8 | public class TabViewModel : ObservableModel
9 | {
10 | public WindowFrameTitle Title { get; }
11 | public DataTemplate TitleTemplate { get; }
12 | public TabModel Model { get; }
13 |
14 | public string DisplayPath => Model.DisplayPath;
15 |
16 | public bool IsPathVisible => DisplayPath != null;
17 |
18 | public TabViewModel(WindowFrameTitle title, DataTemplate titleTemplate, TabModel model)
19 | {
20 | Title = title;
21 | TitleTemplate = titleTemplate;
22 | Model = model;
23 | Model.PropertyChanged += OnModelPropertyChanged;
24 | }
25 |
26 | private void OnModelPropertyChanged(object sender, PropertyChangedEventArgs e)
27 | {
28 | if (e.PropertyName == nameof(TabModel.DisplayPath))
29 | {
30 | OnPropertyChanged(nameof(DisplayPath));
31 | OnPropertyChanged(nameof(IsPathVisible));
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/VSTabPath/Models/TabModel.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using JetBrains.Annotations;
3 |
4 | namespace VSTabPath.Models
5 | {
6 | public class TabModel : ObservableModel
7 | {
8 | private string _fullPath;
9 | private string _displayPath;
10 |
11 | public string FullPath
12 | {
13 | get => _fullPath;
14 | set
15 | {
16 | if (value == _fullPath) return;
17 | _fullPath = value;
18 | OnPropertyChanged();
19 | OnPropertyChanged(nameof(FileName));
20 | }
21 | }
22 |
23 | [CanBeNull]
24 | public string DisplayPath
25 | {
26 | get => _displayPath;
27 | set
28 | {
29 | if (value == _displayPath) return;
30 | _displayPath = value;
31 | OnPropertyChanged();
32 | }
33 | }
34 |
35 | public string DirectoryName => Path.GetDirectoryName(FullPath);
36 |
37 | public string FileName => Path.GetFileName(FullPath);
38 |
39 | public TabModel()
40 | {
41 | }
42 |
43 | public TabModel(string fullPath)
44 | {
45 | FullPath = fullPath;
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/VSTabPath/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("VSTabPath")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("VSTabPath")]
12 | [assembly: AssemblyCopyright("")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // Version information for an assembly consists of the following four values:
22 | //
23 | // Major Version
24 | // Minor Version
25 | // Build Number
26 | // Revision
27 | //
28 | // You can specify all the values or you can default the Build and Revision Numbers
29 | // by using the '*' as shown below:
30 | // [assembly: AssemblyVersion("1.0.*")]
31 | [assembly: AssemblyVersion("1.3.0.0")]
32 | [assembly: AssemblyFileVersion("1.3.0.0")]
33 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TabPath extension
2 |
3 | [](https://ci.appveyor.com/project/DarkDaskin/vstabpath)
4 |
5 | Download: [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=darkdaskin.tabpath)
6 |
7 | ## Purpose
8 |
9 | Visual Studio extension which shows file paths in tab titles with same file names.
10 |
11 | It is inspired by a built-in feature of Visual Studio Code and has similar look and feel, showing relevant path segments next to file names.
12 |
13 | Improvement suggestions are welcome.
14 |
15 | ## Compatibility
16 |
17 | The extension currently works with Visual Studio 2017 - 2022. Support for other versions might be added in future.
18 |
19 | The extension is compatible with the [Custom Document Well](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.CustomDocumentWell) extension (a component of [Productivity Power Tools 2017](https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.ProductivityPowerPack2017)).
20 |
21 | ## Building
22 |
23 | The extension references few assemblies directly from Visual Studio directory, so Visual Studio 2017 has to be installed to build it. No specific work loads are required.
24 |
25 | In case you need to build the extension having only newer version of Visual Studio installed, override the `MinimumVisualStudioVersion` project property (see *VisualStudio.props* for possible values). This will make the extension incompatible with earlier Visual Studio versions.
--------------------------------------------------------------------------------
/VSTabPath/Views/DataTemplates.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
34 |
35 |
--------------------------------------------------------------------------------
/VSTabPath/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | TabPath
6 | Shows file paths in tab titles.
7 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/VSTabPath.Interop.Shared/DteInterop.cs:
--------------------------------------------------------------------------------
1 | using EnvDTE;
2 | using EnvDTE80;
3 | using Microsoft.VisualStudio.Shell;
4 | using Microsoft.VisualStudio.Shell.Interop;
5 | using System;
6 | using System.IO;
7 | using System.Linq;
8 | using VSTabPath.Interop.Contracts;
9 |
10 | namespace VSTabPath.Interop
11 | {
12 | // ReSharper disable once UnusedMember.Global
13 | public class DteInterop : IDteInterop
14 | {
15 | private readonly DTE2 _dte;
16 |
17 | public DteInterop()
18 | {
19 | _dte = (DTE2)Package.GetGlobalService(typeof(SDTE));
20 | }
21 |
22 | public string GetSolutionRootPath()
23 | {
24 | ThreadHelper.ThrowIfNotOnUIThread();
25 |
26 | var solution = _dte.Solution;
27 | if (solution == null)
28 | return null;
29 |
30 | var fullName = solution.FullName;
31 | if (string.IsNullOrEmpty(fullName))
32 | {
33 | // A project has been opened without a solution, so a temporary one is created.
34 | // Use the project root path instead.
35 | fullName = solution.Projects.Cast().FirstOrDefault()?.FullName;
36 | }
37 |
38 | return string.IsNullOrEmpty(fullName) ? null : Path.GetDirectoryName(fullName);
39 | }
40 |
41 | public event Action SolutionOpened
42 | {
43 | add => _dte.Events.SolutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(value);
44 | remove => _dte.Events.SolutionEvents.Opened -= new _dispSolutionEvents_OpenedEventHandler(value);
45 | }
46 |
47 | public event Action SolutionRenamed
48 | {
49 | add => _dte.Events.SolutionEvents.Renamed += new _dispSolutionEvents_RenamedEventHandler(value);
50 | remove => _dte.Events.SolutionEvents.Renamed -= new _dispSolutionEvents_RenamedEventHandler(value);
51 | }
52 |
53 | public event Action SolutionClosed
54 | {
55 | add => _dte.Events.SolutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(value);
56 | remove => _dte.Events.SolutionEvents.AfterClosing -= new _dispSolutionEvents_AfterClosingEventHandler(value);
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/VSTabPath/TabPathViewElementFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Linq;
5 | using System.Windows;
6 | using System.Windows.Media;
7 | using Microsoft.VisualStudio.Platform.WindowManagement;
8 | using Microsoft.VisualStudio.PlatformUI.Shell;
9 | using Microsoft.VisualStudio.PlatformUI.Shell.Controls;
10 |
11 | namespace VSTabPath
12 | {
13 | public class TabPathViewElementFactory : DelegatingViewElementFactory
14 | {
15 | public TabPathViewElementFactory(ViewElementFactory innerFactory) : base(innerFactory)
16 | {
17 | }
18 |
19 | protected override View CreateViewCore(Type viewType)
20 | {
21 | var view = base.CreateViewCore(viewType);
22 |
23 | if (view is DocumentView documentView)
24 | SetupView(documentView);
25 |
26 | return view;
27 | }
28 |
29 | private static void SetupView(DocumentView view)
30 | {
31 | if (!view.IsVisible)
32 | {
33 | view.Shown += OnDocumentViewShown;
34 | return;
35 | }
36 |
37 | Debug.Assert(view.Parent != null, "view.Parent != null");
38 | var titleManager = TabTitleManager.EnsureTabTitleManager(view.Parent);
39 | titleManager.RegisterDocumentView(view);
40 | }
41 |
42 | private static void OnDocumentViewShown(object sender, EventArgs e)
43 | {
44 | var view = (DocumentView) sender;
45 |
46 | view.Shown -= OnDocumentViewShown;
47 |
48 | SetupView(view);
49 | }
50 |
51 | public static void SetupExistingDocuments()
52 | {
53 | var documentViews = FindVisualDescendants(Application.Current.MainWindow)
54 | .Select(e => e.View)
55 | .OfType();
56 | foreach (var view in documentViews)
57 | SetupView(view);
58 | }
59 |
60 | private static IEnumerable FindVisualDescendants(DependencyObject obj)
61 | where T : DependencyObject
62 | {
63 | var childrenCount = VisualTreeHelper.GetChildrenCount(obj);
64 | for (var i = 0; i < childrenCount; i++)
65 | {
66 | var child = VisualTreeHelper.GetChild(obj, i);
67 |
68 | if (child is T tChild)
69 | yield return tChild;
70 |
71 | foreach (var descendant in FindVisualDescendants(child))
72 | yield return descendant;
73 | }
74 | }
75 | }
76 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/VSTabPath/DelegatingViewElementFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.PlatformUI.Shell;
3 |
4 | namespace VSTabPath
5 | {
6 | public class DelegatingViewElementFactory : ViewElementFactory
7 | {
8 | private readonly ViewElementFactory _innerFactory;
9 |
10 | public DelegatingViewElementFactory(ViewElementFactory innerFactory)
11 | {
12 | _innerFactory = innerFactory;
13 | }
14 |
15 | protected override TabGroup CreateTabGroupCore()
16 | {
17 | return _innerFactory?.CreateTabGroup() ?? base.CreateTabGroupCore();
18 | }
19 |
20 | protected override DockGroup CreateDockGroupCore()
21 | {
22 | return _innerFactory?.CreateDockGroup() ?? base.CreateDockGroupCore();
23 | }
24 |
25 | protected override DocumentGroup CreateDocumentGroupCore()
26 | {
27 | return _innerFactory?.CreateDocumentGroup() ?? base.CreateDocumentGroupCore();
28 | }
29 |
30 | protected override DocumentGroupContainer CreateDocumentGroupContainerCore()
31 | {
32 | return _innerFactory?.CreateDocumentGroupContainer() ?? base.CreateDocumentGroupContainerCore();
33 | }
34 |
35 | protected override AutoHideGroup CreateAutoHideGroupCore()
36 | {
37 | return _innerFactory?.CreateAutoHideGroup() ?? base.CreateAutoHideGroupCore();
38 | }
39 |
40 | protected override AutoHideChannel CreateAutoHideChannelCore()
41 | {
42 | return _innerFactory?.CreateAutoHideChannel() ?? base.CreateAutoHideChannelCore();
43 | }
44 |
45 | protected override AutoHideRoot CreateAutoHideRootCore()
46 | {
47 | return _innerFactory?.CreateAutoHideRoot() ?? base.CreateAutoHideRootCore();
48 | }
49 |
50 | protected override DockRoot CreateDockRootCore()
51 | {
52 | return _innerFactory?.CreateDockRoot() ?? base.CreateDockRootCore();
53 | }
54 |
55 | protected override FloatSite CreateFloatSiteCore()
56 | {
57 | return _innerFactory?.CreateFloatSite() ?? base.CreateFloatSiteCore();
58 | }
59 |
60 | protected override MainSite CreateMainSiteCore()
61 | {
62 | return _innerFactory?.CreateMainSite() ?? base.CreateMainSiteCore();
63 | }
64 |
65 | protected override View CreateViewCore(Type viewType)
66 | {
67 | return _innerFactory?.CreateView(viewType) ?? base.CreateViewCore(viewType);
68 | }
69 |
70 | protected override ViewBookmark CreateViewBookmarkCore()
71 | {
72 | return _innerFactory?.CreateViewBookmark() ?? base.CreateViewBookmarkCore();
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/VSTabPath.Tests/VSTabPath.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {13611075-94B6-4EA9-B777-D56A83DB16D6}
8 | Library
9 | Properties
10 | VSTabPath.Tests
11 | VSTabPath.Tests
12 | v4.7.2
13 | 512
14 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 15.0
16 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
17 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
18 | False
19 | UnitTest
20 |
21 |
22 |
23 |
24 |
25 | true
26 | full
27 | false
28 | bin\Debug\
29 | DEBUG;TRACE
30 | prompt
31 | 4
32 |
33 |
34 | pdbonly
35 | true
36 | bin\Release\
37 | TRACE
38 | prompt
39 | 4
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | {e2f60519-d34f-4411-9ab7-7916fc004e9f}
53 | VSTabPath
54 |
55 |
56 |
57 |
58 | 1.3.2
59 |
60 |
61 | 1.3.2
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/VSTabPath/TabPathPackage.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.PlatformUI.Shell;
2 | using Microsoft.VisualStudio.Shell;
3 | using Microsoft.VisualStudio.Shell.Interop;
4 | using System;
5 | using System.Diagnostics.CodeAnalysis;
6 | using System.Reflection;
7 | using System.Runtime.InteropServices;
8 | using System.Threading;
9 | using System.Windows;
10 | using Task = System.Threading.Tasks.Task;
11 |
12 | namespace VSTabPath
13 | {
14 | ///
15 | /// This is the class that implements the package exposed by this assembly.
16 | ///
17 | ///
18 | ///
19 | /// The minimum requirement for a class to be considered a valid package for Visual Studio
20 | /// is to implement the IVsPackage interface and register itself with the shell.
21 | /// This package uses the helper classes defined inside the Managed Package Framework (MPF)
22 | /// to do it: it derives from the Package class that provides the implementation of the
23 | /// IVsPackage interface and uses the registration attributes defined in the framework to
24 | /// register itself and its components with the shell. These attributes tell the pkgdef creation
25 | /// utility what data to put into .pkgdef file.
26 | ///
27 | ///
28 | /// To get loaded into VS, the package must be referred by <Asset Type="Microsoft.VisualStudio.VsPackage" ...> in .vsixmanifest file.
29 | ///
30 | ///
31 | [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
32 | [InstalledProductRegistration("#110", "#112", Vsix.Version, IconResourceID = 400)] // Info on this package for Help/About
33 | [Guid(PackageGuidString)]
34 | [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
35 | [ProvideAutoLoad(UIContextGuids.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
36 | [ProvideAutoLoad(UIContextGuids.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
37 | public sealed class TabPathPackage : AsyncPackage
38 | {
39 | ///
40 | /// TabPathPackage GUID string.
41 | ///
42 | public const string PackageGuidString = "1b0e6e36-6a33-4bc9-b81b-392521ff7fc1";
43 |
44 | ///
45 | /// Initializes a new instance of the class.
46 | ///
47 | public TabPathPackage()
48 | {
49 | // Inside this method you can place any initialization code that does not require
50 | // any Visual Studio service because at this point the package object is created but
51 | // not sited yet inside Visual Studio environment. The place to do all the other
52 | // initialization is the Initialize method.
53 | }
54 |
55 | #region Package Members
56 |
57 | ///
58 | /// Initialization of the package; this method is called right after the package is sited, so this is the place
59 | /// where you can put all the initialization code that rely on services provided by VisualStudio.
60 | ///
61 | protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress)
62 | {
63 | await base.InitializeAsync(cancellationToken, progress);
64 |
65 | await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
66 |
67 | MergeResources();
68 |
69 | TabPathViewElementFactory.SetupExistingDocuments();
70 |
71 | ViewElementFactory.Current = new TabPathViewElementFactory(ViewElementFactory.Current);
72 | }
73 |
74 | #endregion
75 |
76 | private static void MergeResources()
77 | {
78 | var resourceDictionary = LoadResourceDictionary("Views/DataTemplates.xaml");
79 | Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
80 | }
81 |
82 | private static ResourceDictionary LoadResourceDictionary(string xamlName)
83 | {
84 | return (ResourceDictionary)Application.LoadComponent(
85 | new Uri(Assembly.GetExecutingAssembly().GetName().Name + ";component/" + xamlName, UriKind.Relative));
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/VSTabPath.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.32126.317
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VSTabPath", "VSTabPath\VSTabPath.csproj", "{E2F60519-D34F-4411-9AB7-7916FC004E9F}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C1B92749-032B-4BA9-8F41-ADE2E76C0676}"
9 | ProjectSection(SolutionItems) = preProject
10 | README.md = README.md
11 | EndProjectSection
12 | EndProject
13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VSTabPath.Tests", "VSTabPath.Tests\VSTabPath.Tests.csproj", "{13611075-94B6-4EA9-B777-D56A83DB16D6}"
14 | EndProject
15 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Interop", "Interop", "{9BDB0B29-A5FB-464E-A0C1-C4F39FF9FB89}"
16 | EndProject
17 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VSTabPath.Interop.Contracts", "VSTabPath.Interop.Contracts\VSTabPath.Interop.Contracts.csproj", "{9F749E75-5CC7-4358-9F65-E73DACCE9439}"
18 | EndProject
19 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VSTabPath.Interop.X86", "VSTabPath.Interop.X86\VSTabPath.Interop.X86.csproj", "{861326D9-89DA-48AA-95AE-B8D39F2C654F}"
20 | EndProject
21 | Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "VSTabPath.Interop.Shared", "VSTabPath.Interop.Shared\VSTabPath.Interop.Shared.shproj", "{064A5FF7-B156-4165-9594-9867F5A5D382}"
22 | EndProject
23 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VSTabPath.Interop.X64", "VSTabPath.Interop.X64\VSTabPath.Interop.X64.csproj", "{ACD4939F-F3B4-4441-B140-BEFCBA0BE115}"
24 | EndProject
25 | Global
26 | GlobalSection(SharedMSBuildProjectFiles) = preSolution
27 | VSTabPath.Interop.Shared\VSTabPath.Interop.Shared.projitems*{064a5ff7-b156-4165-9594-9867f5a5d382}*SharedItemsImports = 13
28 | VSTabPath.Interop.Shared\VSTabPath.Interop.Shared.projitems*{861326d9-89da-48aa-95ae-b8d39f2c654f}*SharedItemsImports = 5
29 | VSTabPath.Interop.Shared\VSTabPath.Interop.Shared.projitems*{acd4939f-f3b4-4441-b140-befcba0be115}*SharedItemsImports = 5
30 | EndGlobalSection
31 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
32 | Debug|Any CPU = Debug|Any CPU
33 | Release|Any CPU = Release|Any CPU
34 | EndGlobalSection
35 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
36 | {E2F60519-D34F-4411-9AB7-7916FC004E9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {E2F60519-D34F-4411-9AB7-7916FC004E9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {E2F60519-D34F-4411-9AB7-7916FC004E9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {E2F60519-D34F-4411-9AB7-7916FC004E9F}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {13611075-94B6-4EA9-B777-D56A83DB16D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {13611075-94B6-4EA9-B777-D56A83DB16D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {13611075-94B6-4EA9-B777-D56A83DB16D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {13611075-94B6-4EA9-B777-D56A83DB16D6}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {9F749E75-5CC7-4358-9F65-E73DACCE9439}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {9F749E75-5CC7-4358-9F65-E73DACCE9439}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {9F749E75-5CC7-4358-9F65-E73DACCE9439}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {9F749E75-5CC7-4358-9F65-E73DACCE9439}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {861326D9-89DA-48AA-95AE-B8D39F2C654F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {861326D9-89DA-48AA-95AE-B8D39F2C654F}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {861326D9-89DA-48AA-95AE-B8D39F2C654F}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {861326D9-89DA-48AA-95AE-B8D39F2C654F}.Release|Any CPU.Build.0 = Release|Any CPU
52 | {ACD4939F-F3B4-4441-B140-BEFCBA0BE115}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {ACD4939F-F3B4-4441-B140-BEFCBA0BE115}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {ACD4939F-F3B4-4441-B140-BEFCBA0BE115}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {ACD4939F-F3B4-4441-B140-BEFCBA0BE115}.Release|Any CPU.Build.0 = Release|Any CPU
56 | EndGlobalSection
57 | GlobalSection(SolutionProperties) = preSolution
58 | HideSolutionNode = FALSE
59 | EndGlobalSection
60 | GlobalSection(NestedProjects) = preSolution
61 | {9F749E75-5CC7-4358-9F65-E73DACCE9439} = {9BDB0B29-A5FB-464E-A0C1-C4F39FF9FB89}
62 | {861326D9-89DA-48AA-95AE-B8D39F2C654F} = {9BDB0B29-A5FB-464E-A0C1-C4F39FF9FB89}
63 | {064A5FF7-B156-4165-9594-9867F5A5D382} = {9BDB0B29-A5FB-464E-A0C1-C4F39FF9FB89}
64 | {ACD4939F-F3B4-4441-B140-BEFCBA0BE115} = {9BDB0B29-A5FB-464E-A0C1-C4F39FF9FB89}
65 | EndGlobalSection
66 | GlobalSection(ExtensibilityGlobals) = postSolution
67 | SolutionGuid = {73BC04EB-A8B6-4EF6-A137-3E4DC594D994}
68 | EndGlobalSection
69 | EndGlobal
70 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/VSTabPath/TabTitleManager.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Platform.WindowManagement;
2 | using Microsoft.VisualStudio.PlatformUI.Shell;
3 | using Microsoft.VisualStudio.Shell;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Windows;
8 | using System.Windows.Data;
9 | using VSTabPath.Interop.Contracts;
10 | using VSTabPath.Models;
11 | using VSTabPath.ViewModels;
12 |
13 | namespace VSTabPath
14 | {
15 | public class TabTitleManager
16 | {
17 | #region TabTitleManagerProperty
18 |
19 | public static readonly DependencyProperty TabTitleManagerProperty =
20 | DependencyProperty.RegisterAttached(
21 | nameof(TabTitleManager), typeof(TabTitleManager), typeof(TabTitleManager));
22 |
23 | public static TabTitleManager GetTabTitleManager(ViewGroup target)
24 | {
25 | return (TabTitleManager)target.GetValue(TabTitleManagerProperty);
26 | }
27 |
28 | public static void SetTabTitleManager(ViewGroup target, TabTitleManager value)
29 | {
30 | target.SetValue(TabTitleManagerProperty, value);
31 | }
32 |
33 | public static TabTitleManager EnsureTabTitleManager(ViewGroup target)
34 | {
35 | return EnsurePropertyValue(target, TabTitleManagerProperty, () => new TabTitleManager());
36 | }
37 |
38 | #endregion
39 |
40 | #region TitleWithPathProperty
41 |
42 | public static readonly DependencyProperty TabViewModelProperty = DependencyProperty.RegisterAttached(
43 | "TabViewModel", typeof(TabViewModel), typeof(TabTitleManager));
44 |
45 | public static void SetTabViewModel(DependencyObject element, TabViewModel value)
46 | {
47 | element.SetValue(TabViewModelProperty, value);
48 | }
49 |
50 | public static TabViewModel GetTabViewModel(DependencyObject element)
51 | {
52 | return (TabViewModel)element.GetValue(TabViewModelProperty);
53 | }
54 |
55 | #endregion
56 |
57 | private readonly Dictionary _viewModels = new Dictionary();
58 | private readonly DisplayPathResolver _displayPathResolver = new DisplayPathResolver();
59 | private readonly IDteInterop _dte;
60 |
61 | public TabTitleManager()
62 | {
63 | ThreadHelper.ThrowIfNotOnUIThread();
64 |
65 | _dte = DteInteropResolver.Interop;
66 |
67 | _displayPathResolver.SolutionRootPath = GetSolutionRootPath();
68 |
69 | _dte.SolutionOpened += () =>
70 | _displayPathResolver.SolutionRootPath = GetSolutionRootPath();
71 | _dte.SolutionRenamed += _ =>
72 | _displayPathResolver.SolutionRootPath = GetSolutionRootPath();
73 | _dte.SolutionClosed += () =>
74 | _displayPathResolver.SolutionRootPath = null;
75 | }
76 |
77 | private string GetSolutionRootPath() => _dte.GetSolutionRootPath();
78 |
79 | public void RegisterDocumentView(DocumentView view)
80 | {
81 | if (_viewModels.ContainsKey(view))
82 | return;
83 |
84 | InstallTabTitlePath(view);
85 | }
86 |
87 | private void InstallTabTitlePath(DocumentView view)
88 | {
89 | if (!(view.Title is WindowFrameTitle title))
90 | return;
91 |
92 | var bindingExpression = BindingOperations.GetBindingExpression(title, WindowFrameTitle.TitleProperty);
93 | if (!(bindingExpression?.DataItem is WindowFrame frame))
94 | return;
95 |
96 | var model = new TabModel(FixFileNameCase(frame.FrameMoniker.Filename));
97 | frame.PropertyChanged += (sender, args) =>
98 | {
99 | if (args.PropertyName == nameof(WindowFrame.AnnotatedTitle))
100 | model.FullPath = FixFileNameCase(frame.FrameMoniker.Filename);
101 | };
102 |
103 | _displayPathResolver.Add(model);
104 |
105 | var viewModel = new TabViewModel(title, view.TabTitleTemplate, model);
106 | SetTabViewModel(view, viewModel);
107 |
108 | view.DocumentTabTitleTemplate = view.TabTitleTemplate =
109 | (DataTemplate)Application.Current.FindResource("TabPathTemplate");
110 |
111 | _viewModels.Add(view, viewModel);
112 |
113 | frame.FrameDestroyed += (sender, args) =>
114 | {
115 | _displayPathResolver.Remove(_viewModels[view].Model);
116 | _viewModels.Remove(view);
117 | };
118 | }
119 |
120 | private static TProperty EnsurePropertyValue(T target, DependencyProperty property, Func factory)
121 | where T : DependencyObject
122 | {
123 | var value = (TProperty)target.GetValue(property);
124 | if (value == null)
125 | {
126 | value = factory();
127 | target.SetValue(property, value);
128 | }
129 | return value;
130 | }
131 |
132 | private static string FixFileNameCase(string fileName)
133 | {
134 | try
135 | {
136 | var pathParts = fileName.Split(Path.DirectorySeparatorChar);
137 | var fixedPath = pathParts[0].ToUpperInvariant() + "\\";
138 | for (var i = 1; i < pathParts.Length; i++)
139 | fixedPath = Directory.GetFileSystemEntries(fixedPath, pathParts[i])[0];
140 | return fixedPath;
141 | }
142 | catch
143 | {
144 | return fileName;
145 | }
146 | }
147 | }
148 | }
--------------------------------------------------------------------------------
/VSTabPath/VSPackage.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | TabPath Extension
122 |
123 |
124 | Shows file paths in tab titles.
125 |
126 |
127 |
128 | Resources\TabPathPackage.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
129 |
130 |
--------------------------------------------------------------------------------
/VSTabPath.Tests/DisplayPathResolverTests_Solution.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using VSTabPath.Models;
4 |
5 | namespace VSTabPath.Tests
6 | {
7 | [TestClass]
8 | public class DisplayPathResolverTests_Solution
9 | {
10 | [TestMethod]
11 | public void WhenNoDuplicateFileNames_DoNotShowPaths()
12 | {
13 | var models = new[]
14 | {
15 | new TabModel(@"c:\Solution\Directory1\1.txt"),
16 | new TabModel(@"c:\Solution\Directory1\2.txt"),
17 | new TabModel(@"c:\Solution\Directory2\3.txt"),
18 | };
19 |
20 | var resolver = new DisplayPathResolver(@"c:\Solution")
21 | {
22 | models[0],
23 | models[1],
24 | models[2],
25 | };
26 |
27 | Assert.AreEqual(null, models[0].DisplayPath);
28 | Assert.AreEqual(null, models[1].DisplayPath);
29 | Assert.AreEqual(null, models[2].DisplayPath);
30 | }
31 |
32 | [TestMethod]
33 | public void WhenDuplicateFileNames_ShowPaths()
34 | {
35 | var models = new[]
36 | {
37 | new TabModel(@"c:\Solution\Directory1\1.txt"),
38 | new TabModel(@"c:\Solution\Directory1\2.txt"),
39 | new TabModel(@"c:\Solution\Directory2\1.txt"),
40 | };
41 |
42 | var resolver = new DisplayPathResolver(@"c:\Solution")
43 | {
44 | models[0],
45 | models[1],
46 | models[2],
47 | };
48 |
49 | Assert.AreEqual(@"Directory1", models[0].DisplayPath);
50 | Assert.AreEqual(null, models[1].DisplayPath);
51 | Assert.AreEqual(@"Directory2", models[2].DisplayPath);
52 | }
53 |
54 | [TestMethod]
55 | public void WhenDuplicatesInDeepSiblingDirectories_ShowPathsWithEllipsis()
56 | {
57 | var models = new[]
58 | {
59 | new TabModel(@"c:\Solution\Project\Directory1\1.txt"),
60 | new TabModel(@"c:\Solution\Project\Directory2\1.txt"),
61 | };
62 |
63 | var resolver = new DisplayPathResolver(@"c:\Solution")
64 | {
65 | models[0],
66 | models[1],
67 | };
68 |
69 | Assert.AreEqual(@"…\Directory1", models[0].DisplayPath);
70 | Assert.AreEqual(@"…\Directory2", models[1].DisplayPath);
71 | }
72 |
73 | [TestMethod]
74 | public void WhenDuplicatesInVeryDeepSiblingDirectories_ShowPathsWithSingleEllipsis()
75 | {
76 | var models = new[]
77 | {
78 | new TabModel(@"c:\Solution\Project\very\deep\Directory1\1.txt"),
79 | new TabModel(@"c:\Solution\Project\very\deep\Directory2\1.txt"),
80 | };
81 |
82 | var resolver = new DisplayPathResolver(@"c:\Solution")
83 | {
84 | models[0],
85 | models[1],
86 | };
87 |
88 | Assert.AreEqual(@"…\Directory1", models[0].DisplayPath);
89 | Assert.AreEqual(@"…\Directory2", models[1].DisplayPath);
90 | }
91 |
92 | [TestMethod]
93 | public void WhenDuplicatesInSameNamedDirectories_ShowPathsEndWithMultipleDirectory()
94 | {
95 | var models = new[]
96 | {
97 | new TabModel(@"c:\Solution\Project1\SubDirectory1\1.txt"),
98 | new TabModel(@"c:\Solution\Project2\SubDirectory1\1.txt"),
99 | };
100 |
101 | var resolver = new DisplayPathResolver(@"c:\Solution")
102 | {
103 | models[0],
104 | models[1],
105 | };
106 |
107 | Assert.AreEqual(@"Project1\SubDirectory1", models[0].DisplayPath);
108 | Assert.AreEqual(@"Project2\SubDirectory1", models[1].DisplayPath);
109 | }
110 |
111 | [TestMethod]
112 | public void WhenOneDuplicateOutsideSolutionRoot_ShowPathWithDriveLetter()
113 | {
114 | var models = new[]
115 | {
116 | new TabModel(@"c:\Solution\Project1\SubDirectory1\1.txt"),
117 | new TabModel(@"c:\Other\SubDirectory1\1.txt"),
118 | };
119 |
120 | var resolver = new DisplayPathResolver(@"c:\Solution")
121 | {
122 | models[0],
123 | models[1],
124 | };
125 |
126 | Assert.AreEqual(@"…\SubDirectory1", models[0].DisplayPath);
127 | Assert.AreEqual(@"c:\…\SubDirectory1", models[1].DisplayPath);
128 | }
129 |
130 | [TestMethod]
131 | public void WhenOneDuplicateAtSolutionRoot_ShowDotPath()
132 | {
133 | var models = new[]
134 | {
135 | new TabModel(@"c:\Solution\Project1\1.txt"),
136 | new TabModel(@"c:\Solution\1.txt"),
137 | };
138 |
139 | var resolver = new DisplayPathResolver(@"c:\Solution")
140 | {
141 | models[0],
142 | models[1],
143 | };
144 |
145 | Assert.AreEqual(@"Project1", models[0].DisplayPath);
146 | Assert.AreEqual(@".\", models[1].DisplayPath);
147 | }
148 |
149 | [TestMethod]
150 | public void WhenSolutionIsLoaded_UpdatePaths()
151 | {
152 | var models = new[]
153 | {
154 | new TabModel(@"c:\Solution\Project1\1.txt"),
155 | new TabModel(@"c:\Solution\Project2\1.txt"),
156 | };
157 |
158 | var resolver = new DisplayPathResolver
159 | {
160 | models[0],
161 | models[1],
162 | };
163 |
164 | Assert.AreEqual(@"c:\…\Project1", models[0].DisplayPath);
165 | Assert.AreEqual(@"c:\…\Project2", models[1].DisplayPath);
166 |
167 | resolver.SolutionRootPath = @"c:\Solution";
168 |
169 | Assert.AreEqual(@"Project1", models[0].DisplayPath);
170 | Assert.AreEqual(@"Project2", models[1].DisplayPath);
171 | }
172 |
173 | [TestMethod]
174 | public void WhenSolutionIsUnloaded_UpdatePaths()
175 | {
176 | var models = new[]
177 | {
178 | new TabModel(@"c:\Solution\Project1\1.txt"),
179 | new TabModel(@"c:\Solution\Project2\1.txt"),
180 | };
181 |
182 | var resolver = new DisplayPathResolver(@"c:\Solution")
183 | {
184 | models[0],
185 | models[1],
186 | };
187 |
188 | Assert.AreEqual(@"Project1", models[0].DisplayPath);
189 | Assert.AreEqual(@"Project2", models[1].DisplayPath);
190 |
191 | resolver.SolutionRootPath = null;
192 |
193 | Assert.AreEqual(@"c:\…\Project1", models[0].DisplayPath);
194 | Assert.AreEqual(@"c:\…\Project2", models[1].DisplayPath);
195 | }
196 |
197 | [TestMethod]
198 | public void WhenSolutionIsChanged_UpdatePaths()
199 | {
200 | var models = new[]
201 | {
202 | new TabModel(@"c:\Solution1\Project1\1.txt"),
203 | new TabModel(@"c:\Solution2\Project2\1.txt"),
204 | };
205 |
206 | var resolver = new DisplayPathResolver(@"c:\Solution1")
207 | {
208 | models[0],
209 | models[1],
210 | };
211 |
212 | Assert.AreEqual(@"Project1", models[0].DisplayPath);
213 | Assert.AreEqual(@"c:\…\Project2", models[1].DisplayPath);
214 |
215 | resolver.SolutionRootPath = @"c:\Solution2";
216 |
217 | Assert.AreEqual(@"c:\…\Project1", models[0].DisplayPath);
218 | Assert.AreEqual(@"Project2", models[1].DisplayPath);
219 | }
220 | }
221 | }
222 |
--------------------------------------------------------------------------------
/VSTabPath/VSTabPath.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 15.0
5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
6 |
7 |
8 | true
9 |
10 |
11 |
12 | true
13 |
14 |
15 | Key.snk
16 |
17 |
18 |
19 |
20 | Debug
21 | AnyCPU
22 | 2.0
23 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
24 | {E2F60519-D34F-4411-9AB7-7916FC004E9F}
25 | Library
26 | Properties
27 | VSTabPath
28 | VSTabPath
29 | v4.7.2
30 | true
31 | true
32 | true
33 | true
34 | true
35 | false
36 | Program
37 | $(DevEnvDir)devenv.exe
38 | /rootsuffix Exp
39 |
40 |
41 | true
42 | full
43 | false
44 | bin\Debug\
45 | DEBUG;TRACE
46 | prompt
47 | 4
48 |
49 |
50 | pdbonly
51 | true
52 | bin\Release\
53 | TRACE
54 | prompt
55 | 4
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | True
65 | True
66 | source.extension.vsixmanifest
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | Designer
77 | VsixManifestGenerator
78 | source.extension.cs
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | true
107 | VSPackage
108 |
109 |
110 |
111 |
112 | Designer
113 | MSBuild:Compile
114 |
115 |
116 |
117 |
118 | 2021.3.0
119 |
120 |
121 | $(_VisualStudioSdkVersion)
122 |
123 |
124 | 17.0.5234
125 | runtime; build; native; contentfiles; analyzers; buildtransitive
126 | all
127 |
128 |
129 | 4.5.0
130 |
131 |
132 | 2.8.4
133 | runtime; build; native; contentfiles; analyzers; buildtransitive
134 | all
135 |
136 |
137 |
138 |
139 | {9f749e75-5cc7-4358-9f65-e73dacce9439}
140 | VSTabPath.Interop.Contracts
141 |
142 |
143 | {acd4939f-f3b4-4441-b140-befcba0be115}
144 | VSTabPath.Interop.X64
145 | false
146 |
147 |
148 | {861326d9-89da-48aa-95ae-b8d39f2c654f}
149 | VSTabPath.Interop.X86
150 | false
151 |
152 |
153 |
154 |
155 |
156 |
163 |
--------------------------------------------------------------------------------
/VSTabPath/Models/DisplayPathResolver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.IO;
6 | using System.Linq;
7 |
8 | namespace VSTabPath.Models
9 | {
10 | public class DisplayPathResolver : IEnumerable
11 | {
12 | private const string Ellipsis = "…";
13 |
14 | private static readonly char[] DirectorySeparators =
15 | {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar};
16 | private static readonly IEqualityComparer PathComparer = StringComparer.OrdinalIgnoreCase;
17 |
18 | private Dictionary> _modelsByFullPath = new Dictionary>(PathComparer);
19 | private string _solutionRootPath;
20 |
21 | private IEnumerable ModelsWithUniqueFullPaths => _modelsByFullPath.Values.Select(list => list[0]);
22 |
23 | public string SolutionRootPath
24 | {
25 | get => _solutionRootPath;
26 | set
27 | {
28 | _solutionRootPath = value;
29 |
30 | UpdateModels();
31 | }
32 | }
33 |
34 | public DisplayPathResolver()
35 | {
36 | }
37 |
38 | public DisplayPathResolver(string solutionRootPath)
39 | {
40 | _solutionRootPath = solutionRootPath;
41 | }
42 |
43 | public void Add(TabModel model)
44 | {
45 | if (!_modelsByFullPath.TryGetValue(model.FullPath, out var models))
46 | _modelsByFullPath.Add(model.FullPath, models = new List());
47 | models.Add(model);
48 |
49 | model.PropertyChanged += OnModelPropertyChanged;
50 |
51 | UpdateModels(model.FileName);
52 | }
53 |
54 | public void Remove(TabModel model)
55 | {
56 | model.PropertyChanged -= OnModelPropertyChanged;
57 |
58 | if (_modelsByFullPath.TryGetValue(model.FullPath, out var models))
59 | {
60 | models.Remove(model);
61 | if (models.Count == 0)
62 | _modelsByFullPath.Remove(model.FullPath);
63 | }
64 |
65 | UpdateModels(model.FileName);
66 | }
67 |
68 | public IEnumerator GetEnumerator()
69 | {
70 | return _modelsByFullPath.Values.SelectMany(m => m).GetEnumerator();
71 | }
72 |
73 | IEnumerator IEnumerable.GetEnumerator()
74 | {
75 | return GetEnumerator();
76 | }
77 |
78 | private void OnModelPropertyChanged(object sender, PropertyChangedEventArgs args)
79 | {
80 | if (args.PropertyName == nameof(TabModel.FullPath))
81 | {
82 | RegroupTabs();
83 | UpdateModels();
84 | }
85 | }
86 |
87 | private void RegroupTabs()
88 | {
89 | _modelsByFullPath = this
90 | .GroupBy(m => m.FullPath)
91 | .ToDictionary(g => g.Key, g => g.ToList(), PathComparer);
92 | }
93 |
94 | private void UpdateModels(string fileName)
95 | {
96 | var modelsToUpdate = ModelsWithUniqueFullPaths
97 | .Where(m => PathEquals(m.FileName, fileName))
98 | .ToList();
99 | if (modelsToUpdate.Count == 1)
100 | UpdateDisplayPathsByFullPath(modelsToUpdate[0], null);
101 | else
102 | UpdateModelsWithDuplicateFilename(modelsToUpdate);
103 | }
104 |
105 | private void UpdateModels()
106 | {
107 | var modelsByFileName = ModelsWithUniqueFullPaths
108 | .ToLookup(m => m.FileName, PathComparer);
109 |
110 | var modelsWithDuplicateFileName = modelsByFileName
111 | .Where(g => g.Count() > 1)
112 | .SelectMany(g => g)
113 | .ToList();
114 | UpdateModelsWithDuplicateFilename(modelsWithDuplicateFileName);
115 |
116 | var modelsWithUniqueFileName = modelsByFileName
117 | .Where(g => g.Count() == 1)
118 | .SelectMany(g => g);
119 | foreach (var model in modelsWithUniqueFileName)
120 | UpdateDisplayPathsByFullPath(model, null);
121 | }
122 |
123 | private void UpdateDisplayPathsByFullPath(TabModel example, string displayPath)
124 | {
125 | foreach (var model in _modelsByFullPath[example.FullPath])
126 | model.DisplayPath = displayPath;
127 | }
128 |
129 | private void UpdateModelsWithDuplicateFilename(IReadOnlyCollection models)
130 | {
131 | var modelsAtSolutionRoot = models
132 | .Where(m => PathEquals(m.DirectoryName, SolutionRootPath));
133 | foreach (var model in modelsAtSolutionRoot)
134 | UpdateDisplayPathsByFullPath(model, @".\");
135 |
136 | var modelsOutsideSolutionRoot = models
137 | .Where(m => !IsBaseOf(SolutionRootPath, m.DirectoryName) && !PathEquals(m.DirectoryName, SolutionRootPath));
138 | ResolvePartialDisplayPaths(modelsOutsideSolutionRoot, false);
139 |
140 | var modelsUnderSolutionRoot = models
141 | .Where(m => IsBaseOf(SolutionRootPath, m.DirectoryName));
142 | ResolvePartialDisplayPaths(modelsUnderSolutionRoot, true);
143 | }
144 |
145 | private static bool PathEquals(string x, string y)
146 | {
147 | return string.Equals(x, y, StringComparison.OrdinalIgnoreCase);
148 | }
149 |
150 | private static bool IsBaseOf(string root, string path)
151 | {
152 | if (root == null)
153 | return false;
154 | return new Uri(Path.Combine(root, ".")).IsBaseOf(new Uri(path));
155 | }
156 |
157 | private static string GetRelativePath(string root, string path)
158 | {
159 | return new Uri(Path.Combine(root, ".")).MakeRelativeUri(new Uri(path)).ToString()
160 | .Replace('/', '\\');
161 | }
162 |
163 | private void ResolvePartialDisplayPaths(IEnumerable models, bool isUnderSolutionRoot)
164 | {
165 | var modelsByFileName = models.GroupBy(m => m.FileName,
166 | (key, g) => g.ToDictionary(m => m,
167 | m => GetPathParts(m.DirectoryName, isUnderSolutionRoot).Select(p => (p, false)).ToList()),
168 | StringComparer.OrdinalIgnoreCase);
169 | foreach (var group in modelsByFileName)
170 | ResolvePartialDisplayPaths(group, isUnderSolutionRoot);
171 | }
172 |
173 | private string[] GetPathParts(string path, bool isUnderSolutionRoot)
174 | {
175 | if (isUnderSolutionRoot)
176 | path = GetRelativePath(SolutionRootPath, path);
177 |
178 | return path.Split(DirectorySeparators, StringSplitOptions.RemoveEmptyEntries);
179 | }
180 |
181 | private void ResolvePartialDisplayPaths(Dictionary> models, bool isUnderSolutionRoot)
182 | {
183 | // When path is outside solution root, always include the root segment (i.e. drive letter).
184 | // A separator has to be appended to keep it after Path.Combine.
185 | if (!isUnderSolutionRoot)
186 | foreach (var segments in models.Values)
187 | segments[0] = (segments[0].value + Path.DirectorySeparatorChar, true);
188 |
189 | ResolvePartialDisplayPaths(models);
190 | }
191 |
192 | private void ResolvePartialDisplayPaths(Dictionary> models)
193 | {
194 | // Include one more segment from the end.
195 | foreach (var segments in models.Values)
196 | {
197 | for (var i = segments.Count - 1; i >= 0; i--)
198 | {
199 | if (segments[i].isIncluded)
200 | continue;
201 |
202 | segments[i] = (segments[i].value, true);
203 | break;
204 | }
205 | }
206 |
207 | // Replace gaps with ellipsis and build the display path.
208 | foreach (var model in models)
209 | {
210 | var finalSegments = new List();
211 | var hasEllipsis = false;
212 | foreach (var (value, isIncluded) in model.Value)
213 | {
214 | if (isIncluded)
215 | {
216 | hasEllipsis = false;
217 | finalSegments.Add(value);
218 | continue;
219 | }
220 |
221 | if (!hasEllipsis)
222 | {
223 | hasEllipsis = true;
224 | finalSegments.Add(Ellipsis);
225 | }
226 | }
227 |
228 | UpdateDisplayPathsByFullPath(model.Key, Path.Combine(finalSegments.ToArray()));
229 | }
230 |
231 | // Find ambiguous paths and resolve them.
232 | var modelsWithDuplicateDisplayPath = models
233 | .Where(m => m.Value.Any(p => !p.isIncluded))
234 | .GroupBy(m => m.Key.DisplayPath, (key, g) => g.ToDictionary(m => m.Key, m => m.Value),
235 | StringComparer.OrdinalIgnoreCase)
236 | .Where(g => g.Count() > 1);
237 | foreach (var group in modelsWithDuplicateDisplayPath)
238 | ResolvePartialDisplayPaths(group);
239 | }
240 | }
241 | }
--------------------------------------------------------------------------------
/VSTabPath.Tests/DisplayPathResolverTests_NoSolution.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using VSTabPath.Models;
3 |
4 | namespace VSTabPath.Tests
5 | {
6 | [TestClass]
7 | // ReSharper disable once InconsistentNaming
8 | public class DisplayPathResolverTests_NoSolution
9 | {
10 | [TestMethod]
11 | public void WhenNoDuplicateFileNames_DoNotShowPaths()
12 | {
13 | var models = new[]
14 | {
15 | new TabModel(@"c:\Directory1\1.txt"),
16 | new TabModel(@"c:\Directory1\2.txt"),
17 | new TabModel(@"c:\Directory2\3.txt"),
18 | };
19 |
20 | var resolver = new DisplayPathResolver
21 | {
22 | models[0],
23 | models[1],
24 | models[2],
25 | };
26 |
27 | Assert.AreEqual(null, models[0].DisplayPath);
28 | Assert.AreEqual(null, models[1].DisplayPath);
29 | Assert.AreEqual(null, models[2].DisplayPath);
30 | }
31 |
32 | [TestMethod]
33 | public void WhenDuplicateFileNames_ShowPaths()
34 | {
35 | var models = new[]
36 | {
37 | new TabModel(@"c:\Directory1\1.txt"),
38 | new TabModel(@"c:\Directory1\2.txt"),
39 | new TabModel(@"c:\Directory2\1.txt"),
40 | };
41 |
42 | var resolver = new DisplayPathResolver
43 | {
44 | models[0],
45 | models[1],
46 | models[2],
47 | };
48 |
49 | Assert.AreEqual(@"c:\Directory1", models[0].DisplayPath);
50 | Assert.AreEqual(null, models[1].DisplayPath);
51 | Assert.AreEqual(@"c:\Directory2", models[2].DisplayPath);
52 | }
53 |
54 | [TestMethod]
55 | public void WhenDuplicatesInDeepSiblingDirectories_ShowPathsWithEllipsis()
56 | {
57 | var models = new[]
58 | {
59 | new TabModel(@"c:\root\Directory1\1.txt"),
60 | new TabModel(@"c:\root\Directory2\1.txt"),
61 | };
62 |
63 | var resolver = new DisplayPathResolver
64 | {
65 | models[0],
66 | models[1],
67 | };
68 |
69 | Assert.AreEqual(@"c:\…\Directory1", models[0].DisplayPath);
70 | Assert.AreEqual(@"c:\…\Directory2", models[1].DisplayPath);
71 | }
72 |
73 | [TestMethod]
74 | public void WhenDuplicatesInVeryDeepSiblingDirectories_ShowPathsWithSingleEllipsis()
75 | {
76 | var models = new[]
77 | {
78 | new TabModel(@"c:\root\very\deep\Directory1\1.txt"),
79 | new TabModel(@"c:\root\very\deep\Directory2\1.txt"),
80 | };
81 |
82 | var resolver = new DisplayPathResolver
83 | {
84 | models[0],
85 | models[1],
86 | };
87 |
88 | Assert.AreEqual(@"c:\…\Directory1", models[0].DisplayPath);
89 | Assert.AreEqual(@"c:\…\Directory2", models[1].DisplayPath);
90 | }
91 |
92 | [TestMethod]
93 | public void WhenDuplicatesInNonSiblingDirectories_ShowPathsEndWithSingleDirectory()
94 | {
95 | var models = new[]
96 | {
97 | new TabModel(@"c:\root\Directory1\1.txt"),
98 | new TabModel(@"c:\root\1.txt"),
99 | };
100 |
101 | var resolver = new DisplayPathResolver
102 | {
103 | models[0],
104 | models[1],
105 | };
106 |
107 | Assert.AreEqual(@"c:\…\Directory1", models[0].DisplayPath);
108 | Assert.AreEqual(@"c:\root", models[1].DisplayPath);
109 | }
110 |
111 | [TestMethod]
112 | public void WhenDuplicatesInSameNamedDirectories_ShowPathsEndWithMultipleDirectory()
113 | {
114 | var models = new[]
115 | {
116 | new TabModel(@"c:\root\Directory1\SubDirectory1\1.txt"),
117 | new TabModel(@"c:\root\Directory2\SubDirectory1\1.txt"),
118 | };
119 |
120 | var resolver = new DisplayPathResolver
121 | {
122 | models[0],
123 | models[1],
124 | };
125 |
126 | // TODO: VSCode has better display: c:\…\Directory1\…
127 | Assert.AreEqual(@"c:\…\Directory1\SubDirectory1", models[0].DisplayPath);
128 | Assert.AreEqual(@"c:\…\Directory2\SubDirectory1", models[1].DisplayPath);
129 | }
130 |
131 | [TestMethod]
132 | public void WhenDuplicatesDifferByCase_ShowPaths()
133 | {
134 | var models = new[]
135 | {
136 | new TabModel(@"c:\root\Directory1\1.txt"),
137 | new TabModel(@"c:\Root\Directory2\1.txt"),
138 | new TabModel(@"c:\root\Directory1\2.txt"),
139 | new TabModel(@"c:\root\Directory2\2.TXT"),
140 | };
141 |
142 | var resolver = new DisplayPathResolver
143 | {
144 | models[0],
145 | models[1],
146 | models[2],
147 | models[3],
148 | };
149 |
150 | Assert.AreEqual(@"c:\…\Directory1", models[0].DisplayPath);
151 | Assert.AreEqual(@"c:\…\Directory2", models[1].DisplayPath);
152 | Assert.AreEqual(@"c:\…\Directory1", models[2].DisplayPath);
153 | Assert.AreEqual(@"c:\…\Directory2", models[3].DisplayPath);
154 | }
155 |
156 | // TODO: VSCode with different drives: c:\… d:\…
157 |
158 | [TestMethod]
159 | public void WhenDuplicateFullPaths_DoNotShowPaths()
160 | {
161 | var models = new[]
162 | {
163 | new TabModel(@"c:\root\Directory1\1.txt"),
164 | new TabModel(@"c:\root\Directory1\1.txt"),
165 | new TabModel(@"c:\Root\Directory1\1.txt"),
166 | };
167 |
168 | var resolver = new DisplayPathResolver
169 | {
170 | models[0],
171 | models[1],
172 | models[2],
173 | };
174 |
175 | Assert.AreEqual(null, models[0].DisplayPath);
176 | Assert.AreEqual(null, models[1].DisplayPath);
177 | Assert.AreEqual(null, models[2].DisplayPath);
178 | }
179 |
180 | [TestMethod]
181 | public void WhenDuplicatesHaveSamePaths_ShowPaths()
182 | {
183 | var models = new[]
184 | {
185 | new TabModel(@"c:\root\Directory1\1.txt"),
186 | new TabModel(@"c:\root\Directory1\1.txt"),
187 | new TabModel(@"c:\Root\Directory2\1.txt"),
188 | };
189 |
190 | var resolver = new DisplayPathResolver
191 | {
192 | models[0],
193 | models[1],
194 | models[2],
195 | };
196 | Assert.AreEqual(@"c:\…\Directory1", models[0].DisplayPath);
197 | Assert.AreEqual(@"c:\…\Directory1", models[1].DisplayPath);
198 | Assert.AreEqual(@"c:\…\Directory2", models[2].DisplayPath);
199 | }
200 |
201 | [TestMethod]
202 | public void WhenNewTabIsAdded_UpdatePaths()
203 | {
204 | var models = new[]
205 | {
206 | new TabModel(@"c:\Directory1\1.txt"),
207 | new TabModel(@"c:\Directory1\2.txt"),
208 | new TabModel(@"c:\Directory2\1.txt"),
209 | };
210 |
211 | var resolver = new DisplayPathResolver
212 | {
213 | models[0],
214 | models[1],
215 | };
216 |
217 | Assert.AreEqual(null, models[0].DisplayPath);
218 | Assert.AreEqual(null, models[1].DisplayPath);
219 |
220 | resolver.Add(models[2]);
221 |
222 | Assert.AreEqual(@"c:\Directory1", models[0].DisplayPath);
223 | Assert.AreEqual(null, models[1].DisplayPath);
224 | Assert.AreEqual(@"c:\Directory2", models[2].DisplayPath);
225 | }
226 |
227 | [TestMethod]
228 | public void WhenNewTabIsRemoved_UpdatePaths()
229 | {
230 | var models = new[]
231 | {
232 | new TabModel(@"c:\Directory1\1.txt"),
233 | new TabModel(@"c:\Directory1\2.txt"),
234 | new TabModel(@"c:\Directory2\1.txt"),
235 | };
236 |
237 | var resolver = new DisplayPathResolver
238 | {
239 | models[0],
240 | models[1],
241 | models[2],
242 | };
243 |
244 | Assert.AreEqual(@"c:\Directory1", models[0].DisplayPath);
245 | Assert.AreEqual(null, models[1].DisplayPath);
246 | Assert.AreEqual(@"c:\Directory2", models[2].DisplayPath);
247 |
248 | resolver.Remove(models[2]);
249 |
250 | Assert.AreEqual(null, models[0].DisplayPath);
251 | Assert.AreEqual(null, models[1].DisplayPath);
252 | }
253 |
254 | [TestMethod]
255 | public void WhenNewTabIsRenamed_UpdatePaths()
256 | {
257 | var models = new[]
258 | {
259 | new TabModel(@"c:\Directory1\1.txt"),
260 | new TabModel(@"c:\Directory1\2.txt"),
261 | new TabModel(@"c:\Directory2\3.txt"),
262 | };
263 |
264 | var resolver = new DisplayPathResolver
265 | {
266 | models[0],
267 | models[1],
268 | models[2],
269 | };
270 |
271 | Assert.AreEqual(null, models[0].DisplayPath);
272 | Assert.AreEqual(null, models[1].DisplayPath);
273 | Assert.AreEqual(null, models[2].DisplayPath);
274 |
275 | models[2].FullPath = @"c:\Directory2\1.txt";
276 |
277 | Assert.AreEqual(@"c:\Directory1", models[0].DisplayPath);
278 | Assert.AreEqual(null, models[1].DisplayPath);
279 | Assert.AreEqual(@"c:\Directory2", models[2].DisplayPath);
280 | }
281 |
282 | [TestMethod]
283 | public void WhenNewTabIsMoved_UpdatePaths()
284 | {
285 | var models = new[]
286 | {
287 | new TabModel(@"c:\Directory1\1.txt"),
288 | new TabModel(@"c:\Directory1\2.txt"),
289 | new TabModel(@"c:\Directory2\1.txt"),
290 | };
291 |
292 | var resolver = new DisplayPathResolver
293 | {
294 | models[0],
295 | models[1],
296 | models[2],
297 | };
298 |
299 | Assert.AreEqual(@"c:\Directory1", models[0].DisplayPath);
300 | Assert.AreEqual(null, models[1].DisplayPath);
301 | Assert.AreEqual(@"c:\Directory2", models[2].DisplayPath);
302 |
303 | models[2].FullPath = @"c:\Directory3\1.txt";
304 |
305 | Assert.AreEqual(@"c:\Directory1", models[0].DisplayPath);
306 | Assert.AreEqual(null, models[1].DisplayPath);
307 | Assert.AreEqual(@"c:\Directory3", models[2].DisplayPath);
308 | }
309 | }
310 | }
311 |
--------------------------------------------------------------------------------