LineSorter
An extension that allows you to sort rows by different criteria
Simply select the lines you wanna sort in the editor, then navigate Context Menu => LineSorter
and select the sorting mode you need
If you like LineSorter
or my other extensions, you can support my projects via PayPal donation:
Note: PayPal takes a fee of 1.2% + 0.35€ per donation
If you have any questions, don't hesitate to drop me a mail!)
Example situation
using System.Threading.Tasks;
using System.IO;
using System.Collections.Generic;
using Antlr4.Runtime;
using System.Data;
using Microsoft.CodeAnalysis;
using System.Reflection;
using System;
using System.Text;
using System.Drawing;
using System.Numerics;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using Antlr4;
using Microsoft.CodeAnalysis.Text;
using Antlr4.Runtime.Misc;
Now let's sort it)
Sort lines alphabetically
Sort lines alphabetically result (shortcut: (CTRL + E) + (CTRL + A)
):
using Antlr4.Runtime.Misc;
using Antlr4.Runtime;
using Antlr4;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System;
Sort lines alphabetically (desc) result:
using System;
using System.Xml.Linq;
using System.Threading.Tasks;
using System.Text;
using System.Reflection;
using System.Numerics;
using System.Linq;
using System.IO;
using System.Drawing;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Antlr4;
using Antlr4.Runtime;
using Antlr4.Runtime.Misc;
Sort lines by length
Sort lines by length result (shortcut: (CTRL + E) + (CTRL + L)
):
using Antlr4;
using System;
using System.IO;
using System.Data;
using System.Linq;
using System.Text;
using Antlr4.Runtime;
using System.Drawing;
using System.Numerics;
using System.Xml.Linq;
using System.Reflection;
using System.Collections;
using Antlr4.Runtime.Misc;
using Microsoft.CodeAnalysis;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.Text;
Sort lines by length (desc) result:
using Microsoft.CodeAnalysis.Text;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Antlr4.Runtime.Misc;
using System.Collections;
using System.Reflection;
using System.Xml.Linq;
using System.Numerics;
using System.Drawing;
using Antlr4.Runtime;
using System.Text;
using System.Linq;
using System.Data;
using System.IO;
using System;
using Antlr4;
Shuffle
Shuffle result (1 in N):
using System.Numerics;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.Text;
using Antlr4.Runtime;
using Microsoft.CodeAnalysis;
using System.IO;
using Antlr4.Runtime.Misc;
using System.Drawing;
using System;
using System.Reflection;
using System.Text;
using System.Linq;
using Antlr4;
using System.Threading.Tasks;
using System.Data;
Preview
Add custom command
Now users has the opportunity to create their own sorting method!
Ok, let's try to do it)
Imagine that you want to sort these lines:
-200
3
-7
0
5
15
String
-1
25
23
Not a number
150
21
Hello, world!
4
53
-123
110
2
using next rule: numbers are sorted in ascending order, and all strings follow the numbers and are sorted alphabetically
Navigate Context Menu => LineSorter => Add custom sort
After that the following window will appear:
- Using
Language
combobox you can select language you like (C#
or Visual Basic
)
- Using
Function type
combobox you can select implementation you like
- Using
'T' is
combobox you can select generic type of collection to be sorted
- Using
Empty Lines
combobox you can choose the type of processing empty lines
We'll use Comparer
function, since we can describe how the 2 elements of the collection relate to each other
Also we'll use Row
type (visit GitHub repo to see its structure), cause lines including the numbers can contain whitespace-symbols we don't need, but they must be returned to the previos place аfter sorting.
The resulting function will look like this:
Press Compile
and you'll see this:
Press Yes
to test your method directly in the pop-up window:
(We can change the sample text here, but we'll do it in the VS editor))
Of course you can just skip this step. Anyway you'll see this messagebox:
If you like sorting method you've done and you wanna save it, then press Yes
. If you'll press No
, you'll be back to code window
Done! Let's try it:
We've just created our own sort and applied it in the editor. Successfully!
Add custom command by myself
The method above has some disadvantages:
- It will be very inconvenient to write a large sorting function
- You may need some third-party libraries
At the moment LineSorter doesn't have built-in support for adding externally compiled functions, but all this is possible!
Just follow these instructions:
- Download the current version of LineSorter.Export.dll
- Connect it to your project
- Determine the type of your sorting (it doesn't matter what namespace it will be in)
- Indicate that it implements the interface
LineSorter.Export.IUserSort
- Implement the interface:
- The
Guid
property should always return the same unique Guid value (you can generate it using Tools -> Create Guid
inside Visual Studio)
- The
Name
property should always return the same human-readable name of your sort
- The
EmptyLineAction
property should return the method of interaction with empty lines
- Implement the function
Sort
as your heart desires)
- Compile the project
- Put the resulting dll in the
%LocalAppData%\LineSorter\UserSort
folder
- If it has dependent dlls, then put them in the
%LocalAppData%\Microsoft\VisualStudio\<your VS version>\Extensions\<LineSorter Path>
folder next to LineSorter.dll (<LineSorter Path> is always random, but you can find it if you'll search LineSorter.dll)
- After launching Visual Studio, you will see your sorting in the list of available
There're some minuses:
- It's not very pleasant to dig into this pile of folders to make such a simple action
- If your sorting has dependencies and you put them next to the extension, as described above, then when you update the extension, all of them will be deleted and you'll have to re-insert them
All this is fixable, so if all of a sudden you need it - open the issue on GitHub (I just don’t want to implement something that nobody needs))
LineSorter Options
You can manage your sorts in Options => LineSorter
:
Important!
Right-click on the line with the sort and you'll be able to turn it on or off or delete)
Changes
- 1.0 - Initial release
- 1.1 - Fixed bug with deletion of a new line from the last line for sorting
- 2.0 - Localization support and new commands:
- Sort lines by length (desc)
- Sort lines alphabetically
- Sort lines alphabetically (desc)
- 2.1 - XAML files support
- 2.5 - New command:
- Shuffle
- 3.0 - Impressive refactoring and ∞ number of new commands, cause
- Added the ability to create your own sort
- 3.5 - Few improves:
- 3 different scenarios for processing empty lines
- Remove
- Process as ordinary string
- Process as mask
- Fixed critical bug with deletion custom sorts on extension update
- 4.0 - VS 2019 support (#1) and some fixes:
- Different newline representations now available to work with (#2)
- Custom sorting's windows should now display correctly (#3)
- 4.0.1 - JSON files support (#4)
- 4.5 - Some improvements:
- New cool icon by Dessader :3
- New compilers support (no more limitations when creating custom sorts)
- Fixed inappropriate create-custom-sort window behavior
- Ha-ha. From the very first version I forgot about character escaping in regex: "/*.*/"
- 4.6 - Visual Studio MPF 15.0 reference fixed (#5)
- 4.7 - Few improves:
- Improved icon for small sizes
- Fixed exception due to blocked clipboard (#6)
- 4.8 - Now all my extensions work on the basis of a single API, which made it possible to simplify some things and repeatedly reduce the weight of extensions!
- 5.0 - Visual Studio 2022 support. Thanks to @jizc!
Ideas
- If we'll refine the idea of adding third-party sortings, then we can even create a kind of store/marketplace of custom sortings from different people based on our GitHub accounts! If you are interested in this idea - create an appropriate issue