Skip to content
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

msbuild changes #1

Merged
merged 3 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

#ignore DS_Store
.DS_Store
22 changes: 21 additions & 1 deletion PrettyXML.VSMac/PrettyXML.VSMac/PrettyXML.VSMac.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<Target Name="PackageAddin" AfterTargets="Build"></Target>
<PropertyGroup>
<TargetFramework>net471</TargetFramework>
<TargetFramework>net48</TargetFramework>
<IsAddin>True</IsAddin>
<CreatePackage>True</CreatePackage>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MonoDevelop.Addins" Version="0.4.7" />
</ItemGroup>
<ItemGroup>
<Reference Include="XmlFormatter">
<HintPath>lib\XmlFormatter.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Manifest.addin.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="logo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions PrettyXML.VSMac/PrettyXML.VSMac/PrettyXMLCommands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace PrettyXML.VSMac
{
public enum PrettyXMLCommands
{
FormatXML
}
}
13 changes: 8 additions & 5 deletions PrettyXML.VSMac/PrettyXML.VSMac/Properties/AddinInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using Mono.Addins;
using Mono.Addins.Description;

[assembly: Addin(
"PrettyXML VS Mac",
Namespace = "PrettyXML.VSMac",
Version = "1.0"
Version = "1.0.0-beta",
Category = "Code formatters",
Flags = AddinFlags.None,
EnabledByDefault = true,
Url = "https://github.com/pmahend1/PrettyXML.VSMac"
)]

[assembly: AddinName("PrettyXML.VSMac")]
[assembly: AddinCategory("IDE extensions")]
[assembly: AddinName("PrettyXML VS Mac")]
[assembly: AddinCategory("Code formatters")]
[assembly: AddinDescription("PrettyXML.VSMac")]
[assembly: AddinAuthor("Mikayla Hutchinson")]
[assembly: AddinAuthor("Prateek Mahendrakar")]
12 changes: 12 additions & 0 deletions PrettyXML.VSMac/PrettyXML.VSMac/Properties/Manifest.addin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<ExtensionModel>
<Runtime>
<Import assembly="XmlFormatter.dll" />
</Runtime>
<Extension path="/MonoDevelop/Ide/Commands/Edit">
<Command id="PrettyXML.VSMac.PrettyXMLCommands.FormatXML"
_label="Prettify XML"
defaultHandler="PrettyXML.VSMac.XMLFormatter"
macShortcut="Meta+K|J Meta+K|Meta+J"
shortcut="Control+K|J Control+K|Control+J"
description="Formats XML just like Visual Studio" />
</Extension>
<Extension path="/MonoDevelop/Ide/MainMenu/Edit">
<CommandItem id="PrettyXML.VSMac.PrettyXMLCommands.FormatXML" />
</Extension>
</ExtensionModel>
4 changes: 4 additions & 0 deletions PrettyXML.VSMac/PrettyXML.VSMac/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## ReleaseNotes

### 0.0.7 2020-09-16
- First version
83 changes: 83 additions & 0 deletions PrettyXML.VSMac/PrettyXML.VSMac/XMLFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using MonoDevelop.Components.Commands;
using MonoDevelop.Ide;
using XmlFormatter;

namespace PrettyXML.VSMac
{
public class XMLFormatter : CommandHandler
{

protected override void Run(object dataItem)
{
base.Run(dataItem);
var textBuffer = IdeApp.Workbench.ActiveDocument?.GetContent<ITextBuffer>();
var textview = IdeApp.Workbench.ActiveDocument.GetContent<ITextView>();


var textdocument = textBuffer?.Properties?.PropertyList?.FirstOrDefault(x =>x.Key is ITextDocument || x.Value is ITextDocument);
var documentvalue = textdocument?.Value as ITextDocument;

var ext = documentvalue?.FilePath?.Substring(documentvalue?.FilePath?.LastIndexOf(".")??0);

var contentType = textBuffer?.ContentType;
var currentDocumentText = textBuffer?.CurrentSnapshot?.AsText()?.ToString();
var formatter = new Formatter();


var contentTypeDisplayName = contentType?.DisplayName?.ToLower() ?? string.Empty;
if (contentTypeDisplayName.EndsWith("xml") ||
contentTypeDisplayName.EndsWith("resx") ||
contentTypeDisplayName.EndsWith("xsd") ||
contentTypeDisplayName.EndsWith("xaml"))
{
if (currentDocumentText != null)
{
var formattedText = formatter.Format(currentDocumentText);
var span = new Span(0, textBuffer.CurrentSnapshot.Length);
textBuffer.Replace(span, formattedText);
}
else
{
Debug.WriteLine("Editor text is null");
}

}
else
{
if(ext.EndsWith("csproj") ||
ext.EndsWith("config") ||
ext.EndsWith("mobileconfig") ||
ext.EndsWith("xsd") ||
ext.EndsWith("xml") ||
ext.EndsWith("xsl") ||
ext.EndsWith("xaml") ||
ext.EndsWith("axml")||
ext.EndsWith("resx"))
{

var formattedText = formatter.Format(currentDocumentText);
var span = new Span(0, textBuffer.CurrentSnapshot.Length);
textBuffer.Replace(span, formattedText);
}
}


}

protected override void Update(CommandInfo info)
{

var textBuffer = IdeApp.Workbench.ActiveDocument.GetContent<ITextBuffer>();
if (textBuffer != null && textBuffer.AsTextContainer() is SourceTextContainer container)
{
var document = container.GetTextBuffer();
info.Enabled = document != null;
}
}
}
}
Binary file not shown.
Binary file added PrettyXML.VSMac/PrettyXML.VSMac/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.