summaryrefslogtreecommitdiff
path: root/MainForm.cs
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-01-21 01:13:58 +0000
committerIan C <ianc@noddybox.co.uk>2005-01-21 01:13:58 +0000
commitf0a9af7158f2faf6359beef5602451b6a042a539 (patch)
treef9c0b00d2067777d9c7d8548f0d7b00a76a85e6d /MainForm.cs
parent88256e4aed5262e7c50f351264d5f163ffe8e7ef (diff)
Initial checkin
Diffstat (limited to 'MainForm.cs')
-rw-r--r--MainForm.cs304
1 files changed, 304 insertions, 0 deletions
diff --git a/MainForm.cs b/MainForm.cs
new file mode 100644
index 0000000..d062e91
--- /dev/null
+++ b/MainForm.cs
@@ -0,0 +1,304 @@
+// SIDFX
+// Copyright (C) 2004 Ian Cowburn
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// $Id$
+//
+using System;
+using System.Windows.Forms;
+using System.IO;
+using System.Text;
+using System.CodeDom.Compiler;
+using Noddybox.GUI;
+using HardsidInterface;
+
+namespace SIDFX
+{
+ /// <summary>
+ /// Description of MainForm.
+ /// </summary>
+ public class MainForm : System.Windows.Forms.Form
+ {
+ private System.Windows.Forms.RichTextBox m_edit;
+ private System.Windows.Forms.Button m_runButton;
+ private System.Windows.Forms.CheckBox m_showDebug;
+
+ private MainMenu m_mainMenu;
+ private MenuTree m_menu;
+ private string m_path;
+ private bool m_changed;
+ private DebugForm m_debug;
+
+ public MainForm()
+ {
+ //
+ // The InitializeComponent() call is required for Windows Forms designer support.
+ //
+ InitializeComponent();
+
+ m_debug=new DebugForm();
+
+ m_mainMenu=new MainMenu();
+ m_menu=new MenuTree(m_mainMenu);
+
+ m_menu.Add("/file", "File");
+ m_menu.Add("/file/new", "New", new EventHandler(OnNew));
+ m_menu.Add("/file/open", "Open...", new EventHandler(OnOpen));
+ m_menu.Add("/file/save", "Save", new EventHandler(OnSave));
+ m_menu.Add("/file/saveas", "Save as...", new EventHandler(OnSaveAs));
+ m_menu.Add("/file/quit", "Quit", new EventHandler(OnQuit));
+
+ m_menu.Add("/sid","SID");
+ m_menu.Add("/sid/run","Run Script", new EventHandler(OnRun));
+
+ m_menu.Add("/help","Help");
+ m_menu.Add("/help/about","About...", new EventHandler(OnAbout));
+
+ m_menu.Get("/file/save").Enabled=false;
+
+ m_path="";
+ m_changed=false;
+
+ Menu=m_mainMenu;
+
+ //Hardsid.Init();
+ Hardsid.DLLDebug(1);
+ }
+
+ [STAThread]
+ public static void Main(string[] args)
+ {
+ Application.Run(new MainForm());
+ }
+
+ #region Windows Forms Designer generated code
+ /// <summary>
+ /// This method is required for Windows Forms designer support.
+ /// Do not change the method contents inside the source code editor. The Forms designer might
+ /// not be able to load this method if it was changed manually.
+ /// </summary>
+ private void InitializeComponent() {
+ this.m_showDebug = new System.Windows.Forms.CheckBox();
+ this.m_runButton = new System.Windows.Forms.Button();
+ this.m_edit = new System.Windows.Forms.RichTextBox();
+ this.SuspendLayout();
+ //
+ // m_showDebug
+ //
+ this.m_showDebug.Location = new System.Drawing.Point(8, 368);
+ this.m_showDebug.Name = "m_showDebug";
+ this.m_showDebug.Size = new System.Drawing.Size(184, 16);
+ this.m_showDebug.TabIndex = 2;
+ this.m_showDebug.Text = "Show SID Register Window";
+ this.m_showDebug.CheckedChanged += new System.EventHandler(this.OnShowDebug);
+ //
+ // m_runButton
+ //
+ this.m_runButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.m_runButton.Location = new System.Drawing.Point(512, 368);
+ this.m_runButton.Name = "m_runButton";
+ this.m_runButton.Size = new System.Drawing.Size(80, 24);
+ this.m_runButton.TabIndex = 1;
+ this.m_runButton.Text = "Run";
+ this.m_runButton.Click += new System.EventHandler(this.OnRun);
+ //
+ // m_edit
+ //
+ this.m_edit.AcceptsTab = true;
+ this.m_edit.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.m_edit.DetectUrls = false;
+ this.m_edit.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
+ this.m_edit.Location = new System.Drawing.Point(8, 0);
+ this.m_edit.Name = "m_edit";
+ this.m_edit.Size = new System.Drawing.Size(584, 360);
+ this.m_edit.TabIndex = 0;
+ this.m_edit.Text = "";
+ this.m_edit.WordWrap = false;
+ this.m_edit.TextChanged += new System.EventHandler(this.OnTextChanged);
+ this.m_edit.KeyUp += new System.Windows.Forms.KeyEventHandler(this.OnKeyUp);
+ //
+ // MainForm
+ //
+ this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
+ this.ClientSize = new System.Drawing.Size(600, 397);
+ this.Controls.Add(this.m_showDebug);
+ this.Controls.Add(this.m_runButton);
+ this.Controls.Add(this.m_edit);
+ this.Name = "MainForm";
+ this.Text = "SID FX - Untitled";
+ this.Closing += new System.ComponentModel.CancelEventHandler(this.OnFormClosing);
+ this.ResumeLayout(false);
+ }
+ #endregion
+
+ void OnNew(object sender, System.EventArgs e)
+ {
+ m_menu.Get("/file/save").Enabled=false;
+ m_path="";
+ m_edit.Text="";
+ m_changed=false;
+ Text="SID FX - Untitled";
+ }
+
+ void OnOpen(object sender, System.EventArgs e)
+ {
+ if (!m_changed || Util.YesNo("Lose current edits?"))
+ {
+ OpenFileDialog fsel=new OpenFileDialog();
+
+ fsel.FileName=m_path;
+ fsel.Filter="SIDFX files (*.sdx)|*.sdx|All files (*.*)|*.*";
+ fsel.FilterIndex=1;
+
+ if(fsel.ShowDialog()==DialogResult.OK)
+ {
+ m_path=fsel.FileName;
+
+ try
+ {
+ m_edit.LoadFile(m_path,RichTextBoxStreamType.PlainText);
+ m_menu.Get("/file/save").Enabled=true;
+ m_changed=false;
+ Text="SID FX - " + m_path;
+ }
+ catch
+ {
+ Util.Error("Error reading " + m_path);
+ }
+ }
+ }
+ }
+
+ void OnSave(object sender, System.EventArgs e)
+ {
+ try
+ {
+ m_edit.SaveFile(m_path,RichTextBoxStreamType.PlainText);
+ m_changed=false;
+ }
+ catch
+ {
+ Util.Error("Error writing " + m_path);
+ }
+ }
+
+ void OnSaveAs(object sender, System.EventArgs e)
+ {
+ SaveFileDialog fsel=new SaveFileDialog();
+
+ fsel.FileName=m_path;
+ fsel.Filter="SIDFX files (*.sdx)|*.sdx|All files (*.*)|*.*";
+ fsel.FilterIndex=1;
+
+ if(fsel.ShowDialog()==DialogResult.OK)
+ {
+ m_path=fsel.FileName;
+
+ OnSave(sender,e);
+ m_menu.Get("/file/save").Enabled=true;
+ m_changed=false;
+ Text="SID FX - " + m_path;
+ }
+ }
+
+ void OnQuit(object sender, System.EventArgs e)
+ {
+ if (!m_changed || Util.YesNo("Lose current edits?"))
+ {
+ // This prevents OnFormClosing() asking again
+ //
+ m_changed=false;
+
+ Close();
+ }
+ }
+
+ void OnAbout(object sender, System.EventArgs e)
+ {
+ Form about=new About();
+
+ about.ShowDialog(this);
+ }
+
+ void OnRun(object sender, System.EventArgs e)
+ {
+ if (Hardsid.Count<1)
+ {
+ Util.Error("This machine has no HardSIDs!");
+ return;
+ }
+
+ CompileScript comp=new CompileScript(m_edit.Text);
+
+ if (comp.HasErrors)
+ {
+ StringBuilder s=new StringBuilder();
+
+ s.Append("Errors compiling the script:\n");
+
+ foreach (CompilerError err in comp.Errors)
+ {
+ s.Append(err.ToString()+"\n");
+ }
+
+ Util.Error(s.ToString());
+ }
+ else
+ {
+ ExecuteForm exec=new ExecuteForm(comp);
+
+ exec.Run(this);
+ }
+ }
+
+ void OnTextChanged(object sender, System.EventArgs e)
+ {
+ m_changed=true;
+ }
+
+ void OnFormClosing(object sender, System.ComponentModel.CancelEventArgs e)
+ {
+ if (m_changed && !Util.YesNo("Lose current edits?"))
+ {
+ e.Cancel=true;
+ }
+ }
+
+ void OnShowDebug(object sender, System.EventArgs e)
+ {
+ if (m_showDebug.Checked)
+ {
+ m_debug.StartDebug();
+ }
+ else
+ {
+ m_debug.StopDebug();
+ }
+ }
+
+ void OnKeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
+ {
+ if (e.KeyCode==Keys.F5)
+ {
+ OnRun(null,null);
+ e.Handled=true;
+ }
+ }
+
+ }
+}