Skip to content

Instantly share code, notes, and snippets.

Created February 2, 2011 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/807795 to your computer and use it in GitHub Desktop.
Save anonymous/807795 to your computer and use it in GitHub Desktop.
rdnzl example done in clojure
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace AproposGUI
{
public class AproposControl : System.Windows.Forms.UserControl
{
public System.Windows.Forms.TextBox textBox;
public System.Windows.Forms.TextBox listBox;
private System.Windows.Forms.Label label;
public System.Windows.Forms.Label title;
private delegate string callback(string input);
private System.ComponentModel.Container components = null;
public AproposControl()
{
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.textBox = new System.Windows.Forms.TextBox();
this.listBox = new System.Windows.Forms.TextBox();
this.label = new System.Windows.Forms.Label();
this.title = new System.Windows.Forms.Label();
this.SuspendLayout();
this.textBox.Location = new System.Drawing.Point(16, 344);
this.textBox.Name = "textBox";
this.textBox.Size = new System.Drawing.Size(584, 20);
this.textBox.TabIndex = 0;
this.textBox.Text = "";
this.listBox.Location = new System.Drawing.Point(16, 56);
this.listBox.Multiline = true;
this.listBox.Name = "listBox";
this.listBox.ReadOnly = true;
this.listBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.listBox.Size = new System.Drawing.Size(584, 248);
this.listBox.TabIndex = 1;
this.listBox.Text = "";
this.label.Location = new System.Drawing.Point(24, 312);
this.label.Name = "label";
this.label.Size = new System.Drawing.Size(576, 23);
this.label.TabIndex = 2;
this.label.Text = "Enter text below and press RETURN";
this.label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.title.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.title.Location = new System.Drawing.Point(24, 16);
this.title.Name = "title";
this.title.Size = new System.Drawing.Size(568, 24);
this.title.TabIndex = 3;
this.title.Text = "Clojure-CLR Apropos Demo";
this.title.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Controls.Add(this.title);
this.Controls.Add(this.label);
this.Controls.Add(this.listBox);
this.Controls.Add(this.textBox);
this.Name = "MainControl";
this.Size = new System.Drawing.Size(616, 384);
this.ResumeLayout(false);
}
}
}
(System.Reflection.Assembly/LoadWithPartialName "System.Windows.Forms")
(System.Reflection.Assembly/LoadFile "c:\\Users\\singollo\\Desktop\\AproposGUI.dll")
(import '(System Type Array Exception MulticastDelegate)
'(System.Reflection PropertyInfo MethodInfo EventInfo)
'(System.Windows.Forms Application DockStyle Form MessageBox
KeyPressEventHandler TextBox)
'(AproposGUI AproposControl))
(defn- event-get [object event-name]
(let [event-name (if (symbol? event-name) (name event-name) event-name)
o-type (type object)]
(when o-type (.GetEvent o-type event-name))))
(def message-shown)
(defn- copy-to-clipboard [text-box]
(let [selection-start (.SelectionStart text-box)
selection-length (.SelectionLength text-box)
text-length (.Length (.Text text-box))]
(set! (.SelectionStart text-box) ' 0)
(set! (.SelectionLength text-box) text-length)
(.Copy text-box)
(set! (.SelectionStart text-box) selection-start)
(set! (.SelectionLength text-box) selection-length)))
(defn- fill-list-box [object event]
(when (= (.KeyChar event) \return)
(let [input-string (.Text object)
input-length (count input-string)]
(when (< 0 input-length)
(let [apropos-text (format "%s" (apropos input-string))
list-box (.listBox (.Parent object))]
(set! (.Text list-box) apropos-text)
(copy-to-clipboard list-box)
(when (not message-shown)
(MessageBox/Show
"The output of APROPOS has been copied to the clipboard."
"Clojure-CLR")
(set! message-shown true)))
(set! (.SelectionStart object) 0)
(set! (.SelectionLength object) input-length)))))
(defn- run-apropos-form []
(let [control (AproposControl.)
form (Form.)]
(binding [message-shown false]
(set! (.Dock control) DockStyle/Fill)
(set! (.ClientSize form) (.ClientSize control))
(set! (.Text form) "RDNZL Apropos Demo")
(set! (.Text (.title control)) "Clojure-CLR Apropos Demo")
(.add_KeyPress (.textBox control)
(clojure.lang.GenDelegate/Create KeyPressEventHandler
fill-list-box))
(.Add (.Controls form) control)
(Application/Run form))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment