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?

Indent/Unindent Text with Dialog Selection

Description
Use this Macro to indent or unindent text.
Language
C#.net
Minimum Version
Created By
Thomas Malloch (BFS)
Contributors
-
Date Created
Apr 29, 2024
Date Last Modified
Apr 29, 2024

Macro Code

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

public static class ClipboardFusionHelper
{
    public static string ProcessText(string text)
    {
        int indentSize = 1; //Use negative or positve values
        char indentChar = '\t'; //Tab character

		Dictionary<string, int> options = new Dictionary<string, int>
		{						
			{"Add 1 tab", 1},	
			{"Add 2 tabs", 2},
			{"Add 3 tabs", 3},			
			{"Remove 1 tab", -1},
			{"Remove 2 tabs", -2},
			{"Remove 3 tabs", -3},			
		};
		
		string selection = BFS.Dialog.GetUserInputList(
			"How much would you like to indent or unindent the text?",
			options.Keys.ToArray());
		
		if(string.IsNullOrEmpty(selection))
			return text;
		
		if(!options.TryGetValue(selection, out indentSize))
			return text;
		
        if (indentSize > 0)
            text = Regex.Replace(text, @"^", new string(indentChar, indentSize), RegexOptions.Multiline);
        else if (indentSize < 0)
            text = Regex.Replace(text, @"^" + new string(indentChar, Math.Abs(indentSize)), "", RegexOptions.Multiline);

        return text;
    }
}