Monday, March 14, 2016

Using C# on Windows to Create Clipboard Cut & Paste Extensions

This article documents a C#/.NET program that I created to provide “a Windows Clipboard Cut & Paste Extension” mechanism. The idea for “Text Transformations” (TT) is simple: (a) you put some text into your Windows Clipboard in any of the ways you can do this, (b) invoke “TT -Flag”, usually by having a ShortCut that encapsulates the details about how to do this — including which “TT -Flag” you want, and (c) after TT runs, it leaves its results in the clipboard so you just “Paste” the text to wherever you want it.

For example, when I do a regular expression search (e.g.“lhsChars.*rhsString”) and it fails, often the very next thing I want is what “TT -Swap” would do: It returns “rhsString.*lhsChars”. The tool is nothing more than a convenience, but for things you do a lot it can be well worth it. Another example that I use when working with Sql starts with selecting a column of strings or numbers from a SELECT grid; after a “TT -InSql_S”, a Paste might return e.g. the Sql snippet: IN ( '3423', '329', '44993', '21812' ) or “TT -InSql_N” would see that all the strings are numeric so it would produce the same thing but without any quotes. If you spend a lot of time editing Sql or C# (or anything), such TTransformations can be very convenient.

A more significant example provides something like Windows File versioning. Using the Windows Explorer right-mouse convenience called “Copy Path”, I can point to a file (put its path into the Paste buffer) and then invoke “TT -Version”. This operation makes a copy of the file, coming up with a variation on the file name so that nothing gets overwritten. e.g. If I started out with a file name like myFile.txt, “TT -Version” would look in the folder where that file resides and the first time I did this it would create: myFile_00.txt   If I already had an “_012” version, the next “TT -Version” file copy would create myFile_013.txt ... and etc.

Some of the other TT transformations read template files and do substitutions on place-holder markers for things like DateTime strings. A specific one of these that I use every day as part of the Agile methodology is “TT -Scrum” — it analyses a fragment of yesterday's scrum sheet and creates a new one, for today!

The intention of this portfolio is that I make my C# code available to others... so if you are interested in getting your hands on TT, simply contact me and we'll have a conversation about that.