Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

Combine Last N History Items with Numbering and Seperation Options

Description
This is a modification of Keith Lammers script of a similar name that allows you the additional options of choosing the text your history items are concatenated with and numbering the output.
Language
C#.net
Minimum Version
Created By
A Computer User
Contributors
-
Date Created
Mar 30, 2023
Date Last Modified
Mar 30, 2023

Macro Code

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

// The 'text' parameter will contain the text from the:
//   - Current Clipboard when run by HotKey
//   - History Item when run from the History Menu
// The returned string will be:
//   - Placed directly on the Clipboard when run as a Macro
//   - Ignored by ClipboardFusion if it is 'null'
//   - Passed along to the next action in a Trigger (null changed to an empty string)
public static class ClipboardFusionHelper
{
	public static string ProcessText(string text)
	{
		string spaces = "        ";
		string prompt = "<int: Number to combine>\n";
		prompt += "<int: Number to combine> <bool: Include number?>\n";
		prompt += "<int: Number to combine> <bool: Include number?> <string: Text to splice with>\n";
		prompt += "EX:\n";
		prompt += $"{spaces}//Example 1: Numbered and newline seperated\n";
		prompt += $"{spaces}//1: [your text 0]\n";
		prompt += $"{spaces}//2: [your text 1]\n";
		prompt += $"\n{spaces}2 true \\n\n\n";
		prompt += $"{spaces}//Example 2: Newline seperated\n";
		prompt += $"{spaces}//[your text 0]\n";
		prompt += $"{spaces}//[your text 1]\n";
		prompt += $"\n{spaces}2 false \\n\n\n";
		prompt += $"{spaces}//Example 3: Semi-colon seperated\n";
		prompt += $"{spaces}//[your text 0];[your text 1]\n";
		prompt += $"\n{spaces}2 false ;";
		//Output:\n    //2: [your text 0]\n    2 true \\n\n    2 false ;";
		string[] input = BFS.Dialog.GetUserInput($"{prompt}", "2").Split(' ');
		bool includeNumeration = false;
		if (input.Length > 1)
		{
			if (!Boolean.TryParse(input[1], out includeNumeration))
			{
				BFS.Dialog.ShowTrayMessage("Second Parameter (Boolean) Conversion Failed.");
			}
		}
		string input_split_text = input.Length > 2 ? string.Join(" ", new System.ArraySegment<string>(input, 2, input.Length - 2)) : "\n";
		input_split_text = Regex.Unescape(input_split_text);
		int numberOfItems = Convert.ToInt32(input[0]);
		string output = String.Empty;
		for (int i = 0; i < numberOfItems; i++)
		{
			output = output + $"{(includeNumeration ? (i + 1).ToString() + ": " : "")}" + BFS.ClipboardFusion.GetHistoryText(i).Trim();
			if (i < numberOfItems - 1)
			{
				output = output + input_split_text;
			}
		}
		//BFS.Dialog.ShowMessageInfoMonospaced($"input: {string.Join(" | ", input)}\nincludeNumeration: {input[1]}|{includeNumeration}\ninput_split_text: {input_split_text}\nnumberOfItems: {numberOfItems}\noutput:\n{output}");
		BFS.Clipboard.SetText(output);
		return output;
	}
}