Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / operating-systems / Windows / Win64

Copy-Cutter: Code 'Snippet' Manager for Windows

4.50/5 (4 votes)
18 Feb 2022CPOL8 min read 9.2K   256  
A tool to help quickly generate 'snippets' of code in any Windows based IDE - use OneDrive to clipboard PC to PC
Copy-Cutter lets you quickly create code-snippets you can immediately add to your work. 'Text' mode lets you parse out lists of variable names and let Copy-Cutter generate the code snippet for each variable in the list and paste it from the MS-Clipboard. CloudClipboard text from one PC to another using CopyCutter and Microsoft's OneDrive.

Image 1

Microsoft's Snippets are great, but sometimes they just don't do enough. Cut-n-paste comes in handy when you have a lot of similar bits of code to write that only differ in the names of the variables you're instantiating, sampling or setting. Even though Snippets can quickly build the frame-work for For-Loop's or nested If-Else statements, you can't use them to generate a sequence of similar lines-of-code for a list of variables or objects that are all virtually the same with little or no difference between them. Even though you can create your own MS Visual Studio snippets to add to the existing list, there is a bit of work involved in doing that, code snippets are relatively limited and you may not even be writing in a Visual Studio IDE anyway. VS Snippets will help you set up a For-Loop, an Enum or Do-While, but they won't help you instantiate a bunch of buttons that you need to set Colors and Fonts, add Text to. There's still a bit of typing involved in doing that.

Here's where the Copy-Cutter app comes in. It's really quite a simple app to use.

  • Click the 'Format Editor' button on the Copy-Cutter form.
  • Select a Format from the Format Editor's list (or create the format you want) and Click 'Ok'.
  • Copy/Cut as much code (e.g., Variable or Object names) into Microsoft's Clipboard.
  • Click the 'Clipboard - Dump' button on the Copy-Cutter.
  • Position the mouse cursor in your work-space where you want to insert the generated code.
  • Paste the generated code into your project.

Have a look at this video.

Let's say, for example, you needed to create a few buttons that all do basically the same thing.

Your method might look like this:

C++
void Example()
        {
            //                         Button - var1
            System.Windows.Forms.Button btnvar1 = new System.Windows.Forms.Button();
            btnvar1.Text = "var1";
            btnvar1.AutoSize = true;
            btnvar1.BackColor = System.Drawing.Color.Blue;
            btnvar1.ForeColor = System.Drawing.Color.Yellow;
            btnvar1.KeyDown += Btnvar1_KeyDown;
            btnvar1.KeyUp += Btnvar1_KeyUp;

            //                         Button - var2
            System.Windows.Forms.Button btnvar2 = new System.Windows.Forms.Button();
            btnvar2.Text = "var2";
            btnvar2.AutoSize = true;
            btnvar2.BackColor = System.Drawing.Color.Blue;
            btnvar2.ForeColor = System.Drawing.Color.Yellow;
            btnvar2.KeyDown += Btnvar2_KeyDown;
            btnvar2.KeyUp += Btnvar2_KeyUp;

            //                         Button - var3
            System.Windows.Forms.Button btnvar3 = new System.Windows.Forms.Button();
            btnvar3.Text = "var3";
            btnvar3.AutoSize = true;
            btnvar3.BackColor = System.Drawing.Color.Blue;
            btnvar3.ForeColor = System.Drawing.Color.Yellow;
            btnvar3.KeyDown += Btnvar3_KeyDown;
            btnvar3.KeyUp += Btnvar3_KeyUp;

            //                         Button - var4
            System.Windows.Forms.Button btnvar4 = new System.Windows.Forms.Button();
            btnvar4.Text = "var4";
            btnvar4.AutoSize = true;
            btnvar4.BackColor = System.Drawing.Color.Blue;
            btnvar4.ForeColor = System.Drawing.Color.Yellow;
            btnvar4.KeyDown += Btnvar4_KeyDown;
            btnvar4.KeyUp += Btnvar4_KeyUp;
        }

These buttons you've created are virtually the same. You could write the first one, then cut-n-paste the rest and change the variable names for each one. But that's still a lot of work.

