Skip to content

Commit

Permalink
V5.1.0 2022/02/26
Browse files Browse the repository at this point in the history
- Added support for compact title rewriting.
  • Loading branch information
mayerwin committed Feb 27, 2022
1 parent 2b6efbc commit f53b451
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 83 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*.csproj.user
*.bak
[Bb]in
[Dd]ebug*/
obj/
[Rr]elease*/
_ReSharper*/
Expand Down
41 changes: 0 additions & 41 deletions .hgignore

This file was deleted.

4 changes: 2 additions & 2 deletions CustomizeVSWindowTitle.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomizeVSWindowTitle", "C
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "CustomizeVSWindowTitleShared", "CustomizeVSWindowTitleShared\CustomizeVSWindowTitleShared.shproj", "{BBB5B91B-E909-4F08-B623-9F27377EE7DC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomizeVSWindowTitle17", "CustomizeVSWindowTitle17\CustomizeVSWindowTitle17.csproj", "{BF533FE9-559F-4AC7-8506-81F7883F1AA9}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomizeVSWindowTitle2022", "CustomizeVSWindowTitle2022\CustomizeVSWindowTitle2022.csproj", "{BF533FE9-559F-4AC7-8506-81F7883F1AA9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomizeVSWindowTitleSharedResources", "CustomizeVSWindowTitleSharedResources\CustomizeVSWindowTitleSharedResources.csproj", "{A923831E-ED5C-4DBA-85C6-DEF2DB9D23C0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomizeVSWindowTitleSharedResources", "CustomizeVSWindowTitleSharedResources\CustomizeVSWindowTitleSharedResources.csproj", "{A923831E-ED5C-4DBA-85C6-DEF2DB9D23C0}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Expand Down
3 changes: 1 addition & 2 deletions CustomizeVSWindowTitle/CustomizeVSWindowTitle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
</None>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
<LastGenOutput>source.extension.resx</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -158,7 +157,7 @@ if not exist "$(SolutionDir)Releases\" (
if errorlevel 1 goto Error
)

copy /Y "$(TargetDir)$(TargetName).vsix" "$(SolutionDir)Releases\$(TargetName) (new19).vsix"
copy /Y "$(TargetDir)$(TargetName).vsix" "$(SolutionDir)Releases\$(TargetName)2019 (new).vsix"
if errorlevel 1 goto Error

exit /b 0
Expand Down
2 changes: 1 addition & 1 deletion CustomizeVSWindowTitle/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="5126c493-138a-46d7-a04d-ad772f6be159" Version="5.0.2" Language="en-US" Publisher="Erwin Mayer" />
<Identity Id="5126c493-138a-46d7-a04d-ad772f6be159" Version="5.1.0" Language="en-US" Publisher="Erwin Mayer" />
<DisplayName>Customize Visual Studio Window Title</DisplayName>
<Description xml:space="preserve">This lightweight extension allows changing the window title of Visual Studio to include a folder tree with a configurable min depth and max depth distance from the solution/project file, and the use of special tags to help with many other possible scenarios (Git, Hg, TFS, SVN...).
Solution-specific overriding rules are available as well to cover virtually any possible renaming needs. It can also be configured so that the rules apply only when at least two instances of Visual Studio are running with the same window title.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ErwinMayerLabs.RenameVSWindowTitle</RootNamespace>
<AssemblyName>CustomizeVSWindowTitle17</AssemblyName>
<AssemblyName>CustomizeVSWindowTitle2022</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<GeneratePkgDefFile>true</GeneratePkgDefFile>
<UseCodebase>true</UseCodebase>
Expand Down Expand Up @@ -130,7 +130,7 @@ if not exist "$(SolutionDir)Releases\" (
if errorlevel 1 goto Error
)

copy /Y "$(TargetDir)$(TargetName).vsix" "$(SolutionDir)Releases\$(TargetName) (new22).vsix"
copy /Y "$(TargetDir)$(TargetName).vsix" "$(SolutionDir)Releases\$(TargetName) (new).vsix"
if errorlevel 1 goto Error

