Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Show List of Macros

Description
This Macro will show a pop-up dialog with a list of Macros that you can run. Just replace the Macro names in the "MenuEntries" variable at the top of the script, with the names of your Macros.
Language
C#.net
Minimum Version
Created By
DS1508
Contributors
-
Date Created
Oct 5, 2016
Date Last Modified
Oct 6, 2016

Macro Code

using System;
using System.Drawing;
using System.Windows.Forms;

/****************************************************************************************************************
**This Macro will show a pop-up dialog with a list of Macros that you can run.
**Just replace the Macro names in the "MenuEntries" variable at the top of the script, with the names of
**your Macros.
**eg:{{ "PaleGreen", "Black", "Copy and Append", "Copy and &Append selected text", "cb-content" }},
**- "PaleGreen" is the background color
**- "Black" is the foreground-(text) colorQ
**- "Copy and Append" is the macro name as it appears in your macro list
**- "Copy and &Append selected text" is the text you will see in the popup, here the "A" is set as hotkey
**- "cb-content" can be "image", "text", "all". It defines if the entry is clickable or not. If the macro needs
**an image in the clipboard, the entry is disabled if there's only text on the cb.
**
**Color names can be found here:
**http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/colors/ColorTable.htm
**
**Add an ampersand (&) at the fourth parameter to get a hotkey for the entry.
**  eg:{{ "Pink", "Maroon", "--- Cancel ---", "--- &Cancel ---" }},
**{{ "PaleGreen", "Black", "Copy and Append", "Copy and &Append selected text" }},
**
**If you want an entry to cancel the action please use:
**{{ "Background color", "Foreground color", "--- Cancel ---", "--- &Cancel ---" }},
**
** You can also click outside the popup or press ESC to cancel/close.
**
*****************************************************************************************************************/

public static class ClipboardFusionHelper
{
	public static string ProcessText(string text)
	{

		// These are all of the macros from the "Macros" list.
		// See description above.
		string[, ,] MenuEntries = 
		{
			//{{ "Background-Color", "Foreground-Color", "Macro-Name", "Menu entry text", "image text all" }}
			{{ "Pink", "Maroon", "--- Cancel ---", "--- Cancel ---", "all" }},
			{{ "Khaki", "Black", "Remove Extra White Spaces and Trim", "&1 Remove Extra White Spaces and Trim", "text" }},
			{{ "Khaki", "Black", "Replace special chars with spaces, Trim", "&2 Replace special chars with spaces then Trim", "text" }},
			{{ "BurlyWood", "Black", "Auto-Type Clipboard Text", "Auto-&Type Clipboard Text", "text" }},
			{{ "BurlyWood", "Black", "Show History Drop-Down List, Modify", "Show &History Drop-Down List, and modify value", "text" }},
			{{ "PaleGreen", "Black", "Copy and Append", "Copy and &Append selected text", "text" }},
			{{ "Aquamarine", "Black", "Decode Base64-Encoded Text (UTF-8)", "Decode Base64-Encoded Text (UTF-8)", "text" }},
			{{ "Aquamarine", "Black", "Decode URL-Encoded Text", "Decode URL-Encoded Text", "text" }},
			{{ "Aquamarine", "Black", "Encode Text (UTF-8) using Base64-Encoding", "Encode Text (UTF-8) using Base64-Encoding", "text" }},
			{{ "Aquamarine", "Black", "Encode Text using URL-Encoding", "Encode Text using URL-Encoding", "text" }},
			{{ "Darkseagreen", "Black", "Search For Copied Text using Google.de", "Search for text in clipboard using &Google.de", "text" }},
			{{ "Darkseagreen", "Black", "URL Grabber", "URL Grabber", "text" }},
			{{ "White", "Black", "Save Copied Image to Disk", "Save &image in clipboard to disk", "image" }},
			{{ "Pink", "Maroon", "--- Cancel ---", "--- Cancel ---", "all" }}
		};

		// Create a new ContextMenuStrip to show the items
		using(ContextMenuStrip menu = new ContextMenuStrip())
		{
			// Don't show the padding on the left of the menu
			menu.ShowCheckMargin = false;
			menu.ShowImageMargin = false;

			string cbContent = "";
			if ( BFS.Clipboard.HasText() ) cbContent = "text";
			if ( Clipboard.ContainsImage() ) cbContent = "image";

			// Add items to the menu, and use custom function when the user clicks on the items
			for ( int i = 0; i < MenuEntries.GetLength(0); i++ ) {
				ToolStripMenuItem item = new ToolStripMenuItem(MenuEntries[i, 0, 3]);
				item.Click += MenuItem_Click;
				item.BackColor = Color.FromName( MenuEntries[i, 0, 0]);
				item.ForeColor = Color.FromName( MenuEntries[i, 0, 1]);
				item.Tag = MenuEntries[i, 0, 2];
				if ( (MenuEntries[i, 0, 4] == cbContent) || (MenuEntries[i, 0, 4] == "all") || (cbContent == "") )
					item.Enabled = true;
				else
					item.Enabled = false;
				menu.Items.Add(item);
			}

			// Finally show the popup menu
			menu.Show(new Point(BFS.Input.GetMousePositionX(), BFS.Input.GetMousePositionY()), ToolStripDropDownDirection.AboveRight);

			// Set focus to the menu
			menu.BringToFront();
			menu.Focus();
			BFS.Window.Focus(menu.Handle);
			BFS.Window.SetAlwaysOnTop(menu.Handle, true);

			// Wait for the menu to close
			while(menu.Visible)
			{
				Application.DoEvents();
			}
		}
		return null;
	}

	/****************************************************************************************************************
	**This function will get the text of the clicked item and try to run it as a ClipboardFusion Macro.
	*****************************************************************************************************************/
	private static void MenuItem_Click(object sender, EventArgs e)
	{
		ToolStripItem item = sender as ToolStripItem;
		if (item == null) return;
		// Get the macro name
		string macroName = item.Tag as String;
		if ( (macroName == "--- Cancel ---") || (macroName == "") ) return;

		string text = BFS.Clipboard.GetText();
		if (text == null) text = "";
		// Return values
		string rText = "";
		string rError = "";
		// Run the macro
		BFS.ClipboardFusion.RunMacro(macroName, text, out rText, out rError);
		// Any errors?
		if ( rError != "" ) {
			BFS.Dialog.ShowMessageError("An error has occurred:\n"+rError);
		} else {
			BFS.Clipboard.SetText(rText);
		}
	}
}