Skip to content

Feature/autoclose reopen #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/options/Constants/PageConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public static class PageConstants
public const string PackageVersion = "Version Number";
public const string OpenLinksInVS = "Open Links in VS";
public const string EnableStartPagePlusOptions = "Start Page+ Options";
public const string AutoCloseOnSolutionOpen = "Automatically close Start Page+ when solution opens, show when solution closes";
}
}
5 changes: 5 additions & 0 deletions src/options/Pages/GeneralDialogPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ public class GeneralDialogPage : DialogPage
[DisplayName(Enable + Space + Quote + Constants.PageConstants.EnableStartPagePlusOptions + Quote)]
[Description("Determines if a button to open" + Space + Quote + PackageName + Quote + Space + "options is added to the" + Space + Quote + "Tools" + Quote + Space + "Menu")]
public bool EnableStartPagePlusOptions { get; set; } = true;

[Category(H2 + Features)]
[DisplayName(Enable + Space + Quote + Constants.PageConstants.AutoCloseOnSolutionOpen + Quote)]
[Description("Determines whether to automatically close StartPage+ when a solution opens and open StartPage+ when the solution is closed")]
public bool AutomaticallyCloseOnSolutionOpen { get; set; } = true;
}
}
3 changes: 2 additions & 1 deletion src/ui/StartPagePlusWindow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Windows;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.Shell;
using Microsoft.Win32;
Expand All @@ -16,7 +17,7 @@ public StartPagePlusWindow(RegistryKey registryRoot) : base(null)
{
Caption = Vsix.Name;
BitmapImageMoniker = KnownMonikers.Home;
Content = new MainView(registryRoot);
var mainView = (MainView) ( Content = new MainView(registryRoot));
}
}
}
37 changes: 36 additions & 1 deletion src/vsix/Package.class.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices;
using System.Threading;
using EnvDTE;
using Luminous.Code.Extensions.ExceptionExtensions;
using Luminous.Code.VisualStudio.Commands;
using Luminous.Code.VisualStudio.Packages;
Expand Down Expand Up @@ -43,7 +44,41 @@ protected override async Tasks.Task InitializeAsync(CancellationToken cancellati
await ViewStartPagePlus.InstantiateAsync(this);
await StartPagePlusOptions.InstantiateAsync(this);

//await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
this.SolutionEvents = Dte.Events.SolutionEvents;
SolutionEvents.Opened += OnSolutionOpened;
SolutionEvents.AfterClosing += SolutionEventsOnAfterClosing;
}

public EnvDTE.SolutionEvents SolutionEvents { get; set; }

private bool _isExiting;

private async void OnSolutionOpened()
{
if (GeneralOptions.AutomaticallyCloseOnSolutionOpen)
{
var toolWindow = await Instance.FindToolWindowAsync(typeof(StartPagePlusWindow), 0, false, Instance.DisposalToken);
JoinableTaskFactory.Run(async delegate
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var windowPane = toolWindow.GetIVsWindowPane() as StartPagePlusWindow;
(windowPane?.Frame as IVsWindowFrame)?.Hide();
});
}
}

private async void SolutionEventsOnAfterClosing()
{
if (GeneralOptions.AutomaticallyCloseOnSolutionOpen)
{
var toolWindow = await Instance.FindToolWindowAsync(typeof(StartPagePlusWindow), 0, false, Instance.DisposalToken);
JoinableTaskFactory.Run(async delegate
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var windowPane = toolWindow.GetIVsWindowPane() as StartPagePlusWindow;
(windowPane?.Frame as IVsWindowFrame)?.ShowNoActivate();
});
}
}

protected override async Tasks.Task<object> InitializeToolWindowAsync(Type toolWindowType, int id, CancellationToken cancellationToken)
Expand Down