Skip to content

Commit

Permalink
1st commit
Browse files Browse the repository at this point in the history
  • Loading branch information
odalet committed Mar 27, 2022
1 parent 7ff64a2 commit 815b7b3
Show file tree
Hide file tree
Showing 15 changed files with 607 additions and 0 deletions.
1 change: 1 addition & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mode: ContinuousDeployment
31 changes: 31 additions & 0 deletions src/WebBrowserExtension.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32210.238
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebBrowserExtension", "WebBrowserExtension\WebBrowserExtension.csproj", "{E2859467-784A-4EC0-9BA5-B1502C80F1F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E2859467-784A-4EC0-9BA5-B1502C80F1F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2859467-784A-4EC0-9BA5-B1502C80F1F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2859467-784A-4EC0-9BA5-B1502C80F1F1}.Debug|x86.ActiveCfg = Debug|x86
{E2859467-784A-4EC0-9BA5-B1502C80F1F1}.Debug|x86.Build.0 = Debug|x86
{E2859467-784A-4EC0-9BA5-B1502C80F1F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2859467-784A-4EC0-9BA5-B1502C80F1F1}.Release|Any CPU.Build.0 = Release|Any CPU
{E2859467-784A-4EC0-9BA5-B1502C80F1F1}.Release|x86.ActiveCfg = Release|x86
{E2859467-784A-4EC0-9BA5-B1502C80F1F1}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DF426945-2D6E-4A1E-ADF5-30C417F75AB1}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions src/WebBrowserExtension/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>", Scope = "member", Target = "~M:WebBrowserExtension.WebBrowserWindowControl.InitializeAsync")]
[assembly: SuppressMessage("Style", "VSTHRD200:Use \"Async\" suffix for async methods", Justification = "<Pending>", Scope = "member", Target = "~M:WebBrowserExtension.WebBrowserWindowControl.InitializeAsync")]
[assembly: SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>", Scope = "member", Target = "~M:WebBrowserExtension.WebBrowserWindowControl.GoToPageCmdExecuted(System.Object,System.Windows.Input.ExecutedRoutedEventArgs)")]
12 changes: 12 additions & 0 deletions src/WebBrowserExtension/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("WebBrowserExtension")]
[assembly: AssemblyDescription("Brings the embedded Web Browser back to Visual Studio 2022")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Delta Software")]
[assembly: AssemblyProduct("WebBrowserExtension")]
[assembly: AssemblyCopyright("Delta Software - 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
Binary file added src/WebBrowserExtension/Resources/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/WebBrowserExtension/Utils/UriHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace WebBrowserExtension.Utils
{
internal static class UriHelper
{
public static Uri MakeUri(string rawUrl)
{
if (Uri.IsWellFormedUriString(rawUrl, UriKind.Absolute))
return new Uri(rawUrl);

// An invalid URI contains a dot and no spaces, try tacking http:// on the front.
if (!rawUrl.Contains(" ") && rawUrl.Contains("."))
return new Uri("http://" + rawUrl);

// Otherwise treat it as a web search.
return new Uri("https://bing.com/search?q=" +
string.Join("+", Uri.EscapeDataString(rawUrl).Split(new string[] { "%20" }, StringSplitOptions.RemoveEmptyEntries)));
}
}
}
95 changes: 95 additions & 0 deletions src/WebBrowserExtension/WebBrowserCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;

namespace WebBrowserExtension
{
/// <summary>
/// Command handler
/// </summary>
internal sealed class WebBrowserCommand
{
/// <summary>
/// Command ID.
/// </summary>
public const int CommandId = 0x0100;
public const int WebBrowserWindowNavigateId = 0x101;
public const int WebBrowserWindowToolbarID = 0x1000;

/// <summary>
/// Command menu group (command set GUID).
/// </summary>
public static readonly Guid CommandSet = new Guid("48c3fadd-683b-4577-8583-c9817b4e5a50");

/// <summary>
/// VS Package that provides this command, not null.
/// </summary>
private readonly AsyncPackage package;

/// <summary>
/// Initializes a new instance of the <see cref="WebBrowserCommand"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
/// <param name="commandService">Command service to add command to, not null.</param>
private WebBrowserCommand(AsyncPackage package, OleMenuCommandService commandService)
{
this.package = package ?? throw new ArgumentNullException(nameof(package));
commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));

var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new MenuCommand(Execute, menuCommandID);
commandService.AddCommand(menuItem);
}

/// <summary>
/// Gets the instance of the command.
/// </summary>
public static WebBrowserCommand Instance
{
get;
private set;
}

/// <summary>
/// Gets the service provider from the owner package.
/// </summary>
private Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider
{
get
{
return this.package;
}
}

/// <summary>
/// Initializes the singleton instance of the command.
/// </summary>
/// <param name="package">Owner package, not null.</param>
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in WebBrowserWindowCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

var commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new WebBrowserCommand(package, commandService);
}

/// <summary>
/// Shows the tool window when the menu item is clicked.
/// </summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event args.</param>
private void Execute(object sender, EventArgs e)
{
_ = package.JoinableTaskFactory.RunAsync(async delegate
{
var window = await package.ShowToolWindowAsync(typeof(WebBrowserWindow), 0, true, package.DisposalToken);
if (null == window || null == window.Frame)
throw new NotSupportedException("Cannot create tool window");
});
}
}
}
118 changes: 118 additions & 0 deletions src/WebBrowserExtension/WebBrowserExtension.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MinimumVisualStudioVersion>17.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<TargetFrameworkProfile />
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{E2859467-784A-4EC0-9BA5-B1502C80F1F1}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WebBrowserExtension</RootNamespace>
<AssemblyName>WebBrowserExtension</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<GeneratePkgDefFile>true</GeneratePkgDefFile>
<UseCodebase>true</UseCodebase>
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>false</IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
<CopyBuildOutputToOutputDirectory>true</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>true</CopyOutputSymbolsToOutputDirectory>
<StartAction>Program</StartAction>
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils\UriHelper.cs" />
<Compile Include="WebBrowserExtensionPackage.cs" />
<Compile Include="WebBrowserWindow.cs" />
<Compile Include="WebBrowserCommand.cs" />
<Compile Include="WebBrowserWindowControl.xaml.cs">
<DependentUpon>WebBrowserWindowControl.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GitVersion.MsBuild">
<Version>5.9.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.0.32112.339" ExcludeAssets="runtime">
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.2.2141">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Web.WebView2">
<Version>1.0.1150.38</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Page Include="WebBrowserWindowControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Content Include="Resources\Icon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\WebBrowserCommand.png" />
<VSCTCompile Include="WebBrowserExtensionPackage.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
</VSCTCompile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
32 changes: 32 additions & 0 deletions src/WebBrowserExtension/WebBrowserExtensionPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;

