diff --git a/solution/ExcludeFromBuild/ExcludeFromBuildActiveCommand.cs b/solution/ExcludeFromBuild/ExcludeFromBuildActiveCommand.cs index 7916e08..a4198ad 100644 --- a/solution/ExcludeFromBuild/ExcludeFromBuildActiveCommand.cs +++ b/solution/ExcludeFromBuild/ExcludeFromBuildActiveCommand.cs @@ -7,9 +7,11 @@ using EnvDTE; using EnvDTE80; using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; using System; using System.ComponentModel.Design; using System.Threading.Tasks; +using System.Windows.Forms; namespace ExcludeFromBuild { @@ -34,6 +36,7 @@ internal sealed class ExcludeFromBuildActiveCommand private readonly AsyncPackage package; private readonly DTE2 dte; + private readonly IVsStatusbar statusBar; /// /// Initializes a new instance of the class. @@ -41,11 +44,12 @@ internal sealed class ExcludeFromBuildActiveCommand /// /// Owner package, not null. /// Command service to add command to, not null. - private ExcludeFromBuildActiveCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte) + private ExcludeFromBuildActiveCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte, IVsStatusbar statusBar) { this.package = package ?? throw new ArgumentNullException(nameof(package)); commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); this.dte = dte ?? throw new ArgumentNullException(nameof(dte)); + this.statusBar = statusBar ?? throw new ArgumentNullException(nameof(statusBar)); var menuCommandID = new CommandID(CommandSet, CommandId); var menuItem = new MenuCommand(this.Execute, menuCommandID); @@ -82,7 +86,8 @@ public static async Task InitializeAsync(AsyncPackage package) OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; DTE2 dte = await package.GetServiceAsync(typeof(DTE)) as DTE2; - Instance = new ExcludeFromBuildActiveCommand(package, commandService, dte); + IVsStatusbar statusBar = await package.GetServiceAsync(typeof(SVsStatusbar)) as IVsStatusbar; + Instance = new ExcludeFromBuildActiveCommand(package, commandService, dte, statusBar); } /// @@ -96,7 +101,10 @@ private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); - Util.SetExcludedFromBuild(dte, true, Util.Configuration.Active); + Util.UnfreezeStatusBar(statusBar); + Util.SetExcludedFromBuild(dte, true, Util.Configuration.Active, + (string name) => { statusBar.SetText("Exclude (Active): " + name); }); + statusBar.SetText(""); } } } diff --git a/solution/ExcludeFromBuild/ExcludeFromBuildAllCommand.cs b/solution/ExcludeFromBuild/ExcludeFromBuildAllCommand.cs index 5639718..8d0feb3 100644 --- a/solution/ExcludeFromBuild/ExcludeFromBuildAllCommand.cs +++ b/solution/ExcludeFromBuild/ExcludeFromBuildAllCommand.cs @@ -7,9 +7,11 @@ using EnvDTE; using EnvDTE80; using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; using System; using System.ComponentModel.Design; using System.Threading.Tasks; +using System.Windows.Forms; namespace ExcludeFromBuild { @@ -34,6 +36,7 @@ internal sealed class ExcludeFromBuildAllCommand private readonly AsyncPackage package; private readonly DTE2 dte; + private readonly IVsStatusbar statusBar; /// /// Initializes a new instance of the class. @@ -41,11 +44,12 @@ internal sealed class ExcludeFromBuildAllCommand /// /// Owner package, not null. /// Command service to add command to, not null. - private ExcludeFromBuildAllCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte) + private ExcludeFromBuildAllCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte, IVsStatusbar statusBar) { this.package = package ?? throw new ArgumentNullException(nameof(package)); commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); this.dte = dte ?? throw new ArgumentNullException(nameof(dte)); + this.statusBar = statusBar ?? throw new ArgumentNullException(nameof(statusBar)); var menuCommandID = new CommandID(CommandSet, CommandId); var menuItem = new MenuCommand(this.Execute, menuCommandID); @@ -82,7 +86,8 @@ public static async Task InitializeAsync(AsyncPackage package) OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; DTE2 dte = await package.GetServiceAsync(typeof(DTE)) as DTE2; - Instance = new ExcludeFromBuildAllCommand(package, commandService, dte); + IVsStatusbar statusBar = await package.GetServiceAsync(typeof(SVsStatusbar)) as IVsStatusbar; + Instance = new ExcludeFromBuildAllCommand(package, commandService, dte, statusBar); } /// @@ -96,7 +101,10 @@ private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); - Util.SetExcludedFromBuild(dte, true, Util.Configuration.All); + Util.UnfreezeStatusBar(statusBar); + Util.SetExcludedFromBuild(dte, true, Util.Configuration.All, + (string name) => { statusBar.SetText("Exclude (All): " + name); }); + statusBar.SetText(""); } } } diff --git a/solution/ExcludeFromBuild/ExcludeFromBuildCommand.cs b/solution/ExcludeFromBuild/ExcludeFromBuildCommand.cs index 09e4e5e..7c21088 100644 --- a/solution/ExcludeFromBuild/ExcludeFromBuildCommand.cs +++ b/solution/ExcludeFromBuild/ExcludeFromBuildCommand.cs @@ -7,9 +7,13 @@ using EnvDTE; using EnvDTE80; using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; using System; using System.ComponentModel.Design; +using System.Drawing; +using System.Net; using System.Threading.Tasks; +using System.Xml.Linq; namespace ExcludeFromBuild { @@ -34,6 +38,7 @@ internal sealed class ExcludeFromBuildCommand private readonly AsyncPackage package; private readonly DTE2 dte; + private readonly IVsStatusbar statusBar; /// /// Initializes a new instance of the class. @@ -41,11 +46,12 @@ internal sealed class ExcludeFromBuildCommand /// /// Owner package, not null. /// Command service to add command to, not null. - private ExcludeFromBuildCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte) + private ExcludeFromBuildCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte, IVsStatusbar statusBar) { this.package = package ?? throw new ArgumentNullException(nameof(package)); commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); this.dte = dte ?? throw new ArgumentNullException(nameof(dte)); + this.statusBar = statusBar ?? throw new ArgumentNullException(nameof(statusBar)); var menuCommandID = new CommandID(CommandSet, CommandId); var menuItem = new MenuCommand(this.Execute, menuCommandID); @@ -82,9 +88,13 @@ public static async Task InitializeAsync(AsyncPackage package) OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; DTE2 dte = await package.GetServiceAsync(typeof(DTE)) as DTE2; - Instance = new ExcludeFromBuildCommand(package, commandService, dte); + IVsStatusbar statusBar = await package.GetServiceAsync(typeof(SVsStatusbar)) as IVsStatusbar; + Instance = new ExcludeFromBuildCommand(package, commandService, dte, statusBar); } + [System.Runtime.InteropServices.DllImport("gdi32.dll")] + public static extern bool DeleteObject(IntPtr hObject); + /// /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using @@ -96,8 +106,10 @@ private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); - Util.SetExcludedFromBuild(dte, true, Util.GetConfigurationOption()); + Util.UnfreezeStatusBar(statusBar); + Util.SetExcludedFromBuild(dte, true, Util.GetConfigurationOption(), + (string name) => { statusBar.SetText("Exclude: " + name); }); + statusBar.SetText(""); } - } } diff --git a/solution/ExcludeFromBuild/IncludeInBuildActiveCommand.cs b/solution/ExcludeFromBuild/IncludeInBuildActiveCommand.cs index 3c187e2..8ab2fc3 100644 --- a/solution/ExcludeFromBuild/IncludeInBuildActiveCommand.cs +++ b/solution/ExcludeFromBuild/IncludeInBuildActiveCommand.cs @@ -7,9 +7,11 @@ using EnvDTE; using EnvDTE80; using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; using System; using System.ComponentModel.Design; using System.Threading.Tasks; +using System.Windows.Forms; namespace ExcludeFromBuild { @@ -34,6 +36,7 @@ internal sealed class IncludeInBuildActiveCommand private readonly AsyncPackage package; private readonly DTE2 dte; + private readonly IVsStatusbar statusBar; /// /// Initializes a new instance of the class. @@ -41,11 +44,12 @@ internal sealed class IncludeInBuildActiveCommand /// /// Owner package, not null. /// Command service to add command to, not null. - private IncludeInBuildActiveCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte) + private IncludeInBuildActiveCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte, IVsStatusbar statusBar) { this.package = package ?? throw new ArgumentNullException(nameof(package)); commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); this.dte = dte ?? throw new ArgumentNullException(nameof(dte)); + this.statusBar = statusBar ?? throw new ArgumentNullException(nameof(statusBar)); var menuCommandID = new CommandID(CommandSet, CommandId); var menuItem = new MenuCommand(this.Execute, menuCommandID); @@ -82,7 +86,8 @@ public static async Task InitializeAsync(AsyncPackage package) OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; DTE2 dte = await package.GetServiceAsync(typeof(DTE)) as DTE2; - Instance = new IncludeInBuildActiveCommand(package, commandService, dte); + IVsStatusbar statusBar = await package.GetServiceAsync(typeof(SVsStatusbar)) as IVsStatusbar; + Instance = new IncludeInBuildActiveCommand(package, commandService, dte, statusBar); } /// @@ -96,7 +101,10 @@ private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); - Util.SetExcludedFromBuild(dte, false, Util.Configuration.Active); + Util.UnfreezeStatusBar(statusBar); + Util.SetExcludedFromBuild(dte, false, Util.Configuration.Active, + (string name) => { statusBar.SetText("Include (Active): " + name); }); + statusBar.SetText(""); } } } diff --git a/solution/ExcludeFromBuild/IncludeInBuildAllCommand.cs b/solution/ExcludeFromBuild/IncludeInBuildAllCommand.cs index a95f201..788b671 100644 --- a/solution/ExcludeFromBuild/IncludeInBuildAllCommand.cs +++ b/solution/ExcludeFromBuild/IncludeInBuildAllCommand.cs @@ -7,9 +7,11 @@ using EnvDTE; using EnvDTE80; using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; using System; using System.ComponentModel.Design; using System.Threading.Tasks; +using System.Windows.Forms; namespace ExcludeFromBuild { @@ -34,6 +36,7 @@ internal sealed class IncludeInBuildAllCommand private readonly AsyncPackage package; private readonly DTE2 dte; + private readonly IVsStatusbar statusBar; /// /// Initializes a new instance of the class. @@ -41,11 +44,12 @@ internal sealed class IncludeInBuildAllCommand /// /// Owner package, not null. /// Command service to add command to, not null. - private IncludeInBuildAllCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte) + private IncludeInBuildAllCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte, IVsStatusbar statusBar) { this.package = package ?? throw new ArgumentNullException(nameof(package)); commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); this.dte = dte ?? throw new ArgumentNullException(nameof(dte)); + this.statusBar = statusBar ?? throw new ArgumentNullException(nameof(statusBar)); var menuCommandID = new CommandID(CommandSet, CommandId); var menuItem = new MenuCommand(this.Execute, menuCommandID); @@ -82,7 +86,8 @@ public static async Task InitializeAsync(AsyncPackage package) OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; DTE2 dte = await package.GetServiceAsync(typeof(DTE)) as DTE2; - Instance = new IncludeInBuildAllCommand(package, commandService, dte); + IVsStatusbar statusBar = await package.GetServiceAsync(typeof(SVsStatusbar)) as IVsStatusbar; + Instance = new IncludeInBuildAllCommand(package, commandService, dte, statusBar); } /// @@ -96,7 +101,10 @@ private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); - Util.SetExcludedFromBuild(dte, false, Util.Configuration.All); + Util.UnfreezeStatusBar(statusBar); + Util.SetExcludedFromBuild(dte, false, Util.Configuration.All, + (string name) => { statusBar.SetText("Include (All): " + name); }); + statusBar.SetText(""); } } } diff --git a/solution/ExcludeFromBuild/IncludeInBuildCommand.cs b/solution/ExcludeFromBuild/IncludeInBuildCommand.cs index 362c10f..ddbcf0b 100644 --- a/solution/ExcludeFromBuild/IncludeInBuildCommand.cs +++ b/solution/ExcludeFromBuild/IncludeInBuildCommand.cs @@ -7,9 +7,11 @@ using EnvDTE; using EnvDTE80; using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; using System; using System.ComponentModel.Design; using System.Threading.Tasks; +using System.Windows.Forms; namespace ExcludeFromBuild { @@ -34,6 +36,7 @@ internal sealed class IncludeInBuildCommand private readonly AsyncPackage package; private readonly DTE2 dte; + private readonly IVsStatusbar statusBar; /// /// Initializes a new instance of the class. @@ -41,11 +44,12 @@ internal sealed class IncludeInBuildCommand /// /// Owner package, not null. /// Command service to add command to, not null. - private IncludeInBuildCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte) + private IncludeInBuildCommand(AsyncPackage package, OleMenuCommandService commandService, DTE2 dte, IVsStatusbar statusBar) { this.package = package ?? throw new ArgumentNullException(nameof(package)); commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); this.dte = dte ?? throw new ArgumentNullException(nameof(dte)); + this.statusBar = statusBar ?? throw new ArgumentNullException(nameof(statusBar)); var menuCommandID = new CommandID(CommandSet, CommandId); var menuItem = new MenuCommand(this.Execute, menuCommandID); @@ -82,7 +86,8 @@ public static async Task InitializeAsync(AsyncPackage package) OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; DTE2 dte = await package.GetServiceAsync(typeof(DTE)) as DTE2; - Instance = new IncludeInBuildCommand(package, commandService, dte); + IVsStatusbar statusBar = await package.GetServiceAsync(typeof(SVsStatusbar)) as IVsStatusbar; + Instance = new IncludeInBuildCommand(package, commandService, dte, statusBar); } /// @@ -96,7 +101,10 @@ private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); - Util.SetExcludedFromBuild(dte, false, Util.GetConfigurationOption()); + Util.UnfreezeStatusBar(statusBar); + Util.SetExcludedFromBuild(dte, false, Util.GetConfigurationOption(), + (string name) => { statusBar.SetText("Include: " + name); }); + statusBar.SetText(""); } } } diff --git a/solution/ExcludeFromBuild/Util.cs b/solution/ExcludeFromBuild/Util.cs index ac465c9..11d0e33 100644 --- a/solution/ExcludeFromBuild/Util.cs +++ b/solution/ExcludeFromBuild/Util.cs @@ -7,10 +7,14 @@ using EnvDTE; using EnvDTE80; using Microsoft.VisualStudio; +using Microsoft.VisualStudio.Shell.Interop; +using Microsoft.VisualStudio.Shell; using System; using System.Collections; using System.Collections.Generic; using System.Reflection; +using System.Windows.Forms; +using System.Drawing; namespace ExcludeFromBuild { @@ -36,8 +40,10 @@ private class ItemType public static readonly string Resource = "Resource"; } + public delegate void Callback(string name); + #pragma warning disable VSTHRD010 - public static void SetExcludedFromBuild(DTE2 dte, bool value, Configuration configuration) + public static void SetExcludedFromBuild(DTE2 dte, bool value, Configuration configuration, Callback callback) { if (dte == null) return; @@ -45,7 +51,7 @@ public static void SetExcludedFromBuild(DTE2 dte, bool value, Configuration conf if (items == null) return; HashSet visited = new HashSet(); - SetExcludedFromBuildRecursive(items, value, configuration, visited); + SetExcludedFromBuildRecursive(items, value, configuration, callback, visited); } // Casting COM objects to VCFile and VCFilter works but the problem is that @@ -56,6 +62,7 @@ public static void SetExcludedFromBuild(DTE2 dte, bool value, Configuration conf private static void SetExcludedFromBuildRecursive(IEnumerable items, bool value, Configuration configuration, + Callback callback, HashSet visited) { foreach (var item in items) @@ -91,6 +98,7 @@ private static void SetExcludedFromBuildRecursive(IEnumerable items, SetExcludedFromBuildRecursive(hitem.UIHierarchyItems, value, configuration, + callback, visited); } @@ -107,12 +115,16 @@ private static void SetExcludedFromBuildRecursive(IEnumerable items, // C#, VB if (extension == ".cs" || extension == ".vb") { + callback(pitem.Name); + SetPropertyValue(pitem, "BuildAction", (int)(value ? BuildAction.None : BuildAction.Compile)); } // WPF else if (extension == ".xaml") { + callback(pitem.Name); + if (value) SetPropertyValue(pitem, "BuildAction", (int)BuildAction.None); else @@ -144,6 +156,8 @@ private static void SetExcludedFromBuildRecursive(IEnumerable items, string kind = GetPropertyValue(pitem, "Kind") as string; if (kind == "VCFile") { + callback(pitem.Name); + var activeConfig = pitem.ContainingProject.ConfigurationManager.ActiveConfiguration; string activeConfigName = activeConfig.ConfigurationName; string activePlatformName = activeConfig.PlatformName; @@ -367,5 +381,14 @@ private static string RootXMLElementName(string url) return null; } } + + public static void UnfreezeStatusBar(IVsStatusbar statusBar) + { + statusBar.IsFrozen(out int frozen); + if (frozen != 0) + { + statusBar.FreezeOutput(0); + } + } } }