Windows Form File /AgentMovieEditor/MainForm.cs (C#)
using System;  
using System.Drawing;  
using System.Collections;  
using System.ComponentModel;  
using System.Windows.Forms;  
using System.Data;  
using YariSoft.Utils;  
  
namespace YariSoft.AgentMovieEditor  
{  
    public class MainForm : System.Windows.Forms.Form  
    {  
        #region Protected variables  
        private const string applicationName            = "Movie Editor";  
        private YariSoft.Utils.AgentPlayer workObject    = new AgentPlayer();  
        private YariSoft.Utils.AgentManager agent        = new YariSoft.Utils.AgentManager();  
  
        private System.Windows.Forms.MainMenu mainMenu;  
        private System.Windows.Forms.ImageList imageList;  
        private System.Windows.Forms.ToolBar toolBar;  
        private System.Windows.Forms.ToolBarButton toolSep0;  
        private System.Windows.Forms.ToolBarButton toolNewButton;  
        private System.Windows.Forms.ToolBarButton toolOpenButton;  
        private System.Windows.Forms.ToolBarButton toolSaveButton;  
        private System.Windows.Forms.ToolBarButton toolSep1;  
        private System.Windows.Forms.ToolBarButton toolRunButton;  
        private System.Windows.Forms.TreeView tree;  
        private System.Windows.Forms.MenuItem fileMenuItem;  
        private System.Windows.Forms.MenuItem newMenuItem;  
        private System.Windows.Forms.MenuItem openMenuItem;  
        private System.Windows.Forms.MenuItem saveMenuItem;  
        private System.Windows.Forms.MenuItem saveAsMenuItem;  
        private System.Windows.Forms.MenuItem exitMenuItem;  
        private System.Windows.Forms.MenuItem helpMenuItem;  
        private System.Windows.Forms.MenuItem aboutMenuItem;  
        private System.Windows.Forms.DataGrid grid;  
        private System.Windows.Forms.Splitter splitter;  
        private System.Windows.Forms.MenuItem actionMenuItem;  
        private System.Windows.Forms.ContextMenu popup;  
        private System.Windows.Forms.MenuItem newActionItem;  
        private System.Windows.Forms.MenuItem renameActionItem;  
        private System.Windows.Forms.MenuItem deleteAcionItem;  
        private System.Windows.Forms.MenuItem menuItem1;  
        private System.Windows.Forms.MenuItem newPopupItem;  
        private System.Windows.Forms.MenuItem renamePopupItem;  
        private System.Windows.Forms.MenuItem deletePopupItem;  
        private System.Windows.Forms.MenuItem playActionItem;  
        private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;  
        private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;  
        private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;  
        private System.Windows.Forms.ContextMenu gridPopup;  
        private System.Windows.Forms.MenuItem newOperationItem;  
        private System.Windows.Forms.MenuItem deleteOperationItem;  
        private System.Windows.Forms.MenuItem menuItem5;  
        private System.Windows.Forms.MenuItem upOperationItem;  
        private System.Windows.Forms.MenuItem downOperationItem;  
        private System.Windows.Forms.MenuItem animationOperationItem;  
        private System.Windows.Forms.MenuItem talkOperationItem;  
        private System.Windows.Forms.MenuItem positionOperationItem;  
        private System.Windows.Forms.MenuItem editOperationItem;  
        private System.Windows.Forms.ToolBarButton toolSep2;  
        private System.Windows.Forms.ToolBarButton toolUpButton;  
        private System.Windows.Forms.ToolBarButton toolDownButton;  
        private System.Windows.Forms.MenuItem propActionItem;  
        private System.Windows.Forms.MenuItem menuSep0;  
        private System.Windows.Forms.MenuItem menuSep1;  
        private System.Windows.Forms.MenuItem menuSep2;  
        private System.Windows.Forms.MenuItem menuSep3;  
        private System.ComponentModel.IContainer components;  
        #endregion  
  
        #region Constructor/Destructor  
        public MainForm()  
        {  
            this.agent.Init( new AgentInfo() );  
            this.agent.Show();  
            InitializeComponent();  
        }  
  
        protected override void Dispose( bool disposing )  
        {  
            this.agent.Hide();  
            if( disposing )  
            {  
                if (components != null)  
                {  
                    components.Dispose();  
                }  
            }  
            base.Dispose( disposing );  
        }  
        #endregion  
  
        #region Windows Form Designer generated code  
        /// <summary>  
        /// Required method for Designer support - do not modify  
        /// the contents of this method with the code editor.  
        /// </summary>  
        private void InitializeComponent()  
        {  
            this.components = new System.ComponentModel.Container();  
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));  
            this.tree = new System.Windows.Forms.TreeView();  
            this.popup = new System.Windows.Forms.ContextMenu();  
            this.newPopupItem = new System.Windows.Forms.MenuItem();  
            this.renamePopupItem = new System.Windows.Forms.MenuItem();  
            this.deletePopupItem = new System.Windows.Forms.MenuItem();  
            this.newActionItem = new System.Windows.Forms.MenuItem();  
            this.renameActionItem = new System.Windows.Forms.MenuItem();  
            this.deleteAcionItem = new System.Windows.Forms.MenuItem();  
            this.mainMenu = new System.Windows.Forms.MainMenu();  
            this.fileMenuItem = new System.Windows.Forms.MenuItem();  
            this.newMenuItem = new System.Windows.Forms.MenuItem();  
            this.openMenuItem = new System.Windows.Forms.MenuItem();  
            this.menuSep0 = new System.Windows.Forms.MenuItem();  
            this.saveMenuItem = new System.Windows.Forms.MenuItem();  
            this.saveAsMenuItem = new System.Windows.Forms.MenuItem();  
            this.menuSep1 = new System.Windows.Forms.MenuItem();  
            this.exitMenuItem = new System.Windows.Forms.MenuItem();  
            this.actionMenuItem = new System.Windows.Forms.MenuItem();  
            this.menuSep2 = new System.Windows.Forms.MenuItem();  
            this.playActionItem = new System.Windows.Forms.MenuItem();  
            this.menuSep3 = new System.Windows.Forms.MenuItem();  
            this.propActionItem = new System.Windows.Forms.MenuItem();  
            this.helpMenuItem = new System.Windows.Forms.MenuItem();  
            this.aboutMenuItem = new System.Windows.Forms.MenuItem();  
            this.splitter = new System.Windows.Forms.Splitter();  
            this.grid = new System.Windows.Forms.DataGrid();  
            this.gridPopup = new System.Windows.Forms.ContextMenu();  
            this.newOperationItem = new System.Windows.Forms.MenuItem();  
            this.animationOperationItem = new System.Windows.Forms.MenuItem();  
            this.talkOperationItem = new System.Windows.Forms.MenuItem();  
            this.positionOperationItem = new System.Windows.Forms.MenuItem();  
            this.editOperationItem = new System.Windows.Forms.MenuItem();  
            this.deleteOperationItem = new System.Windows.Forms.MenuItem();  
            this.menuItem5 = new System.Windows.Forms.MenuItem();  
            this.upOperationItem = new System.Windows.Forms.MenuItem();  
            this.downOperationItem = new System.Windows.Forms.MenuItem();  
            this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();  
            this.dataGridTextBoxColumn1 = new System.Windows.Forms.DataGridTextBoxColumn();  
            this.dataGridTextBoxColumn2 = new System.Windows.Forms.DataGridTextBoxColumn();  
            this.imageList = new System.Windows.Forms.ImageList(this.components);  
            this.toolBar = new System.Windows.Forms.ToolBar();  
            this.toolSep0 = new System.Windows.Forms.ToolBarButton();  
            this.toolNewButton = new System.Windows.Forms.ToolBarButton();  
            this.toolOpenButton = new System.Windows.Forms.ToolBarButton();  
            this.toolSaveButton = new System.Windows.Forms.ToolBarButton();  
            this.toolSep1 = new System.Windows.Forms.ToolBarButton();  
            this.toolRunButton = new System.Windows.Forms.ToolBarButton();  
            this.toolSep2 = new System.Windows.Forms.ToolBarButton();  
            this.toolDownButton = new System.Windows.Forms.ToolBarButton();  
            this.toolUpButton = new System.Windows.Forms.ToolBarButton();  
            this.menuItem1 = new System.Windows.Forms.MenuItem();  
            ((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit();  
            this.SuspendLayout();  
            //    
            // tree  
            //    
            this.tree.ContextMenu = this.popup;  
            this.tree.Dock = System.Windows.Forms.DockStyle.Left;  
            this.tree.ImageIndex = -1;  
            this.tree.Location = new System.Drawing.Point(0, 25);  
            this.tree.Name = "tree";  
            this.tree.SelectedImageIndex = -1;  
            this.tree.Size = new System.Drawing.Size(170, 320);  
            this.tree.TabIndex = 0;  
            this.tree.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tree_MouseDown);  
            this.tree.DoubleClick += new System.EventHandler(this.tree_DoubleClick);  
            this.tree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tree_AfterSelect);  
            //    
            // popup  
            //    
            this.popup.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                  this.newPopupItem,  
                                                                                  this.renamePopupItem,  
                                                                                  this.deletePopupItem});  
            //    
            // newPopupItem  
            //    
            this.newPopupItem.Index = 0;  
            this.newPopupItem.Text = "New";  
            this.newPopupItem.Click += new System.EventHandler(this.newActionItem_Click);  
            //    
            // renamePopupItem  
            //    
            this.renamePopupItem.Index = 1;  
            this.renamePopupItem.Text = "Rename";  
            this.renamePopupItem.Click += new System.EventHandler(this.renameActionItem_Click);  
            //    
            // deletePopupItem  
            //    
            this.deletePopupItem.Index = 2;  
            this.deletePopupItem.Text = "Delete";  
            this.deletePopupItem.Click += new System.EventHandler(this.deleteAcionItem_Click);  
            //    
            // newActionItem  
            //    
            this.newActionItem.Index = 0;  
            this.newActionItem.Text = "&New";  
            this.newActionItem.Click += new System.EventHandler(this.newActionItem_Click);  
            //    
            // renameActionItem  
            //    
            this.renameActionItem.Index = 1;  
            this.renameActionItem.Text = "&Rename";  
            this.renameActionItem.Click += new System.EventHandler(this.renameActionItem_Click);  
            //    
            // deleteAcionItem  
            //    
            this.deleteAcionItem.Index = 2;  
            this.deleteAcionItem.Text = "&Delete";  
            this.deleteAcionItem.Click += new System.EventHandler(this.deleteAcionItem_Click);  
            //    
            // mainMenu  
            //    
            this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                     this.fileMenuItem,  
                                                                                     this.actionMenuItem,  
                                                                                     this.helpMenuItem});  
            //    
            // fileMenuItem  
            //    
            this.fileMenuItem.Index = 0;  
            this.fileMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                         this.newMenuItem,  
                                                                                         this.openMenuItem,  
                                                                                         this.menuSep0,  
                                                                                         this.saveMenuItem,  
                                                                                         this.saveAsMenuItem,  
                                                                                         this.menuSep1,  
                                                                                         this.exitMenuItem});  
            this.fileMenuItem.Text = "&File";  
            //    
            // newMenuItem  
            //    
            this.newMenuItem.Index = 0;  
            this.newMenuItem.Text = "&New";  
            this.newMenuItem.Click += new System.EventHandler(this.newMenuItem_Click);  
            //    
            // openMenuItem  
            //    
            this.openMenuItem.Index = 1;  
            this.openMenuItem.Text = "&Open";  
            this.openMenuItem.Click += new System.EventHandler(this.openMenuItem_Click);  
            //    
            // menuSep0  
            //    
            this.menuSep0.Index = 2;  
            this.menuSep0.Text = "-";  
            //    
            // saveMenuItem  
            //    
            this.saveMenuItem.Index = 3;  
            this.saveMenuItem.Text = "&Save";  
            this.saveMenuItem.Click += new System.EventHandler(this.saveMenuItem_Click);  
            //    
            // saveAsMenuItem  
            //    
            this.saveAsMenuItem.Index = 4;  
            this.saveAsMenuItem.Text = "Save &As...";  
            this.saveAsMenuItem.Click += new System.EventHandler(this.saveAsMenuItem_Click);  
            //    
            // menuSep1  
            //    
            this.menuSep1.Index = 5;  
            this.menuSep1.Text = "-";  
            //    
            // exitMenuItem  
            //    
            this.exitMenuItem.Index = 6;  
            this.exitMenuItem.Text = "&Exit";  
            this.exitMenuItem.Click += new System.EventHandler(this.exitMenuItem_Click);  
            //    
            // actionMenuItem  
            //    
            this.actionMenuItem.Index = 1;  
            this.actionMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                           this.newActionItem,  
                                                                                           this.renameActionItem,  
                                                                                           this.deleteAcionItem,  
                                                                                           this.menuSep2,  
                                                                                           this.playActionItem,  
                                                                                           this.menuSep3,  
                                                                                           this.propActionItem});  
            this.actionMenuItem.Text = "&Action";  
            //    
            // menuSep2  
            //    
            this.menuSep2.Index = 3;  
            this.menuSep2.Text = "-";  
            //    
            // playActionItem  
            //    
            this.playActionItem.Index = 4;  
            this.playActionItem.Text = "&Play";  
            this.playActionItem.Click += new System.EventHandler(this.playActionItem_Click);  
            //    
            // menuSep3  
            //    
            this.menuSep3.Index = 5;  
            this.menuSep3.Text = "-";  
            //    
            // propActionItem  
            //    
            this.propActionItem.Index = 6;  
            this.propActionItem.Text = "Agent &Properties";  
            this.propActionItem.Click += new System.EventHandler(this.propActionItem_Click);  
            //    
            // helpMenuItem  
            //    
            this.helpMenuItem.Index = 2;  
            this.helpMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                         this.aboutMenuItem});  
            this.helpMenuItem.Text = "&Help";  
            //    
            // aboutMenuItem  
            //    
            this.aboutMenuItem.Index = 0;  
            this.aboutMenuItem.Text = "&About";  
            this.aboutMenuItem.Click += new System.EventHandler(this.aboutMenuItem_Click);  
            //    
            // splitter  
            //    
            this.splitter.Location = new System.Drawing.Point(170, 25);  
            this.splitter.Name = "splitter";  
            this.splitter.Size = new System.Drawing.Size(3, 320);  
            this.splitter.TabIndex = 2;  
            this.splitter.TabStop = false;  
            //    
            // grid  
            //    
            this.grid.AllowNavigation = false;  
            this.grid.AllowSorting = false;  
            this.grid.CaptionVisible = false;  
            this.grid.ContextMenu = this.gridPopup;  
            this.grid.DataMember = "";  
            this.grid.Dock = System.Windows.Forms.DockStyle.Fill;  
            this.grid.HeaderForeColor = System.Drawing.SystemColors.ControlText;  
            this.grid.Location = new System.Drawing.Point(173, 25);  
            this.grid.Name = "grid";  
            this.grid.ParentRowsVisible = false;  
            this.grid.ReadOnly = true;  
            this.grid.RowHeadersVisible = false;  
            this.grid.Size = new System.Drawing.Size(259, 320);  
            this.grid.TabIndex = 3;  
            this.grid.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {  
                                                                                             this.dataGridTableStyle1});  
            this.grid.DoubleClick += new System.EventHandler(this.grid_DoubleClick);  
            this.grid.MouseUp += new System.Windows.Forms.MouseEventHandler(this.grid_MouseUp);  
            //    
            // gridPopup  
            //    
            this.gridPopup.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                      this.newOperationItem,  
                                                                                      this.editOperationItem,  
                                                                                      this.deleteOperationItem,  
                                                                                      this.menuItem5,  
                                                                                      this.upOperationItem,  
                                                                                      this.downOperationItem});  
            this.gridPopup.Popup += new System.EventHandler(this.gridPopup_Popup);  
            //    
            // newOperationItem  
            //    
            this.newOperationItem.Index = 0;  
            this.newOperationItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                             this.animationOperationItem,  
                                                                                             this.talkOperationItem,  
                                                                                             this.positionOperationItem});  
            this.newOperationItem.Text = "New";  
            //    
            // animationOperationItem  
            //    
            this.animationOperationItem.Index = 0;  
            this.animationOperationItem.Text = "Animation";  
            this.animationOperationItem.Click += new System.EventHandler(this.animationOperationItem_Click);  
            //    
            // talkOperationItem  
            //    
            this.talkOperationItem.Index = 1;  
            this.talkOperationItem.Text = "Talk";  
            this.talkOperationItem.Click += new System.EventHandler(this.talkOperationItem_Click);  
            //    
            // positionOperationItem  
            //    
            this.positionOperationItem.Index = 2;  
            this.positionOperationItem.Text = "Position";  
            this.positionOperationItem.Click += new System.EventHandler(this.positionOperationItem_Click);  
            //    
            // editOperationItem  
            //    
            this.editOperationItem.Index = 1;  
            this.editOperationItem.Text = "Edit";  
            this.editOperationItem.Click += new System.EventHandler(this.editOperationItem_Click);  
            //    
            // deleteOperationItem  
            //    
            this.deleteOperationItem.Index = 2;  
            this.deleteOperationItem.Text = "Delete";  
            this.deleteOperationItem.Click += new System.EventHandler(this.deleteOperationItem_Click);  
            //    
            // menuItem5  
            //    
            this.menuItem5.Index = 3;  
            this.menuItem5.Text = "-";  
            //    
            // upOperationItem  
            //    
            this.upOperationItem.Index = 4;  
            this.upOperationItem.Text = "Move Up";  
            this.upOperationItem.Click += new System.EventHandler(this.upOperationItem_Click);  
            //    
            // downOperationItem  
            //    
            this.downOperationItem.Index = 5;  
            this.downOperationItem.Text = "Move Down";  
            this.downOperationItem.Click += new System.EventHandler(this.downOperationItem_Click);  
            //    
            // dataGridTableStyle1  
            //    
            this.dataGridTableStyle1.AllowSorting = false;  
            this.dataGridTableStyle1.DataGrid = this.grid;  
            this.dataGridTableStyle1.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {  
                                                                                                                  this.dataGridTextBoxColumn1,  
                                                                                                                  this.dataGridTextBoxColumn2});  
            this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;  
            this.dataGridTableStyle1.MappingName = "Table";  
            this.dataGridTableStyle1.ReadOnly = true;  
            //    
            // dataGridTextBoxColumn1  
            //    
            this.dataGridTextBoxColumn1.Format = "";  
            this.dataGridTextBoxColumn1.FormatInfo = null;  
            this.dataGridTextBoxColumn1.HeaderText = "Type";  
            this.dataGridTextBoxColumn1.MappingName = "TypeName";  
            this.dataGridTextBoxColumn1.Width = 75;  
            //    
            // dataGridTextBoxColumn2  
            //    
            this.dataGridTextBoxColumn2.Format = "";  
            this.dataGridTextBoxColumn2.FormatInfo = null;  
            this.dataGridTextBoxColumn2.HeaderText = "Description";  
            this.dataGridTextBoxColumn2.MappingName = "Description";  
            this.dataGridTextBoxColumn2.Width = 145;  
            //    
            // imageList  
            //    
            this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;  
            this.imageList.ImageSize = new System.Drawing.Size(16, 16);  
            this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));  
            this.imageList.TransparentColor = System.Drawing.Color.Transparent;  
            //    
            // toolBar  
            //    
            this.toolBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;  
            this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {  
                                                                                       this.toolSep0,  
                                                                                       this.toolNewButton,  
                                                                                       this.toolOpenButton,  
                                                                                       this.toolSaveButton,  
                                                                                       this.toolSep1,  
                                                                                       this.toolRunButton,  
                                                                                       this.toolSep2,  
                                                                                       this.toolDownButton,  
                                                                                       this.toolUpButton});  
            this.toolBar.ButtonSize = new System.Drawing.Size(24, 23);  
            this.toolBar.DropDownArrows = true;  
            this.toolBar.ImageList = this.imageList;  
            this.toolBar.Name = "toolBar";  
            this.toolBar.ShowToolTips = true;  
            this.toolBar.Size = new System.Drawing.Size(432, 25);  
            this.toolBar.TabIndex = 13;  
            this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);  
            //    
            // toolSep0  
            //    
            this.toolSep0.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;  
            //    
            // toolNewButton  
            //    
            this.toolNewButton.ImageIndex = 0;  
            this.toolNewButton.ToolTipText = "New";  
            //    
            // toolOpenButton  
            //    
            this.toolOpenButton.ImageIndex = 1;  
            this.toolOpenButton.ToolTipText = "Open";  
            //    
            // toolSaveButton  
            //    
            this.toolSaveButton.ImageIndex = 2;  
            this.toolSaveButton.ToolTipText = "Save";  
            //    
            // toolSep1  
            //    
            this.toolSep1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;  
            //    
            // toolRunButton  
            //    
            this.toolRunButton.ImageIndex = 3;  
            this.toolRunButton.ToolTipText = "Play";  
            //    
            // toolSep2  
            //    
            this.toolSep2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;  
            //    
            // toolDownButton  
            //    
            this.toolDownButton.ImageIndex = 5;  
            //    
            // toolUpButton  
            //    
            this.toolUpButton.ImageIndex = 4;  
            //    
            // menuItem1  
            //    
            this.menuItem1.Index = -1;  
            this.menuItem1.Text = "1";  
            //    
            // MainForm  
            //    
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);  
            this.ClientSize = new System.Drawing.Size(432, 345);  
            this.Controls.AddRange(new System.Windows.Forms.Control[] {  
                                                                          this.grid,  
                                                                          this.splitter,  
                                                                          this.tree,  
                                                                          this.toolBar});  
            this.Menu = this.mainMenu;  
            this.Name = "MainForm";  
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;  
            this.Text = "Movie Editor";  
            this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);  
            this.Load += new System.EventHandler(this.MainForm_Load);  
            ((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();  
            this.ResumeLayout(false);  
  
        }  
        #endregion  
  
        #region Static functions  
        [STAThread]  
        static void Main( string[] args )  
        {  
            MainForm main = new MainForm();  
            if( args.Length > 0 ){  
                main.workObject = AgentPlayer.LoadFromFile ( args[0] );  
                main.BuildTree();  
                main.SetFormCaption();  
            }  
            Application.Run(main);  
        }  
        #endregion  
  
        #region Private functions  
        private void MainForm_Load(object sender, System.EventArgs e)  
        {  
            this.RefreshMenuItems();  
        }  
  
        private void BuildTree()  
        {  
            this.tree.Nodes.Clear();  
            TreeNode parentNode = new TreeNode("Movies");  
            this.tree.Nodes.Add( parentNode );  
              
            this.BuildMovieNode ( parentNode, "Start",        YariSoft.Utils.AgentPlayer.MovieTypeEnum.Start    );  
            this.BuildMovieNode ( parentNode, "Stop",        YariSoft.Utils.AgentPlayer.MovieTypeEnum.Stop    );  
            this.BuildMovieNode ( parentNode, "Error",        YariSoft.Utils.AgentPlayer.MovieTypeEnum.Error    );  
            this.BuildMovieNode ( parentNode, "Question",    YariSoft.Utils.AgentPlayer.MovieTypeEnum.Question );  
            this.BuildMovieNode ( parentNode, "Busy",        YariSoft.Utils.AgentPlayer.MovieTypeEnum.Busy    );  
              
            parentNode.Expand();  
        }  
          
        private void BuildMovieNode( TreeNode ParentNode, string Name, YariSoft.Utils.AgentPlayer.MovieTypeEnum MovieType )  
        {  
            TreeNode Node = this.BuildNode( ParentNode, Name, MovieType );  
            ArrayList MovieCollection = ( ArrayList )this.workObject.Movies[ MovieType ];  
            foreach( AgentMovie agentMovie in MovieCollection ){  
                this.BuildNode( Node, agentMovie.Name, agentMovie );      
            }  
        }  
  
        private TreeNode BuildNode( TreeNode ParentNode, string Name, object ConnectedObject )  
        {  
            TreeNode childNode    = new TreeNode( Name );  
            childNode.Tag        = ConnectedObject;  
            ParentNode.Nodes.Add( childNode );  
            return childNode;  
        }  
  
        private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)  
        {  
            if( e.Button == this.toolNewButton ){  
                this.newMenuItem_Click( this, null );  
            } else if( e.Button == this.toolOpenButton ) {  
                this.openMenuItem_Click( this, null );  
            } else if( e.Button == this.toolSaveButton ) {  
                this.saveMenuItem_Click( this, null );  
            } else if( e.Button == this.toolRunButton ) {  
                this.playActionItem_Click( this, null );  
            } else if( e.Button == this.toolDownButton ) {  
                if( this.grid.DataSource != null && this.grid.CurrentRowIndex != ((DataTable)this.grid.DataSource).Rows.Count - 1 ){  
                    this.downOperationItem_Click(this, null);  
                }  
            } else if( e.Button == this.toolUpButton ) {  
                if( this.grid.DataSource != null && this.grid.CurrentRowIndex != 0 ){  
                    this.upOperationItem_Click(this, null);  
                }  
            }  
        }  
  
        private void exitMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.Close();  
        }  
  
        private void newMenuItem_Click(object sender, System.EventArgs e)  
        {  
            if( ! this.CheckChanges() ){  
                return;  
            }  
            this.workObject = new AgentPlayer();  
            this.BuildTree();  
        }  
  
        private void openMenuItem_Click(object sender, System.EventArgs e)  
        {  
            if( ! this.CheckChanges() ){  
                return;  
            }  
  
            OpenFileDialog Dialog = new OpenFileDialog();  
            Dialog.Filter = "Agent config files(*.amv)|*.amv";  
            if( Dialog.ShowDialog() == DialogResult.Cancel ){  
                return;  
            }  
            string fileName = Dialog.FileName;  
            Dialog.Dispose();  
  
            this.workObject = AgentPlayer.LoadFromFile ( fileName );  
            this.BuildTree();  
            this.SetFormCaption();  
        }  
  
        private void saveMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.workObject.SaveToFile();  
        }  
  
        private void saveAsMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.workObject.SaveAsToFile();  
            this.SetFormCaption();  
        }  
  
        private void newActionItem_Click(object sender, System.EventArgs e)  
        {  
            TreeNode node = this.tree.SelectedNode;  
            if( node == null ){  
                return;  
            }  
  
            if( node.Tag is AgentMovie ){  
                node = node.Parent;  
            }  
  
            string name = "";  
            if( this.EditValue( "Please specify movie name", "Movie name:", ref name ) ){  
                AgentMovie agentMovie = new AgentMovie( name );  
                YariSoft.Utils.AgentPlayer.MovieTypeEnum movieType = ( YariSoft.Utils.AgentPlayer.MovieTypeEnum )node.Tag;  
                ArrayList MovieCollection = ( ArrayList )this.workObject.Movies[ movieType ];  
                MovieCollection.Add( agentMovie );  
                this.tree.SelectedNode = this.BuildNode( node, name, agentMovie );  
                if( !node.IsExpanded ){  
                    node.Expand();  
                }  
                this.workObject.HasChanges = true;  
            }  
        }  
  
        private void renameActionItem_Click(object sender, System.EventArgs e)  
        {  
            TreeNode node = this.tree.SelectedNode;  
            if( node == null ){  
                return;  
            }  
  
            AgentMovie agentMovie = (AgentMovie)node.Tag;  
            if( this.EditValue( "Please specify movie name", "Movie name:", ref agentMovie.Name ) ){  
                node.Text = agentMovie.Name;  
                this.workObject.HasChanges = true;  
            }  
        }  
  
        private void deleteAcionItem_Click(object sender, System.EventArgs e)  
        {  
            TreeNode node = this.tree.SelectedNode;  
            if( node == null ){  
                return;  
            }  
  
            DialogResult res = MessageBox.Show( "Are you sure you want to delete selected item?",  applicationName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question );  
            if( res == DialogResult.Cancel ){  
                return;  
            }  
  
            YariSoft.Utils.AgentPlayer.MovieTypeEnum movieType = ( YariSoft.Utils.AgentPlayer.MovieTypeEnum )node.Parent.Tag;  
            ArrayList MovieCollection = ( ArrayList )this.workObject.Movies[ movieType ];  
            for( int i = 0; i < MovieCollection.Count; i++ ){  
                if( (( AgentMovie )MovieCollection[i]).Name == node.Text ){  
                    MovieCollection.RemoveAt(i);      
                    node.Remove();  
                    this.workObject.HasChanges = true;  
                    break;  
                }  
            }  
            if( ! ( thi