Commits

Anonymous committed d92fd7f

Add the ability to copy an existing project as a basis for a new one.
Disabled the copy/delete buttons if there are no projects, as these buttons
require the context of a selected project.

Comments (0)

Files changed (6)

src/Core/Presenters/ProjectsPresenter.cs

             View.ProjectSelected += ProjectSelected;
             View.AddProject += AddProject;
             View.ProjectDeleted += DeleteProject;
+            View.CopyProject += CopyProject;
 
             DomainEvents.Register<ProjectAdded>(ProjectAdded);
         }
         {
             DomainEvents.Raise(new EditProjectRequested(projects.ElementAt(projectIndex)));
         }
+
+        private void CopyProject(int projectIndex)
+        {
+            var selectedProject = projects.ElementAt(projectIndex);
+            var newProject = new Project
+                                 {
+                                     Name = selectedProject.Name,
+                                     Username = selectedProject.Username,
+                                     Password = selectedProject.Password,
+                                     ServerType = selectedProject.ServerType,
+                                     Url = selectedProject.Url,
+                                 };
+            DomainEvents.Raise(new EditProjectRequested(newProject));
+        }
     }
 }

src/Core/Presenters/Views/IProjectsView.cs

 {
     public interface IProjectsView : IView
     {
-        IEnumerable<Project> Projects { set; }
+        ICollection<Project> Projects { set; }
         event SimpleHandler<int> ProjectSelected;
         event SimpleHandler<int> ProjectDeleted;
         event VoidHandler AddProject;
+        event SimpleHandler<int> CopyProject;
     }
 }

src/Tests/Presenters/ProjectsPresenterSpecs.cs

             [Test]
             public void it_should_refresh_the_display()
             {
-                View.VerifySet(v => v.Projects = It.IsAny<IEnumerable<Project>>());    
+                View.VerifySet(v => v.Projects = It.IsAny<ICollection<Project>>());
+            }
+        }
+
+        public class when_copying_a_project : under.context_where_the_view_has_already_been_loaded
+        {
+            private Project project;
+            protected override void EstablishContext()
+            {
+                base.EstablishContext();
+                DomainEvents.Register<EditProjectRequested>(args => project = args.Project);
+            }
+
+            protected override void When()
+            {
+                View.Raise(v => v.CopyProject += null, 0);
+            }
+
+            [Test]
+            public void it_should_raise_an_event_to_copy_the_project()
+            {
+                Assert.IsNotNull(project);
+                Assert.AreEqual("first-project", project.Name);
             }
         }
 
                 protected Mock<IProjectRepository> ProjectRepository;
                 protected Mock<IProjectsView> View;
                 protected ProjectsPresenter SUT;
-                protected IEnumerable<Project> Projects;
+                protected ICollection<Project> Projects;
 
                 protected override void EstablishContext()
                 {
                     Projects = new List<Project>
                         {
-                            new Project(),
-                            new Project()
+                            new Project { Id = 1234, Name = "first-project" },
+                            new Project { Id = 5678, Name = "second-project" }
                         };
                     
                     ProjectRepository = new Mock<IProjectRepository>();

src/UI/ProjectsView.Designer.cs

             this.bsProjects = new System.Windows.Forms.BindingSource(this.components);
             this.pnlMain = new System.Windows.Forms.Panel();
             this.pnlButtons = new System.Windows.Forms.Panel();
+            this.btnDeleteProject = new System.Windows.Forms.Button();
             this.btnAddProject = new System.Windows.Forms.Button();
-            this.btnDeleteProject = new System.Windows.Forms.Button();
+            this.btnCopyProject = new System.Windows.Forms.Button();
             ((System.ComponentModel.ISupportInitialize)(this.dgProjects)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.bsProjects)).BeginInit();
             this.pnlMain.SuspendLayout();
             // 
             // pnlButtons
             // 
+            this.pnlButtons.Controls.Add(this.btnCopyProject);
             this.pnlButtons.Controls.Add(this.btnDeleteProject);
             this.pnlButtons.Controls.Add(this.btnAddProject);
             this.pnlButtons.Dock = System.Windows.Forms.DockStyle.Bottom;
             this.pnlButtons.Size = new System.Drawing.Size(644, 31);
             this.pnlButtons.TabIndex = 1;
             // 
-            // btnAddProject
-            // 
-            this.btnAddProject.Location = new System.Drawing.Point(566, 4);
-            this.btnAddProject.Name = "btnAddProject";
-            this.btnAddProject.Size = new System.Drawing.Size(75, 23);
-            this.btnAddProject.TabIndex = 0;
-            this.btnAddProject.Text = "Add Project";
-            this.btnAddProject.UseVisualStyleBackColor = true;
-            // 
             // btnDeleteProject
             // 
             this.btnDeleteProject.Location = new System.Drawing.Point(3, 4);
             this.btnDeleteProject.Text = "Delete Project";
             this.btnDeleteProject.UseVisualStyleBackColor = true;
             // 
+            // btnAddProject
+            // 
+            this.btnAddProject.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+            this.btnAddProject.Location = new System.Drawing.Point(489, 4);
+            this.btnAddProject.Name = "btnAddProject";
+            this.btnAddProject.Size = new System.Drawing.Size(75, 23);
+            this.btnAddProject.TabIndex = 0;
+            this.btnAddProject.Text = "Add Project";
+            this.btnAddProject.UseVisualStyleBackColor = true;
+            // 
+            // btnCopyProject
+            // 
+            this.btnCopyProject.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+            this.btnCopyProject.Location = new System.Drawing.Point(566, 4);
+            this.btnCopyProject.Name = "btnCopyProject";
+            this.btnCopyProject.Size = new System.Drawing.Size(75, 23);
+            this.btnCopyProject.TabIndex = 2;
+            this.btnCopyProject.Text = "Copy Project";
+            this.btnCopyProject.UseVisualStyleBackColor = true;
+            // 
             // ProjectsView
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         private System.Windows.Forms.Panel pnlButtons;
         private System.Windows.Forms.Button btnAddProject;
         private System.Windows.Forms.Button btnDeleteProject;
+        private System.Windows.Forms.Button btnCopyProject;
     }
 }

src/UI/ProjectsView.cs

             Closing += (sender, e) => bsProjects.DataSource = null;
             dgProjects.CellDoubleClick += (sender, e) => ProjectSelected(e.RowIndex);
             btnAddProject.Click += (sender, args) => AddProject();
+            btnCopyProject.Click += (sender, args) => CopyProject(dgProjects.SelectedRows[0].Index);
             btnDeleteProject.Click += (sender, args) => ProjectDeleted(dgProjects.SelectedRows[0].Index);
         }
 
-        public IEnumerable<Project> Projects
+        public ICollection<Project> Projects
         {
-            set { bsProjects.DataSource = value; }
+            set
+            {
+                bsProjects.DataSource = value;
+                bool hasProjects = (value != null && value.Count > 0);
+                btnDeleteProject.Enabled = btnCopyProject.Enabled = hasProjects;
+            }
         }
 
         public event SimpleHandler<int> ProjectSelected = delegate { };
         public event SimpleHandler<int> ProjectDeleted = delegate { };
         public event VoidHandler AddProject = delegate { };
+        public event SimpleHandler<int> CopyProject = delegate { };
     }
 }

src/UI/ProjectsView.resx

   <metadata name="bsProjects.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>17, 17</value>
   </metadata>
-  <metadata name="colName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="colUrl.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="bsProjects.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>17, 17</value>
-  </metadata>
 </root>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.