using System;
using System.Collections.Generic;
// 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
// - Ignored by ClipboardFusion if it is 'null'
public static class ClipboardFusionHelper
{
public static string ProcessText(string text)
{
// Tell ClipboardFusion to ignore any changes to the Clipboard
BFS.ClipboardFusion.PauseClipboardListener();
// If the clipboard manager is open, reset the index and paste
// Otherwise, keep incrementing the index and pasting
IntPtr handle;
if( IsClipboardManagerOpen(out handle) )
{
// Get the selected Clipboard Manager index, and make sure that it's at least 0
int index = BFS.ClipboardFusion.GetClipboardManagerSelectedIndex();
if(index == -1)
index = 0;
// Save the value
BFS.ScriptSettings.WriteValueInt("ClipboardFusion_Script_IncrementIndex", index);
// Paste the selected index
BFS.Clipboard.PasteText( BFS.ClipboardFusion.GetHistoryText(index) );
// Close the ClipboardManager
BFS.Window.Close(handle);
}
else
{
// Get the saved index
int index = BFS.ScriptSettings.ReadValueInt("ClipboardFusion_Script_IncrementIndex");
// Increment the index
index++;
// Save the incremented index
BFS.ScriptSettings.WriteValueInt("ClipboardFusion_Script_IncrementIndex", index);
// Tell ClipboardFusion to ignore any changes to the Clipboard
BFS.ClipboardFusion.PauseClipboardListener();
// Paste the selected index
BFS.Clipboard.PasteText( BFS.ClipboardFusion.GetHistoryText(index) );
}
// Get ClipboardFusion to start watching the Clipboard again
BFS.ClipboardFusion.ResumeClipboardListener();
// Tell ClipboardFusion to not do anything with the result of this Macro
return null;
}
// This isn't the
private static bool IsClipboardManagerOpen(out IntPtr handle)
{
handle = IntPtr.Zero;
// Loop through all visible windows and look for a window with the right title that is run by the ClipboardFusion process
foreach(IntPtr window in BFS.Window.GetVisibleWindowHandles())
{
if(BFS.Window.GetText(window).IndexOf("ClipboardFusion", StringComparison.OrdinalIgnoreCase) != 0)
continue;
if(BFS.Application.GetMainFileByWindow(window).IndexOf("clipboardfusion.exe", StringComparison.OrdinalIgnoreCase) == -1)
continue;
// Set the handle to the window we found
handle = window;
return true;
}
// If we got this far, that means we didn't find anything
return false;
}
}