exit /b 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="CustomizeVSWindowTitle17.8f96ef44-09b8-47c5-ae51-2d83310a23a1" Version="5.0.2" Language="en-US" Publisher="Erwin Mayer" />
<Identity Id="CustomizeVSWindowTitle17.8f96ef44-09b8-47c5-ae51-2d83310a23a1" Version="5.1.0" Language="en-US" Publisher="Erwin Mayer" />
<DisplayName>Customize Visual Studio Window Title</DisplayName>
<Description xml:space="preserve">This lightweight extension allows changing the window title of Visual Studio to include a folder tree with a configurable min depth and max depth distance from the solution/project file, and the use of special tags to help with many other possible scenarios (Git, Hg, TFS, SVN...).
Solution-specific overriding rules are available as well to cover virtually any possible renaming needs. It can also be configured so that the rules apply only when at least two instances of Visual Studio are running with the same window title.
Expand All @@ -13,21 +13,21 @@ This is particularly useful when branching a solution/project: it becomes possib
<Tags>Git, Hg, TFS, Team Foundation Server, SVN, Window title, solution path, path, explicit title, multiple instances, rename title, change title, replace title, branch name</Tags>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0, 18.0)">
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0,)">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Id="Microsoft.VisualStudio.Pro" Version="[17.0, 18.0)">
<InstallationTarget Id="Microsoft.VisualStudio.Pro" Version="[17.0,)">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Id="Microsoft.VisualStudio.Enterprise" Version="[17.0, 18.0)">
<InstallationTarget Id="Microsoft.VisualStudio.Enterprise" Version="[17.0,)">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,18.0)" DisplayName="Visual Studio core editor" />
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
Expand Down
65 changes: 36 additions & 29 deletions CustomizeVSWindowTitleShared/CustomizeVSWindowTitlePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ select this.GetVSSolutionName(vsInstance.MainWindowTitle)).Any(vsInstanceName =>
var pattern = this.GetPattern(solutionFp, useDefaultPattern, settings);
var newTitle = this.GetNewTitle(solution, pattern, settings);
this.ChangeWindowTitle(newTitle);
this.ChangeXamlTitle(newTitle);
if (this.UiSettings.RewriteCompactTitle) this.ChangeXamlTitle(!string.IsNullOrWhiteSpace(this.IDEName) ? newTitle.Replace(" - " + this.IDEName, "") : newTitle);
}
catch (Exception ex) {
try {
Expand Down Expand Up @@ -558,7 +558,7 @@ private void ChangeWindowTitle(string title) {
try {
Globals.BeginInvokeOnUIThread(() => {
try {
var mw = System.Windows.Application.Current.MainWindow;
var mw = Application.Current.MainWindow;
mw.Title = Globals.DTE.MainWindow.Caption;
if (mw.Title != title) {
mw.Title = title;
Expand Down Expand Up @@ -586,20 +586,35 @@ private void ChangeWindowTitle(string title) {
}
}

private void ChangeXamlTitle(string title)
{
var mw = System.Windows.Application.Current.MainWindow;
// This part was found by looking at the Document tree. Could possibly change in future releases
// but this is the name for 2019 and 2022.
var statusBartTextBlock = FindChild<DependencyObject>(mw, "PART_SolutionNameTextBlock");
private TextBlock TitleTextBlock;
private void ChangeXamlTitle(string title) {
try {
Globals.BeginInvokeOnUIThread(() => {
try {
if (this.TitleTextBlock == null) {
var mw = Application.Current.MainWindow;
// This part was found by looking at the Document tree. Could possibly change in future releases
// but this is the name for 2019 and 2022.
var statusBartTextBlock = FindChild<DependencyObject>(mw, "PART_SolutionNameTextBlock");

if (statusBartTextBlock is null) {
return;
}

if (statusBartTextBlock is null)
{
return;
this.TitleTextBlock = FindChild<TextBlock>(statusBartTextBlock);
}
this.TitleTextBlock.Text = title;
}
catch (Exception) {
// ignored
}
});
}
catch (Exception ex) {
if (this.UiSettings.EnableDebugMode) {
WriteOutput("ChangeWindowTitle failed: " + ex);
}
}

var textBlock = FindChild<TextBlock>(statusBartTextBlock);
textBlock.Text = title;
}

public static void WriteOutput(string str, params object[] args) {
Expand All @@ -620,7 +635,6 @@ public static void WriteOutput(string str, params object[] args) {
}
}


/// <summary>
/// Finds a Child of a given item in the visual tree.
/// </summary>
Expand All @@ -635,36 +649,29 @@ public static void WriteOutput(string str, params object[] args) {
/// If not matching item can be found,
/// a <see langword="null"/> is returned.</returns>
private static T FindChild<T>(DependencyObject parent, string childName = null)
where T : DependencyObject
{
where T : DependencyObject {
// Confirm parent and childName are valid.
if (parent == null) return null;

T foundChild = null;

int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < childrenCount; i++)
{
for (int i = 0; i < childrenCount; i++) {
var child = VisualTreeHelper.GetChild(parent, i);
if (!string.IsNullOrEmpty(childName))
{
if (!string.IsNullOrEmpty(childName)) {
// If the child is not of the request child type child
var frameworkElement = child as FrameworkElement;
// If the child's name is set for search
if (frameworkElement != null)
{
if (frameworkElement.Name == childName)
{
if (frameworkElement != null) {
if (frameworkElement.Name == childName) {
// if the child's name is of the request name
foundChild = (T)child;
break;
}
}
}
else
{
if (child is T typedChild)
{
else {
if (child is T typedChild) {
foundChild = typedChild;
break;
}
Expand Down
6 changes: 6 additions & 0 deletions CustomizeVSWindowTitleShared/GlobalSettingsPageGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class GlobalSettingsPageGrid : DialogPage {
[DefaultValue(true)]
public bool AlwaysRewriteTitles { get; set; } = true;

[Category("General")]
[DisplayName("Support for compact mode")]
[Description("Default: true. If true, will also rewrite the compact window title when compact mode is enabled (without \"- [ideName]\" if present).")]
[DefaultValue(true)]
public bool RewriteCompactTitle { get; set; } = true;

[Category("General")]
[DisplayName("Farthest parent folder depth")]
[Description("Default: 1. Distance of the farthest parent folder to be shown. 1 will only show the folder of the opened project/solution file, before the project/folder name")]
Expand Down

0 comments on commit f53b451

Please sign in to comment.