1

I have implemented an annotate function in the Visual Studio Extension AnkhSVN2019 using a custom margin on an editor window.

In the current version, the tab on the editor window just contains the filename, and looks identical to a normal editor window. I would like to modify the caption, for example by appending the word "Annotated".

I am opening the editor window with

dte.ItemOperations.OpenFile

In the margin factory, I get the interface IWpfTextViewHost.

How can I modify the caption in the tab?

Phil Jollans
  • 3,605
  • 2
  • 37
  • 50
  • l think you can use `dte.ActiveWindow.Caption`. Please refer to [ActiveWindow Property](https://learn.microsoft.com/en-us/dotnet/api/envdte._dte.activewindow?view=visualstudiosdk-2017) and when you open the editor window, you can use activewindow to catch it. – Mr Qian Jan 15 '20 at 09:35
  • Unfortunately this lead to an **InvalidOperationException** with the message **"The caption of a Document or the MainWindow cannot be modified."** – Phil Jollans Jan 16 '20 at 22:38
  • Hi The Caption can be set for tool windows in [Window.Caption Property][1] Not sure how could you realize the custom margin the editor window. Could you please provide more specific detail in your project. I am also try to customer the margin for an editor windows. [1]: https://learn.microsoft.com/en-us/dotnet/api/envdte.window.caption?view=visualstudiosdk-2017 – DevPreSupport_MSFT Mar 09 '20 at 09:51
  • The custom margin is on an editor window, not a tool window. If you are looking for examples, the custom margin I implemented is in the [Annotate subdirectory of the Anhh.UI project](https://github.com/PhilJollans/AnkhSVN2019/tree/master/src/Ankh.UI/Annotate). I got some ideas from the [GitDiffMargin project](https://github.com/laurentkempe/GitDiffMargin). If you want to add a something to the glyph margin, there is a good walkthrough from Microsoft. You can add a simple margin in Visual Studio via Add/New Item -> C#/Extensibility/Editor -> Editor Margin. – Phil Jollans Mar 09 '20 at 19:21
  • Base on the getDiffMargin, It edit the caption by following code, It doesn't use the Object dte,itemoperations. I don't find the way to customize the editor window. using SVsDifferenceService = Microsoft.VisualStudio.Shell.Interop.SVsDifferenceService; IVsDifferenceService differenceService = _serviceProvider.GetService(typeof(SVsDifferenceService)) as IVsDifferenceService; differenceService.OpenComparisonWindow2(leftFileMoniker, rightFileMoniker, caption, tooltip, leftLabel, rightLabel, inlineLabel, roles, (uint)grfDiffOptions); – DevPreSupport_MSFT May 06 '20 at 01:39

1 Answers1

1

You can implement your own Microsoft.VisualStudio.PlatformUI.Shell.ViewElementFactory from <VS installation>\Common7\IDE\Microsoft.VisualStudio.Shell.ViewManager.dll to overide the tab appearance i.e. showing the caption as you wish.

Look at VSTabPath extension code for inspiration.

Bohdan
  • 468
  • 5
  • 6
  • Thanks. I have managed to compile the VSTabPath extension and it certainly works, so I know there is a solution to the problem. I haven't quite figured out how it works yet, but I hope to understand it soon. – Phil Jollans Nov 22 '20 at 22:49