using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using JJC.Psharp.Lang;
using System.Threading;
namespace PsharpGUI
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem14;
private System.Windows.Forms.MenuItem menuItem25;
private System.Windows.Forms.MenuItem menuItem30;
private System.Windows.Forms.MenuItem menuItem33;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.MenuItem menuItem41;
private System.Windows.Forms.MenuItem menuOpen;
private System.Windows.Forms.MenuItem menuClose;
private System.Windows.Forms.MenuItem menuSave;
private System.Windows.Forms.MenuItem menuSaveAs;
private System.Windows.Forms.MenuItem menuUndo;
private System.Windows.Forms.MenuItem menuRedo;
private System.Windows.Forms.MenuItem menuCut;
private System.Windows.Forms.MenuItem menuCopy;
private System.Windows.Forms.MenuItem menuPaste;
private System.Windows.Forms.MenuItem menuSelectAll;
private System.Windows.Forms.MenuItem menuCall;
private System.Windows.Forms.MenuItem menuRedoItem;
private System.Windows.Forms.MenuItem menuFinish;
private System.Windows.Forms.MenuItem menuReset;
private System.Windows.Forms.MenuItem menuResetIntrp;
private System.Windows.Forms.MenuItem menuResetOutput;
private System.Windows.Forms.MenuItem menuRunAsScript;
private System.Windows.Forms.MenuItem menuConsult;
private System.Windows.Forms.MenuItem menuCompile;
private System.Windows.Forms.MenuItem menuInternal;
private System.Windows.Forms.MenuItem menuEXE;
private System.Windows.Forms.MenuItem menuDebugOn;
private System.Windows.Forms.MenuItem menuDebugOff;
private System.Windows.Forms.MenuItem menuLast;
private System.Windows.Forms.MenuItem menuNext;
private System.Windows.Forms.MenuItem menuClear;
private System.Windows.Forms.Button buttonFinish;
private System.Windows.Forms.Button buttonRedo;
private System.Windows.Forms.TextBox textBoxQuery;
private System.Windows.Forms.MenuItem menuExit;
private System.Windows.Forms.MenuItem menuNew;
private System.Windows.Forms.MenuItem menuSaveAll;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.TabControl tabControl;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.RichTextBox richTextBox2;
private System.Windows.Forms.RichTextBox richTextBoxOutput;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
/* Extra variables */
private QueryReader qr;
private PushbackReader uin;
private System.IO.TextWriter uout;
private System.IO.TextWriter uerr;
private System.Windows.Forms.MenuItem menuDebugOnItem;
private System.Windows.Forms.MenuItem menuUnload;
static System.Threading.Thread t;
public Form1() {
//
// Required for Windows Form Designer support
//
InitializeComponent();
qr = new QueryReader( this.textBoxQuery );
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuNew = new System.Windows.Forms.MenuItem();
this.menuOpen = new System.Windows.Forms.MenuItem();
this.menuClose = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuSave = new System.Windows.Forms.MenuItem();
this.menuSaveAs = new System.Windows.Forms.MenuItem();
this.menuSaveAll = new System.Windows.Forms.MenuItem();
this.menuItem41 = new System.Windows.Forms.MenuItem();
this.menuExit = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuUndo = new System.Windows.Forms.MenuItem();
this.menuRedo = new System.Windows.Forms.MenuItem();
this.menuItem14 = new System.Windows.Forms.MenuItem();
this.menuCut = new System.Windows.Forms.MenuItem();
this.menuCopy = new System.Windows.Forms.MenuItem();
this.menuPaste = new System.Windows.Forms.MenuItem();
this.menuSelectAll = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuCall = new System.Windows.Forms.MenuItem();
this.menuRedoItem = new System.Windows.Forms.MenuItem();
this.menuFinish = new System.Windows.Forms.MenuItem();
this.menuItem25 = new System.Windows.Forms.MenuItem();
this.menuReset = new System.Windows.Forms.MenuItem();
this.menuResetIntrp = new System.Windows.Forms.MenuItem();
this.menuResetOutput = new System.Windows.Forms.MenuItem();
this.menuUnload = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuRunAsScript = new System.Windows.Forms.MenuItem();
this.menuItem30 = new System.Windows.Forms.MenuItem();
this.menuConsult = new System.Windows.Forms.MenuItem();
this.menuCompile = new System.Windows.Forms.MenuItem();
this.menuItem33 = new System.Windows.Forms.MenuItem();
this.menuInternal = new System.Windows.Forms.MenuItem();
this.menuEXE = new System.Windows.Forms.MenuItem();
this.menuDebugOn = new System.Windows.Forms.MenuItem();
this.menuDebugOnItem = new System.Windows.Forms.MenuItem();
this.menuDebugOff = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuLast = new System.Windows.Forms.MenuItem();
this.menuNext = new System.Windows.Forms.MenuItem();
this.menuClear = new System.Windows.Forms.MenuItem();
this.richTextBoxOutput = new System.Windows.Forms.RichTextBox();
this.splitter1 = new System.Windows.Forms.Splitter();
this.buttonFinish = new System.Windows.Forms.Button();
this.buttonRedo = new System.Windows.Forms.Button();
this.textBoxQuery = new System.Windows.Forms.TextBox();
this.panel1 = new System.Windows.Forms.Panel();
this.tabControl = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.richTextBox2 = new System.Windows.Forms.RichTextBox();
this.panel1.SuspendLayout();
this.tabControl.SuspendLayout();
this.tabPage1.SuspendLayout();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem3,
this.menuItem4,
this.menuItem5,
this.menuDebugOn,
this.menuItem7});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuNew,
this.menuOpen,
this.menuClose,
this.menuItem9,
this.menuSave,
this.menuSaveAs,
this.menuSaveAll,
this.menuItem41,
this.menuExit});
this.menuItem1.Text = "File";
//
// menuNew
//
this.menuNew.Index = 0;
this.menuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
this.menuNew.Text = "New";
this.menuNew.Click += new System.EventHandler(this.menuNew_Click);
//
// menuOpen
//
this.menuOpen.Index = 1;
this.menuOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
this.menuOpen.Text = "Open...";
this.menuOpen.Click += new System.EventHandler(this.menuOpen_Click);
//
// menuClose
//
this.menuClose.Index = 2;
this.menuClose.Shortcut = System.Windows.Forms.Shortcut.CtrlQ;
this.menuClose.Text = "Close";
this.menuClose.Click += new System.EventHandler(this.menuClose_Click);
//
// menuItem9
//
this.menuItem9.Index = 3;
this.menuItem9.Text = "-";
//
// menuSave
//
this.menuSave.Index = 4;
this.menuSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
this.menuSave.Text = "Save";
this.menuSave.Click += new System.EventHandler(this.menuSave_Click);
//
// menuSaveAs
//
this.menuSaveAs.Index = 5;
this.menuSaveAs.Text = "Save As...";
this.menuSaveAs.Click += new System.EventHandler(this.menuSaveAs_Click);
//
// menuSaveAll
//
this.menuSaveAll.Index = 6;
this.menuSaveAll.Text = "Save All";
this.menuSaveAll.Click += new System.EventHandler(this.menuSaveAll_Click);
//
// menuItem41
//
this.menuItem41.Index = 7;
this.menuItem41.Text = "-";
//
// menuExit
//
this.menuExit.Index = 8;
this.menuExit.Shortcut = System.Windows.Forms.Shortcut.CtrlShiftX;
this.menuExit.Text = "Exit";
this.menuExit.Click += new System.EventHandler(this.menuExit_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuUndo,
this.menuRedo,
this.menuItem14,
this.menuCut,
this.menuCopy,
this.menuPaste,
this.menuSelectAll});
this.menuItem3.Text = "Edit";
//
// menuUndo
//
this.menuUndo.Index = 0;
this.menuUndo.Shortcut = System.Windows.Forms.Shortcut.CtrlZ;
this.menuUndo.Text = "Undo";
this.menuUndo.Click += new System.EventHandler(this.menuUndo_Click);
//
// menuRedo
//
this.menuRedo.Index = 1;
this.menuRedo.Shortcut = System.Windows.Forms.Shortcut.CtrlY;
this.menuRedo.Text = "Redo";
this.menuRedo.Click += new System.EventHandler(this.menuRedo_Click);
//
// menuItem14
//
this.menuItem14.Index = 2;
this.menuItem14.Text = "-";
//
// menuCut
//
this.menuCut.Index = 3;
this.menuCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
this.menuCut.Text = "Cut";
this.menuCut.Click += new System.EventHandler(this.menuCut_Click);
//
// menuCopy
//
this.menuCopy.Index = 4;
this.menuCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
this.menuCopy.Text = "Copy";
this.menuCopy.Click += new System.EventHandler(this.menuCopy_Click);
//
// menuPaste
//
this.menuPaste.Index = 5;
this.menuPaste.Shortcut = System.Windows.Forms.Shortcut.CtrlV;
this.menuPaste.Text = "Paste";
this.menuPaste.Click += new System.EventHandler(this.menuPaste_Click);
//
// menuSelectAll
//
this.menuSelectAll.Index = 6;
this.menuSelectAll.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.menuSelectAll.Text = "Select All";
this.menuSelectAll.Click += new System.EventHandler(this.menuSelectAll_Click);
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuCall,
this.menuRedoItem,
this.menuFinish,
this.menuItem25,
this.menuReset,
this.menuResetIntrp,
this.menuResetOutput,
this.menuUnload});
this.menuItem4.Text = "Query";
//
// menuCall
//
this.menuCall.Index = 0;
this.menuCall.Text = "Call";
this.menuCall.Click += new System.EventHandler(this.menuCall_Click);
//
// menuRedoItem
//
this.menuRedoItem.Index = 1;
this.menuRedoItem.Text = "Redo";
this.menuRedoItem.Click += new System.EventHandler(this.menuRedoItem_Click);
//
// menuFinish
//
this.menuFinish.Index = 2;
this.menuFinish.Text = "Finish";
this.menuFinish.Click += new System.EventHandler(this.menuFinish_Click);
//
// menuItem25
//
this.menuItem25.Index = 3;
this.menuItem25.Text = "-";
//
// menuReset
//
this.menuReset.Index = 4;
this.menuReset.Shortcut = System.Windows.Forms.Shortcut.F4;
this.menuReset.Text = "Reset";
this.menuReset.Click += new System.EventHandler(this.menuReset_Click);
//
// menuResetIntrp
//
this.menuResetIntrp.Index = 5;
this.menuResetIntrp.Text = "Reset Interpreter";
this.menuResetIntrp.Click += new System.EventHandler(this.menuResetIntrp_Click);
//
// menuResetOutput
//
this.menuResetOutput.Index = 6;
this.menuResetOutput.Text = "Reset Output";
this.menuResetOutput.Click += new System.EventHandler(this.menuResetOutput_Click);
//
// menuUnload
//
this.menuUnload.Index = 7;
this.menuUnload.Text = "Unload Assemblies";
this.menuUnload.Click += new System.EventHandler(this.menuUnload_Click);
//
// menuItem5
//
this.menuItem5.Index = 3;
this.menuItem5.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuRunAsScript,
this.menuItem30,
this.menuConsult,
this.menuCompile,
this.menuItem33,
this.menuInternal,
this.menuEXE});
this.menuItem5.Text = "Editor";
//
// menuRunAsScript
//
this.menuRunAsScript.Index = 0;
this.menuRunAsScript.Shortcut = System.Windows.Forms.Shortcut.CtrlShiftS;
this.menuRunAsScript.Text = "Run as Script";
this.menuRunAsScript.Click += new System.EventHandler(this.menuRunAsScript_Click);
//
// menuItem30
//
this.menuItem30.Index = 1;
this.menuItem30.Text = "-";
//
// menuConsult
//
this.menuConsult.Index = 2;
this.menuConsult.Shortcut = System.Windows.Forms.Shortcut.CtrlShiftJ;
this.menuConsult.Text = "Consult";
this.menuConsult.Click += new System.EventHandler(this.menuConsult_Click);
//
// menuCompile
//
this.menuCompile.Index = 3;
this.menuCompile.Shortcut = System.Windows.Forms.Shortcut.CtrlShiftC;
this.menuCompile.Text = "Compile to C#";
this.menuCompile.Click += new System.EventHandler(this.menuCompile_Click);
//
// menuItem33
//
this.menuItem33.Index = 4;
this.menuItem33.Text = "-";
//
// menuInternal
//
this.menuInternal.Index = 5;
this.menuInternal.Shortcut = System.Windows.Forms.Shortcut.CtrlShiftI;
this.menuInternal.Text = "Internal Compile";
this.menuInternal.Click += new System.EventHandler(this.menuInternal_Click);
//
// menuEXE
//
this.menuEXE.Index = 6;
this.menuEXE.Shortcut = System.Windows.Forms.Shortcut.CtrlShiftE;
this.menuEXE.Text = "Compile to EXE";
this.menuEXE.Click += new System.EventHandler(this.menuEXE_Click);
//
// menuDebugOn
//
this.menuDebugOn.Index = 4;
this.menuDebugOn.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuDebugOnItem,
this.menuDebugOff});
this.menuDebugOn.Text = "Debug";
//
// menuDebugOnItem
//
this.menuDebugOnItem.Index = 0;
this.menuDebugOnItem.Text = "Debug on";
this.menuDebugOnItem.Click += new System.EventHandler(this.menuDebugOnItem_Click);
//
// menuDebugOff
//
this.menuDebugOff.Index = 1;
this.menuDebugOff.Text = "Debug off";
this.menuDebugOff.Click += new System.EventHandler(this.menuDebugOff_Click);
//
// menuItem7
//
this.menuItem7.Index = 5;
this.menuItem7.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuLast,
this.menuNext,
this.menuClear});
this.menuItem7.Text = "History";
//
// menuLast
//
this.menuLast.Index = 0;
this.menuLast.Text = "Last";
this.menuLast.Click += new System.EventHandler(this.menuLast_Click);
//
// menuNext
//
this.menuNext.Index = 1;
this.menuNext.Text = "Next";
this.menuNext.Click += new System.EventHandler(this.menuNext_Click);
//
// menuClear
//
this.menuClear.Index = 2;
this.menuClear.Text = "Clear History";
this.menuClear.Click += new System.EventHandler(this.menuClear_Click);
//
// richTextBoxOutput
//
this.richTextBoxOutput.BackColor = System.Drawing.SystemColors.Info;
this.richTextBoxOutput.Dock = System.Windows.Forms.DockStyle.Top;
this.richTextBoxOutput.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.richTextBoxOutput.Name = "richTextBoxOutput";
this.richTextBoxOutput.Size = new System.Drawing.Size(592, 160);
this.richTextBoxOutput.TabIndex = 0;
this.richTextBoxOutput.Text = "";
//
// splitter1
//
this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
this.splitter1.Location = new System.Drawing.Point(0, 160);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(592, 3);
this.splitter1.TabIndex = 1;
this.splitter1.TabStop = false;
//
// buttonFinish
//
this.buttonFinish.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.buttonFinish.Location = new System.Drawing.Point(528, 8);
this.buttonFinish.Name = "buttonFinish";
this.buttonFinish.Size = new System.Drawing.Size(56, 24);
this.buttonFinish.TabIndex = 2;
this.buttonFinish.Text = "Finish";
this.buttonFinish.Click += new System.EventHandler(this.buttonFinish_Click_1);
//
// buttonRedo
//
this.buttonRedo.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.buttonRedo.Location = new System.Drawing.Point(464, 8);
this.buttonRedo.Name = "buttonRedo";
this.buttonRedo.Size = new System.Drawing.Size(56, 23);
this.buttonRedo.TabIndex = 3;
this.buttonRedo.Text = "Redo";
this.buttonRedo.Click += new System.EventHandler(this.buttonRedo_Click_1);
//
// textBoxQuery
//
this.textBoxQuery.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.textBoxQuery.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.textBoxQuery.ForeColor = System.Drawing.Color.Red;
this.textBoxQuery.Location = new System.Drawing.Point(8, 8);
this.textBoxQuery.Name = "textBoxQuery";
this.textBoxQuery.Size = new System.Drawing.Size(440, 22);
this.textBoxQuery.TabIndex = 4;
this.textBoxQuery.Text = "";
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.ControlDark;
this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabControl,
this.buttonFinish,
this.buttonRedo,
this.textBoxQuery});
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 163);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(592, 179);
this.panel1.TabIndex = 5;
//
// tabControl
//
this.tabControl.Alignment = System.Windows.Forms.TabAlignment.Bottom;
this.tabControl.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.tabControl.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabPage1});
this.tabControl.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.tabControl.Location = new System.Drawing.Point(0, 40);
this.tabControl.Name = "tabControl";
this.tabControl.SelectedIndex = 0;
this.tabControl.Size = new System.Drawing.Size(600, 141);
this.tabControl.TabIndex = 5;
//
// tabPage1
//
this.tabPage1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.richTextBox2});
this.tabPage1.Location = new System.Drawing.Point(4, 4);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(592, 112);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "CodeFile1.pl";
//
// richTextBox2
//
this.richTextBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBox2.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.richTextBox2.Name = "richTextBox2";
this.richTextBox2.Size = new System.Drawing.Size(592, 112);
this.richTextBox2.TabIndex = 0;
this.richTextBox2.Text = "";
this.richTextBox2.TextChanged += new System.EventHandler(this.richTextBox2_TextChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(592, 342);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel1,
this.splitter1,
this.richTextBoxOutput});
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "P# Console";
this.Load += new System.EventHandler(this.Form1_Load);
this.panel1.ResumeLayout(false);
this.tabControl.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main() {
Form1 pf = new Form1( );
t = new Thread( new ThreadStart( pf.StartPsharp ) );
t.IsBackground = true;
t.Start( );
System.Threading.Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
Application.Run( pf );
}
private void StartPsharp( ) {
uin = new PushbackReader( qr );
uout = new richTextBoxOutputWriter( this.richTextBoxOutput, this.textBoxQuery );
uerr = new richTextBoxOutputWriter( this.richTextBoxOutput, this.textBoxQuery );
while( true ) {
try {
uout.WriteLine( );
PrologMainGUI.Start( uin, uout, uerr );
} catch( ThreadAbortException ) {
} catch( Exception e ) {
uout.WriteLine( "\nSession Terminated by Exception" );
uout.WriteLine( e.Message );
}
}
}
private void richTextBoxOutput_KeyPress( object sender, KeyPressEventArgs args ) {
textBoxQuery.Focus( );
textBoxQuery.AppendText( args.KeyChar.ToString( ) );
}
private void AppendRed( string msg ) {
int old = richTextBoxOutput.Text.Length;
richTextBoxOutput.AppendText( msg );
int newPos = richTextBoxOutput.Text.Length;
richTextBoxOutput.Select( old, msg.Length - 2 );
richTextBoxOutput.SelectionColor = Color.Red;
}
private ArrayList history = new ArrayList( );
private int historyPtr = 0;
private void doCall( ) {
string msg = textBoxQuery.Text;
if( !msg.Equals( "" ) )
if( msg[ msg.Length - 1 ] != '.' && !msg.Equals( ";" ) )
msg += ".";
if( !msg.Equals( "" ) && !msg.Equals( ";" ) ) {
history.Add( msg );
historyPtr = history.Count;
}
msg += "\r\n";
AppendRed( msg );
qr.Write( msg );
textBoxQuery.Text = "";
}
private void textBoxQuery_KeyPress( object sender, KeyPressEventArgs e ) {
KeyPressEventArgs kpea = (KeyPressEventArgs)e;
char c = kpea.KeyChar;
if( c == (char)13 ) {
doCall( );
}
}
/* Menu Items for Interpretation and Compilation.
*/
private string GenerateTempFilename( ) {
// improve on this sometime
return "temp";
}
private void DeleteTempFile( string temp ) {
}
private RichTextBox GetCurrentEditor( ) {
return this.getSelectedPage( );
/*
int i = Tabs.SelectedIndex;
switch( i ) {
default: return null; // Editor1;
case 0: return Editor1;
case 1: return Editor2;
case 2: return Editor3;
case 3: return Editor4;
}
*/
}
private void SaveCurrentEditor( string temp ) {
GetCurrentEditor( ).SaveFile(
".\\" + temp + ".pl",
RichTextBoxStreamType.PlainText );
// save the currently selected editor as .pl
}
/* Files
*/
private void menuItem4_Click(object sender, System.EventArgs e) {
// load file.
OpenFileDialog ofd = new OpenFileDialog( );
ofd.DefaultExt = ".pl";
ofd.RestoreDirectory = false;
if(ofd.ShowDialog() == DialogResult.OK) {
this.GetCurrentEditor( ).LoadFile(
ofd.FileName,
RichTextBoxStreamType.PlainText );
}
}
private void menuItem5_Click(object sender, System.EventArgs e) {
// save file
SaveFileDialog sfd = new SaveFileDialog( );
sfd.DefaultExt = ".pl";
sfd.RestoreDirectory = false;
if(sfd.ShowDialog() == DialogResult.OK) {
this.GetCurrentEditor( ).SaveFile(
sfd.FileName,
RichTextBoxStreamType.PlainText );
}
}
private void menuItem3_Click(object sender, System.EventArgs e) {
// include file.
OpenFileDialog ofd = new OpenFileDialog( );
ofd.DefaultExt = ".pl";
ofd.RestoreDirectory = false;
if(ofd.ShowDialog() == DialogResult.OK) {
RichTextBox rtb = new RichTextBox( );
rtb.LoadFile(
ofd.FileName,
RichTextBoxStreamType.PlainText );
RichTextBox ce = this.GetCurrentEditor( );
ce.AppendText( rtb.Text );
}
}
/* History
*/
private void HistoryLast( ) {
if( history.Count != 0 ) {
if( historyPtr != 0 )
historyPtr--;
textBoxQuery.Text = (string)history[ historyPtr ];
}
// silly hack: desired side-effect is that caret moves to end of line.
textBoxQuery.AppendText( "" );
}
private void HistoryNext( ) {
if( history.Count != 0 ) {
if( historyPtr < history.Count - 1 )
historyPtr++;
else
historyPtr = history.Count - 1;
textBoxQuery.Text = (string)history[ historyPtr ];
}
// silly hack: desired side-effect is that caret moves to end of line.
textBoxQuery.AppendText( "" );
}
private void textBoxQuery_KeyDown( object sender, KeyEventArgs e ) {
switch( e.KeyCode.ToString( ) ) {
case "Up":
HistoryLast( );
e.Handled = true;
break;
case "Down":
HistoryNext( );
e.Handled = true;
break;
}
}
private void richTextBoxOutput_TextChanged(object sender, System.EventArgs e) {
}
int nextCodeFile = 2;
Hashtable fullFilenames = new Hashtable( );
Hashtable textChanged = new Hashtable( );
private void menuNew_Click(object sender, System.EventArgs e) {
RichTextBox newrtb = new RichTextBox( );
newrtb.Dock = System.Windows.Forms.DockStyle.Fill;
newrtb.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
//newrtb.Size = new System.Drawing.Size(592, 112);
newrtb.Text = "";
TabPage newtp = new TabPage( "CodeFile" + nextCodeFile + ".pl" );
nextCodeFile++;
tabControl.TabPages.Add( newtp );
newtp.Controls.AddRange( new Control[] { newrtb } );
newtp.TextChanged += new System.EventHandler(this.richTextBox2_TextChanged);
}
private string BaseName( string fullFilename ) {
System.IO.FileInfo f = new System.IO.FileInfo( fullFilename );
return f.Name;
}
private void menuOpen_Click(object sender, System.EventArgs e) {
OpenFileDialog ofd = new OpenFileDialog( );
ofd.DefaultExt = ".pl";
ofd.RestoreDirectory = false;
if(ofd.ShowDialog() == DialogResult.OK) {
RichTextBox newrtb = new RichTextBox( );
newrtb.Dock = System.Windows.Forms.DockStyle.Fill;
newrtb.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
newrtb.LoadFile(
ofd.FileName,
RichTextBoxStreamType.PlainText );
TabPage newtp = new TabPage( BaseName( ofd.FileName ) );
tabControl.TabPages.Add( newtp );
newtp.Controls.AddRange( new Control[] { newrtb } );
this.fullFilenames[ newrtb ] = ofd.FileName;
this.textChanged[ newrtb ] = false;
newrtb.TextChanged += new System.EventHandler(this.richTextBox2_TextChanged);
tabControl.SelectedTab = newtp;
}
}
private RichTextBox getSelectedPage( ) {
int i = tabControl.SelectedIndex;
if( i != -1 )
return (RichTextBox)( tabControl.TabPages[ i ].Controls[ 0 ] );
else
return null;
}
private void menuClose_Click(object sender, System.EventArgs e) {
int i = tabControl.SelectedIndex;
if( i != -1 ) {
RichTextBox toClose = (RichTextBox)( tabControl.TabPages[ i ].Controls[ 0 ] );
if( (bool)textChanged[ toClose ] ) {
DialogResult dr = MessageBox.Show(
"Do you wish to save the file " + tabControl.TabPages[ i ].Text + " ?",
"Question", MessageBoxButtons.YesNoCancel );
switch( dr ) {
case DialogResult.Yes:
toClose.SaveFile( (string)( this.fullFilenames[ toClose ] ), RichTextBoxStreamType.PlainText );
textChanged[ toClose ] = false;
break;
case DialogResult.No:
break;
case DialogResult.Cancel:
return;
}
}
tabControl.TabPages.RemoveAt( i );
}
}
private void menuSave_Click(object sender, System.EventArgs e) {
RichTextBox toSave = this.getSelectedPage( );
toSave.SaveFile( (string)( this.fullFilenames[ toSave ] ), RichTextBoxStreamType.PlainText );
textChanged[ toSave ] = false;
}
private void menuSaveAs_Click(object sender, System.EventArgs e) {
if( tabControl.SelectedIndex != - 1 ) {
SaveFileDialog sfd = new SaveFileDialog( );
sfd.DefaultExt = ".pl";
sfd.RestoreDirectory = false;
if(sfd.ShowDialog() == DialogResult.OK) {
RichTextBox toSave = this.getSelectedPage( );
toSave.SaveFile( sfd.FileName, RichTextBoxStreamType.PlainText );
this.fullFilenames[ toSave ] = sfd.FileName;
tabControl.TabPages[ tabControl.SelectedIndex ].Text = BaseName( sfd.FileName );
textChanged[ toSave ] = false;
}
}
}
private void menuSaveAll_Click(object sender, System.EventArgs e) {
foreach( TabPage tp in tabControl.TabPages ) {
RichTextBox toSave = (RichTextBox)( tp.Controls[ 0 ] );
toSave.SaveFile(
(string)( this.fullFilenames[ toSave ] ),
RichTextBoxStreamType.PlainText );
textChanged[ toSave ] = false;
}
}
private void menuExit_Click(object sender, System.EventArgs e) {
foreach( TabPage tp in tabControl.TabPages ) {
RichTextBox toClose = (RichTextBox)( tp.Controls[ 0 ] );
if( (bool)textChanged[ toClose ] ) {
DialogResult dr = MessageBox.Show(
"Do you wish to save the file " + tp.Text + " ?",
"Question", MessageBoxButtons.YesNoCancel );
switch( dr ) {
case DialogResult.Yes:
toClose.SaveFile( (string)( this.fullFilenames[ toClose ] ), RichTextBoxStreamType.PlainText );
textChanged[ toClose ] = false;
break;
case DialogResult.No:
break;
case DialogResult.Cancel:
return;
}
}
}
Application.Exit( );
}
private void menuUndo_Click(object sender, System.EventArgs e) {
Control ac = this.ActiveControl;
if( ac is System.Windows.Forms.TextBoxBase ) {
TextBoxBase tbb = (TextBoxBase)ac;
if( tbb.CanUndo )
tbb.Undo( );
}
}
private void menuRedo_Click(object sender, System.EventArgs e) {
Control ac = this.ActiveControl;
if( ac is System.Windows.Forms.RichTextBox ) {
RichTextBox rtb = (RichTextBox)ac;
if( rtb.CanRedo )
rtb.Redo( );
}
}
private void menuCut_Click(object sender, System.EventArgs e) {
Control ac = this.ActiveControl;
if( ac is System.Windows.Forms.TextBoxBase ) {
TextBoxBase tbb = (TextBoxBase)ac;
tbb.Cut( );
}
}
private void menuCopy_Click(object sender, System.EventArgs e) {
Control ac = this.ActiveControl;
if( ac is System.Windows.Forms.TextBoxBase ) {
TextBoxBase tbb = (TextBoxBase)ac;
tbb.Copy( );
}
}
private void menuPaste_Click(object sender, System.EventArgs e) {
Control ac = this.ActiveControl;
if( ac is System.Windows.Forms.TextBoxBase ) {
TextBoxBase tbb = (TextBoxBase)ac;
tbb.Paste( );
}
}
private void menuSelectAll_Click(object sender, System.EventArgs e) {
Control ac = this.ActiveControl;
if( ac is System.Windows.Forms.TextBoxBase ) {
TextBoxBase tbb = (TextBoxBase)ac;
tbb.SelectAll( );
}
}
private void menuFind_Click(object sender, System.EventArgs e) {
}
private void menuReplace_Click(object sender, System.EventArgs e) {
}
private void menuCall_Click(object sender, System.EventArgs e) {
doCall( );
}
private void menuRedoItem_Click(object sender, System.EventArgs e) {
buttonRedo_Click( null, null );
}
private void menuFinish_Click(object sender, System.EventArgs e) {
buttonFinish_Click( null, null );
}
private void menuReset_Click(object sender, System.EventArgs e) {
richTextBoxOutput.Text = "";
t.Abort( );
t = new Thread( new ThreadStart( this.StartPsharp ) );
t.IsBackground = true;
t.Start( );
}
private void menuResetIntrp_Click(object sender, System.EventArgs e) {
qr.WriteLine( "halt." );
}
private void menuResetOutput_Click(object sender, System.EventArgs e) {
this.richTextBoxOutput.Text = "";
}
private void menuUnload_Click/*unload*/ (object sender, System.EventArgs e) {
AssemblyList.Clear( );
}
private void menuRunAsScript_Click(object sender, System.EventArgs e) {
string queries = GetCurrentEditor( ).Text;
qr.WriteLine( queries );
}
private void menuConsult_Click(object sender, System.EventArgs e) {
string temp = GenerateTempFilename( ); // excludes the .pl suffix
try {
SaveCurrentEditor( temp );
AppendRed( "< consult editor contents >\r\n" );
qr.WriteLine( "[ '" + temp + "' ]." );
} finally {
DeleteTempFile( temp );
}
}
private void menuCompile_Click(object sender, System.EventArgs e) {
string temp = GenerateTempFilename( ); // excludes the .pl suffix
try {
SaveCurrentEditor( temp );
AppendRed( "< compile editor contents to C# >\r\n" );
qr.WriteLine( "compile( '" + temp + "' )." );
} finally {
DeleteTempFile( temp );
}
}
private void menuInternal_Click(object sender, System.EventArgs e) {
string temp = GenerateTempFilename( ); // excludes the .pl suffix
try {
SaveCurrentEditor( temp );
AppendRed( "< internal compile editor contents >\r\n" );
qr.WriteLine( "plcomp( '" + temp + "' )." );
} finally {
DeleteTempFile( temp );
}
}
private void menuEXE_Click(object sender, System.EventArgs e) {
string temp = GenerateTempFilename( ); // excludes the .pl suffix
SaveFileDialog sfd = new SaveFileDialog( );
sfd.DefaultExt = ".exe";
string exeName = "";
if(sfd.ShowDialog() == DialogResult.OK)
exeName = sfd.FileName;
else
return;
try {
SaveCurrentEditor( temp );
AppendRed( "< compile editor contents to EXE file : " + exeName + " >\r\n" );
qr.WriteLine( "plcomp( '" + temp + "', ' " + exeName + " ' )." );
} finally {
DeleteTempFile( temp );
}
}
private void menuDebugOff_Click(object sender, System.EventArgs e) {
qr.WriteLine( "nodebug." );
}
private void menuLast_Click(object sender, System.EventArgs e) {
HistoryLast( );
}
private void menuNext_Click(object sender, System.EventArgs e) {
HistoryNext( );
}
private void menuClear_Click(object sender, System.EventArgs e) {
historyPtr = 0;
history.Clear( );
}
private void menuDebugOnItem_Click(object sender, System.EventArgs e) {
qr.WriteLine( "trace." );
}
private void buttonRedo_Click(object sender, System.EventArgs e) {
qr.WriteLine( ";" );
}
private void buttonFinish_Click(object sender, System.EventArgs e) {
qr.WriteLine( "" );
}
private void Form1_Load(object sender, System.EventArgs e) {
textBoxQuery.KeyPress += new KeyPressEventHandler( this.textBoxQuery_KeyPress );
textBoxQuery.KeyDown += new KeyEventHandler( this.textBoxQuery_KeyDown );
richTextBoxOutput.KeyPress += new KeyPressEventHandler( this.richTextBoxOutput_KeyPress );
}
private void richTextBox2_TextChanged(object sender, System.EventArgs e) {
this.textChanged[ sender ] = true;
}
private void buttonRedo_Click_1(object sender, System.EventArgs e) {
buttonRedo_Click( sender, e );
}
private void buttonFinish_Click_1(object sender, System.EventArgs e) {
buttonFinish_Click( sender, e );
}
}
class richTextBoxOutputWriter : System.IO.StringWriter {
RichTextBox richTextBoxOutput;
TextBox textBoxQuery;
public richTextBoxOutputWriter( RichTextBox richTextBoxOutput,
TextBox textBoxQuery ) {
this.richTextBoxOutput = richTextBoxOutput;
this.textBoxQuery = textBoxQuery;
this.buffer = "";
System.Timers.Timer t = new System.Timers.Timer( );
t.Elapsed += new System.Timers.ElapsedEventHandler( Flush_obj_args );
t.Interval = 1000;
}
public void Flush_obj_args( object o, System.Timers.ElapsedEventArgs a ) {
Flush( );
}
public void AsynchDoWrite( string s ) {
richTextBoxOutput.AppendText( s );
}
public void AsynchFlush( ) {
richTextBoxOutput.Focus( );
richTextBoxOutput.ScrollToCaret( );
textBoxQuery.Focus( );
}
public override void Flush( ) {
while( !richTextBoxOutput.Created )
;
lock( this ) {
System.IAsyncResult iar;
iar =
richTextBoxOutput.BeginInvoke(
new StringToVoid( this.AsynchDoWrite ),
new Object[] { buffer } );
richTextBoxOutput.EndInvoke( iar );
buffer = "";
iar =
richTextBoxOutput.BeginInvoke(
new VoidToVoid( this.AsynchFlush ),
new Object[] { } );
richTextBoxOutput.EndInvoke( iar );
}
}
delegate void StringToVoid( string s );
delegate void VoidToVoid( );
string buffer;
public override void Write( string s ) {
lock( this ) {
buffer += s;
}
}
public override void WriteLine( ) {
lock( this )
buffer += "\r\n";
Flush( );
}
public override void Write( char s ) {
Write( s.ToString( ) );
}
public override void WriteLine( char s ) {
Write( s );
WriteLine( );
}
public override void WriteLine( string s ) {
Write( s );
WriteLine( );
}
}
public class QueryReader : System.IO.TextReader {
System.Windows.Forms.TextBox textBoxQuery;
public QueryReader( System.Windows.Forms.TextBox textBoxQuery ) {
this.textBoxQuery = textBoxQuery;
}
System.Text.StringBuilder buffer = new System.Text.StringBuilder( "" );
public void Write( string s ) {
lock( this ) {
buffer.Append( s );
if( buffer.Length != 0 )
System.Threading.Monitor.Pulse( this );
}
}
public void WriteLine( string s ) {
Write( s + "\r\n" );
}
public override int Read( ) {
lock( this ) {
while( buffer.Length == 0 )
System.Threading.Monitor.Wait( this );
int ret = (int)buffer[ 0 ];
buffer.Remove( 0, 1 );
return ret;
}
}
}
}