using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.AutoCAD.DatabaseServices;
namespace Autodesk.AutoCAD.Runtime
{
public static class VLClipboardHelper
{
/// <summary>
/// Returns the text contents of the
/// clipboard if it contains text, or
/// nil otherwise.
///
/// Usage: (clipboard-get-text)
///
/// </summary>
[LispFunction( "CLIPBOARD-GET-TEXT" )]
public static string VLCBGetText( ResultBuffer unused )
{
if( Clipboard.ContainsText() )
return Clipboard.GetText();
else
return null;
}
/// <summary>
/// Returns non-nil if the clipboard
/// contains text, or nil otherwise.
///
/// Usage: (clipboard-contains-text)
///
/// </summary>
[LispFunction( "CLIPBOARD-CONTAINS-TEXT" )]
public static bool VLCBHasText( ResultBuffer unused )
{
return Clipboard.ContainsText();
}
/// <summary>
/// Clears the clipboard of all contents.
///
/// Usage: (clipboard-clear)
///
/// </summary>
[LispFunction( "CLIPBOARD-CLEAR" )]
public static void ClipboardClear( ResultBuffer unused )
{
Clipboard.Clear();
}
/// <summary>
/// Places the given text on the clipboard.
///
/// Usage: (clipboard-set-text <string>...)
///
/// If multiple strings are provided, all but the
/// first argument are concatenated into a single
/// string using the first argument as a delimiter.
///
/// Hence:
///
/// (clipboard-set-text "," "Moe" "Larry" "Curly")
///
/// sets the clipboard text to "Moe,Larry,Curly"
///
/// </summary>
[LispFunction( "CLIPBOARD-SET-TEXT" )]
public static void VLCBSetText( ResultBuffer rb )
{
const int RTSTR = (int) LispDataType.Text;
const string errmsg = "Requires one or more strings";
if( rb == null )
throw new ArgumentException
( errmsg
); TypedValue[] items = rb.AsArray();
if( items.Length == 0 )
throw new ArgumentException
( errmsg
); TypedValue first = items[0];
if( first.TypeCode != RTSTR )
throw new ArgumentException
( errmsg
); string text = (string) first.Value;
if( items.Length > 1 )
{
if( !items.All( tv => tv.TypeCode == RTSTR ) )
throw new ArgumentException
( errmsg
); var rest = items.Skip( 1 ).Select( tv => (string) tv.Value );
text = string.Join( text, rest );
}
Clipboard.SetText( text );
}
}
}