namespace WebBrowserExtension
{
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[Guid(PackageGuidString)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideToolWindow(typeof(WebBrowserWindow))]
public sealed class WebBrowserExtensionPackage : AsyncPackage
{
public const string PackageGuidString = "1ba34956-275f-48c6-889b-a8834db18c23";

/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
/// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
/// <param name="progress">A provider for progress updates.</param>
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
// When initialized asynchronously, the current thread may be a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
await WebBrowserCommand.InitializeAsync(this);
}
}
}
58 changes: 58 additions & 0 deletions src/WebBrowserExtension/WebBrowserExtensionPackage.vsct
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- This is the file that defines the actual layout and type of the commands.
It is divided in different sections (e.g. command definition, command
placement, ...), with each defining a specific set of properties.
See the comment before each section for more details about how to
use it. -->

<!-- The VSCT compiler (the tool that translates this file into the binary
format that VisualStudio will consume) has the ability to run a preprocessor
on the vsct file; this preprocessor is (usually) the C++ preprocessor, so
it is possible to define includes and macros with the same syntax used
in C++ files. Using this ability of the compiler here, we include some files
defining some of the constants that we will use inside the file. -->

<!--This is the file that defines the IDs for all the commands exposed by VisualStudio. -->
<Extern href="stdidcmd.h"/>

<!--This header contains the command ids for the menus provided by the shell. -->
<Extern href="vsshlids.h"/>

<!--The Commands section is where commands, menus, and menu groups are defined.
This section uses a Guid to identify the package that provides the command defined inside it. -->
<Commands package="guidWebBrowserExtensionPackage">
<Buttons>
<Button guid="guidWebBrowserExtensionPackageCmdSet" id="WebBrowserWindowCommandId" priority="0x0100" type="Button">
<Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1"/>
<Icon guid="guidImages" id="bmpPic1" />
<Strings>
<ButtonText>Web Browser</ButtonText>
</Strings>
</Button>
</Buttons>
<Bitmaps>
<Bitmap guid="guidImages" href="Resources\WebBrowserCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
</Bitmaps>
</Commands>

<Symbols>
<!-- This is the package guid. -->
<GuidSymbol name="guidWebBrowserExtensionPackage" value="{1ba34956-275f-48c6-889b-a8834db18c23}" />

<!-- This is the guid used to group the menu commands together -->
<GuidSymbol name="guidWebBrowserExtensionPackageCmdSet" value="{48c3fadd-683b-4577-8583-c9817b4e5a50}">
<IDSymbol name="WebBrowserWindowCommandId" value="0x0100" />
</GuidSymbol>

<GuidSymbol name="guidImages" value="{4b371d22-ef5e-4ea3-9ce4-d4903129d549}" >
<IDSymbol name="bmpPic1" value="1" />
<IDSymbol name="bmpPic2" value="2" />
<IDSymbol name="bmpPicSearch" value="3" />
<IDSymbol name="bmpPicX" value="4" />
<IDSymbol name="bmpPicArrows" value="5" />
<IDSymbol name="bmpPicStrikethrough" value="6" />
</GuidSymbol>
</Symbols>
</CommandTable>
Loading

0 comments on commit 815b7b3

Please sign in to comment.