Hi, I need some help!

Feb 9, 2010 at 10:22 AM

Hello, I'm using Deja-Vu engine, and I'm haveing some problems with implementation.

This is my code below, so can anybody tell me what I'm doing wrong?????

 

//==========Form1.Designer.cs==========================//

namespace MyUndoRedo {
    partial class Form1 {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing) {
            if(disposing && (components != null)) {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #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.btnAdd = new System.Windows.Forms.Button();
            this.btnRemove = new System.Windows.Forms.Button();
            this.btnUndo = new System.Windows.Forms.Button();
            this.btnRedo = new System.Windows.Forms.Button();
            this.lstNames = new System.Windows.Forms.ListBox();
            this.lblFirstName = new System.Windows.Forms.Label();
            this.lblSecondName = new System.Windows.Forms.Label();
            this.txtFirstName = new System.Windows.Forms.TextBox();
            this.txtSecondName = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            //
            // btnAdd
            //
            this.btnAdd.Location = new System.Drawing.Point(270,4);
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(75,23);
            this.btnAdd.TabIndex = 0;
            this.btnAdd.Text = "Add";
            this.btnAdd.UseVisualStyleBackColor = true;
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            //
            // btnRemove
            //
            this.btnRemove.Location = new System.Drawing.Point(270,30);
            this.btnRemove.Name = "btnRemove";
            this.btnRemove.Size = new System.Drawing.Size(75,23);
            this.btnRemove.TabIndex = 1;
            this.btnRemove.Text = "Remove";
            this.btnRemove.UseVisualStyleBackColor = true;
            this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
            //
            // btnUndo
            //
            this.btnUndo.Location = new System.Drawing.Point(7,249);
            this.btnUndo.Name = "btnUndo";
            this.btnUndo.Size = new System.Drawing.Size(75,23);
            this.btnUndo.TabIndex = 2;
            this.btnUndo.Text = "Undo";
            this.btnUndo.UseVisualStyleBackColor = true;
            this.btnUndo.Click += new System.EventHandler(this.btnUndo_Click);
            //
            // btnRedo
            //
            this.btnRedo.Location = new System.Drawing.Point(165,249);
            this.btnRedo.Name = "btnRedo";
            this.btnRedo.Size = new System.Drawing.Size(75,23);
            this.btnRedo.TabIndex = 3;
            this.btnRedo.Text = "Redo";
            this.btnRedo.UseVisualStyleBackColor = true;
            this.btnRedo.Click += new System.EventHandler(this.btnRedo_Click);
            //
            // lstNames
            //
            this.lstNames.FormattingEnabled = true;
            this.lstNames.Location = new System.Drawing.Point(9,70);
            this.lstNames.Name = "lstNames";
            this.lstNames.Size = new System.Drawing.Size(231,173);
            this.lstNames.TabIndex = 4;
            //
            // lblFirstName
            //
            this.lblFirstName.AutoSize = true;
            this.lblFirstName.Location = new System.Drawing.Point(6,9);
            this.lblFirstName.Name = "lblFirstName";
            this.lblFirstName.Size = new System.Drawing.Size(58,13);
            this.lblFirstName.TabIndex = 5;
            this.lblFirstName.Text = "First name:";
            //
            // lblSecondName
            //
            this.lblSecondName.AutoSize = true;
            this.lblSecondName.Location = new System.Drawing.Point(6,35);
            this.lblSecondName.Name = "lblSecondName";
            this.lblSecondName.Size = new System.Drawing.Size(76,13);
            this.lblSecondName.TabIndex = 6;
            this.lblSecondName.Text = "Second name:";
            //
            // txtFirstName
            //
            this.txtFirstName.Location = new System.Drawing.Point(88,6);
            this.txtFirstName.Name = "txtFirstName";
            this.txtFirstName.Size = new System.Drawing.Size(152,20);
            this.txtFirstName.TabIndex = 7;
            //
            // txtSecondName
            //
            this.txtSecondName.Location = new System.Drawing.Point(88,32);
            this.txtSecondName.Name = "txtSecondName";
            this.txtSecondName.Size = new System.Drawing.Size(152,20);
            this.txtSecondName.TabIndex = 8;
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F,13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(357,283);
            this.Controls.Add(this.txtSecondName);
            this.Controls.Add(this.txtFirstName);
            this.Controls.Add(this.lblSecondName);
            this.Controls.Add(this.lblFirstName);
            this.Controls.Add(this.lstNames);
            this.Controls.Add(this.btnRedo);
            this.Controls.Add(this.btnUndo);
            this.Controls.Add(this.btnRemove);
            this.Controls.Add(this.btnAdd);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button btnAdd;
        private System.Windows.Forms.Button btnRemove;
        private System.Windows.Forms.Button btnUndo;
        private System.Windows.Forms.Button btnRedo;
        private System.Windows.Forms.ListBox lstNames;
        private System.Windows.Forms.Label lblFirstName;
        private System.Windows.Forms.Label lblSecondName;
        private System.Windows.Forms.TextBox txtFirstName;
        private System.Windows.Forms.TextBox txtSecondName;
    }
}

//==========End of Form1.Designer.cs==========================//

 

 

 

//==========Form1=====================//\

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UndoRedoFramework;

namespace MyUndoRedo {
    public partial class Form1 :Form {
        public Form1() {
            InitializeComponent();


            UndoRedoManager.CommandDone += delegate {

               lstNames.DataSource = new List<string>(UndoRedoManager.UndoCommands);
               lstNames.DataSource = new List<string>(UndoRedoManager.RedoCommands);

                btnUndo.Enabled = UndoRedoManager.CanUndo;
                btnRedo.Enabled = UndoRedoManager.CanRedo;
            };
        }

        private void btnAdd_Click(object sender,EventArgs e) {

            string firstName = txtFirstName.Text;
            string secondName = txtSecondName.Text;
            
           using (UndoRedoManager.Start(""))
            {
                NewUser user = new NewUser(firstName,secondName);
                lstNames.Items.Add(user);
                UndoRedoManager.Commit();
            }
        }

        private void btnRemove_Click(object sender,EventArgs e) {
            if(lstNames.SelectedItem != null) {
                using(UndoRedoManager.Start("")) {
                    lstNames.Items.Remove(lstNames.SelectedItem);
                    UndoRedoManager.Commit();
                }
            }
        }

        private void btnUndo_Click(object sender,EventArgs e) {
            UndoRedoManager.Undo();
        }

        private void btnRedo_Click(object sender,EventArgs e) {
            UndoRedoManager.Redo();
        }
    }
}

 

 

//=================End of Form1 ===============///

 

//===============NewUser.cs=========//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UndoRedoFramework;

namespace MyUndoRedo {
    class NewUser {

        public NewUser(string _firstName, string _secondName){
            FirstName = _firstName;
            SecondName = _secondName;
        }

        readonly UndoRedo<string> firstName = new UndoRedo<string>();
        public string FirstName {
            get { return firstName.Value; }
            set { firstName.Value = value; }
        }

        readonly UndoRedo<string> secondName = new UndoRedo<string>();
        public string SecondName {
            get { return secondName.Value; }
            set { secondName.Value = value; }
        }
    }
}

 

//===============End of NewUser.cs===============//