Skip to content

Commit

Permalink
+ Transform markdown document command
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Aug 30, 2024
1 parent 8fea1e8 commit 3a0f74e
Show file tree
Hide file tree
Showing 12 changed files with 7,125 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Codist/Codist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@
<Compile Include="AutoBuildVersion\BuildSetting.cs" />
<Compile Include="AutoBuildVersion\VersionRewriteMode.cs" />
<Compile Include="AutoBuildVersion\VersionSetting.cs" />
<Compile Include="Commands\TransformDocumentCommand.cs" />
<Compile Include="Commands\ShowSupportedFileTypesCommand.cs" />
<Compile Include="Commands\TransformDocumentWindow.cs" />
<Compile Include="Controls\ThemedRichTextBox.cs" />
<Compile Include="Commands\CancelRepeatingActionCommand.cs" />
<Compile Include="Helpers\VsImageHelper.cs" />
Expand Down Expand Up @@ -350,19 +352,34 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\CLR.dll</HintPath>
</Reference>
<Reference Include="Markdig">
<HintPath>Lib\Markdig.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.CommandBars, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml" />
Expand Down Expand Up @@ -492,6 +509,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Xml.SgmlReader">
<Version>1.8.30</Version>
</PackageReference>
<PackageReference Include="NETStandard.Library">
<Version>2.0.0</Version>
</PackageReference>
Expand Down
23 changes: 23 additions & 0 deletions Codist/Commands/CodistPackage.en-US.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
<ToolTipText>Display file types supported by Visual Studio</ToolTipText>
</Strings>
</Button>
<Button guid="guidCodistPackageCmdSet" id="TransformDocumentId" priority="4135" type="Button">
<Parent guid="guidCodistPackageCmdSet" id="CodistMenuGroup" />
<Icon guid="ImageCatalogGuid" id="XMLTransformation" />
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>IconIsMoniker</CommandFlag>
<Strings>
<ButtonText>Transform Document...</ButtonText>
<ToolTipText>Save active document to another format</ToolTipText>
</Strings>
</Button>
<Button guid="guidCodistPackageCmdSet" id="IncrementVsixVersionId" priority="0x0100" type="Button">
<Parent guid="guidCodistPackageCmdSet" id="EDIT_PROJECT_GROUP_ID" />
<Icon guid="ImageCatalogGuid" id="Counter" />
Expand Down Expand Up @@ -165,6 +176,18 @@
<LocCanonicalName>.Refactor.RefactoringCode</LocCanonicalName>
</Strings>
</Button>
<Button guid="guidCodistPackageCmdSet" id="FavoriteWindowCommandId" priority="0x1000" type="Button">
<Parent guid="guidSHLMainMenu" id="IDG_VS_VIEW_BROWSER" />
<Icon guid="ImageCatalogGuid" id="Favorite" />
<CommandFlag>IconIsMoniker</CommandFlag>
<Strings>
<MenuText>Favorites Window...</MenuText>
<ButtonText>Favorites</ButtonText>
<ToolTipText>Displays Favorite Window...</ToolTipText>
<CanonicalName>.View.FavoriteWindow</CanonicalName>
<LocCanonicalName>.View.FavoriteWindow</LocCanonicalName>
</Strings>
</Button>
</Buttons>
</Commands>
</CommandTable>
3 changes: 2 additions & 1 deletion Codist/Commands/CodistPackage.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<IDSymbol name="ScreenshotCommandId" value="0x4001" />
<IDSymbol name="ShowActiveWindowPropertiesId" value="0x4002" />
<IDSymbol name="ShowSupportedFileTypesId" value="0x400F" />
<IDSymbol name="TransformDocumentId" value="0x4010" />
<IDSymbol name="EDIT_PROJECT_GROUP_ID" value="0x1000" />
<IDSymbol name="IncrementVsixVersionId" value="0x4003" />
<IDSymbol name="AutoBuildVersionWindowId" value="0x4009" />
Expand All @@ -91,7 +92,7 @@
<IDSymbol name="OpenDebugOutputFolderId" value="0x400D" />
<IDSymbol name="OpenReleaseOutputFolderId" value="0x400E" />
<IDSymbol name="IDG_VS_TOOLS_OPTIONS" value="0x1020" />
<IDSymbol name="SymbolFinderWindowCommandId" value="0x4004" />
<IDSymbol name="FavoriteWindowCommandId" value="0x4004" />
<IDSymbol name="SyntaxCustomizeHighlightId" value="0x4005" />
<IDSymbol name="NaviBarSearchDeclarationId" value="0x4006" />
<IDSymbol name="NaviBarSearchActiveClassId" value="0x4007" />
Expand Down
23 changes: 23 additions & 0 deletions Codist/Commands/CodistPackage.zh-Hans.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
<ToolTipText>显示 Visual Studio 支持的文件类型</ToolTipText>
</Strings>
</Button>
<Button guid="guidCodistPackageCmdSet" id="TransformDocumentId" priority="4135" type="Button">
<Parent guid="guidCodistPackageCmdSet" id="CodistMenuGroup" />
<Icon guid="ImageCatalogGuid" id="XMLTransformation" />
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>IconIsMoniker</CommandFlag>
<Strings>
<ButtonText>转换文档格式...</ButtonText>
<ToolTipText>将当前文档转换为另一个格式</ToolTipText>
</Strings>
</Button>
<Button guid="guidCodistPackageCmdSet" id="IncrementVsixVersionId" priority="0x0100" type="Button">
<Parent guid="guidCodistPackageCmdSet" id="EDIT_PROJECT_GROUP_ID" />
<Icon guid="ImageCatalogGuid" id="Counter" />
Expand Down Expand Up @@ -158,6 +169,18 @@
<LocCanonicalName>.重构.重构代码</LocCanonicalName>
</Strings>
</Button>
<Button guid="guidCodistPackageCmdSet" id="FavoriteWindowCommandId" priority="0x1000" type="Button">
<Parent guid="guidSHLMainMenu" id="IDG_VS_VIEW_BROWSER" />
<Icon guid="ImageCatalogGuid" id="Favorite" />
<CommandFlag>IconIsMoniker</CommandFlag>
<Strings>
<MenuText>收藏夹...</MenuText>
<ButtonText>收藏夹</ButtonText>
<ToolTipText>显示收藏夹窗口...</ToolTipText>
<CanonicalName>.View.FavoriteWindow</CanonicalName>
<LocCanonicalName>.视图.收藏夹窗口</LocCanonicalName>
</Strings>
</Button>
</Buttons>
</Commands>
</CommandTable>
36 changes: 36 additions & 0 deletions Codist/Commands/TransformDocumentCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Windows;
using Microsoft.VisualStudio.Shell;

namespace Codist.Commands
{
/// <summary>A command which performs XSLT on the active code document window.</summary>
internal static class TransformDocumentCommand
{
public static void Initialize() {
if (CodistPackage.VsVersion.Major < 17) {
return;
}
Command.TransformDocument.Register(Execute, (s, args) => {
ThreadHelper.ThrowIfNotOnUIThread();
((OleMenuCommand)s).Visible = TextEditorHelper.GetActiveWpfDocumentView()?.TextBuffer.LikeContentType("markdown") == true;
});
}

static void Execute(object sender, EventArgs e) {
ThreadHelper.ThrowIfNotOnUIThread();
var doc = CodistPackage.DTE.ActiveDocument;
if (doc == null) {
return;
}
var docWindow = TextEditorHelper.GetActiveWpfDocumentView();
if (docWindow == null) {
return;
}
new TransformDocumentWindow(VsShellHelper.GetActiveProjectInSolutionExplorer(), docWindow.TextSnapshot, doc.FullName) {
Owner = Application.Current.MainWindow,
WindowStartupLocation = WindowStartupLocation.CenterOwner
}.ShowDialog();
}
}
}
Loading

0 comments on commit 3a0f74e

Please sign in to comment.