diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToDirectoryCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToDirectoryCommand.cs new file mode 100644 index 0000000000..885f912276 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToDirectoryCommand.cs @@ -0,0 +1,21 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.Core; + +namespace ICSharpCode.WixBinding +{ + public class AddFilesToDirectoryCommand : AbstractMenuCommand + { + public override void Run() + { + PackageFilesView.ActiveView.AddFiles(); + } + } +} + diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs index 5faaa72deb..0aa75495fc 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs @@ -136,7 +136,7 @@ namespace ICSharpCode.WixBinding } /// - /// Adds files to the selected Component element tree node. + /// Adds files to the selected Component element or Directory element tree node. /// public void AddFiles() { diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs index 43195d02b2..7432197007 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs @@ -251,10 +251,15 @@ namespace ICSharpCode.WixBinding void AddFile(string fileName) { WixComponentElement componentElement = view.SelectedElement as WixComponentElement; + WixDirectoryElement directoryElement = view.SelectedElement as WixDirectoryElement; if (componentElement != null) { WixFileElement fileElement = AddFile(componentElement, fileName); view.AddElement(fileElement); view.IsDirty = true; + } else if (directoryElement != null) { + componentElement = AddFileWithParentComponent(directoryElement, fileName); + view.AddElement(componentElement); + view.IsDirty = true; } } @@ -415,17 +420,25 @@ namespace ICSharpCode.WixBinding foreach (string fileName in DirectoryReader.GetFiles(directory)) { if (!excludedNames.IsExcluded(fileName)) { string path = Path.Combine(directory, fileName); - string id = WixComponentElement.GenerateIdFromFileName(document, path); - WixComponentElement component = AddComponent(directoryElement, id); - AddFile(component, path); + AddFileWithParentComponent(directoryElement, path); } } } + + /// + /// Adds a new Wix Component to the directory element. The file will then be added to this + /// component. + /// + WixComponentElement AddFileWithParentComponent(WixDirectoryElement directoryElement, string fileName) + { + string id = WixComponentElement.GenerateIdFromFileName(document, fileName); + WixComponentElement component = AddComponent(directoryElement, id); + AddFile(component, fileName); + return component; + } IDirectoryReader DirectoryReader { - get { - return directoryReader; - } + get { return directoryReader; } } /// diff --git a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin index c352b1da1c..b048039a79 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin +++ b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin @@ -213,6 +213,9 @@ + diff --git a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj index 627b084c39..eb74fd0fe1 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj +++ b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj @@ -45,6 +45,7 @@ + diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesToDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesToDirectoryTestFixture.cs new file mode 100644 index 0000000000..65d9e16cd0 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesToDirectoryTestFixture.cs @@ -0,0 +1,154 @@ +// +// +// +// +// $Revision$ +// + +using ICSharpCode.SharpDevelop.Project; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using System; +using System.Collections.Specialized; +using System.IO; +using System.Xml; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + /// + /// Tests that files can be added when a directory element is selected in the PackageFilesEditor. + /// + [TestFixture] + public class AddFilesToDirectoryTestFixture : PackageFilesTestFixtureBase + { + XmlElement exeFileElement; + XmlElement installDirElement; + XmlElement readmeFileElement; + XmlElement exeFileComponentElement; + XmlElement readmeFileComponentElement; + string[] fileNames; + string exeFileName; + string readmeFileName; + + [SetUp] + public void Init() + { + base.InitFixture(); + installDirElement = (XmlElement)editor.Document.RootDirectory.ChildNodes[0].ChildNodes[0]; + view.SelectedElement = installDirElement; + editor.SelectedElementChanged(); + exeFileName = Path.Combine(project.Directory, @"bin\TestApplication.exe"); + readmeFileName = Path.Combine(project.Directory, @"docs\readme.rtf"); + fileNames = new string[] {exeFileName, readmeFileName}; + editor.AddFiles(fileNames); + if (installDirElement.ChildNodes.Count > 1) { + exeFileComponentElement = (XmlElement)installDirElement.ChildNodes[0]; + if (exeFileComponentElement.HasChildNodes) { + exeFileElement = (XmlElement)exeFileComponentElement.ChildNodes[0]; + } + readmeFileComponentElement = (XmlElement)installDirElement.ChildNodes[1]; + if (readmeFileComponentElement.HasChildNodes) { + readmeFileElement = (XmlElement)readmeFileComponentElement.ChildNodes[0]; + } + } + } + + [Test] + public void IsDirty() + { + Assert.IsTrue(view.IsDirty); + } + + /// + /// The two parent component elements are added to the view. The child elements + /// are not added directly to the view since they are child nodes of the component elements. + /// + [Test] + public void TwoElementsAddedToView() + { + Assert.AreEqual(2, view.ElementsAdded.Length); + } + + [Test] + public void SanityCheckInstallDirectoryElement() + { + Assert.AreEqual("INSTALLDIR", installDirElement.GetAttribute("Id")); + } + + [Test] + public void InstallDirectoryElementHasTwoChildNodes() + { + Assert.AreEqual(2, installDirElement.ChildNodes.Count); + } + + [Test] + public void ExeFileComponentElementExists() + { + Assert.IsNotNull(exeFileComponentElement); + } + + [Test] + public void ReadmeFileComponentElementExists() + { + Assert.IsNotNull(readmeFileComponentElement); + } + + [Test] + public void ExeFileComponentId() + { + string expectedId = WixComponentElement.GenerateIdFromFileName("TestApplication.exe"); + Assert.AreEqual(expectedId, exeFileComponentElement.GetAttribute("Id")); + } + + [Test] + public void ReadmeFileComponentId() + { + string expectedId = WixComponentElement.GenerateIdFromFileName("readme.rtf"); + Assert.AreEqual(expectedId, readmeFileComponentElement.GetAttribute("Id")); + } + + [Test] + public void ExeFileId() + { + Assert.AreEqual("TestApplication.exe", exeFileElement.GetAttribute("Id")); + } + + [Test] + public void ReadmeFileId() + { + Assert.AreEqual("readme.rtf", readmeFileElement.GetAttribute("Id")); + } + + [Test] + public void ExeFileElementExists() + { + Assert.IsNotNull(exeFileElement); + } + + [Test] + public void ReadmeFileElementExists() + { + Assert.IsNotNull(readmeFileElement); + } + + protected override string GetWixXml() + { + return "\r\n" + + "\t\r\n" + + "\t\t\r\n" + + "\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\t\t\r\n" + + "\t\t\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj b/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj index 31b1af3f07..532c50ea81 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj @@ -54,6 +54,7 @@ +