diff --git a/New_Extensibility_Model/Samples/SettingsSample/.vsextension/string-resources.json b/New_Extensibility_Model/Samples/SettingsSample/.vsextension/string-resources.json new file mode 100644 index 00000000..46593c69 --- /dev/null +++ b/New_Extensibility_Model/Samples/SettingsSample/.vsextension/string-resources.json @@ -0,0 +1,14 @@ +{ + "SettingsSample.MyToolWindowCommand.DisplayName": "Sample Text Tool Window", + "SettingsSample.Settings.Category.DisplayName": "Settings Sample", + "SettingsSample.Settings.Category.Description": "Settings for the LoremIpsum sample generator.", + "SettingsSample.Settings.AutoUpdate.DisplayName": "Auto Update", + "SettingsSample.Settings.AutoUpdate.Description": "Whether to update the sample text when a setting changes.", + "SettingsSample.Settings.TextLength.DisplayName": "Text Length", + "SettingsSample.Settings.TextLength.Description": "Number of characters to include in the generated text.", + "SettingsSample.Settings.QuoteStyle.DisplayName": "Quote Style", + "SettingsSample.Settings.QuoteStyle.Description": "Style of quotes to enclose the generated text.", + "SettingsSample.Settings.QuoteStyle.None": "None", + "SettingsSample.Settings.QuoteStyle.Single": "Single", + "SettingsSample.Settings.QuoteStyle.Double": "Double" +} \ No newline at end of file diff --git a/New_Extensibility_Model/Samples/SettingsSample/MyToolWindow.cs b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindow.cs new file mode 100644 index 00000000..c7cb157a --- /dev/null +++ b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindow.cs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace SettingsSample; + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.VisualStudio.Extensibility; +using Microsoft.VisualStudio.Extensibility.Commands; +using Microsoft.VisualStudio.Extensibility.ToolWindows; +using Microsoft.VisualStudio.RpcContracts.RemoteUI; + +/// +/// A sample tool window. +/// +[VisualStudioContribution] +public class MyToolWindow : ToolWindow +{ + private object? dataContext; + + /// + /// Initializes a new instance of the class. + /// + public MyToolWindow() + { + this.Title = "Settings Sample Tool Window"; + } + + /// + public override ToolWindowConfiguration ToolWindowConfiguration => new() + { + Placement = ToolWindowPlacement.DocumentWell, + AllowAutoCreation = false, + }; + + /// + public override Task InitializeAsync(CancellationToken cancellationToken) + { + this.dataContext = new MyToolWindowData(this.Extensibility); + + return Task.CompletedTask; + } + + /// + public override Task GetContentAsync(CancellationToken cancellationToken) + { + return Task.FromResult(new MyToolWindowControl(this.dataContext)); + } +} diff --git a/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowCommand.cs b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowCommand.cs new file mode 100644 index 00000000..2ca4cf54 --- /dev/null +++ b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowCommand.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace SettingsSample; + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.VisualStudio.Extensibility; +using Microsoft.VisualStudio.Extensibility.Commands; + +/// +/// A sample command for showing a tool window. +/// +[VisualStudioContribution] +public class MyToolWindowCommand : Command +{ + /// + public override CommandConfiguration CommandConfiguration => new("%SettingsSample.MyToolWindowCommand.DisplayName%") + { + Placements = [CommandPlacement.KnownPlacements.ToolsMenu], + Icon = new(ImageMoniker.KnownValues.ToolWindow, IconSettings.IconAndText), + }; + + /// + public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) + { + await this.Extensibility.Shell().ShowToolWindowAsync(activate: true, cancellationToken); + } +} diff --git a/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowControl.cs b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowControl.cs new file mode 100644 index 00000000..31d79e2e --- /dev/null +++ b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowControl.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace SettingsSample; + +using System.Threading; +using Microsoft.VisualStudio.Extensibility.UI; + +/// +/// A sample remote user control to use as tool window UI content. +/// +internal class MyToolWindowControl : RemoteUserControl +{ + /// + /// Initializes a new instance of the class. + /// + /// + /// Data context of the remote control which can be referenced from xaml through data binding. + /// + /// + /// Optional synchronizationContext that the extender can provide to ensure that + /// are executed and properties are read and updated from the extension main thread. + /// + public MyToolWindowControl(object? dataContext, SynchronizationContext? synchronizationContext = null) + : base(dataContext, synchronizationContext) + { + } +} diff --git a/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowControl.xaml b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowControl.xaml new file mode 100644 index 00000000..fc320a67 --- /dev/null +++ b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowControl.xaml @@ -0,0 +1,31 @@ + + + + + + +