├── art ├── edit-menu.png ├── line-sub-menu.png ├── encoding-sub-menu.png └── transform-sub-menu.png ├── src ├── Resources │ └── Icon.png ├── Properties │ └── AssemblyInfo.cs ├── Helpers │ ├── LineComparer.cs │ ├── Logger.cs │ └── Disposable.cs ├── source.extension.cs ├── Commands │ ├── RemoveDuplicateLinesCommand.cs │ ├── RemoveEmptyLinesCommand.cs │ ├── EncodingsCommand.cs │ ├── SortLinesCommand.cs │ ├── BaseCommand.cs │ └── TransformsCommand.cs ├── VSPackage.cs ├── source.extension.vsixmanifest ├── VSCommandTable.cs ├── Editorsk.csproj └── VSCommandTable.vsct ├── .gitignore ├── .github ├── ISSUE_TEMPLATE.md └── CONTRIBUTING.md ├── .gitattributes ├── LICENSE ├── appveyor.yml ├── Editorsk.sln └── README.md /art/edit-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madskristensen/Editorsk/master/art/edit-menu.png -------------------------------------------------------------------------------- /art/line-sub-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madskristensen/Editorsk/master/art/line-sub-menu.png -------------------------------------------------------------------------------- /src/Resources/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madskristensen/Editorsk/master/src/Resources/Icon.png -------------------------------------------------------------------------------- /art/encoding-sub-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madskristensen/Editorsk/master/art/encoding-sub-menu.png -------------------------------------------------------------------------------- /art/transform-sub-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madskristensen/Editorsk/master/art/transform-sub-menu.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | packages 2 | 3 | # User files 4 | *.suo 5 | *.user 6 | *.sln.docstates 7 | .vs/ 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Rr]elease/ 12 | x64/ 13 | [Bb]in/ 14 | [Oo]bj/ 15 | 16 | # MSTest test Results 17 | [Tt]est[Rr]esult*/ 18 | [Bb]uild[Ll]og.* 19 | 20 | # NCrunch 21 | *.ncrunchsolution 22 | *.ncrunchproject 23 | _NCrunch_WebCompiler -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Installed product versions 2 | - Visual Studio: [example 2015 Professional] 3 | - This extension: [example 1.1.21] 4 | 5 | ### Description 6 | Replace this text with a short description 7 | 8 | ### Steps to recreate 9 | 1. Replace this 10 | 2. text with 11 | 3. the steps 12 | 4. to recreate 13 | 14 | ### Current behavior 15 | Explain what it's doing and why it's wrong 16 | 17 | ### Expected behavior 18 | Explain what it should be doing after it's fixed. -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2016 Mads Kristensen 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /src/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | using Editorsk; 4 | 5 | [assembly: AssemblyTitle(Vsix.Name)] 6 | [assembly: AssemblyDescription(Vsix.Description)] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany(Vsix.Author)] 9 | [assembly: AssemblyProduct(Vsix.Name)] 10 | [assembly: AssemblyCopyright(Vsix.Author)] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture(Vsix.Language)] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: AssemblyVersion(Vsix.Version)] 17 | [assembly: AssemblyFileVersion(Vsix.Version)] 18 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2019 2 | 3 | install: 4 | - ps: (new-object Net.WebClient).DownloadString("https://raw.github.com/madskristensen/ExtensionScripts/master/AppVeyor/vsix.ps1") | iex 5 | 6 | before_build: 7 | - ps: Vsix-IncrementVsixVersion | Vsix-UpdateBuildVersion 8 | - ps: Vsix-TokenReplacement src\source.extension.cs 'Version = "([0-9\\.]+)"' 'Version = "{version}"' 9 | 10 | build_script: 11 | - nuget restore -Verbosity quiet 12 | - msbuild /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m 13 | 14 | after_test: 15 | - ps: Vsix-PushArtifacts | Vsix-PublishToGallery -------------------------------------------------------------------------------- /src/Helpers/LineComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Editorsk 5 | { 6 | public class LineComparer : IEqualityComparer 7 | { 8 | public bool Equals(string x, string y) 9 | { 10 | if (string.IsNullOrWhiteSpace(x) || string.IsNullOrWhiteSpace(y)) 11 | return false; 12 | 13 | if (Object.ReferenceEquals(x, y)) return true; 14 | 15 | return string.Equals(x.Trim(), y.Trim(), StringComparison.CurrentCultureIgnoreCase); 16 | } 17 | 18 | public int GetHashCode(string obj) 19 | { 20 | if (Object.ReferenceEquals(obj, null)) return 0; 21 | 22 | return StringComparer.CurrentCultureIgnoreCase.GetHashCode(obj.Trim()); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/source.extension.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This file was generated by VSIX Synchronizer 4 | // 5 | // ------------------------------------------------------------------------------ 6 | namespace Editorsk 7 | { 8 | internal sealed partial class Vsix 9 | { 10 | public const string Id = "13a2ec1a-6b20-46a9-af99-b1064b00c9a8"; 11 | public const string Name = "Editor Enhancements"; 12 | public const string Description = @"Provides additional features such as HTML and URL encodings, transformations and sorting of selected text the editor."; 13 | public const string Language = "en-US"; 14 | public const string Version = "1.0"; 15 | public const string Author = "Mads Kristensen"; 16 | public const string Tags = "editor, strings, lines, encoding"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Commands/RemoveDuplicateLinesCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using EnvDTE; 5 | using Microsoft.VisualStudio.Shell; 6 | 7 | namespace Editorsk 8 | { 9 | internal class RemoveDuplicateLinesCommand : BaseCommand 10 | { 11 | protected override void SetupCommands() 12 | { 13 | RegisterCommand(PackageGuids.guidLinesCmdSet, PackageIds.cmdRemoveDuplicateLines, Execute); 14 | } 15 | 16 | private void Execute() 17 | { 18 | ThreadHelper.ThrowIfNotOnUIThread(); 19 | 20 | try 21 | { 22 | TextDocument document = GetTextDocument(); 23 | IEnumerable lines = GetSelectedLines(document); 24 | 25 | string result = string.Join(Environment.NewLine, lines.Distinct(new LineComparer())); 26 | 27 | if (result == document.Selection.Text) 28 | return; 29 | 30 | using (UndoContext("Remove Duplicate Lines")) 31 | { 32 | document.Selection.Insert(result, 0); 33 | } 34 | } 35 | catch (Exception ex) 36 | { 37 | Logger.Log(ex); 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/VSPackage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.Design; 3 | using System.Runtime.InteropServices; 4 | using System.Threading; 5 | using EnvDTE; 6 | using EnvDTE80; 7 | using Microsoft.VisualStudio.Shell; 8 | 9 | namespace Editorsk 10 | { 11 | [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] 12 | [InstalledProductRegistration("#110", "#112", Vsix.Version, IconResourceID = 400)] 13 | [ProvideMenuResource("Menus.ctmenu", 1)] 14 | [Guid(PackageGuids.guidPackageString)] 15 | public sealed class VSPackage : AsyncPackage 16 | { 17 | protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) 18 | { 19 | await Logger.InitializeAsync(this, Vsix.Name); 20 | 21 | var dte = await GetServiceAsync(typeof(DTE)) as DTE2; 22 | var commandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; 23 | 24 | EncodingCommand.Initialize(dte, commandService); 25 | TransformCommand.Initialize(dte, commandService); 26 | SortLinesCommand.Initialize(dte, commandService); 27 | RemoveEmptyLinesCommand.Initialize(dte, commandService); 28 | RemoveDuplicateLinesCommand.Initialize(dte, commandService); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Commands/RemoveEmptyLinesCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using EnvDTE; 5 | using Microsoft.VisualStudio.Shell; 6 | 7 | namespace Editorsk 8 | { 9 | internal class RemoveEmptyLinesCommand : BaseCommand 10 | { 11 | private delegate void Replacement(Direction direction); 12 | 13 | protected override void SetupCommands() 14 | { 15 | RegisterCommand(PackageGuids.guidLinesCmdSet, PackageIds.cmdRemoveEmptyLines, Execute); 16 | } 17 | 18 | private void Execute() 19 | { 20 | ThreadHelper.ThrowIfNotOnUIThread(); 21 | 22 | try 23 | { 24 | TextDocument document = GetTextDocument(); 25 | IEnumerable lines = GetSelectedLines(document); 26 | 27 | string result = string.Join(Environment.NewLine, lines.Where(s => !string.IsNullOrWhiteSpace(s))); 28 | 29 | if (result == document.Selection.Text) 30 | return; 31 | 32 | using (UndoContext("Remove Empty Lines")) 33 | { 34 | document.Selection.Insert(result, 0); 35 | } 36 | } 37 | catch (Exception ex) 38 | { 39 | Logger.Log(ex); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Editorsk.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27806.3004 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Editorsk", "src\Editorsk.csproj", "{0393496E-0D81-4AD2-B9C9-B883CD41E8B6}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{37A1009B-BA2B-46DF-99B8-BDC1C0DA3990}" 9 | ProjectSection(SolutionItems) = preProject 10 | appveyor.yml = appveyor.yml 11 | README.md = README.md 12 | EndProjectSection 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {0393496E-0D81-4AD2-B9C9-B883CD41E8B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {0393496E-0D81-4AD2-B9C9-B883CD41E8B6}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {0393496E-0D81-4AD2-B9C9-B883CD41E8B6}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {0393496E-0D81-4AD2-B9C9-B883CD41E8B6}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {F94D4AA1-3326-4151-BE0F-2117034C841A} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /src/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Editor Enhancements 6 | Provides additional features such as HTML and URL encodings, transformations and sorting of selected text the editor. 7 | https://github.com/madskristensen/Editorsk 8 | Resources\LICENSE 9 | Resources\Icon.png 10 | Resources\Icon.png 11 | editor, strings, lines, encoding 12 | 13 | 14 | 15 | amd64 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Helpers/Logger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.Shell; 3 | using Microsoft.VisualStudio.Shell.Interop; 4 | using task = System.Threading.Tasks.Task; 5 | 6 | internal static class Logger 7 | { 8 | private static string _name; 9 | private static IVsOutputWindowPane _pane; 10 | private static IVsOutputWindow _output; 11 | 12 | public static async task InitializeAsync(AsyncPackage package, string name) 13 | { 14 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 15 | 16 | _output = await package.GetServiceAsync(typeof(SVsOutputWindow)) as IVsOutputWindow; 17 | _name = name; 18 | } 19 | 20 | public static void Log(object message) 21 | { 22 | ThreadHelper.ThrowIfNotOnUIThread(); 23 | try 24 | { 25 | if (EnsurePane()) 26 | { 27 | _pane.OutputString(DateTime.Now.ToString() + ": " + message + Environment.NewLine); 28 | } 29 | } 30 | catch (Exception ex) 31 | { 32 | System.Diagnostics.Debug.Write(ex); 33 | } 34 | } 35 | 36 | private static bool EnsurePane() 37 | { 38 | ThreadHelper.ThrowIfNotOnUIThread(); 39 | 40 | if (_pane == null && _output != null) 41 | { 42 | var guid = Guid.NewGuid(); 43 | _output.CreatePane(ref guid, _name, 1, 1); 44 | _output.GetPane(ref guid, out _pane); 45 | } 46 | 47 | return _pane != null; 48 | } 49 | } -------------------------------------------------------------------------------- /src/Helpers/Disposable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Editorsk 4 | { 5 | public sealed class Disposable : IDisposable 6 | { 7 | Action onDispose; 8 | 9 | ///Creates a non-repeatable Disposable instance. 10 | ///The delegate to be called by the Dispose method. The delegate will only be called once. 11 | public Disposable(Action disposer) : this(disposer, false) { } 12 | ///Creates a Disposable instance. 13 | ///The delegate to be called by the Dispose method. 14 | ///Indicates whether the underlying delegate should be called multiple times if this instance is disposed multiple times. 15 | public Disposable(Action disposer, bool repeatable) 16 | { 17 | if (disposer == null) throw new ArgumentNullException("disposer"); 18 | 19 | onDispose = disposer; 20 | Repeatable = repeatable; 21 | } 22 | 23 | ///Gets whether the underlying delegate will be called multiple times if this instance is disposed multiple times. 24 | public bool Repeatable { get; private set; } 25 | ///Gets whether the Dispose method has been called. 26 | public bool Disposed { get; private set; } 27 | 28 | ///Calls the disposer delegate specified in the constructor. 29 | public void Dispose() 30 | { 31 | if (Disposed && !Repeatable) return; 32 | Disposed = true; 33 | onDispose(); 34 | if (!Repeatable) onDispose = null; //Free the reference to allow the delegate & its Target to be GC'd. 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Commands/EncodingsCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Web; 3 | using EnvDTE; 4 | using Microsoft.VisualStudio.Shell; 5 | 6 | namespace Editorsk 7 | { 8 | internal class EncodingCommand : BaseCommand 9 | { 10 | private delegate string Replacement(string original); 11 | 12 | protected override void SetupCommands() 13 | { 14 | SetupCommand(PackageIds.cmdHtmlEncode, new Replacement(HttpUtility.HtmlEncode)); 15 | SetupCommand(PackageIds.cmdAttrEncode, new Replacement(HttpUtility.HtmlAttributeEncode)); 16 | SetupCommand(PackageIds.cmdHtmlDecode, new Replacement(HttpUtility.HtmlDecode)); 17 | SetupCommand(PackageIds.cmdUrlEncode, new Replacement(HttpUtility.UrlEncode)); 18 | SetupCommand(PackageIds.cmdUrlDecode, new Replacement(HttpUtility.UrlDecode)); 19 | SetupCommand(PackageIds.cmdJavaScriptEncode, new Replacement(HttpUtility.JavaScriptStringEncode)); 20 | } 21 | 22 | private void SetupCommand(int commandId, Replacement callback) 23 | { 24 | RegisterCommand(PackageGuids.guidEncodingCmdSet, commandId, () => Execute(callback)); 25 | } 26 | 27 | private void Execute(Replacement callback) 28 | { 29 | ThreadHelper.ThrowIfNotOnUIThread(); 30 | 31 | try 32 | { 33 | TextDocument document = GetTextDocument(); 34 | string result = callback(document.Selection.Text); 35 | 36 | if (result == document.Selection.Text) 37 | return; 38 | 39 | using (UndoContext(callback.Method.Name)) 40 | { 41 | document.Selection.Insert(result, 0); 42 | } 43 | } 44 | catch (Exception ex) 45 | { 46 | Logger.Log(ex); 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Editor Enhancements 2 | 3 | [![Build status](https://ci.appveyor.com/api/projects/status/ft7r0hidvyl37d4b?svg=true)](https://ci.appveyor.com/project/madskristensen/editorsk) 4 | 5 | Download this extension from the [VS Gallery](https://visualstudiogallery.msdn.microsoft.com/4f64e542-3772-4136-8f87-0113441c7aa1) 6 | or get the [CI build](http://vsixgallery.com/extension/a3112f81-e423-4f88-9f2c-e089a309e48e/). 7 | 8 | --------------------------------------- 9 | 10 | Provides additional features such as HTML and URL encodings, 11 | transformations and sorting of selected text the editor. 12 | 13 | ## Features 14 | 15 | - String encodings/decoding 16 | - String transformation 17 | - Hashing 18 | - Remove duplicate lines 19 | - Remove empty lines 20 | - Line sorting 21 | 22 | ## Edit menu 23 | The features are located in 3 menus under the top level 24 | **Edit** menu. 25 | 26 | ![Edit menu](art/edit-menu.png) 27 | 28 | You can also find them in the context-menu inside the editor. 29 | 30 | ### Encode Selection 31 | This is a collection of various encodings and decodings 32 | primarily used in HTML and XML documents and strings. 33 | 34 | ![Encoding menu](art/encoding-sub-menu.png) 35 | 36 | ### Transform Selection 37 | Some simple commands to transform the selected strings. 38 | 39 | ![Transform menu](art/transform-sub-menu.png) 40 | 41 | It even has some popular hashing algorithms handy. 42 | 43 | ### Selected Lines 44 | This gives you easy access to sort the selected lines 45 | alphabetically, as well as removing empty- and duplicate 46 | lines. 47 | 48 | ![Lines menu](art/line-sub-menu.png) 49 | 50 | ## Contribute 51 | Check out the [contribution guidelines](.github/CONTRIBUTING.md) 52 | if you want to contribute to this project. 53 | 54 | For cloning and building this project yourself, make sure 55 | to install the 56 | [Extensibility Tools 2015](https://visualstudiogallery.msdn.microsoft.com/ab39a092-1343-46e2-b0f1-6a3f91155aa6) 57 | extension for Visual Studio which enables some features 58 | used by this project. 59 | 60 | ## License 61 | [Apache 2.0](LICENSE) -------------------------------------------------------------------------------- /src/Commands/SortLinesCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.Design; 4 | using System.Linq; 5 | using EnvDTE; 6 | using Microsoft.VisualStudio.Shell; 7 | 8 | namespace Editorsk 9 | { 10 | internal class SortLinesCommand : BaseCommand 11 | { 12 | private delegate void Replacement(Direction direction); 13 | 14 | protected override void SetupCommands() 15 | { 16 | var cmdAsc = new CommandID(PackageGuids.guidLinesCmdSet, PackageIds.cmdSortAsc); 17 | RegisterCommand(cmdAsc, () => Execute(Direction.Ascending)); 18 | 19 | var cmdDesc = new CommandID(PackageGuids.guidLinesCmdSet, PackageIds.cmdSortDesc); 20 | RegisterCommand(cmdDesc, () => Execute(Direction.Descending)); 21 | } 22 | 23 | private void Execute(Direction direction) 24 | { 25 | ThreadHelper.ThrowIfNotOnUIThread(); 26 | 27 | try 28 | { 29 | TextDocument document = GetTextDocument(); 30 | IEnumerable lines = GetSelectedLines(document); 31 | 32 | string result = SortLines(direction, lines); 33 | 34 | if (result == document.Selection.Text) 35 | return; 36 | 37 | using (UndoContext("Sort Selected Lines")) 38 | { 39 | document.Selection.Insert(result, 0); 40 | } 41 | } 42 | catch (Exception ex) 43 | { 44 | Logger.Log(ex); 45 | } 46 | } 47 | 48 | private string SortLines(Direction direction, IEnumerable lines) 49 | { 50 | if (direction == Direction.Ascending) 51 | lines = lines.OrderBy(t => t); 52 | else 53 | lines = lines.OrderByDescending(t => t); 54 | 55 | return string.Join(Environment.NewLine, lines); 56 | } 57 | } 58 | 59 | public enum Direction 60 | { 61 | Ascending, 62 | Descending 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Commands/BaseCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.Design; 4 | using EnvDTE; 5 | using EnvDTE80; 6 | using Microsoft.VisualStudio.Shell; 7 | 8 | namespace Editorsk 9 | { 10 | abstract class BaseCommand where T : BaseCommand, new() 11 | { 12 | public static T Instance { get; private set; } 13 | public DTE2 DTE { get; private set; } 14 | 15 | private OleMenuCommandService CommandService { get; set; } 16 | 17 | public static void Initialize(DTE2 dte, OleMenuCommandService commandService) 18 | { 19 | Instance = new T 20 | { 21 | DTE = dte, 22 | CommandService = commandService 23 | }; 24 | 25 | Instance.SetupCommands(); 26 | } 27 | 28 | protected abstract void SetupCommands(); 29 | 30 | protected void RegisterCommand(CommandID commandId, Action action) 31 | { 32 | var menuCommand = new OleMenuCommand((s, e) => action(), commandId); 33 | CommandService.AddCommand(menuCommand); 34 | } 35 | 36 | protected void RegisterCommand(Guid commandGuid, int commandId, Action action) 37 | { 38 | var cmd = new CommandID(commandGuid, commandId); 39 | RegisterCommand(cmd, action); 40 | } 41 | 42 | public TextDocument GetTextDocument() 43 | { 44 | ThreadHelper.ThrowIfNotOnUIThread(); 45 | return DTE.ActiveDocument?.Object("TextDocument") as TextDocument; 46 | } 47 | 48 | public IDisposable UndoContext(string name) 49 | { 50 | ThreadHelper.ThrowIfNotOnUIThread(); 51 | 52 | DTE.UndoContext.Open(name); 53 | return new Disposable(DTE.UndoContext.Close); 54 | } 55 | 56 | public IEnumerable GetSelectedLines(TextDocument document) 57 | { 58 | ThreadHelper.ThrowIfNotOnUIThread(); 59 | 60 | int firstLine = Math.Min(document.Selection.TopLine, document.Selection.BottomLine); 61 | int lineCount = document.Selection.TextRanges.Count; 62 | 63 | document.Selection.MoveToLineAndOffset(firstLine, 1); 64 | document.Selection.LineDown(true, lineCount); 65 | document.Selection.CharRight(true, -1); 66 | 67 | for (int i = 1; i <= document.Selection.TextRanges.Count; i++) 68 | { 69 | TextRange range = document.Selection.TextRanges.Item(i); 70 | yield return range.StartPoint.GetText(range.EndPoint).TrimEnd(); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Commands/TransformsCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Security.Cryptography; 5 | using System.Text; 6 | using EnvDTE; 7 | using Microsoft.VisualStudio.Shell; 8 | 9 | namespace Editorsk 10 | { 11 | internal class TransformCommand : BaseCommand 12 | { 13 | private delegate string Replacement(string original); 14 | 15 | protected override void SetupCommands() 16 | { 17 | SetupCommand(PackageIds.cmdTitleCase, new Replacement(x => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(x))); 18 | SetupCommand(PackageIds.cmdReverse, new Replacement(x => new string(x.Reverse().ToArray()))); 19 | SetupCommand(PackageIds.cmdNormalize, new Replacement(x => RemoveDiacritics(x))); 20 | SetupCommand(PackageIds.cmdMd5, new Replacement(x => Hash(x, new MD5CryptoServiceProvider()))); 21 | SetupCommand(PackageIds.cmdSha1, new Replacement(x => Hash(x, new SHA1CryptoServiceProvider()))); 22 | SetupCommand(PackageIds.cmdSha256, new Replacement(x => Hash(x, new SHA256CryptoServiceProvider()))); 23 | SetupCommand(PackageIds.cmdSha384, new Replacement(x => Hash(x, new SHA384CryptoServiceProvider()))); 24 | SetupCommand(PackageIds.cmdSha512, new Replacement(x => Hash(x, new SHA512CryptoServiceProvider()))); 25 | } 26 | 27 | private void SetupCommand(int commandId, Replacement callback) 28 | { 29 | RegisterCommand(PackageGuids.guidTransformCmdSet, commandId, () => Execute(callback)); 30 | } 31 | 32 | private static string RemoveDiacritics(string s) 33 | { 34 | string stFormD = s.Normalize(NormalizationForm.FormD); 35 | StringBuilder sb = new StringBuilder(); 36 | 37 | for (int ich = 0; ich < stFormD.Length; ich++) 38 | { 39 | UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[ich]); 40 | if (uc != UnicodeCategory.NonSpacingMark) 41 | { 42 | sb.Append(stFormD[ich]); 43 | } 44 | } 45 | 46 | return (sb.ToString().Normalize(NormalizationForm.FormC)); 47 | } 48 | 49 | private static string Hash(string original, HashAlgorithm algorithm) 50 | { 51 | byte[] hash = algorithm.ComputeHash(Encoding.UTF8.GetBytes(original)); 52 | algorithm.Dispose(); 53 | 54 | StringBuilder sb = new StringBuilder(); 55 | 56 | foreach (byte b in hash) 57 | { 58 | sb.Append(b.ToString("x2", CultureInfo.InvariantCulture).ToLowerInvariant()); 59 | } 60 | 61 | return sb.ToString(); 62 | } 63 | 64 | private void Execute(Replacement callback) 65 | { 66 | ThreadHelper.ThrowIfNotOnUIThread(); 67 | 68 | try 69 | { 70 | TextDocument document = GetTextDocument(); 71 | string result = callback(document.Selection.Text); 72 | 73 | if (result == document.Selection.Text) 74 | return; 75 | 76 | using (UndoContext(callback.Method.Name)) 77 | { 78 | document.Selection.Insert(result, 0); 79 | } 80 | } 81 | catch (Exception ex) 82 | { 83 | Logger.Log(ex); 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/VSCommandTable.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This file was generated by VSIX Synchronizer 4 | // 5 | // ------------------------------------------------------------------------------ 6 | namespace Editorsk 7 | { 8 | using System; 9 | 10 | /// 11 | /// Helper class that exposes all GUIDs used across VS Package. 12 | /// 13 | internal sealed partial class PackageGuids 14 | { 15 | public const string guidPackageString = "3dc4f9d3-0070-4393-8c0b-c3952e944624"; 16 | public static Guid guidPackage = new Guid(guidPackageString); 17 | 18 | public const string guidTopMenuString = "f321cac5-e101-459b-b24e-ba72ad25a2f3"; 19 | public static Guid guidTopMenu = new Guid(guidTopMenuString); 20 | 21 | public const string guidEncodingCmdSetString = "02af2694-ed70-4c77-b1ab-e1ecb5eda6e7"; 22 | public static Guid guidEncodingCmdSet = new Guid(guidEncodingCmdSetString); 23 | 24 | public const string guidTransformCmdSetString = "f4c95200-781f-4ca3-b2c6-e6f444368df8"; 25 | public static Guid guidTransformCmdSet = new Guid(guidTransformCmdSetString); 26 | 27 | public const string guidLinesCmdSetString = "243f9ffe-bb22-44f7-bc28-75a5f69c6431"; 28 | public static Guid guidLinesCmdSet = new Guid(guidLinesCmdSetString); 29 | 30 | public const string HtmlCmdSetString = "78f03954-2fb8-4087-8ce7-59d71710b3bb"; 31 | public static Guid HtmlCmdSet = new Guid(HtmlCmdSetString); 32 | 33 | public const string CssCmdSetString = "64da400e-b4ad-4d67-aa92-4b7acb01ecd5"; 34 | public static Guid CssCmdSet = new Guid(CssCmdSetString); 35 | 36 | public const string JsonCmdSetString = "f718ca06-cf4f-4a0c-9106-e79e9ee5e7cd"; 37 | public static Guid JsonCmdSet = new Guid(JsonCmdSetString); 38 | 39 | public const string guidXmlUiCmdsString = "fb87333b-16c8-400e-bc8f-f6b890410582"; 40 | public static Guid guidXmlUiCmds = new Guid(guidXmlUiCmdsString); 41 | } 42 | /// 43 | /// Helper class that encapsulates all CommandIDs uses across VS Package. 44 | /// 45 | internal sealed partial class PackageIds 46 | { 47 | public const int TopMenu = 0x3001; 48 | public const int EncodeMenu = 0x0100; 49 | public const int HtmlEncodingMenuGroup = 0x0110; 50 | public const int JavaScriptEncodingMenuGroup = 0x0120; 51 | public const int UrlEncodingMenuGroup = 0x0130; 52 | public const int cmdHtmlEncode = 0x0102; 53 | public const int cmdHtmlDecode = 0x0103; 54 | public const int cmdUrlEncode = 0x0106; 55 | public const int cmdUrlDecode = 0x0107; 56 | public const int cmdJavaScriptEncode = 0x0108; 57 | public const int cmdAttrEncode = 0x0109; 58 | public const int TransformMenu = 0x0100; 59 | public const int CasingTransformMenuGroup = 0x0110; 60 | public const int MiscTransformMenuGroup = 0x0120; 61 | public const int CryptoTransformMenuGroup = 0x0130; 62 | public const int cmdTitleCase = 0x0001; 63 | public const int cmdReverse = 0x0002; 64 | public const int cmdNormalize = 0x0003; 65 | public const int cmdMd5 = 0x0004; 66 | public const int cmdSha1 = 0x0005; 67 | public const int cmdSha256 = 0x0006; 68 | public const int cmdSha384 = 0x0007; 69 | public const int cmdSha512 = 0x0008; 70 | public const int LinesMenu = 0x0001; 71 | public const int LinesMenuGroup = 0x0002; 72 | public const int cmdSortAsc = 0x0003; 73 | public const int cmdSortDesc = 0x0004; 74 | public const int cmdRemoveDuplicateLines = 0x0005; 75 | public const int cmdRemoveEmptyLines = 0x0007; 76 | public const int htmlContextMenu = 0x0001; 77 | public const int CssContextMenu = 0x0002; 78 | public const int JsonContextMenu = 0x0003; 79 | } 80 | } -------------------------------------------------------------------------------- /src/Editorsk.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(VisualStudioVersion) 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | true 7 | Program 8 | $(DevEnvDir)\devenv.exe 9 | /rootsuffix Exp 10 | 11 | 12 | 13 | 14 | 15 | 16 | Debug 17 | AnyCPU 18 | 2.0 19 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 20 | {0393496E-0D81-4AD2-B9C9-B883CD41E8B6} 21 | Library 22 | Properties 23 | Editorsk 24 | Editorsk 25 | v4.8 26 | true 27 | true 28 | true 29 | true 30 | true 31 | false 32 | 33 | 34 | true 35 | full 36 | false 37 | bin\Debug\ 38 | DEBUG;TRACE 39 | prompt 40 | 4 41 | 42 | 43 | pdbonly 44 | true 45 | bin\Release\ 46 | TRACE 47 | prompt 48 | 4 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | True 62 | True 63 | source.extension.vsixmanifest 64 | 65 | 66 | True 67 | True 68 | VSCommandTable.vsct 69 | 70 | 71 | 72 | 73 | 74 | 75 | Resources\LICENSE 76 | true 77 | 78 | 79 | Designer 80 | VsixManifestGenerator 81 | source.extension.cs 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | Menus.ctmenu 93 | VsctGenerator 94 | VSCommandTable.cs 95 | 96 | 97 | 98 | 99 | true 100 | 101 | 102 | 103 | 104 | 17.0.0-previews-4-31709-430 105 | 106 | 107 | 17.0.5232 108 | runtime; build; native; contentfiles; analyzers 109 | all 110 | 111 | 112 | 113 | 114 | 121 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Looking to contribute something? **Here's how you can help.** 4 | 5 | Please take a moment to review this document in order to make the contribution 6 | process easy and effective for everyone involved. 7 | 8 | Following these guidelines helps to communicate that you respect the time of 9 | the developers managing and developing this open source project. In return, 10 | they should reciprocate that respect in addressing your issue or assessing 11 | patches and features. 12 | 13 | 14 | ## Using the issue tracker 15 | 16 | The issue tracker is the preferred channel for [bug reports](#bug-reports), 17 | [features requests](#feature-requests) and 18 | [submitting pull requests](#pull-requests), but please respect the 19 | following restrictions: 20 | 21 | * Please **do not** use the issue tracker for personal support requests. Stack 22 | Overflow is a better place to get help. 23 | 24 | * Please **do not** derail or troll issues. Keep the discussion on topic and 25 | respect the opinions of others. 26 | 27 | * Please **do not** open issues or pull requests which *belongs to* third party 28 | components. 29 | 30 | 31 | ## Bug reports 32 | 33 | A bug is a _demonstrable problem_ that is caused by the code in the repository. 34 | Good bug reports are extremely helpful, so thanks! 35 | 36 | Guidelines for bug reports: 37 | 38 | 1. **Use the GitHub issue search** — check if the issue has already been 39 | reported. 40 | 41 | 2. **Check if the issue has been fixed** — try to reproduce it using the 42 | latest `master` or development branch in the repository. 43 | 44 | 3. **Isolate the problem** — ideally create an 45 | [SSCCE](http://www.sscce.org/) and a live example. 46 | Uploading the project on cloud storage (OneDrive, DropBox, et el.) 47 | or creating a sample GitHub repository is also helpful. 48 | 49 | 50 | A good bug report shouldn't leave others needing to chase you up for more 51 | information. Please try to be as detailed as possible in your report. What is 52 | your environment? What steps will reproduce the issue? What browser(s) and OS 53 | experience the problem? Do other browsers show the bug differently? What 54 | would you expect to be the outcome? All these details will help people to fix 55 | any potential bugs. 56 | 57 | Example: 58 | 59 | > Short and descriptive example bug report title 60 | > 61 | > A summary of the issue and the Visual Studio, browser, OS environments 62 | > in which it occurs. If suitable, include the steps required to reproduce the bug. 63 | > 64 | > 1. This is the first step 65 | > 2. This is the second step 66 | > 3. Further steps, etc. 67 | > 68 | > `` - a link to the project/file uploaded on cloud storage or other publicly accessible medium. 69 | > 70 | > Any other information you want to share that is relevant to the issue being 71 | > reported. This might include the lines of code that you have identified as 72 | > causing the bug, and potential solutions (and your opinions on their 73 | > merits). 74 | 75 | 76 | ## Feature requests 77 | 78 | Feature requests are welcome. But take a moment to find out whether your idea 79 | fits with the scope and aims of the project. It's up to *you* to make a strong 80 | case to convince the project's developers of the merits of this feature. Please 81 | provide as much detail and context as possible. 82 | 83 | 84 | ## Pull requests 85 | 86 | Good pull requests, patches, improvements and new features are a fantastic 87 | help. They should remain focused in scope and avoid containing unrelated 88 | commits. 89 | 90 | **Please ask first** before embarking on any significant pull request (e.g. 91 | implementing features, refactoring code, porting to a different language), 92 | otherwise you risk spending a lot of time working on something that the 93 | project's developers might not want to merge into the project. 94 | 95 | Please adhere to the [coding guidelines](#code-guidelines) used throughout the 96 | project (indentation, accurate comments, etc.) and any other requirements 97 | (such as test coverage). 98 | 99 | Adhering to the following process is the best way to get your work 100 | included in the project: 101 | 102 | 1. [Fork](http://help.github.com/fork-a-repo/) the project, clone your fork, 103 | and configure the remotes: 104 | 105 | ```bash 106 | # Clone your fork of the repo into the current directory 107 | git clone https://github.com//.git 108 | # Navigate to the newly cloned directory 109 | cd 110 | # Assign the original repo to a remote called "upstream" 111 | git remote add upstream https://github.com/madskristensen/.git 112 | ``` 113 | 114 | 2. If you cloned a while ago, get the latest changes from upstream: 115 | 116 | ```bash 117 | git checkout master 118 | git pull upstream master 119 | ``` 120 | 121 | 3. Create a new topic branch (off the main project development branch) to 122 | contain your feature, change, or fix: 123 | 124 | ```bash 125 | git checkout -b 126 | ``` 127 | 128 | 4. Commit your changes in logical chunks. Please adhere to these [git commit 129 | message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) 130 | or your code is unlikely be merged into the main project. Use Git's 131 | [interactive rebase](https://help.github.com/articles/interactive-rebase) 132 | feature to tidy up your commits before making them public. Also, prepend name of the feature 133 | to the commit message. For instance: "SCSS: Fixes compiler results for IFileListener.\nFixes `#123`" 134 | 135 | 5. Locally merge (or rebase) the upstream development branch into your topic branch: 136 | 137 | ```bash 138 | git pull [--rebase] upstream master 139 | ``` 140 | 141 | 6. Push your topic branch up to your fork: 142 | 143 | ```bash 144 | git push origin 145 | ``` 146 | 147 | 7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/) 148 | with a clear title and description against the `master` branch. 149 | 150 | 151 | ## Code guidelines 152 | 153 | - Always use proper indentation. 154 | - In Visual Studio under `Tools > Options > Text Editor > C# > Advanced`, make sure 155 | `Place 'System' directives first when sorting usings` option is enabled (checked). 156 | - Before committing, organize usings for each updated C# source file. Either you can 157 | right-click editor and select `Organize Usings > Remove and sort` OR use extension 158 | like [BatchFormat](http://visualstudiogallery.msdn.microsoft.com/a7f75c34-82b4-4357-9c66-c18e32b9393e). 159 | - Before committing, run Code Analysis in `Debug` configuration and follow the guidelines 160 | to fix CA issues. Code Analysis commits can be made separately. 161 | -------------------------------------------------------------------------------- /src/VSCommandTable.vsct: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | DynamicVisibility 13 | 14 | Encode Selection 15 | 16 | 17 | 18 | 19 | DynamicVisibility 20 | 21 | Transform Selection 22 | 23 | 24 | 25 | 26 | DynamicVisibility 27 | 28 | Selected Lines 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 72 | 73 | 80 | 81 | 88 | 89 | 96 | 97 | 104 | 105 | 114 | 115 | 122 | 123 | 132 | 133 | 140 | 141 | 148 | 149 | 156 | 157 | 164 | 165 | 172 | 173 | 180 | 181 | 190 | 191 | 200 | 201 | 208 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | --------------------------------------------------------------------------------