Using this app, you would go to the Format Editor. Create the format you need (if it's not already saved in your format list). Select it, click 'ok'. Then write the names of each variable one at a time into the MS Clipboard (type the name, highlight it and press Ctrl-X). Then dump-it-all to the Clipboard using the 'Clipboard-Dump' button and when you paste it into your work, it will look exactly as it appears above.

Here's what the Format Editor needs to look like when you've created the appropriate format for this particular example.

Image 2

The words <Source_Text> will be replaced by whatever you copied to the Clipboard. What happens is, every time you copy text to the clipboard while the CopyCutter app is on, that text will be added to a growing list of text (usually Variable or Object names). When you click the 'Clipboard - Dump' button each item in the list that you copied to the clipboard will generate the formatted text above with the Variable/Object name replacing the tag <Source_Text> found in your selected format.

Since you write the Formats into the Copy-Cutter yourself, they can be tailored to your exact needs and are not limited to Visual Studio or any other language. You can use this in Arduino, Python, Assembly or even your own Mark-Up creations. You need not type the <Source_Text> tag in the Format Editor but simply press the same Control-Insert key-combination that Shows/Hides the app while it's running in the background waiting for your call.

The code needed to do this itself is relatively simple. All the formats are saved to an XML file which you need never bother with. The Format Editor's interface is user friendly enough that you can create your own formats on the fly and use them whenever you like.

Now, in the example above, you've generated the buttons but they have events attached to them. You will have to generate the events as well and that can be a hassle. Most times, you'll just hit the Tab-key after the '+=' before the event name when you're defining the button but since we had Copy-Cutter generate that code for us we'll have to use the Copy-Cutter to generate the event handlers as well. No problem.

  • Summon Copy-Cutter to the screen (if you have it in the background just click Ctrl-Insert).
  • Click the 'Format Editor' button on the Copy-Cutter form.
  • Select the Event-Standard format from the list and press 'ok'.
  • Copy the Event names from your code to the Clipboard.
  • Press 'Clipboard - Dump'.
  • Paste the code to your app.

All this saves a lot of time.

Maybe you like the monotonous brain-dead tedium of writing all these by hand or maybe you don't, but either way, this app makes writing code much quicker.

The example above can be made even faster if you just type the names of the variables in one line of text with a single space between them, then define the 'Parse String Delimiter' as a single space (or any text that separates them all from each other) and copy the entire line to the MS Clipboard. Copy Cutter will look at the 'Parse String Delimiter' and break the copied text up into the separate variable names. So, in this way, you can create the entire method by just typing the names of the variables then Cut & Paste the lot into your project using this simple easy-to-use app.

Alternately, you could toggle the 'Live-Swap' option On. This feature allows you to cut/paste one Variable/Object name at a time and produce the same code. When this option is On, the app will NOT accumulate a list and wait for you to press Clipboard-Dump but rather generate the code you formatted each time you copy something to the MS clipboard and replace the content of the clipboard with the formatted code you want. Just Cut and immediately Paste wherever you like.

I use it all the time. Presto-magico, its freakin' awesome.

Convenient, versatile, user-friendly, all it needs now is a mini-bar but you'll have to put that on your tab along with room service.

Cloud - Clipboard 

Since I've recently bought a second computer and am now a proud custodian of not only one but two computers, I've recently discovered something called 'the cloud'.   Microsoft's OneDrive is a convenient way to copy information from one MS PC to another but they still don't share 'clipboard'.  Copy Cutter has a cloud feature that allows you to use Microsoft's Clipboard (cut, copy & paste text) on one computer and have Copy Cutter place that text in a different computer's clipboard.  

To do this you need only have CopyCutter running on two computers. 

  1. Set both copies of this app to the CloudClipboard mode by clicking the mode button until you've found it. 
  2. At the time of writing, it currently only sends information in one direction : from a Sender to a Receiver.  You'll have to set both the apps to the appropriate Sender/Receiver selections depending on how you want to use this feature.  
  3. Since they rely on MS OneDrive and files you share between the two computers, you'll have to tell the app in which directory you want it to operate. 

Image 3

Once this is done, you toggle them both on and you're ready to go.  Just copy into the Sender's clipboard any text you want to send to the Receiver and in a moment (when OneDrive has copied the sender's changes into the receiver's copy) the Receiver's CopyCutter will detect the text's arrival and(when Auto Packet is selected)  overwrite whatever was stored in its ClipBoard with the text that was copied in the Sender's clipboard.

If you want to accumulate a list of text copied from the sender and refer to them later, be certain Auto Packet is NOT selected and the text will accumulate at the Receiver's CopyCutter.

Image 4

When you want to retrieve the text received, click the Packet Arrived button and the text will be copied from CopyCutter's list to your PC's Clipboard one at a time.

If you have a copy of my Words : A Creative Writer's Word Processor you can use CopyCutter:CloudClipboard in combination with the Notes-taking feature (blue cloud icon with red lightning toggle on the ToolBar) in conjunction with the Copy-Cutter app.  Follow the steps above and select Auto Packet so that the Receiver will automatically overwrite the Clipboard with new text that Words will pick up.

CloudClipboard : How it Works

The CloudClipboard feature relies on Microsoft's OneDrive keeping your files up to date by regularly overwriting old files on one computer with the changes made on another computer.  What CopyCutter does is take advantage of this feature by trading information between two PCs via files stored in the selected shared OneDrive directory.

Both the Sender and Receiver write to only one file on OneDrive.

These files are saved on their respective computer's OneDrive directory.  The image below shows that once MS OneDrive copies the changes from one PC to the other they both have the same files available to them which CopyCutter needs in order to transfer information from one ClipBoard to the other.

Image 5

 

The Sender reads the date-time stamp which the Receiver confirms to have read and copied into the Receiver-File.  Then the Sender finds that time-stamp in the Sender-File, deletes everything on that file written before it, then appends the Sender-File with whatever new text was found on the Clipboard then saves it on its own OneDrive.

OneDrive copies the Sender-File changes from the Sender's computer to the Receiver's computer.

The Receiver keeps track of the most recent Time-Stamp it has read and confirmed.  It reads the Sender-File ignores everything before the most recent Time-Stamp and then overwrites the latest time-stamp onto its own Receiver-File to let the Sender know how much information it has received.

OneDrive copies the Receiver-File changes from the Receiver's computer to the Sender's computer.

when the Sender detects something new in its computer's clipboard the process starts again.

History
  • 17th March, 2021: Initial version
  • 1st April, 2021 : fixed issue with Load Format 
  • 18th February, 2022 : added new Cloud feature

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)