Browse Source

Wix addin now uses the new text editor interfaces. Restructured various Wix addin classes and added missing unit tests.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5280 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 16 years ago
parent
commit
67ec85874e
  1. 40
      src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AbstractActivePackageFilesViewCommand.cs
  2. 17
      src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs
  3. 18
      src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddElementCommand.cs
  4. 30
      src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesCommand.cs
  5. 17
      src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/HideDiffCommand.cs
  6. 17
      src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/RemoveElementCommand.cs
  7. 17
      src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ShowDiffCommand.cs
  8. 3
      src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewDialogXmlCommand.cs
  9. 44
      src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewSetupFilesCommand.cs
  10. 28
      src/AddIns/BackendBindings/WixBinding/Project/Src/DefaultFileLoader.cs
  11. 27
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/ActivePackageFilesView.cs
  12. 9
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/IFormsDesignerView.cs
  13. 42
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/OpenTextEditors.cs
  14. 263
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs
  15. 3
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs
  16. 60
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs
  17. 30
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerDisplayBinding.cs
  18. 55
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs
  19. 111
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerLoader.cs
  20. 195
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs
  21. 34
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentWindow.cs
  22. 48
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs
  23. 16
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs
  24. 2
      src/AddIns/BackendBindings/WixBinding/Project/Src/IFileLoader.cs
  25. 12
      src/AddIns/BackendBindings/WixBinding/Project/Src/IPackageFilesViewFactory.cs
  26. 31
      src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPackageFilesControl.cs
  27. 23
      src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPropertyValueProvider.cs
  28. 24
      src/AddIns/BackendBindings/WixBinding/Project/Src/PackageFilesViewFactory.cs
  29. 54
      src/AddIns/BackendBindings/WixBinding/Project/Src/Project/WixProject.cs
  30. 2
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs
  31. 36
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaryElement.cs
  32. 148
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs
  33. 8
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs
  34. 22
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialogElement.cs
  35. 17
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs
  36. 18
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs
  37. 708
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs
  38. 69
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentLineSegment.cs
  39. 293
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentReader.cs
  40. 47
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixElementBase.cs
  41. 231
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs
  42. 49
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileName.cs
  43. 2
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesDiff.cs
  44. 39
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs
  45. 18
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixPropertyParser.cs
  46. 58
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixTextWriter.cs
  47. 4
      src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin
  48. 43
      src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj
  49. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapFromProjectTestFixture.cs
  50. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapTestFixture.cs
  51. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonFontTestFixture.cs
  52. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonTextTestFixture.cs
  53. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonsTestFixture.cs
  54. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/CheckBoxTestFixture.cs
  55. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ComboBoxTestFixture.cs
  56. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DefaultUIFontTestFixture.cs
  57. 3
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogMinimizeBoxTestFixture.cs
  58. 3
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogTitleTestFixture.cs
  59. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DirectoryListTestFixture.cs
  60. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DisabledButtonTestFixture.cs
  61. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/GroupBoxTestFixture.cs
  62. 7
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidLocationTests.cs
  63. 11
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidSizeTests.cs
  64. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelFontFromPropertyTestFixture.cs
  65. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelTestFixture.cs
  66. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LineTestFixture.cs
  67. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListBoxTestFixture.cs
  68. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListViewTestFixture.cs
  69. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MaskedEditTestFixture.cs
  70. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingBitmapBinaryTestFixture.cs
  71. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingRadioButtonGroupTestFixture.cs
  72. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/NullComponentCreatorTestFixture.cs
  73. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/PathEditTestFixture.cs
  74. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ProgressBarTestFixture.cs
  75. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/RadioButtonTestFixture.cs
  76. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ScrollableTextTestFixture.cs
  77. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SelectionTreeTestFixture.cs
  78. 5
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogTestFixture.cs
  79. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogUsingObjectCreatorTestFixture.cs
  80. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextBoxTestFixture.cs
  81. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextStyleNameWithSpecialXmlCharsTestFixture.cs
  82. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TransparentLabelsTestFixture.cs
  83. 3
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/AddAcceptAndCancelButtonTestFixture.cs
  84. 3
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonAddedTestFixture.cs
  85. 3
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonChangedTestFixture.cs
  86. 3
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonRemovedTestFixture.cs
  87. 8
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonTextRemovedTestFixture.cs
  88. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxItemAddedTestFixture.cs
  89. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxPropertyWithSpecialXmlCharsTestFixture.cs
  90. 42
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/DialogXmlWritingTestFixture.cs
  91. 3
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/GroupBoxContainingControlsTestFixture.cs
  92. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxAddedTestFixture.cs
  93. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemAddedTestFixture.cs
  94. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemRemovedTestFixture.cs
  95. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxPropertyWithSpecialXmlCharsTestFixture.cs
  96. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxUpdatedTestFixture.cs
  97. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewAddedTestFixture.cs
  98. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemAddedTestFixture.cs
  99. 2
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemRemovedTestFixture.cs
  100. 4
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewPropertyWithSpecialXmlCharsTestFixture.cs
  101. Some files were not shown because too many files have changed in this diff Show More

40
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AbstractActivePackageFilesViewCommand.cs

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
public abstract class AbstractActivePackageFilesViewCommand : AbstractMenuCommand
{
IWorkbench workbench;
ActivePackageFilesView activePackageFilesView;
public AbstractActivePackageFilesViewCommand()
: this(WorkbenchSingleton.Workbench)
{
}
public AbstractActivePackageFilesViewCommand(IWorkbench workbench)
{
this.workbench = workbench;
activePackageFilesView = new ActivePackageFilesView(workbench);
}
public override void Run()
{
PackageFilesView view = activePackageFilesView.GetActiveView();
if (view != null) {
Run(view);
}
}
protected abstract void Run(PackageFilesView view);
}
}

17
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
@ -14,11 +14,20 @@ namespace ICSharpCode.WixBinding @@ -14,11 +14,20 @@ namespace ICSharpCode.WixBinding
/// Adds a directory and all its contents to the currently selected directory
/// node.
/// </summary>
public class AddDirectoryCommand : AbstractMenuCommand
public class AddDirectoryCommand : AbstractActivePackageFilesViewCommand
{
public override void Run()
public AddDirectoryCommand()
{
PackageFilesView.ActiveView.AddDirectory();
}
public AddDirectoryCommand(IWorkbench workbench)
: base(workbench)
{
}
protected override void Run(PackageFilesView view)
{
view.AddDirectory();
}
}
}

18
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddElementCommand.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
@ -16,16 +17,29 @@ namespace ICSharpCode.WixBinding @@ -16,16 +17,29 @@ namespace ICSharpCode.WixBinding
public class AddElementCommand : ToolStripMenuItem
{
string name;
IWorkbench workbench;
ActivePackageFilesView activePackageFilesView;
public AddElementCommand(string name) : base(name)
public AddElementCommand(string name)
: this(name, WorkbenchSingleton.Workbench)
{
}
public AddElementCommand(string name, IWorkbench workbench)
{
this.name = name;
this.workbench = workbench;
activePackageFilesView = new ActivePackageFilesView(workbench);
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
PackageFilesView.ActiveView.AddElement(name);
PackageFilesView view = activePackageFilesView.GetActiveView();
if (view != null) {
view.AddElement(name);
}
}
}
}

30
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesCommand.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
public class AddFilesCommand : AbstractActivePackageFilesViewCommand
{
public AddFilesCommand()
{
}
public AddFilesCommand(IWorkbench workbench)
: base(workbench)
{
}
protected override void Run(PackageFilesView view)
{
view.AddFiles();
}
}
}

17
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/HideDiffCommand.cs

@ -6,18 +6,27 @@ @@ -6,18 +6,27 @@
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
/// <summary>
/// Hides the diff control from the Setup Files window.
/// </summary>
public class HideDiffCommand : AbstractMenuCommand
public class HideDiffCommand : AbstractActivePackageFilesViewCommand
{
public override void Run()
public HideDiffCommand()
{
PackageFilesView.ActiveView.HideDiff();
}
public HideDiffCommand(IWorkbench workbench)
: base(workbench)
{
}
protected override void Run(PackageFilesView view)
{
view.HideDiff();
}
}
}

17
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/RemoveElementCommand.cs

@ -6,18 +6,27 @@ @@ -6,18 +6,27 @@
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
/// <summary>
/// Remove the selected element from the Wix document.
/// </summary>
public class RemoveElementCommand : AbstractMenuCommand
public class RemoveElementCommand : AbstractActivePackageFilesViewCommand
{
public override void Run()
public RemoveElementCommand()
{
PackageFilesView.ActiveView.RemoveSelectedElement();
}
public RemoveElementCommand(IWorkbench workbench)
: base(workbench)
{
}
protected override void Run(PackageFilesView view)
{
view.RemoveSelectedElement();
}
}
}

17
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ShowDiffCommand.cs

@ -6,15 +6,24 @@ @@ -6,15 +6,24 @@
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
public class ShowDiffCommand : AbstractMenuCommand
public class ShowDiffCommand : AbstractActivePackageFilesViewCommand
{
public override void Run()
public ShowDiffCommand()
{
PackageFilesView.ActiveView.ShowDiff();
}
public ShowDiffCommand(IWorkbench workbench)
: base(workbench)
{
}
protected override void Run(PackageFilesView view)
{
view.CalculateDiff();
}
}
}

3
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewDialogXmlCommand.cs

@ -54,7 +54,8 @@ namespace ICSharpCode.WixBinding @@ -54,7 +54,8 @@ namespace ICSharpCode.WixBinding
try {
WorkbenchTextFileReader workbenchTextFileReader = new WorkbenchTextFileReader();
using (TextReader reader = workbenchTextFileReader.Create(fileName)) {
return WixDocument.GetStartElementLocation(reader, "Dialog", id);
WixDocumentReader wixReader = new WixDocumentReader(reader);
return wixReader.GetStartElementLocation("Dialog", id);
}
} catch (XmlException ex) {
WixBindingService.ShowErrorInErrorList(fileName, ex);

44
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewSetupFilesCommand.cs

@ -17,12 +17,54 @@ namespace ICSharpCode.WixBinding @@ -17,12 +17,54 @@ namespace ICSharpCode.WixBinding
/// </summary>
public class ViewSetupFilesCommand : AbstractMenuCommand
{
IPackageFilesViewFactory factory;
IWorkbench workbench;
public ViewSetupFilesCommand()
: this(new PackageFilesViewFactory(), WorkbenchSingleton.Workbench)
{
}
public ViewSetupFilesCommand(IPackageFilesViewFactory factory, IWorkbench workbench)
{
this.factory = factory;
this.workbench = workbench;
}
public override void Run()
{
WixProject project = ProjectService.CurrentProject as WixProject;
if (project != null) {
PackageFilesView.Show(project, WorkbenchSingleton.Workbench);
Run(project);
}
}
public void Run(WixProject project)
{
PackageFilesView openView = GetOpenPackageFilesView(project);
if (openView != null) {
openView.WorkbenchWindow.SelectWindow();
} else {
OpenNewPackageFilesView(project);
}
}
void OpenNewPackageFilesView(WixProject project)
{
PackageFilesView view = factory.Create(project, workbench);
workbench.ShowView(view);
view.ShowFiles();
}
PackageFilesView GetOpenPackageFilesView(WixProject project)
{
foreach (IViewContent view in workbench.ViewContentCollection) {
PackageFilesView packageFilesView = view as PackageFilesView;
if ((packageFilesView != null) && (packageFilesView.IsForProject(project))) {
return packageFilesView;
}
}
return null;
}
}
}

28
src/AddIns/BackendBindings/WixBinding/Project/Src/DefaultFileLoader.cs

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Drawing;
using System.IO;
namespace ICSharpCode.WixBinding
{
public class DefaultFileLoader : IFileLoader
{
public DefaultFileLoader()
{
}
public Bitmap LoadBitmap(string fileName)
{
if (File.Exists(fileName)) {
return new Bitmap(fileName);
}
return null;
}
}
}

27
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/ActivePackageFilesView.cs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
public class ActivePackageFilesView
{
IWorkbench workbench;
public ActivePackageFilesView(IWorkbench workbench)
{
this.workbench = workbench;
}
public PackageFilesView GetActiveView()
{
return workbench.ActiveContent as PackageFilesView;
}
}
}

9
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToComponentCommand.cs → src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/IFormsDesignerView.cs

@ -6,15 +6,12 @@ @@ -6,15 +6,12 @@
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
namespace ICSharpCode.WixBinding
{
public class AddFilesToComponentCommand : AbstractMenuCommand
public interface IFormsDesignerView
{
public override void Run()
{
PackageFilesView.ActiveView.AddFiles();
}
OpenedFile PrimaryFile { get; }
}
}

42
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/OpenTextEditors.cs

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
public class OpenTextEditors
{
IWorkbench workbench;
public OpenTextEditors(IWorkbench workbench)
{
this.workbench = workbench;
}
public ITextEditor FindTextEditorForDocument(WixDocument document)
{
foreach (IViewContent view in workbench.ViewContentCollection) {
ITextEditorProvider textEditorProvider = view as ITextEditorProvider;
if (textEditorProvider != null) {
if (AreFileNamesEqual(view.PrimaryFileName, document.FileName)) {
return textEditorProvider.TextEditor;
}
}
}
return null;
}
bool AreFileNamesEqual(FileName lhs, string rhs)
{
return FileUtility.IsEqualFileName(lhs.ToString(), rhs);
}
}
}

263
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs

@ -10,59 +10,79 @@ using System.IO; @@ -10,59 +10,79 @@ using System.IO;
using System.Windows.Forms;
using System.Xml;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.AddIn.Options;
using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;
namespace ICSharpCode.WixBinding
{
/// <summary>
/// Displays the setup package files.
/// </summary>
public class PackageFilesView : AbstractViewContentWithoutFile, ITextFileReader, IWixDocumentWriter
public class PackageFilesView : AbstractViewContentWithoutFile, IWixDocumentWriter
{
WixPackageFilesControl packageFilesControl;
WorkbenchTextFileReader textFileReader = new WorkbenchTextFileReader();
IWixPackageFilesControl packageFilesControl;
WixProject project;
IWorkbench workbench;
bool reload;
public override object Control {
get {
return packageFilesControl;
}
WixDocumentWindow wixDocumentWindow;
OpenTextEditors openTextEditors;
WixTextWriter wixTextWriter;
public PackageFilesView(WixProject project, IWorkbench workbench)
: this(project, workbench, new WixPackageFilesControl())
{
}
PackageFilesView(WixProject project)
public PackageFilesView(WixProject project, IWorkbench workbench, IWixPackageFilesControl packageFilesControl)
: this(project, workbench, packageFilesControl, null)
{
packageFilesControl = new WixPackageFilesControl();
wixTextWriter = new WixTextWriter(GetTextEditorOptions());
}
public PackageFilesView(WixProject project,
IWorkbench workbench,
IWixPackageFilesControl packageFilesControl,
WixTextWriter wixTextWriter)
{
this.packageFilesControl = packageFilesControl;
packageFilesControl.DirtyChanged += delegate { base.RaiseIsDirtyChanged(); };
SetLocalizedTitle("${res:ICSharpCode.WixBinding.PackageFilesView.Title}");
this.project = project;
WorkbenchSingleton.Workbench.ActiveViewContentChanged += ActiveViewContentChanged;
this.workbench = workbench;
wixDocumentWindow = new WixDocumentWindow(workbench);
workbench.ActiveViewContentChanged += ActiveViewContentChanged;
this.wixTextWriter = wixTextWriter;
openTextEditors = new OpenTextEditors(workbench);
}
public static PackageFilesView ActiveView {
get {
return WorkbenchSingleton.Workbench.ActiveContent as PackageFilesView;
}
static ITextEditorOptions GetTextEditorOptions()
{
ICSharpCode.AvalonEdit.TextEditor editor = new ICSharpCode.AvalonEdit.TextEditor();
AvalonEditTextEditorAdapter adapter = new AvalonEditTextEditorAdapter(editor);
return adapter.Options;
}
/// <summary>
/// Gets the project that this view is associated with.
/// </summary>
public WixProject Project {
get {
return project;
}
set {
project = value;
}
public override object Control {
get { return packageFilesControl; }
}
public bool IsActiveWindow {
get { return Object.ReferenceEquals(workbench.ActiveViewContent, this); }
}
public bool IsForProject(WixProject project)
{
return this.project == project;
}
public override void Load()
@ -75,46 +95,28 @@ namespace ICSharpCode.WixBinding @@ -75,46 +95,28 @@ namespace ICSharpCode.WixBinding
}
public override bool IsDirty {
get {
return packageFilesControl.IsDirty;
}
}
/// <summary>
/// Shows the view for the specified project.
/// </summary>
public static void Show(WixProject project, IWorkbench workbench)
{
PackageFilesView openView = GetOpenPackageFilesView(project, workbench);
if (openView != null) {
openView.WorkbenchWindow.SelectWindow();
} else {
PackageFilesView newView = new PackageFilesView(project);
workbench.ShowView(newView);
newView.ShowFiles();
}
get { return packageFilesControl.IsDirty; }
}
public override void Dispose()
{
if (packageFilesControl != null) {
WorkbenchSingleton.Workbench.ActiveViewContentChanged -= ActiveViewContentChanged;
workbench.ActiveViewContentChanged -= ActiveViewContentChanged;
packageFilesControl.Dispose();
packageFilesControl = null;
}
base.Dispose();
}
public TextReader Create(string fileName)
{
return textFileReader.Create(fileName);
}
public void Write(WixDocument document)
{
if (!UpdateOpenFile(document)) {
ITextEditorProperties properties = SharpDevelopTextEditorProperties.Instance;
document.Save(properties.LineTerminator, properties.ConvertTabsToSpaces, properties.IndentationSize);
ITextEditor openTextEditor = openTextEditors.FindTextEditorForDocument(document);
if (openTextEditor != null) {
UpdateOpenTextEditor(openTextEditor, document);
} else {
using (XmlWriter xmlWriter = wixTextWriter.Create(document.FileName)) {
document.Save(xmlWriter);
}
}
packageFilesControl.IsDirty = false;
}
@ -145,7 +147,7 @@ namespace ICSharpCode.WixBinding @@ -145,7 +147,7 @@ namespace ICSharpCode.WixBinding
public void ShowFiles()
{
packageFilesControl.ShowFiles(project, this, this);
packageFilesControl.ShowFiles(project, new WorkbenchTextFileReader(), this);
}
/// <summary>
@ -157,9 +159,9 @@ namespace ICSharpCode.WixBinding @@ -157,9 +159,9 @@ namespace ICSharpCode.WixBinding
packageFilesControl.AddDirectory();
}
public void ShowDiff()
public void CalculateDiff()
{
packageFilesControl.ShowDiff();
packageFilesControl.CalculateDiff();
}
public void HideDiff()
@ -167,46 +169,13 @@ namespace ICSharpCode.WixBinding @@ -167,46 +169,13 @@ namespace ICSharpCode.WixBinding
packageFilesControl.IsDiffVisible = false;
}
/// <summary>
/// Gets the package files view that is already open and displaying the files
/// for the specified project.
/// </summary>
static PackageFilesView GetOpenPackageFilesView(WixProject project, IWorkbench workbench)
{
foreach (IViewContent view in workbench.ViewContentCollection) {
PackageFilesView packageFilesView = view as PackageFilesView;
if (packageFilesView != null && packageFilesView.Project == project) {
return packageFilesView;
}
}
return null;
}
TextAreaControl GetTextAreaControl(string fileName)
{
ITextEditorControlProvider textEditorControlProvider = FileService.GetOpenFile(fileName) as ITextEditorControlProvider;
if (textEditorControlProvider != null) {
return textEditorControlProvider.TextEditorControl.ActiveTextAreaControl;
}
return null;
}
/// <summary>
/// Merges the changes to the Wix document to the file currently open in
/// SharpDevelop.
/// </summary>
bool UpdateOpenFile(WixDocument wixDocument)
void UpdateOpenTextEditor(ITextEditor textEditor, WixDocument document)
{
TextAreaControl textAreaControl = GetTextAreaControl(packageFilesControl.Document.FileName);
if (textAreaControl != null) {
if (wixDocument.IsProductDocument) {
UpdateOpenFileWithRootDirectoryChanges(wixDocument, textAreaControl);
} else {
// Directory ref.
UpdateOpenFileWithRootDirectoryRefChanges(wixDocument, textAreaControl);
}
if (document.HasProduct) {
UpdateOpenTextEditorWithRootDirectoryChanges(textEditor, document);
} else {
UpdateOpenTextEditorWithRootDirectoryRefChanges(textEditor, document);
}
return false;
}
/// <summary>
@ -221,8 +190,11 @@ namespace ICSharpCode.WixBinding @@ -221,8 +190,11 @@ namespace ICSharpCode.WixBinding
// Set IsDirty to false first since we get another workbench window
// changed event whilst updating the open file. The
// DefaultDocument.Replace method triggers this.
packageFilesControl.IsDirty= false;
UpdateOpenFile(packageFilesControl.Document);
ITextEditor textEditor = openTextEditors.FindTextEditorForDocument(packageFilesControl.Document);
if (textEditor != null) {
UpdateOpenTextEditor(textEditor, packageFilesControl.Document);
packageFilesControl.IsDirty = false;
}
}
reload = true;
} else if (reload && IsActiveWindow) {
@ -231,93 +203,40 @@ namespace ICSharpCode.WixBinding @@ -231,93 +203,40 @@ namespace ICSharpCode.WixBinding
}
}
/// <summary>
/// Checks whether the active window is the Wix document window.
/// </summary>
bool IsWixDocumentWindowActive {
get {
WixDocument document = packageFilesControl.Document;
if (document != null) {
IViewContent view = WorkbenchSingleton.Workbench.ActiveViewContent;
if (view != null) {
return FileUtility.IsEqualFileName(view.PrimaryFileName, document.FileName);
}
}
return false;
}
get { return wixDocumentWindow.IsActive(packageFilesControl.Document); }
}
/// <summary>
/// Checks whether the active window is this window.
/// </summary>
bool IsActiveWindow {
get {
return Object.ReferenceEquals(WorkbenchSingleton.Workbench.ActiveViewContent, this);
}
}
bool UpdateOpenFileWithRootDirectoryChanges(WixDocument wixDocument, TextAreaControl textAreaControl)
void UpdateOpenTextEditorWithRootDirectoryChanges(ITextEditor textEditor, WixDocument document)
{
// Get the xml for the root directory.
WixDirectoryElement rootDirectory = wixDocument.RootDirectory;
string xml = GetWixXml(rootDirectory);
// Find the root directory location.
bool updated = ReplaceElement(rootDirectory.Id, WixDirectoryElement.DirectoryElementName, textAreaControl, xml);
if (updated) {
return true;
WixDirectoryElement rootDirectory = document.GetRootDirectory();
string xml = rootDirectory.GetXml(wixTextWriter);
WixDocumentEditor documentEditor = new WixDocumentEditor(textEditor);
DomRegion region = documentEditor.ReplaceElement(rootDirectory.Id, WixDirectoryElement.DirectoryElementName, xml);
if (!region.IsEmpty) {
return;
}
// Find the product end element location.
IDocument document = textAreaControl.Document;
Location location = WixDocument.GetEndElementLocation(new StringReader(document.TextContent), "Product", wixDocument.Product.GetAttribute("Id"));
XmlElement productElement = document.GetProduct();
StringReader reader = new StringReader(textEditor.Document.Text);
string productId = productElement.GetAttribute("Id");
WixDocumentReader wixReader = new WixDocumentReader(reader);
Location location = wixReader.GetEndElementLocation("Product", productId);
if (!location.IsEmpty) {
// Insert the xml with an extra new line at the end.
ITextEditorProperties properties = SharpDevelopTextEditorProperties.Instance;
WixDocumentEditor documentEditor = new WixDocumentEditor(textAreaControl);
documentEditor.Insert(location.Y, location.X, String.Concat(xml, properties.LineTerminator));
return true;
documentEditor.InsertIndented(location, String.Concat(xml, "\r\n"));
}
return false;
}
bool UpdateOpenFileWithRootDirectoryRefChanges(WixDocument wixDocument, TextAreaControl textAreaControl)
void UpdateOpenTextEditorWithRootDirectoryRefChanges(ITextEditor textEditor, WixDocument document)
{
// Get the xml for the root directory ref.
WixDirectoryRefElement rootDirectoryRef = wixDocument.RootDirectoryRef;
string xml = GetWixXml(rootDirectoryRef);
// Find the root directory ref location.
return ReplaceElement(rootDirectoryRef.Id, WixDirectoryRefElement.DirectoryRefElementName, textAreaControl, xml);
}
/// <summary>
/// Gets the Wix xml for the specified element.
/// </summary>
string GetWixXml(XmlElement element)
{
ITextEditorProperties properties = SharpDevelopTextEditorProperties.Instance;
return WixDocument.GetXml(element, properties.LineTerminator, properties.ConvertTabsToSpaces, properties.IndentationSize);
}
/// <summary>
/// Tries to replace the element defined by element name and its Id attribute in the
/// text editor with the specified xml.
/// </summary>
/// <param name="id">The Id attribute of the element.</param>
/// <param name="elementName">The name of the element.</param>
/// <param name="textAreaControl">The text area control to update.</param>
/// <param name="xml">The replacement xml.</param>
bool ReplaceElement(string id, string elementName, TextAreaControl textAreaControl, string xml)
{
WixDocumentEditor documentEditor = new WixDocumentEditor(textAreaControl);
IDocument document = textAreaControl.Document;
DomRegion region = WixDocument.GetElementRegion(new StringReader(document.TextContent), elementName, id);
if (!region.IsEmpty) {
documentEditor.Replace(region, xml);
return true;
}
return false;
WixDirectoryRefElement rootDirectoryRef = document.GetRootDirectoryRef();
string xml = rootDirectoryRef.GetXml(wixTextWriter);
WixDocumentEditor documentEditor = new WixDocumentEditor(textEditor);
documentEditor.ReplaceElement(rootDirectoryRef.Id, WixDirectoryRefElement.DirectoryRefElementName, xml);
}
}
}

3
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs

@ -140,7 +140,8 @@ namespace ICSharpCode.WixBinding @@ -140,7 +140,8 @@ namespace ICSharpCode.WixBinding
{
WorkbenchTextFileReader workbenchTextFileReader = new WorkbenchTextFileReader();
using (TextReader reader = workbenchTextFileReader.Create(fileName)) {
setupDialogListView.AddDialogs(fileName, WixDocument.GetDialogIds(reader));
WixDocumentReader wixReader = new WixDocumentReader(reader);
setupDialogListView.AddDialogs(fileName, wixReader.GetDialogIds());
}
}

60
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs

@ -5,7 +5,6 @@ @@ -5,7 +5,6 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Refactoring;
using System;
using System.Collections.ObjectModel;
using System.IO;
@ -13,10 +12,10 @@ using System.Xml; @@ -13,10 +12,10 @@ using System.Xml;
using ICSharpCode.FormsDesigner;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.TextEditor;
using ICSharpCode.SharpDevelop.Refactoring;
namespace ICSharpCode.WixBinding
{
@ -88,8 +87,8 @@ namespace ICSharpCode.WixBinding @@ -88,8 +87,8 @@ namespace ICSharpCode.WixBinding
// and text selection operations done by the WiX designer actually
// become visible in the text editor.
if (!this.SourceCodeStorage.ContainsFile(file)) {
TextEditorControl editor = ((ITextEditorControlProvider)this.PrimaryViewContent).TextEditorControl;
this.SourceCodeStorage.AddFile(file, new TextEditorDocument(editor.Document), editor.Encoding ?? ParserService.DefaultFileEncoding, true);
ITextEditor editor = ((ITextEditorProvider)this.PrimaryViewContent).TextEditor;
this.SourceCodeStorage.AddFile(file, editor.Document, ParserService.DefaultFileEncoding, true);
}
try {
@ -120,7 +119,7 @@ namespace ICSharpCode.WixBinding @@ -120,7 +119,7 @@ namespace ICSharpCode.WixBinding
public override bool SupportsSwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView)
{
return newView == this || newView == this.PrimaryViewContent;
return (newView == this) || (newView == this.PrimaryViewContent);
}
public override void SwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView)
@ -132,8 +131,8 @@ namespace ICSharpCode.WixBinding @@ -132,8 +131,8 @@ namespace ICSharpCode.WixBinding
public override bool SupportsSwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
{
return this.DesignerCodeFile != null &&
(oldView == this || oldView == this.PrimaryViewContent);
return (this.DesignerCodeFile != null) &&
((oldView == this) || (oldView == this.PrimaryViewContent));
}
public override void SwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
@ -149,18 +148,14 @@ namespace ICSharpCode.WixBinding @@ -149,18 +148,14 @@ namespace ICSharpCode.WixBinding
/// Gets the Wix document filename.
/// </summary>
public string DocumentFileName {
get {
return this.PrimaryFileName;
}
get { return this.PrimaryFileName; }
}
/// <summary>
/// Gets the wix project containing the document open in the designer.
/// </summary>
public WixProject Project {
get {
return wixProject;
}
get { return wixProject; }
}
/// <summary>
@ -203,9 +198,11 @@ namespace ICSharpCode.WixBinding @@ -203,9 +198,11 @@ namespace ICSharpCode.WixBinding
/// </summary>
string GetDialogIdSelectedInTextEditor()
{
TextAreaControl textArea = ActiveTextAreaControl;
if (textArea != null) {
return WixDocument.GetDialogId(new StringReader(textArea.Document.TextContent), textArea.Caret.Line);
ITextEditor textEditor = ActiveTextEditor;
if (textEditor != null) {
StringReader reader = new StringReader(textEditor.Document.Text);
WixDocumentReader wixReader = new WixDocumentReader(reader);
return wixReader.GetDialogId(textEditor.Caret.Line);
}
return null;
}
@ -215,10 +212,11 @@ namespace ICSharpCode.WixBinding @@ -215,10 +212,11 @@ namespace ICSharpCode.WixBinding
/// </summary>
string GetFirstDialogIdInTextEditor()
{
TextAreaControl textArea = ActiveTextAreaControl;
if (textArea != null) {
StringReader reader = new StringReader(textArea.Document.TextContent);
ReadOnlyCollection<string> ids = WixDocument.GetDialogIds(reader);
ITextEditor textEditor = ActiveTextEditor;
if (textEditor != null) {
StringReader reader = new StringReader(textEditor.Document.Text);
WixDocumentReader wixReader = new WixDocumentReader(reader);
ReadOnlyCollection<string> ids = wixReader.GetDialogIds();
if (ids.Count > 0) {
return ids[0];
}
@ -229,11 +227,11 @@ namespace ICSharpCode.WixBinding @@ -229,11 +227,11 @@ namespace ICSharpCode.WixBinding
/// <summary>
/// Gets the active text area control.
/// </summary>
TextAreaControl ActiveTextAreaControl {
ITextEditor ActiveTextEditor {
get {
ITextEditorControlProvider provider = this.PrimaryViewContent as ITextEditorControlProvider;
ITextEditorProvider provider = this.PrimaryViewContent as ITextEditorProvider;
if (provider != null) {
return provider.TextEditorControl.ActiveTextAreaControl;
return provider.TextEditor;
}
return null;
}
@ -274,10 +272,12 @@ namespace ICSharpCode.WixBinding @@ -274,10 +272,12 @@ namespace ICSharpCode.WixBinding
{
try {
if (dialogId != null) {
TextAreaControl textArea = ActiveTextAreaControl;
if (textArea != null) {
Location location = WixDocument.GetStartElementLocation(new StringReader(textArea.Document.TextContent), "Dialog", dialogId);
textArea.JumpTo(location.Y);
ITextEditor textEditor = ActiveTextEditor;
if (textEditor != null) {
StringReader reader = new StringReader(textEditor.Document.Text);
WixDocumentReader wixReader = new WixDocumentReader(reader);
Location location = wixReader.GetStartElementLocation("Dialog", dialogId);
textEditor.JumpTo(location.Y, 1);
}
}
} catch (XmlException) {
@ -301,9 +301,7 @@ namespace ICSharpCode.WixBinding @@ -301,9 +301,7 @@ namespace ICSharpCode.WixBinding
public override object ToolsContent {
get {
return SetupDialogControlsToolBox;
}
get { return SetupDialogControlsToolBox; }
}
}
}

30
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerDisplayBinding.cs

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
using System;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
@ -19,38 +19,30 @@ namespace ICSharpCode.WixBinding @@ -19,38 +19,30 @@ namespace ICSharpCode.WixBinding
}
public bool ReattachWhenParserServiceIsReady {
get {
return false;
}
get { return false; }
}
/// <summary>
/// Wix dialog designer can attach to Wix source files (.wxs) and
/// Wix include files (.wxi).
/// </summary>
public bool CanAttachTo(IViewContent content)
public bool CanAttachTo(IViewContent view)
{
ITextEditorControlProvider textAreaControlProvider = content as ITextEditorControlProvider;
if (textAreaControlProvider == null) {
return false;
}
string fileName = GetViewContentFileName(content);
if (fileName == null) {
return false;
if (IsViewTextEditorProvider(view)) {
return WixFileName.IsWixFileName(view.PrimaryFileName);
}
return WixDocument.IsWixFileName(fileName);
return false;
}
public IViewContent[] CreateSecondaryViewContent(IViewContent viewContent)
public IViewContent[] CreateSecondaryViewContent(IViewContent view)
{
return new IViewContent[] {new WixDialogDesigner(viewContent)};
return new IViewContent[] {new WixDialogDesigner(view)};
}
static string GetViewContentFileName(IViewContent viewContent)
bool IsViewTextEditorProvider(IViewContent view)
{
return viewContent.PrimaryFileName;
ITextEditorProvider textEditorProvider = view as ITextEditorProvider;
return textEditorProvider != null;
}
}
}

55
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs

@ -18,7 +18,6 @@ using System.Xml; @@ -18,7 +18,6 @@ using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.FormsDesigner;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.TextEditor;
@ -44,30 +43,26 @@ namespace ICSharpCode.WixBinding @@ -44,30 +43,26 @@ namespace ICSharpCode.WixBinding
public class WixDialogDesignerGenerator : IDesignerGenerator, IWixDialogDesignerGenerator
{
FormsDesignerViewContent view;
public WixDialogDesignerGenerator()
{
}
ITextEditor textEditor;
public CodeDomProvider CodeDomProvider {
get {
return new CSharpCodeProvider();
}
get { return new CSharpCodeProvider(); }
}
public FormsDesignerViewContent ViewContent {
get { return this.view; }
get { return view; }
}
public IEnumerable<OpenedFile> GetSourceFiles(out OpenedFile designerCodeFile)
{
designerCodeFile = this.view.PrimaryFile;
designerCodeFile = view.PrimaryFile;
return new [] {designerCodeFile};
}
public void Attach(FormsDesignerViewContent viewContent)
public void Attach(FormsDesignerViewContent view)
{
this.view = viewContent;
this.view = view;
textEditor = ((ITextEditorProvider)view.PrimaryViewContent).TextEditor;
}
public void Detach()
@ -80,20 +75,32 @@ namespace ICSharpCode.WixBinding @@ -80,20 +75,32 @@ namespace ICSharpCode.WixBinding
/// </summary>
void IWixDialogDesignerGenerator.MergeFormChanges(string dialogId, XmlElement dialogElement)
{
// Get the text region we are replacing.
IDocument document = view.DesignerCodeFileDocument;
DomRegion region = WixDocument.GetElementRegion(new StringReader(document.Text), "Dialog", dialogId);
DomRegion region = GetTextEditorRegionForDialogElement(dialogId);
if (region.IsEmpty) {
throw new FormsDesignerLoadException(String.Format(StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}"), dialogId));
ThrowDialogElementCouldNotBeFoundError(dialogId);
}
// Get the replacement dialog xml.
TextEditorControl textEditorControl = ((ITextEditorControlProvider)view.PrimaryViewContent).TextEditorControl;
var properties = textEditorControl.TextEditorProperties;
string replacementXml = WixDocument.GetXml(dialogElement, properties.LineTerminator, properties.ConvertTabsToSpaces, properties.IndentationSize);
// Replace the xml and select the inserted text.
WixDocumentEditor editor = new WixDocumentEditor(textEditorControl.ActiveTextAreaControl);
editor.Replace(region, replacementXml);
WixTextWriter writer = new WixTextWriter(textEditor.Options);
WixDialogElement wixDialogElement = (WixDialogElement)dialogElement;
string newDialogXml = wixDialogElement.GetXml(writer);
WixDocumentEditor editor = new WixDocumentEditor(textEditor);
editor.Replace(region, newDialogXml);
}
DomRegion GetTextEditorRegionForDialogElement(string dialogId)
{
IDocument document = view.DesignerCodeFileDocument;
StringReader reader = new StringReader(document.Text);
WixDocumentReader wixReader = new WixDocumentReader(reader);
return wixReader.GetElementRegion("Dialog", dialogId);
}
void ThrowDialogElementCouldNotBeFoundError(string dialogId)
{
string messageFormat = StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}");
string message = String.Format(messageFormat, dialogId);
throw new FormsDesignerLoadException(message);
}
public void MergeFormChanges(CodeCompileUnit unit)

111
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerLoader.cs

@ -10,6 +10,7 @@ using System.ComponentModel; @@ -10,6 +10,7 @@ using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Security.Permissions;
using System.Windows.Forms;
using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.FormsDesigner;
@ -27,7 +28,7 @@ namespace ICSharpCode.WixBinding @@ -27,7 +28,7 @@ namespace ICSharpCode.WixBinding
IWixDialogDesigner designer;
public WixDialogDesignerLoader(IWixDialogDesigner designer, IWixDialogDesignerGenerator generator)
: this(designer, generator, null)
: this(designer, generator, new DefaultFileLoader())
{
}
@ -42,51 +43,83 @@ namespace ICSharpCode.WixBinding @@ -42,51 +43,83 @@ namespace ICSharpCode.WixBinding
this.fileLoader = fileLoader;
if (designer == null) {
throw new ArgumentException("Cannot be null.", "designer");
throw new ArgumentNullException("designer");
}
if (generator == null) {
throw new ArgumentException("Cannot be null.", "generator");
throw new ArgumentNullException("generator");
}
}
/// <summary>
/// Gets the designer used by the loader.
/// </summary>
public IWixDialogDesigner Designer {
get {
return designer;
}
get { return designer; }
}
/// <summary>
/// Gets the designer generator used by the loader.
/// </summary>
public IWixDialogDesignerGenerator Generator {
get {
return generator;
}
get { return generator; }
}
public override void BeginLoad(IDesignerLoaderHost host)
{
// Check dialog id.
if (designer.DialogId == null) {
throw new FormsDesignerLoadException(StringParser.Parse("${res:ICSharpCode.WixBinding.WixDialogDesigner.NoDialogSelectedInDocumentMessage}"));
}
VerifyDesignerHasDialogId();
// Get dialog element.
GetDialogElement();
VerifyDialogElementFound();
AddServicesToHost(host);
base.BeginLoad(host);
}
void VerifyDesignerHasDialogId()
{
if (DesignerHasDialogId) {
ThrowNoDialogSelectedInDocumentException();
}
}
bool DesignerHasDialogId {
get { return designer.DialogId == null; }
}
void ThrowNoDialogSelectedInDocumentException()
{
string message = StringParser.Parse("${res:ICSharpCode.WixBinding.WixDialogDesigner.NoDialogSelectedInDocumentMessage}");
throw new FormsDesignerLoadException(message);
}
void GetDialogElement()
{
WixDocument document = CreateWixDocument();
document.LoadXml(designer.GetDocumentXml());
wixDialog = document.GetDialog(designer.DialogId, new WorkbenchTextFileReader());
wixDialog = document.CreateWixDialog(designer.DialogId, new WorkbenchTextFileReader());
}
WixDocument CreateWixDocument()
{
WixDocument document = new WixDocument(designer.Project, fileLoader);
document.FileName = designer.DocumentFileName;
return document;
}
void VerifyDialogElementFound()
{
if (wixDialog == null) {
throw new FormsDesignerLoadException(String.Format(StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}"), designer.DialogId));
ThrowDialogIdNotFoundException(designer.DialogId);
}
}
void ThrowDialogIdNotFoundException(string dialogId)
{
string messageFormat = StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}");
string message = String.Format(messageFormat, designer.DialogId);
throw new FormsDesignerLoadException(message);
}
void AddServicesToHost(IDesignerLoaderHost host)
{
host.AddService(typeof(ComponentSerializationService), new CodeDomComponentSerializationService((IServiceProvider)host));
host.AddService(typeof(INameCreationService), new XmlDesignerNameCreationService(host));
host.AddService(typeof(IDesignerSerializationService), new DesignerSerializationService(host));
base.BeginLoad(host);
}
/// <summary>
@ -103,28 +136,24 @@ namespace ICSharpCode.WixBinding @@ -103,28 +136,24 @@ namespace ICSharpCode.WixBinding
/// </summary>
protected override void PerformFlush(IDesignerSerializationManager serializationManager)
{
Form dialog = (Form)base.LoaderHost.RootComponent;
generator.MergeFormChanges(designer.DialogId, wixDialog.UpdateDialogElement(dialog));
XmlElement updatedDialogElement = GenerateNewDialogElementFromDesignedForm();
MergeDialogChangesIntoFullWixDocument(updatedDialogElement);
}
protected override void PerformLoad(IDesignerSerializationManager serializationManager)
XmlElement GenerateNewDialogElementFromDesignedForm()
{
wixDialog.CreateDialog(this);
Form form = (Form)base.LoaderHost.RootComponent;
return wixDialog.UpdateDialogElement(form);
}
WixDocument CreateWixDocument()
void MergeDialogChangesIntoFullWixDocument(XmlElement updatedDialogElement)
{
WixDocument document;
if (fileLoader != null && designer != null) {
document = new WixDocument(designer.Project, fileLoader);
} else if (designer != null) {
document = new WixDocument(designer.Project);
} else {
document = new WixDocument();
}
document.FileName = designer.DocumentFileName;
return document;
generator.MergeFormChanges(designer.DialogId, updatedDialogElement);
}
protected override void PerformLoad(IDesignerSerializationManager serializationManager)
{
wixDialog.CreateDialog(this);
}
}
}

195
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs

@ -6,24 +6,45 @@ @@ -6,24 +6,45 @@
// </file>
using System;
using System.Drawing;
using System.IO;
using System.Text;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.WixBinding
{
/// <summary>
/// A utility class that can replace xml in a Wix document currently open
/// in the text editor.
/// </summary>
/// </summary>
public class WixDocumentEditor
{
TextAreaControl textAreaControl;
ITextEditor textEditor;
IDocument document;
public WixDocumentEditor(TextAreaControl textAreaControl)
public WixDocumentEditor(ITextEditor textEditor)
{
this.textAreaControl = textAreaControl;
this.textEditor = textEditor;
this.document = textEditor.Document;
}
/// <summary>
/// Tries to replace the element defined by element name and its Id attribute in the
/// text editor with the specified xml.
/// </summary>
/// <param name="id">The Id attribute of the element.</param>
/// <param name="elementName">The name of the element.</param>
/// <param name="xml">The replacement xml.</param>
public DomRegion ReplaceElement(string elementAttributeId, string elementName, string replacementXml)
{
WixDocumentReader wixReader = new WixDocumentReader(new StringReader(document.Text));
DomRegion region = wixReader.GetElementRegion(elementName, elementAttributeId);
if (!region.IsEmpty) {
Replace(region, replacementXml);
}
return region;
}
/// <summary>
@ -32,92 +53,146 @@ namespace ICSharpCode.WixBinding @@ -32,92 +53,146 @@ namespace ICSharpCode.WixBinding
/// </summary>
public void Replace(DomRegion region, string xml)
{
IDocument document = textAreaControl.Document;
ISegment segment = WixDocument.ConvertRegionToSegment(document, region);
// Replace the original xml with the new xml and indent it.
int originalLineCount = document.TotalNumberOfLines;
document.Replace(segment.Offset, segment.Length, xml);
int addedLineCount = document.TotalNumberOfLines - originalLineCount;
WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);
// Make sure the text inserted is visible.
textAreaControl.ScrollTo(region.BeginLine);
using (textEditor.Document.OpenUndoGroup()) {
// Indent the xml.
int insertedCharacterCount = IndentLines(textAreaControl.TextArea, region.BeginLine + 1, region.EndLine + addedLineCount, document.FormattingStrategy);
// Replace the original xml with the new xml and indent it.
int originalLineCount = document.TotalNumberOfLines;
int initialIndent = GetIndent(region.BeginLine);
document.Replace(segment.Offset, segment.Length, xml);
int addedLineCount = document.TotalNumberOfLines - originalLineCount;
// Indent the xml.
int insertedCharacterCount = IndentAllLinesTheSame(region.BeginLine + 1, region.EndLine + addedLineCount, initialIndent);
// Select the text just inserted.
int textInsertedLength = insertedCharacterCount + xml.Length;
textEditor.Select(segment.Offset, textInsertedLength);
// Select the text just inserted.
SelectText(textAreaControl.SelectionManager, document, segment.Offset, xml.Length + insertedCharacterCount);
// Make sure the text inserted is visible.
textEditor.JumpTo(region.BeginLine + 1, 1);
textEditor.Caret.Position = document.OffsetToPosition(segment.Offset + textInsertedLength);
}
}
/// <summary>
/// Inserts and indents the xml at the specified location.
/// </summary>
public void Insert(int line, int column, string xml)
public void InsertIndented(Location location, string xml)
{
IDocument document = textAreaControl.Document;
ISegment segment = document.GetLineSegment(line);
// Insert the xml and indent it.
int originalLineCount = document.TotalNumberOfLines;
int offset = segment.Offset + column;
document.Insert(offset, xml);
int addedLineCount = document.TotalNumberOfLines - originalLineCount;
// Make sure the text inserted is visible.
textAreaControl.ScrollTo(line);
// Indent the xml.
int insertedCharacterCount = IndentLines(textAreaControl.TextArea, line, line + addedLineCount, document.FormattingStrategy);
// Select the text just inserted.
SelectText(textAreaControl.SelectionManager, document, offset, xml.Length + insertedCharacterCount);
InsertIndented(location.Y, location.X, xml);
}
/// <summary>
/// Selects the specified text range.
/// Inserts and indents the xml at the specified location.
/// </summary>
static void SelectText(SelectionManager selectionManager, IDocument document, int startOffset, int length)
/// <remarks>
/// Lines and columns are zero based.
/// </remarks>
public void InsertIndented(int line, int column, string xml)
{
selectionManager.ClearSelection();
TextLocation selectionStart = document.OffsetToPosition(startOffset);
TextLocation selectionEnd = document.OffsetToPosition(startOffset + length);
selectionManager.SetSelection(selectionStart, selectionEnd);
using (textEditor.Document.OpenUndoGroup()) {
// Insert the xml and indent it.
IDocumentLine documentLine = document.GetLine(line + 1);
int initialIndent = GetIndent(line);
int offset = documentLine.Offset + column;
int originalLineCount = document.TotalNumberOfLines;
document.Insert(offset, xml);
int addedLineCount = document.TotalNumberOfLines - originalLineCount;
// Indent the xml.
int insertedCharacterCount = IndentLines(line, line + addedLineCount, initialIndent);
// Select the text just inserted.
int textInsertedLength = xml.Length + insertedCharacterCount;
textEditor.Select(offset, textInsertedLength);
// Make sure the text inserted is visible.
textEditor.JumpTo(line + 1, 1);
textEditor.Caret.Position = document.OffsetToPosition(offset + textInsertedLength);
}
}
/// <summary>
/// Indents the lines and returns the total number of extra characters added.
/// </summary>
static int IndentLines(TextArea textArea, int begin, int end, IFormattingStrategy formattingStrategy)
int IndentLines(int begin, int end, int initialIndent)
{
int totalInsertedCharacters = 0;
textArea.Document.UndoStack.StartUndoGroup();
for (int i = begin; i <= end; ++i) {
int existingCharacterCount = GetIndent(textArea, i);
int insertedCharacterCount = formattingStrategy.IndentLine(textArea, i) - existingCharacterCount;
totalInsertedCharacters += insertedCharacterCount;
if ((i == end) || (i == begin)) {
totalInsertedCharacters += IndentLine(i, initialIndent);
} else {
totalInsertedCharacters += IndentLine(i, initialIndent + 1);
}
}
textArea.Document.UndoStack.EndUndoGroup();
return totalInsertedCharacters;
}
int IndentAllLinesTheSame(int begin, int end, int indent)
{
int totalInsertedCharacters = 0;
for (int i = begin; i <= end; ++i) {
totalInsertedCharacters += IndentLine(i, indent);
}
return totalInsertedCharacters;
}
/// <summary>
/// Gets the current indentation for the specified line.
/// </summary>
static int GetIndent(TextArea textArea, int line)
int GetIndent(int line)
{
int indentCount = 0;
string lineText = TextUtilities.GetLineAsString(textArea.Document, line);
int whitespaceCharacterCount = 0;
string lineText = GetLineAsString(line);
foreach (char ch in lineText) {
if (Char.IsWhiteSpace(ch)) {
indentCount++;
whitespaceCharacterCount++;
} else {
break;
}
}
return indentCount;
if (textEditor.Options.ConvertTabsToSpaces) {
return (whitespaceCharacterCount / textEditor.Options.IndentationSize);
}
return whitespaceCharacterCount;
}
string GetLineAsString(int line)
{
IDocumentLine documentLine = document.GetLine(line + 1);
return documentLine.Text;
}
int IndentLine(int line, int howManyIndents)
{
IDocumentLine documentLine = document.GetLine(line + 1);
int offset = documentLine.Offset;
string indentationString = GetIndentationString(howManyIndents);
document.Insert(offset, indentationString);
return indentationString.Length;
}
string GetIndentationString(int howManyIndents)
{
string singleIndent = GetSingleIndentString();
StringBuilder indent = new StringBuilder();
for (int i = 0; i < howManyIndents; ++i) {
indent.Append(singleIndent);
}
return indent.ToString();
}
string GetSingleIndentString()
{
if (textEditor.Options.ConvertTabsToSpaces) {
return new String(' ', textEditor.Options.IndentationSize);
}
return "\t";
}
}
}

34
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentWindow.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
public class WixDocumentWindow
{
IWorkbench workbench;
public WixDocumentWindow(IWorkbench workbench)
{
this.workbench = workbench;
}
public bool IsActive(WixDocument document)
{
if (document != null) {
IViewContent view = workbench.ActiveViewContent;
if (view != null) {
return FileUtility.IsEqualFileName(view.PrimaryFileName, document.FileName);
}
}
return false;
}
}
}

48
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs

@ -17,7 +17,7 @@ using ICSharpCode.SharpDevelop; @@ -17,7 +17,7 @@ using ICSharpCode.SharpDevelop;
namespace ICSharpCode.WixBinding
{
public class WixPackageFilesControl : System.Windows.Forms.UserControl, IWixPackageFilesView
public class WixPackageFilesControl : System.Windows.Forms.UserControl, IWixPackageFilesView, IWixPackageFilesControl
{
bool errorMessageTextBoxVisible;
bool diffVisible;
@ -32,25 +32,19 @@ namespace ICSharpCode.WixBinding @@ -32,25 +32,19 @@ namespace ICSharpCode.WixBinding
InitializeComponent();
diffControl.ContextMenuStrip = MenuService.CreateContextMenu(this, "/AddIns/WixBinding/WixPackageFilesDiffControl/ContextMenu");
}
public delegate void DirtyChangedEventHandler(object source, EventArgs e);
/// <summary>
/// Raised when the files are changed and require saving.
/// </summary>
public event DirtyChangedEventHandler DirtyChanged;
public event EventHandler DirtyChanged;
/// <summary>
/// Gets or sets the error message that will be displayed instead of the
/// property grid.
/// </summary>
public string ErrorMessage {
get {
return errorMessageTextBox.Text;
}
set {
errorMessageTextBox.Text = value;
}
get { return errorMessageTextBox.Text; }
set { errorMessageTextBox.Text = value; }
}
/// <summary>
@ -58,9 +52,7 @@ namespace ICSharpCode.WixBinding @@ -58,9 +52,7 @@ namespace ICSharpCode.WixBinding
/// error message text box replaces the property grid.
/// </summary>
public bool IsErrorMessageTextBoxVisible {
get {
return errorMessageTextBoxVisible;
}
get { return errorMessageTextBoxVisible; }
set {
errorMessageTextBoxVisible = value;
if (value) {
@ -75,9 +67,7 @@ namespace ICSharpCode.WixBinding @@ -75,9 +67,7 @@ namespace ICSharpCode.WixBinding
/// Shows or hides the diff panel.
/// </summary>
public bool IsDiffVisible {
get {
return diffVisible;
}
get { return diffVisible; }
set {
if (diffVisible != value) {
diffVisible = value;
@ -94,9 +84,7 @@ namespace ICSharpCode.WixBinding @@ -94,9 +84,7 @@ namespace ICSharpCode.WixBinding
/// Gets the project that is currently being displayed.
/// </summary>
public WixProject Project {
get {
return project;
}
get { return project; }
}
/// <summary>
@ -120,9 +108,7 @@ namespace ICSharpCode.WixBinding @@ -120,9 +108,7 @@ namespace ICSharpCode.WixBinding
}
public bool IsDirty {
get {
return dirty;
}
get { return dirty; }
set {
bool oldValue = dirty;
dirty = value;
@ -149,9 +135,7 @@ namespace ICSharpCode.WixBinding @@ -149,9 +135,7 @@ namespace ICSharpCode.WixBinding
}
public XmlElement SelectedElement {
get {
return packageFilesTreeView.SelectedElement;
}
get { return packageFilesTreeView.SelectedElement; }
set {
packageFilesTreeView.SelectedElement = value;
if (value == null) {
@ -164,9 +148,7 @@ namespace ICSharpCode.WixBinding @@ -164,9 +148,7 @@ namespace ICSharpCode.WixBinding
/// Gets the attributes for the selected xml element.
/// </summary>
public WixXmlAttributeCollection Attributes {
get {
return wixXmlAttributes;
}
get { return wixXmlAttributes; }
}
/// <summary>
@ -179,9 +161,7 @@ namespace ICSharpCode.WixBinding @@ -179,9 +161,7 @@ namespace ICSharpCode.WixBinding
}
public StringCollection AllowedChildElements {
get {
return packageFilesTreeView.AllowedChildElements;
}
get { return packageFilesTreeView.AllowedChildElements; }
}
public void ShowNoRootDirectoryFoundMessage()
@ -297,9 +277,9 @@ namespace ICSharpCode.WixBinding @@ -297,9 +277,9 @@ namespace ICSharpCode.WixBinding
/// Wix document and the files on the file system and displays
/// the results.
/// </summary>
public void ShowDiff()
public void CalculateDiff()
{
editor.ShowDiff();
editor.CalculateDiff();
}
/// <summary>

16
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs

@ -46,18 +46,14 @@ namespace ICSharpCode.WixBinding @@ -46,18 +46,14 @@ namespace ICSharpCode.WixBinding
/// initialized then all the child nodes have been added to this node.
/// </summary>
public bool IsInitialized {
get {
return isInitialized;
}
get { return isInitialized; }
}
/// <summary>
/// Can delete all Wix tree nodes.
/// </summary>
public override bool EnableDelete {
get {
return true;
}
get { return true; }
}
public override void Delete()
@ -70,15 +66,11 @@ namespace ICSharpCode.WixBinding @@ -70,15 +66,11 @@ namespace ICSharpCode.WixBinding
/// Gets the XmlElement associated with this tree node.
/// </summary>
public XmlElement XmlElement {
get {
return element;
}
get { return element; }
}
public WixPackageFilesTreeView WixPackageFilesTreeView {
get {
return (WixPackageFilesTreeView)TreeView;
}
get { return (WixPackageFilesTreeView)TreeView; }
}
/// <summary>

2
src/AddIns/BackendBindings/WixBinding/Project/Src/IFileLoader.cs

@ -21,6 +21,6 @@ namespace ICSharpCode.WixBinding @@ -21,6 +21,6 @@ namespace ICSharpCode.WixBinding
/// <returns>
/// <see langword="null"/> if the file does not exist.
/// </returns>
Bitmap GetBitmap(string fileName);
Bitmap LoadBitmap(string fileName);
}
}

12
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToDirectoryCommand.cs → src/AddIns/BackendBindings/WixBinding/Project/Src/IPackageFilesViewFactory.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
@ -6,16 +6,12 @@ @@ -6,16 +6,12 @@
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
public class AddFilesToDirectoryCommand : AbstractMenuCommand
public interface IPackageFilesViewFactory
{
public override void Run()
{
PackageFilesView.ActiveView.AddFiles();
}
PackageFilesView Create(WixProject project, IWorkbench workbench);
}
}

31
src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPackageFilesControl.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.WixBinding
{
public interface IWixPackageFilesControl : IDisposable
{
event EventHandler DirtyChanged;
bool IsDirty { get; set; }
void Save();
void AddElement(string name);
void RemoveSelectedElement();
void AddFiles();
void AddDirectory();
void ShowFiles(WixProject project, ITextFileReader fileReader, IWixDocumentWriter documentWriter);
void CalculateDiff();
bool IsDiffVisible { get; set; }
WixDocument Document { get; }
}
}

23
src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPropertyValueProvider.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.WixBinding
{
/// <summary>
/// Interface that allows a class to convert a Wix property name into a value.
/// </summary>
public interface IWixPropertyValueProvider
{
/// <summary>
/// Gets the property value for the specified name. Wix property names are
/// case sensitive.
/// </summary>
string GetValue(string name);
}
}

24
src/AddIns/BackendBindings/WixBinding/Project/Src/PackageFilesViewFactory.cs

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
public class PackageFilesViewFactory : IPackageFilesViewFactory
{
public PackageFilesViewFactory()
{
}
public PackageFilesView Create(WixProject project, IWorkbench workbench)
{
return new PackageFilesView(project, workbench);
}
}
}

54
src/AddIns/BackendBindings/WixBinding/Project/Src/Project/WixProject.cs

@ -68,7 +68,7 @@ namespace ICSharpCode.WixBinding @@ -68,7 +68,7 @@ namespace ICSharpCode.WixBinding
{
switch (StartAction) {
case StartAction.Project:
return CreateStartInfo(InstallerFullPath);
return CreateStartInfo(GetInstallerFullPath());
default:
return base.CreateStartInfo();
}
@ -111,49 +111,39 @@ namespace ICSharpCode.WixBinding @@ -111,49 +111,39 @@ namespace ICSharpCode.WixBinding
/// Gets the full path to the installer file that will be generated by
/// the Wix compiler and linker.
/// </summary>
public string InstallerFullPath {
get {
string outputPath = GetEvaluatedProperty("OutputPath") ?? String.Empty;
string outputType = GetEvaluatedProperty("OutputType") ?? String.Empty;
string outputName = GetEvaluatedProperty("OutputName") ?? String.Empty;
string fileName = String.Concat(outputName, GetInstallerExtension(outputType));
return Path.Combine(Path.Combine(Directory, outputPath), fileName);
}
public string GetInstallerFullPath()
{
string outputPath = GetEvaluatedProperty("OutputPath") ?? String.Empty;
string outputType = GetEvaluatedProperty("OutputType") ?? String.Empty;
string outputName = GetEvaluatedProperty("OutputName") ?? String.Empty;
string fileName = String.Concat(outputName, GetInstallerExtension(outputType));
return Path.Combine(Directory, outputPath, fileName);
}
/// <summary>
/// Adds a set of Wix libraries (.wixlib) to the project.
/// </summary>
public void AddWixLibraries(string[] files)
public void AddWixLibraries(string[] fileNames)
{
foreach (string fileName in files) {
foreach (string fileName in fileNames) {
AddWixLibrary(fileName);
}
}
/// <summary>
/// Adds a Wix library (.wixlib) to the project.
/// </summary>
public void AddWixLibrary(string fileName)
{
WixLibraryProjectItem projectItem = new WixLibraryProjectItem(this);
projectItem.FileName = fileName;
ProjectService.AddProjectItem(this, projectItem);
}
/// <summary>
/// Adds a set of Wix extensions to the project.
/// </summary>
public void AddWixExtensions(string[] files)
public void AddWixExtensions(string[] fileNames)
{
foreach (string fileName in files) {
foreach (string fileName in fileNames) {
AddWixExtension(fileName);
}
}
/// <summary>
/// Adds a Wix extension to the project.
/// </summary>
public void AddWixExtension(string fileName)
{
WixExtensionProjectItem projectItem = new WixExtensionProjectItem(this);
@ -166,14 +156,14 @@ namespace ICSharpCode.WixBinding @@ -166,14 +156,14 @@ namespace ICSharpCode.WixBinding
/// their filename.
/// </summary>
public ReadOnlyCollection<FileProjectItem> WixFiles {
get { return GetMatchingFiles(WixDocument.IsWixFileName); }
get { return GetMatchingFiles(WixFileName.IsWixFileName); }
}
/// <summary>
/// Returns the file project items that are Wix source files (.wxs).
/// </summary>
public ReadOnlyCollection<FileProjectItem> WixSourceFiles {
get { return GetMatchingFiles(WixDocument.IsWixSourceFileName); }
get { return GetMatchingFiles(WixFileName.IsWixSourceFileName); }
}
/// <summary>
@ -189,9 +179,7 @@ namespace ICSharpCode.WixBinding @@ -189,9 +179,7 @@ namespace ICSharpCode.WixBinding
/// <remarks>
/// TODO: This can be configuration specific.
/// </remarks>
/// <param name="name">The preprocessor variable name.</param>
/// <returns>An empty string if the name cannot be found.</returns>
public string GetVariable(string name)
public string GetPreprocessorVariableValue(string name)
{
string constants = GetEvaluatedProperty("DefineConstants") ?? String.Empty;
NameValuePairCollection nameValuePairs = new NameValuePairCollection(constants);
@ -201,7 +189,7 @@ namespace ICSharpCode.WixBinding @@ -201,7 +189,7 @@ namespace ICSharpCode.WixBinding
/// <summary>
/// Gets the MSBuild Property value for the given name.
/// </summary>
public string GetValue(string name)
string IWixPropertyValueProvider.GetValue(string name)
{
string propertyValue;
if (MSBuildEngine.MSBuildProperties.TryGetValue(name, out propertyValue)) {
@ -220,10 +208,10 @@ namespace ICSharpCode.WixBinding @@ -220,10 +208,10 @@ namespace ICSharpCode.WixBinding
/// in MSBuildBasedProject is called.</returns>
public override ItemType GetDefaultItemType(string fileName)
{
if (WixDocument.IsWixFileName(fileName))
if (WixFileName.IsWixFileName(fileName)) {
return ItemType.Compile;
else
return base.GetDefaultItemType(fileName);
}
return base.GetDefaultItemType(fileName);
}
/// <summary>

2
src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs

@ -100,7 +100,7 @@ namespace ICSharpCode.WixBinding @@ -100,7 +100,7 @@ namespace ICSharpCode.WixBinding
document.FileName = fileName;
foreach (WixBinaryElement element in document.GetBinaries()) {
if (!binaries.ContainsKey(element.Id)) {
binaries.Add(element.Id, element.FileName);
binaries.Add(element.Id, element.GetFileName());
}
}
} catch (FileNotFoundException) {

36
src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaryElement.cs

@ -11,24 +11,15 @@ using System.Xml; @@ -11,24 +11,15 @@ using System.Xml;
namespace ICSharpCode.WixBinding
{
public class WixBinaryElement : XmlElement
public class WixBinaryElement : WixElementBase
{
public const string BinaryElementName = "Binary";
public WixBinaryElement(WixDocument document)
: base(document.WixNamespacePrefix, BinaryElementName, WixNamespaceManager.Namespace, document)
: base(BinaryElementName, document)
{
}
public string Id {
get {
return GetAttribute("Id");
}
set {
SetAttribute("Id", value);
}
}
public string Source {
get {
if (HasAttribute("SourceFile")) {
@ -44,18 +35,19 @@ namespace ICSharpCode.WixBinding @@ -44,18 +35,19 @@ namespace ICSharpCode.WixBinding
/// <remarks>
/// The full path is generated by using the WixDocument's filename.
/// </remarks>
public string FileName {
get {
WixDocument document = (WixDocument)OwnerDocument;
string binaryFileName = WixPropertyParser.Parse(Source, document);
// If we have the Wix document filename return the full filename.
string documentFileName = document.FileName;
if (documentFileName.Length > 0) {
return Path.Combine(Path.GetDirectoryName(documentFileName), binaryFileName);
}
return binaryFileName;
public string GetFileName()
{
string relativeFileName = WixPropertyParser.Parse(Source, OwnerWixDocument);
return GetFullPath(relativeFileName);
}
string GetFullPath(string relativeFileName)
{
string documentFileName = OwnerWixDocument.FileName;
if (!String.IsNullOrEmpty(documentFileName)) {
return Path.Combine(Path.GetDirectoryName(documentFileName), relativeFileName);
}
return relativeFileName;
}
}
}

148
src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs

@ -12,12 +12,12 @@ using System.Xml; @@ -12,12 +12,12 @@ using System.Xml;
namespace ICSharpCode.WixBinding
{
public class WixComponentElement : XmlElement
public class WixComponentElement : WixElementBase
{
public const string ComponentElementName = "Component";
public WixComponentElement(WixDocument document)
: base(document.WixNamespacePrefix, ComponentElementName, WixNamespaceManager.Namespace, document)
: base(ComponentElementName, document)
{
}
@ -26,76 +26,59 @@ namespace ICSharpCode.WixBinding @@ -26,76 +26,59 @@ namespace ICSharpCode.WixBinding
set { SetAttribute("Guid", value); }
}
public string Id {
get { return GetAttribute("Id"); }
set { SetAttribute("Id", value); }
}
public string DiskId {
get { return GetAttribute("DiskId"); }
set { SetAttribute("DiskId", value); }
}
/// <summary>
/// Checks whether the disk id has already been set for this component.
/// </summary>
public bool HasDiskId {
get { return HasAttribute("DiskId"); }
}
/// <summary>
/// Generates a new guid for this component element.
/// </summary>
public void GenerateNewGuid()
{
Guid = System.Guid.NewGuid().ToString().ToUpperInvariant();
}
public WixFileElement[] GetFiles()
{
List<WixFileElement> files = new List<WixFileElement>();
foreach (XmlNode childNode in ChildNodes) {
WixFileElement childElement = childNode as WixFileElement;
if (childElement != null) {
files.Add(childElement);
}
}
return files.ToArray();
}
/// <summary>
/// Creates a new file element with the specified filename.
/// </summary>
public WixFileElement AddFile(string fileName)
{
WixFileElement fileElement = new WixFileElement(this, fileName);
return (WixFileElement)AppendChild(fileElement);
AppendChild(fileElement);
return fileElement;
}
/// <summary>
/// Creates an id from the filename.
/// </summary>
/// <remarks>
/// Takes the filename, removes all periods, and
/// capitalises the first character and first extension character.
/// </remarks>
/// <param name="document">The Wix document is used to make sure the
/// id generated is unique for that document.</param>
/// <param name="fileName">The full filename including the directory to
/// use when generating the id.</param>
public static string GenerateIdFromFileName(WixDocument document, string fileName)
public void GenerateUniqueIdFromFileName(string fileName)
{
string id = GenerateIdFromFileName(fileName);
if (!document.ComponentIdExists(id)) {
return id;
Id = GenerateIdFromFileName(fileName);
if (!OwnerWixDocument.ComponentIdExists(Id)) {
return;
}
// Add the parent folder to the id.
string parentDirectory = WixDirectoryElement.GetLastDirectoryName(Path.GetDirectoryName(fileName));
parentDirectory = FirstCharacterToUpperInvariant(parentDirectory);
parentDirectory = WixFileElement.GenerateId(parentDirectory).Replace(".", String.Empty);
id = String.Concat(parentDirectory, id);
if (!document.ComponentIdExists(id)) {
return id;
Id = GenerateIdFromParentDirectoryAndFileName(fileName, Id);
if (!OwnerWixDocument.ComponentIdExists(Id)) {
return;
}
// Add a number to the end until we generate a unique id.
int count = 0;
string baseId = id;
do {
++count;
id = String.Concat(baseId, count);
} while (document.ComponentIdExists(id));
return id;
Id = GenerateUniqueIdByAppendingNumberToEnd(Id);
}
/// <summary>
@ -105,44 +88,77 @@ namespace ICSharpCode.WixBinding @@ -105,44 +88,77 @@ namespace ICSharpCode.WixBinding
/// Takes the filename, removes all periods, and
/// capitalises the first character and first extension character.
/// </remarks>
public static string GenerateIdFromFileName(string fileName)
public string GenerateIdFromFileName(string fileName)
{
string fileNameWithoutExtension = UpperCaseFirstCharacterOfFileNameWithoutExtension(fileName);
fileNameWithoutExtension = RemoveDotCharacters(fileNameWithoutExtension);
string extension = GetFileExtensionWithoutDotCharacter(fileName);
extension = UpperCaseFirstCharacter(extension);
string modifiedFileName = String.Concat(fileNameWithoutExtension, extension);
return WixFileElement.GenerateId(modifiedFileName);
}
string UpperCaseFirstCharacterOfFileNameWithoutExtension(string fileName)
{
string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName);
string idStart = String.Empty;
if (fileNameNoExtension.Length > 0) {
idStart = FirstCharacterToUpperInvariant(fileNameNoExtension).Replace(".", String.Empty);
return UpperCaseFirstCharacter(fileNameNoExtension);
}
// Remove period from extension and uppercase first extension char.
return String.Empty;
}
string GetFileExtensionWithoutDotCharacter(string fileName)
{
string extension = Path.GetExtension(fileName);
string idEnd = String.Empty;
if (extension.Length > 1) {
idEnd = FirstCharacterToUpperInvariant(extension.Substring(1));
if (!String.IsNullOrEmpty(extension)) {
return extension.Substring(1);
}
return WixFileElement.GenerateId(String.Concat(idStart, idEnd));
return String.Empty;
}
/// <summary>
/// Gets any child file elements.
/// </summary>
public WixFileElement[] GetFiles()
string UpperCaseFirstCharacter(string s)
{
List<WixFileElement> files = new List<WixFileElement>();
foreach (XmlNode childNode in ChildNodes) {
WixFileElement childElement = childNode as WixFileElement;
if (childElement != null) {
files.Add(childElement);
}
if (!String.IsNullOrEmpty(s)) {
string firstCharacter = s.Substring(0, 1);
string restOfString = s.Substring(1);
return String.Concat(firstCharacter.ToUpperInvariant(), restOfString);
}
return files.ToArray();
return String.Empty;
}
/// <summary>
/// Upper cases first character of string.
/// </summary>
static string FirstCharacterToUpperInvariant(string s)
string GenerateIdFromParentDirectoryAndFileName(string fileName, string idGeneratedFromFileName)
{
return String.Concat(s.Substring(0, 1).ToUpperInvariant(), s.Substring(1));
string id = GenerateIdFromParentDirectory(fileName);
return String.Concat(id, idGeneratedFromFileName);
}
string GenerateIdFromParentDirectory(string fileName)
{
string fullParentDirectory = Path.GetDirectoryName(fileName);
string lastFolder = WixDirectoryElement.GetLastFolderInDirectoryName(fullParentDirectory);
string id = UpperCaseFirstCharacter(lastFolder);
id = WixFileElement.GenerateId(id);
id = RemoveDotCharacters(id);
return id;
}
string RemoveDotCharacters(string text)
{
return text.Replace(".", String.Empty);
}
string GenerateUniqueIdByAppendingNumberToEnd(string id)
{
int count = 0;
string baseId = id;
do {
++count;
id = String.Concat(baseId, count);
} while (OwnerWixDocument.ComponentIdExists(id));
return id;
}
}
}

8
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs

@ -52,8 +52,8 @@ namespace ICSharpCode.WixBinding @@ -52,8 +52,8 @@ namespace ICSharpCode.WixBinding
/// </summary>
/// <param name="dialogElement">The dialog XML element loaded from
/// the Wix document</param>
public WixDialog(WixDocument document, XmlElement dialogElement) :
this(document, dialogElement, null)
public WixDialog(WixDocument document, XmlElement dialogElement)
: this(document, dialogElement, null)
{
}
@ -1141,9 +1141,9 @@ namespace ICSharpCode.WixBinding @@ -1141,9 +1141,9 @@ namespace ICSharpCode.WixBinding
{
if (binaries != null) {
string fileName = binaries.GetBinaryFileName(id);
return document.GetBitmapFromFileName(fileName);
return document.LoadBitmapWithFileName(fileName);
}
return document.GetBitmapFromId(id);
return document.LoadBitmapWithId(id);
}
static string XmlEncode(string item)

22
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialogElement.cs

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Xml;
namespace ICSharpCode.WixBinding
{
public class WixDialogElement : WixElementBase
{
public const string DialogElementName = "Dialog";
public WixDialogElement(WixDocument document)
: base(DialogElementName, document)
{
}
}
}

17
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs

@ -24,18 +24,10 @@ namespace ICSharpCode.WixBinding @@ -24,18 +24,10 @@ namespace ICSharpCode.WixBinding
{
}
/// <summary>
/// Determines whether the specified element name refers to a Directory element.
/// </summary>
public static bool IsDirectoryElement(string name)
{
return name == DirectoryElementName;
}
/// <summary>
/// Returns the last directory specified in the path
/// </summary>
public static string GetLastDirectoryName(string path)
public static string GetLastFolderInDirectoryName(string path)
{
int index = path.LastIndexOf(Path.DirectorySeparatorChar);
return path.Substring(index + 1);
@ -55,12 +47,13 @@ namespace ICSharpCode.WixBinding @@ -55,12 +47,13 @@ namespace ICSharpCode.WixBinding
/// <summary>
/// Adds a new component element to this directory element.
/// </summary>
public WixComponentElement AddComponent(string id)
public WixComponentElement AddComponent(string fileName)
{
WixComponentElement componentElement = new WixComponentElement((WixDocument)OwnerDocument);
componentElement.GenerateUniqueIdFromFileName(fileName);
componentElement.GenerateNewGuid();
componentElement.Id = id;
return (WixComponentElement)AppendChild(componentElement);
AppendChild(componentElement);
return componentElement;
}
public string SourceName {

18
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs

@ -17,18 +17,13 @@ namespace ICSharpCode.WixBinding @@ -17,18 +17,13 @@ namespace ICSharpCode.WixBinding
/// Common base class for the WixDirectoryElement and WixDirectoryRefElement
/// classes.
/// </summary>
public abstract class WixDirectoryElementBase : XmlElement
public abstract class WixDirectoryElementBase : WixElementBase
{
public WixDirectoryElementBase(string localName, WixDocument document)
: base(document.WixNamespacePrefix, localName, WixNamespaceManager.Namespace, document)
: base(localName, document)
{
}
public string Id {
get { return GetAttribute("Id"); }
set { SetAttribute("Id", value); }
}
/// <summary>
/// Gets any child directory elements.
/// </summary>
@ -38,9 +33,7 @@ namespace ICSharpCode.WixBinding @@ -38,9 +33,7 @@ namespace ICSharpCode.WixBinding
foreach (XmlNode childNode in ChildNodes) {
WixDirectoryElement childElement = childNode as WixDirectoryElement;
if (childElement != null) {
if (WixDirectoryElement.IsDirectoryElement(childElement.LocalName)) {
directories.Add(childElement);
}
directories.Add(childElement);
}
}
return directories.ToArray();
@ -70,7 +63,8 @@ namespace ICSharpCode.WixBinding @@ -70,7 +63,8 @@ namespace ICSharpCode.WixBinding
WixDirectoryElement directoryElement = new WixDirectoryElement((WixDocument)OwnerDocument);
directoryElement.Id = WixFileElement.GenerateId(name);
directoryElement.DirectoryName = name;
return (WixDirectoryElement)AppendChild(directoryElement);
}
AppendChild(directoryElement);
return directoryElement;
}
}
}

708
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs

@ -16,7 +16,7 @@ using System.Xml; @@ -16,7 +16,7 @@ using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.XmlEditor;
namespace ICSharpCode.WixBinding
@ -25,64 +25,19 @@ namespace ICSharpCode.WixBinding @@ -25,64 +25,19 @@ namespace ICSharpCode.WixBinding
/// A Wix document (.wxs or .wxi).
/// </summary>
public class WixDocument : XmlDocument, IWixPropertyValueProvider
{
public const string WixSourceFileExtension = ".wxs";
public const string WixIncludeFileExtension = ".wxi";
/// <summary>
/// Class used to store the line number and dialog id of the
/// dialog element start tag.
/// </summary>
class DialogStartElement
{
int line = -1;
string id = String.Empty;
public DialogStartElement(int line, string id)
{
this.id = id;
this.line = line;
}
public int Line {
get {
return line;
}
}
public string Id {
get {
return id;
}
}
}
/// <summary>
/// Default IFileLoader implementation which tries to load
/// the bitmap from the specified filename. If the file does
/// not exist the bitmap is not loaded.
/// </summary>
class FileLoader : IFileLoader
{
public Bitmap GetBitmap(string fileName)
{
if (File.Exists(fileName)) {
return new Bitmap(fileName);
}
return null;
}
}
{
WixNamespaceManager namespaceManager;
IFileLoader fileLoader;
WixProject project;
string fileName = String.Empty;
public WixDocument() : this((WixProject)null)
public WixDocument()
: this((WixProject)null)
{
}
public WixDocument(WixProject project) : this(project, new FileLoader())
public WixDocument(WixProject project)
: this(project, new DefaultFileLoader())
{
}
@ -94,411 +49,82 @@ namespace ICSharpCode.WixBinding @@ -94,411 +49,82 @@ namespace ICSharpCode.WixBinding
{
this.project = project;
this.fileLoader = fileLoader;
if (fileLoader == null) {
throw new ArgumentException("Cannot be null.", "fileLoader");
throw new ArgumentNullException("fileLoader");
}
namespaceManager = new WixNamespaceManager(NameTable);
}
/// <summary>
/// Gets the project that this document belongs to.
/// </summary>
public WixProject Project {
get {
return project;
}
get { return project; }
}
/// <summary>
/// Gets or sets the filename for the Wix Document.
/// </summary>
public string FileName {
get {
return fileName;
}
set {
fileName = value;
}
get { return fileName; }
set { fileName = value; }
}
/// <summary>
/// Gets the dialogs from a Wix file.
/// </summary>
public static ReadOnlyCollection<string> GetDialogIds(string fileName)
{
using (XmlTextReader reader = new XmlTextReader(new FileStream(fileName, FileMode.Open, FileAccess.Read))) {
return GetDialogIds(reader);
}
}
/// <summary>
/// Gets the dialogs from a Wix file.
/// </summary>
public static ReadOnlyCollection<string> GetDialogIds(TextReader reader)
{
XmlTextReader xmlReader = new XmlTextReader(reader);
return GetDialogIds(xmlReader);
}
/// <summary>
/// Gets the dialog Ids in a Wix file.
/// </summary>
public static ReadOnlyCollection<string> GetDialogIds(XmlTextReader reader)
{
using (reader) {
List<string> dialogIds = new List<string>();
object dialogElementName = reader.NameTable.Add("Dialog");
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
if (IsElementMatch(dialogElementName, reader.LocalName)) {
AddDialogId(reader, dialogIds);
}
break;
}
}
return new ReadOnlyCollection<string>(dialogIds);
}
}
/// <summary>
/// Gets the line and column where the specified element starts. The column
/// returned is the column containing the opening tag (&lt;).
/// </summary>
/// <param name="name">The element name.</param>
/// <param name="id">The id attribute value.</param>
public static Location GetStartElementLocation(TextReader reader, string name, string id)
{
XmlTextReader xmlReader = new XmlTextReader(reader);
return GetStartElementLocation(xmlReader, name, id);
}
/// <summary>
/// Gets the line and column where the specified element starts. The column
/// returned is the column containing the opening tag (&lt;).
/// </summary>
/// <param name="name">The element name.</param>
/// <param name="id">The id attribute value.</param>
public static Location GetStartElementLocation(XmlTextReader reader, string name, string id)
{
using (reader) {
object elementName = reader.NameTable.Add(name);
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
if (IsElementMatch(elementName, reader.LocalName)) {
Location location = GetStartElementLocationIfMatch(reader, id);
if (!location.IsEmpty) {
return location;
}
}
break;
}
}
}
return Location.Empty;
}
/// <summary>
/// Gets the line and column where the specified element ends. The column
/// returned is the column containing the opening tag (&lt;) of the end element.
/// </summary>
/// <param name="name">The element name.</param>
/// <param name="id">The id attribute value.</param>
public static Location GetEndElementLocation(TextReader reader, string name, string id)
{
XmlTextReader xmlReader = new XmlTextReader(reader);
return GetEndElementLocation(xmlReader, name, id);
}
/// <summary>
/// Gets the line and column where the specified element ends. The column
/// returned is the column containing the opening tag (&lt;) of the end element.
/// </summary>
/// <param name="name">The element name.</param>
/// <param name="id">The id attribute value.</param>
public static Location GetEndElementLocation(XmlTextReader reader, string name, string id)
{
using (reader) {
bool startElementFound = false;
object elementName = reader.NameTable.Add(name);
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
if (IsElementMatch(elementName, reader.LocalName)) {
Location location = GetStartElementLocationIfMatch(reader, id);
startElementFound = !location.IsEmpty;
}
break;
case XmlNodeType.EndElement:
if (startElementFound) {
if (IsElementMatch(elementName, reader.LocalName)) {
// Take off an extra 2 from the line position so we get the
// correct column for the < tag rather than the element name.
return new Location(reader.LinePosition - 3, reader.LineNumber - 1);
}
}
break;
}
}
}
return Location.Empty;
}
/// <summary>
/// Gets the dialog id at the specified line.
/// </summary>
/// <param name="index">Line numbers start from zero.</param>
/// <returns>The dialog id found at the specified line;
/// <see langword="null"/> if no dialog found.</returns>
public static string GetDialogId(TextReader reader, int line)
{
XmlTextReader xmlReader = new XmlTextReader(reader);
return GetDialogId(xmlReader, line);
}
/// <summary>
/// Gets the dialog id at the specified line.
/// Gets a WixDialog object for the specified dialog id.
/// </summary>
/// <param name="index">Line numbers start from zero.</param>
/// <returns>The dialog id found at the specified line;
/// <see langword="null"/> if no dialog found.</returns>
public static string GetDialogId(XmlTextReader reader, int line)
public WixDialog CreateWixDialog(string id, ITextFileReader reader)
{
// Add one to line since XmlTextReader line numbers start from one.
++line;
DialogStartElement dialogStartElement = null;
using (reader) {
object dialogElementName = reader.NameTable.Add("Dialog");
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
if (IsElementMatch(dialogElementName, reader.LocalName)) {
if (line < reader.LineNumber) {
return null;
} else if (line == reader.LineNumber) {
return GetIdFromCurrentNode(reader);
} else if (reader.IsStartElement()) {
dialogStartElement = new DialogStartElement(reader.LineNumber, GetIdFromCurrentNode(reader));
}
}
break;
case XmlNodeType.EndElement:
if (IsElementMatch(dialogElementName, reader.LocalName)) {
if (line > dialogStartElement.Line && line <= reader.LineNumber) {
return dialogStartElement.Id;
}
}
break;
}
}
XmlElement dialogElement = GetDialogElement(id);
if (dialogElement != null) {
return new WixDialog(this, dialogElement, new WixBinaries(this, reader));
}
return null;
}
/// <summary>
/// Checks the file extension to see if the file is a Wix file. The file
/// can either be a Wix source file (.wxs) or a Wix include file (.wxi).
/// </summary>
public static bool IsWixFileName(string fileName)
{
if (fileName == null) {
return false;
}
string extension = Path.GetExtension(fileName.ToLowerInvariant());
switch (extension) {
case WixSourceFileExtension:
return true;
case WixIncludeFileExtension:
return true;
}
return false;
}
/// <summary>
/// Checks whether the file extension is for a Wix source file (.wxs).
/// </summary>
public static bool IsWixSourceFileName(string fileName)
{
return String.Compare(Path.GetExtension(fileName), WixSourceFileExtension, true) == 0;
}
/// <summary>
/// Converts a DomRegion to an ISegment for the given document.
/// </summary>
public static ISegment ConvertRegionToSegment(IDocument document, DomRegion region)
XmlElement GetDialogElement(string id)
{
// Single line region
if (region.BeginLine == region.EndLine) {
ICSharpCode.TextEditor.Document.LineSegment documentSegment = document.GetLineSegment(region.BeginLine);
return new WixDocumentLineSegment(documentSegment.Offset + region.BeginColumn,
region.EndColumn + 1 - region.BeginColumn);
}
// Multiple line region.
int length = 0;
int startOffset = 0;
for (int line = region.BeginLine; line <= region.EndLine; ++line) {
ICSharpCode.TextEditor.Document.LineSegment currentSegment = document.GetLineSegment(line);
if (line == region.BeginLine) {
length += currentSegment.TotalLength - region.BeginColumn;
startOffset = currentSegment.Offset + region.BeginColumn;
} else if (line < region.EndLine) {
length += currentSegment.TotalLength;
} else {
length += region.EndColumn + 1;
}
}
return new WixDocumentLineSegment(startOffset, length);
string xpath = GetXPath("//w:Dialog[@Id='{0}']", id);
return (XmlElement)SelectSingleElement(xpath);
}
/// <summary>
/// Creates an XML fragment string for the specified element.
/// </summary>
/// <param name="lineTerminator">The line terminator.</param>
/// <param name="tabsToSpaces">Indicates whether tabs will be converted to spaces.</param>
/// <param name="tabIndent">The indent to be used when converting tabs to spaces.</param>
/// <returns>An XML fragment string without any Wix namespace attributes.</returns>
public static string GetXml(XmlElement element, string lineTerminator, bool tabsToSpaces, int tabIndent)
string GetXPath(string xpathFormat, string arg)
{
StringBuilder xml = new StringBuilder();
StringWriter stringWriter = new StringWriter(xml);
XmlWriterSettings xmlWriterSettings = CreateXmlWriterSettings(lineTerminator, tabsToSpaces, tabIndent);
using (XmlWriter xmlWriter = XmlTextWriter.Create(stringWriter, xmlWriterSettings)) {
element.WriteTo(xmlWriter);
}
return xml.ToString().Replace(String.Concat(" xmlns=\"", WixNamespaceManager.Namespace, "\""), String.Empty);;
return String.Format(xpathFormat, XmlEncode(arg));
}
/// <summary>
/// Gets the region (start line, column to end line, column) of the xml
/// element that has the specified id. This includes the start and end tags, the start column is the column
/// containing the start tag and the end column is the column containing the final
/// end tag marker.
/// </summary>
/// <param name="name">The name of the element.</param>
/// <param name="id">The id attribute value of the element.</param>
public static DomRegion GetElementRegion(TextReader reader, string name, string id)
string GetXPath(string xpathFormat, string arg1, string arg2)
{
XmlTextReader xmlTextReader = new XmlTextReader(reader);
return GetElementRegion(xmlTextReader, name, id);
return String.Format(xpathFormat, XmlEncode(arg1), XmlEncode(arg2));
}
/// <summary>
/// Gets the region (start line, column to end line, column) of the xml
/// element that has the specified id. This includes the start and end tags, the start column is the column
/// containing the start tag and the end column is the column containing the final
/// end tag marker.
/// </summary>
/// <param name="name">The name of the element.</param>
/// <param name="id">The id attribute value of the element.</param>
public static DomRegion GetElementRegion(XmlTextReader reader, string name, string id)
string XmlEncode(string item)
{
Location startLocation = Location.Empty;
using (reader) {
int nestedElementsCount = -1;
object elementName = reader.NameTable.Add(name);
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
if (IsElementMatch(elementName, reader.LocalName)) {
if (nestedElementsCount == -1) {
bool isEmptyElement = reader.IsEmptyElement;
startLocation = GetStartElementLocationIfMatch(reader, id);
if (!startLocation.IsEmpty) {
nestedElementsCount = 0;
if (isEmptyElement) {
Location endLocation = GetEmptyElementEnd(reader);
return DomRegion.FromLocation(startLocation, endLocation);
}
}
} else if (!reader.IsEmptyElement) {
++nestedElementsCount;
}
}
break;
case XmlNodeType.EndElement:
if (!startLocation.IsEmpty && IsElementMatch(elementName, reader.LocalName)) {
if (nestedElementsCount == 0) {
Location endLocation = GetEndElementEnd(reader);
return DomRegion.FromLocation(startLocation, endLocation);
}
--nestedElementsCount;
}
break;
}
}
}
return DomRegion.Empty;
char quoteChar = '\'';
return XmlEncoder.Encode(item, quoteChar);
}
/// <summary>
/// Gets a WixDialog object for the specified dialog id.
/// </summary>
/// <param name="id">The id of the dialog.</param>
/// <returns>A <see cref="WixDialog"/> for the dialog id
/// found; otherwise <see langword="null"/> if no dialog
/// with the specified id can be found.</returns>
public WixDialog GetDialog(string id)
XmlElement SelectSingleElement(string xpath)
{
XmlElement dialogElement = GetDialogElement(id);
if (dialogElement != null) {
return new WixDialog(this, dialogElement);
}
return null;
return (XmlElement)SelectSingleNode(xpath, namespaceManager);
}
/// <summary>
/// Gets a WixDialog object for the specified dialog id.
/// </summary>
/// <param name="id">The id of the dialog.</param>
/// <param name="reader">The text file reader to use when looking up
/// binary filenames.</param>
/// <returns>A <see cref="WixDialog"/> for the dialog id
/// found; otherwise <see langword="null"/> if no dialog
/// with the specified id can be found.</returns>
public WixDialog GetDialog(string id, ITextFileReader reader)
public Bitmap LoadBitmapWithId(string id)
{
XmlElement dialogElement = GetDialogElement(id);
if (dialogElement != null) {
return new WixDialog(this, dialogElement, new WixBinaries(this, reader));
}
return null;
string bitmapFileName = GetBinaryFileName(id);
return LoadBitmapWithFileName(bitmapFileName);
}
/// <summary>
/// Gets the binary filename for the specified id.
/// </summary>
/// <returns><see langword="null"/> if the id cannot be found.</returns>
public string GetBinaryFileName(string id)
{
string xpath = String.Concat("//w:Binary[@Id='", XmlEncode(id), "']");
WixBinaryElement binaryElement = (WixBinaryElement)SelectSingleNode(xpath, namespaceManager);
string xpath = GetXPath("//w:Binary[@Id='{0}']", id);
WixBinaryElement binaryElement = (WixBinaryElement)SelectSingleElement(xpath);
if (binaryElement != null) {
return binaryElement.FileName;
return binaryElement.GetFileName();
}
return null;
}
/// <summary>
/// Loads the bitmap using the Wix Bitmap id.
/// </summary>
public Bitmap GetBitmapFromId(string id)
{
string bitmapFileName = GetBinaryFileName(id);
return GetBitmapFromFileName(bitmapFileName);
}
/// <summary>
/// Loads the bitmap.
/// </summary>
public Bitmap GetBitmapFromFileName(string fileName)
public Bitmap LoadBitmapWithFileName(string fileName)
{
if (fileName != null) {
return fileLoader.GetBitmap(fileName);
return fileLoader.LoadBitmap(fileName);
}
return null;
}
@ -506,24 +132,20 @@ namespace ICSharpCode.WixBinding @@ -506,24 +132,20 @@ namespace ICSharpCode.WixBinding
/// <summary>
/// Gets a property value defined in the Wix document.
/// </summary>
/// <returns>The property value if it is found; an empty string otherwise.</returns>
public string GetProperty(string name)
{
string xpath = String.Concat("//w:Property[@Id='", XmlEncode(name), "']");
XmlElement textStyleElement = (XmlElement)SelectSingleNode(xpath, namespaceManager);
string xpath = GetXPath("//w:Property[@Id='{0}']", name);
XmlElement textStyleElement = SelectSingleElement(xpath);
if (textStyleElement != null) {
return textStyleElement.InnerText;
}
return String.Empty;
}
/// <summary>
/// Gets the preprocessor variable value from the WixProject.
/// </summary>
public string GetValue(string name)
string IWixPropertyValueProvider.GetValue(string name)
{
if (project != null) {
return project.GetVariable(name);
return project.GetPreprocessorVariableValue(name);
}
return null;
}
@ -531,100 +153,59 @@ namespace ICSharpCode.WixBinding @@ -531,100 +153,59 @@ namespace ICSharpCode.WixBinding
/// <summary>
/// Gets the top SOURCEDIR directory.
/// </summary>
public WixDirectoryElement RootDirectory {
get {
string xpath = String.Concat("//w:Product/w:Directory[@Id='", WixDirectoryElement.RootDirectoryId, "']");
return (WixDirectoryElement)SelectSingleNode(xpath, namespaceManager);
}
public WixDirectoryElement GetRootDirectory()
{
string xpath = GetXPath("//w:Product/w:Directory[@Id='{0}']", WixDirectoryElement.RootDirectoryId);
return (WixDirectoryElement)SelectSingleElement(xpath);
}
/// <summary>
/// Gets a reference to the root directory.
/// </summary>
public WixDirectoryRefElement RootDirectoryRef {
get {
string xpath = String.Concat("//w:DirectoryRef[@Id='", WixDirectoryElement.RootDirectoryId, "']");
return (WixDirectoryRefElement)SelectSingleNode(xpath, namespaceManager);
}
public WixDirectoryRefElement GetRootDirectoryRef()
{
string xpath = GetXPath("//w:DirectoryRef[@Id='{0}']", WixDirectoryElement.RootDirectoryId);
return (WixDirectoryRefElement)SelectSingleElement(xpath);
}
/// <summary>
/// The Wix document contains the Product element.
/// </summary>
public bool IsProductDocument {
get {
return Product != null;
}
public bool HasProduct {
get { return GetProduct() != null; }
}
/// <summary>
/// Gets the prefix used for the Wix namespace.
/// </summary>
public string WixNamespacePrefix {
get {
XmlElement documentElement = DocumentElement;
if (documentElement != null) {
return documentElement.GetPrefixOfNamespace(WixNamespaceManager.Namespace);
}
return String.Empty;
public string GetWixNamespacePrefix()
{
XmlElement documentElement = DocumentElement;
if (documentElement != null) {
return documentElement.GetPrefixOfNamespace(WixNamespaceManager.Namespace);
}
return String.Empty;
}
/// <summary>
/// Adds a new root directory.
/// </summary>
public WixDirectoryElement AddRootDirectory()
{
// Add product element if it does not exist.
XmlElement productElement = Product;
XmlElement productElement = GetProduct();
if (productElement == null) {
productElement = CreateWixElement("Product");
DocumentElement.AppendChild(productElement);
productElement = AddProduct();
}
// Add root directory.
WixDirectoryElement rootDirectory = WixDirectoryElement.CreateRootDirectory(this);
return (WixDirectoryElement)productElement.AppendChild(rootDirectory);
return AddRootDirectoryToProduct(productElement);
}
/// <summary>
/// Creates a new Xml element belonging to the Wix namespace.
/// </summary>
public XmlElement CreateWixElement(string name)
XmlElement AddProduct()
{
return CreateElement(WixNamespacePrefix, name, WixNamespaceManager.Namespace);
XmlElement productElement = CreateWixElement("Product");
DocumentElement.AppendChild(productElement);
return productElement;
}
/// <summary>
/// Saves the document to the location specified by WixDocument.FileName.
/// </summary>
public void Save(string lineTerminator, bool tabsToSpaces, int tabIndent)
WixDirectoryElement AddRootDirectoryToProduct(XmlElement parentProductElement)
{
XmlWriterSettings xmlWriterSettings = CreateXmlWriterSettings(lineTerminator, tabsToSpaces, tabIndent);
using (XmlWriter xmlWriter = XmlTextWriter.Create(fileName, xmlWriterSettings)) {
Save(xmlWriter);
}
}
/// <summary>
/// Gets the Product element.
/// </summary>
public XmlElement Product {
get {
return (XmlElement)SelectSingleNode("w:Wix/w:Product", namespaceManager);
}
WixDirectoryElement rootDirectory = WixDirectoryElement.CreateRootDirectory(this);
return (WixDirectoryElement)parentProductElement.AppendChild(rootDirectory);
}
/// <summary>
/// Gets the binary elements defined in this document.
/// </summary>
public WixBinaryElement[] GetBinaries()
public XmlElement CreateWixElement(string name)
{
List<WixBinaryElement> binaries = new List<WixBinaryElement>();
foreach (WixBinaryElement element in SelectNodes("//w:Binary", namespaceManager)) {
binaries.Add(element);
}
return binaries.ToArray();
return CreateElement(GetWixNamespacePrefix(), name, WixNamespaceManager.Namespace);
}
/// <summary>
@ -644,6 +225,8 @@ namespace ICSharpCode.WixBinding @@ -644,6 +225,8 @@ namespace ICSharpCode.WixBinding
return new WixDirectoryRefElement(this);
case WixBinaryElement.BinaryElementName:
return new WixBinaryElement(this);
case WixDialogElement.DialogElementName:
return new WixDialogElement(this);
}
}
return base.CreateElement(prefix, localName, namespaceURI);
@ -658,6 +241,13 @@ namespace ICSharpCode.WixBinding @@ -658,6 +241,13 @@ namespace ICSharpCode.WixBinding
return ElementIdExists(WixFileElement.FileElementName, id);
}
bool ElementIdExists(string elementName, string id)
{
string xpath = GetXPath("//w:{0}[@Id='{1}']", elementName, id);
XmlNodeList nodes = SelectNodes(xpath, new WixNamespaceManager(NameTable));
return nodes.Count > 0;
}
/// <summary>
/// Checks to see if a Component element exists with the specified id in this
/// document.
@ -673,7 +263,7 @@ namespace ICSharpCode.WixBinding @@ -673,7 +263,7 @@ namespace ICSharpCode.WixBinding
/// </summary>
public string GetFullPath(string relativePath)
{
if (fileName != null && fileName.Length > 0) {
if (!String.IsNullOrEmpty(fileName)) {
string basePath = Path.GetDirectoryName(fileName);
return FileUtility.GetAbsolutePath(basePath, relativePath);
}
@ -686,149 +276,25 @@ namespace ICSharpCode.WixBinding @@ -686,149 +276,25 @@ namespace ICSharpCode.WixBinding
/// </summary>
public string GetRelativePath(string fullPath)
{
if (fileName != null && fileName.Length > 0) {
if (!String.IsNullOrEmpty(fileName)) {
string basePath = Path.GetDirectoryName(fileName);
return FileUtility.GetRelativePath(basePath, fullPath);
}
return fullPath;
}
/// <summary>
/// Reads the dialog id and adds it to the list of dialogs found so far.
/// </summary>
/// <param name="reader">An XmlReader which is currently at the dialog start element.</param>
static void AddDialogId(XmlReader reader, List<string> dialogIds)
public XmlElement GetProduct()
{
string id = GetIdFromCurrentNode(reader);
if (id.Length > 0) {
dialogIds.Add(id);
}
return SelectSingleElement("w:Wix/w:Product");
}
/// <summary>
/// Gets the id for the current element.
/// </summary>
/// <param name="reader">An XmlReader which is currently at the start element.</param>
static string GetIdFromCurrentNode(XmlReader reader)
{
if (reader.MoveToAttribute("Id")) {
if (reader.Value != null) {
return reader.Value;
}
}
return String.Empty;
}
/// <summary>
/// Checks that the atomised element names match.
/// </summary>
static bool IsElementMatch(object elementName, object currentElementName)
{
return elementName == currentElementName;
}
/// <summary>
/// Gets the line and column position if the dialog id matches the dialog
/// element at the current reader position. This returns the column for the
/// starting less than start tag.
/// </summary>
/// <param name="id">A dialog id.</param>
/// <param name="reader">An XmlTextReader currently at the dialog start element.</param>
/// <returns><see langword="null"/> if the dialog id does not match.</returns>
static Location GetStartElementLocationIfMatch(XmlTextReader reader, string id)
{
// Store the column and line position since the call to GetDialogId will
// move to the <Dialog> Id attribute.
int line = reader.LineNumber - 1;
int column = reader.LinePosition - 2; // Take off 2 to so the '<' is located.
if (id == GetIdFromCurrentNode(reader)) {
return new Location(column, line);
}
return Location.Empty;
}
/// <summary>
/// Determines the end of the end element including the final end tag marker
/// (the greater than sign). This method moves the XmlTextReader to the end of
/// the end tag.
/// </summary>
static Location GetEndElementEnd(XmlTextReader reader)
{
reader.ReadEndElement();
int line = reader.LineNumber - 1;
// Take off two as we have moved passed the end tag column.
int column = reader.LinePosition - 2;
// If ReadEndElement has moved to the start of another element
// take off one from the column value otherwise the column
// value includes the start tag of the next element.
if (reader.NodeType == XmlNodeType.Element) {
--column;
}
return new Location(column, line);
}
/// <summary>
/// Determines the end of the empty element including the final end tag marker
/// (the greater than sign). This method moves the XmlTextReader to the end
/// of the element tag.
/// </summary>
static Location GetEmptyElementEnd(XmlTextReader reader)
{
reader.ReadStartElement();
int line = reader.LineNumber - 1;
// Take off two as we have moved passed the end tag
// column.
int column = reader.LinePosition - 2;
return new Location(column, line);
}
/// <summary>
/// Creates an XmlWriterSettings based on the text editor properties.
/// </summary>
static XmlWriterSettings CreateXmlWriterSettings(string lineTerminator, bool tabsToSpaces, int tabIndent)
public WixBinaryElement[] GetBinaries()
{
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.CloseOutput = true;
xmlWriterSettings.Indent = true;
xmlWriterSettings.NewLineChars = lineTerminator;
xmlWriterSettings.OmitXmlDeclaration = true;
if (tabsToSpaces) {
string spaces = " ";
xmlWriterSettings.IndentChars = spaces.PadRight(tabIndent);
} else {
xmlWriterSettings.IndentChars = "\t";
List<WixBinaryElement> binaries = new List<WixBinaryElement>();
foreach (WixBinaryElement element in SelectNodes("//w:Binary", namespaceManager)) {
binaries.Add(element);
}
return xmlWriterSettings;
}
/// <summary>
/// Gets the dialog element with the specified id.
/// </summary>
XmlElement GetDialogElement(string id)
{
string xpath = String.Concat("//w:Dialog[@Id='", XmlEncode(id), "']");
return (XmlElement)SelectSingleNode(xpath, namespaceManager);
}
/// <summary>
/// Checks to see if an element exists with the specified Id attribute.
/// </summary>
bool ElementIdExists(string elementName, string id)
{
string xpath = String.Concat("//w:", elementName, "[@Id='", XmlEncode(id), "']");
XmlNodeList nodes = SelectNodes(xpath, new WixNamespaceManager(NameTable));
return nodes.Count > 0;
}
static string XmlEncode(string item)
{
char quoteChar = '\'';
return XmlEncoder.Encode(item, quoteChar);
return binaries.ToArray();
}
}
}

69
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentLineSegment.cs

@ -6,11 +6,12 @@ @@ -6,11 +6,12 @@
// </file>
using System;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.WixBinding
{
public class WixDocumentLineSegment : ISegment
public class WixDocumentLineSegment
{
int offset;
int length;
@ -22,21 +23,13 @@ namespace ICSharpCode.WixBinding @@ -22,21 +23,13 @@ namespace ICSharpCode.WixBinding
}
public int Offset {
get {
return offset;
}
set {
offset = value;
}
get { return offset; }
set { offset = value; }
}
public int Length {
get {
return length;
}
set {
length = value;
}
get { return length; }
set { length = value; }
}
public override string ToString()
@ -51,10 +44,50 @@ namespace ICSharpCode.WixBinding @@ -51,10 +44,50 @@ namespace ICSharpCode.WixBinding
public override bool Equals(object obj)
{
WixDocumentLineSegment lineSegment = obj as WixDocumentLineSegment;
if (lineSegment == null) return false;
if (this == lineSegment) return true;
return offset == lineSegment.offset && length == lineSegment.length;
WixDocumentLineSegment rhs = obj as WixDocumentLineSegment;
if (rhs != null) {
return (offset == rhs.offset) && (length == rhs.length);
}
return false;
}
public static WixDocumentLineSegment ConvertRegionToSegment(IDocument document, DomRegion region)
{
// Single line region
if (IsSingleLineRegion(region)) {
return ConvertRegionToSingleLineSegment(document, region);
}
return ConvertRegionToMultiLineSegment(document, region);
}
static bool IsSingleLineRegion(DomRegion region)
{
return region.BeginLine == region.EndLine;
}
static WixDocumentLineSegment ConvertRegionToSingleLineSegment(IDocument document, DomRegion region)
{
IDocumentLine documentLine = document.GetLine(region.BeginLine + 1);
return new WixDocumentLineSegment(documentLine.Offset + region.BeginColumn,
region.EndColumn + 1 - region.BeginColumn);
}
static WixDocumentLineSegment ConvertRegionToMultiLineSegment(IDocument document, DomRegion region)
{
int length = 0;
int startOffset = 0;
for (int line = region.BeginLine; line <= region.EndLine; ++line) {
IDocumentLine currentDocumentLine = document.GetLine(line + 1);
if (line == region.BeginLine) {
length += currentDocumentLine.TotalLength - region.BeginColumn;
startOffset = currentDocumentLine.Offset + region.BeginColumn;
} else if (line < region.EndLine) {
length += currentDocumentLine.TotalLength;
} else {
length += region.EndColumn + 1;
}
}
return new WixDocumentLineSegment(startOffset, length);
}
}
}

293
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentReader.cs

@ -0,0 +1,293 @@ @@ -0,0 +1,293 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Xml;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.WixBinding
{
public class WixDocumentReader
{
XmlTextReader reader;
/// <summary>
/// Class used to store the line number and dialog id of the
/// dialog element start tag.
/// </summary>
class DialogStartElement
{
int line = -1;
string id = String.Empty;
public DialogStartElement(int line, string id)
{
this.id = id;
this.line = line;
}
public int Line {
get { return line; }
}
public string Id {
get { return id; }
}
}
public WixDocumentReader(TextReader textReader)
{
reader = new XmlTextReader(textReader);
}
public ReadOnlyCollection<string> GetDialogIds()
{
using (reader) {
List<string> dialogIds = new List<string>();
object dialogElementName = reader.NameTable.Add("Dialog");
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
if (IsElementMatch(dialogElementName, reader.LocalName)) {
AddDialogId(dialogIds);
}
break;
}
}
return new ReadOnlyCollection<string>(dialogIds);
}
}
/// <summary>
/// Checks that the atomised element names match.
/// </summary>
bool IsElementMatch(object elementName, object currentElementName)
{
return elementName == currentElementName;
}
/// <summary>
/// Reads the dialog id and adds it to the list of dialogs found so far.
/// </summary>
void AddDialogId(List<string> dialogIds)
{
string id = GetIdAttributeValueFromCurrentNode();
if (id.Length > 0) {
dialogIds.Add(id);
}
}
string GetIdAttributeValueFromCurrentNode()
{
if (reader.MoveToAttribute("Id")) {
if (reader.Value != null) {
return reader.Value;
}
}
return String.Empty;
}
/// <summary>
/// Gets the line and column where the specified element starts. The column
/// returned is the column containing the opening tag (&lt;).
/// </summary>
public Location GetStartElementLocation(string elementName, string elementIdAttribute)
{
using (reader) {
object elementNameObject = reader.NameTable.Add(elementName);
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
if (IsElementMatch(elementNameObject, reader.LocalName)) {
Location location = GetStartElementLocationIfMatch(elementIdAttribute);
if (!location.IsEmpty) {
return location;
}
}
break;
}
}
}
return Location.Empty;
}
/// <summary>
/// Gets the line and column position if the element's attribute id matches the
/// element at the current reader position.
/// </summary>
Location GetStartElementLocationIfMatch(string idAttributeValue)
{
// Store the column and line position since the call to GetIdFromCurrentNode will
// move to the <Dialog> Id attribute.
int line = reader.LineNumber - 1;
int column = reader.LinePosition - 2; // Take off 2 to so the '<' is located.
if (idAttributeValue == GetIdAttributeValueFromCurrentNode()) {
return new Location(column, line);
}
return Location.Empty;
}
public Location GetEndElementLocation(string name, string id)
{
using (reader) {
bool startElementFound = false;
object elementName = reader.NameTable.Add(name);
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
if (IsElementMatch(elementName, reader.LocalName)) {
Location location = GetStartElementLocationIfMatch(id);
startElementFound = !location.IsEmpty;
}
break;
case XmlNodeType.EndElement:
if (startElementFound) {
if (IsElementMatch(elementName, reader.LocalName)) {
// Take off an extra 2 from the line position so we get the
// correct column for the < tag rather than the element name.
return new Location(reader.LinePosition - 3, reader.LineNumber - 1);
}
}
break;
}
}
}
return Location.Empty;
}
/// <summary>
/// Gets the dialog id at the specified line.
/// </summary>
/// <param name="index">Line numbers start from zero.</param>
public string GetDialogId(int line)
{
// Add one to line since XmlTextReader line numbers start from one.
++line;
DialogStartElement dialogStartElement = null;
using (reader) {
object dialogElementName = reader.NameTable.Add("Dialog");
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
if (IsElementMatch(dialogElementName, reader.LocalName)) {
if (line < reader.LineNumber) {
return null;
} else if (line == reader.LineNumber) {
return GetIdAttributeValueFromCurrentNode();
} else if (reader.IsStartElement()) {
dialogStartElement = new DialogStartElement(reader.LineNumber, GetIdAttributeValueFromCurrentNode());
}
}
break;
case XmlNodeType.EndElement:
if (IsElementMatch(dialogElementName, reader.LocalName)) {
if (line > dialogStartElement.Line && line <= reader.LineNumber) {
return dialogStartElement.Id;
}
}
break;
}
}
}
return null;
}
/// <summary>
/// Gets the region (start line, column to end line, column) of the xml
/// element that has the specified id. This includes the start and end tags, the start column is the column
/// containing the start tag and the end column is the column containing the final
/// end tag marker.
/// </summary>
/// <param name="name">The name of the element.</param>
/// <param name="id">The id attribute value of the element.</param>
public DomRegion GetElementRegion(string name, string id)
{
Location startLocation = Location.Empty;
using (reader) {
int nestedElementsCount = -1;
object elementName = reader.NameTable.Add(name);
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
if (IsElementMatch(elementName, reader.LocalName)) {
if (nestedElementsCount == -1) {
bool isEmptyElement = reader.IsEmptyElement;
startLocation = GetStartElementLocationIfMatch(id);
if (!startLocation.IsEmpty) {
nestedElementsCount = 0;
if (isEmptyElement) {
Location endLocation = GetEmptyElementEnd();
return DomRegion.FromLocation(startLocation, endLocation);
}
}
} else if (!reader.IsEmptyElement) {
++nestedElementsCount;
}
}
break;
case XmlNodeType.EndElement:
if (!startLocation.IsEmpty && IsElementMatch(elementName, reader.LocalName)) {
if (nestedElementsCount == 0) {
Location endLocation = GetEndElementEnd();
return DomRegion.FromLocation(startLocation, endLocation);
}
--nestedElementsCount;
}
break;
}
}
}
return DomRegion.Empty;
}
/// <summary>
/// Determines the end of the empty element including the final end tag marker
/// (the greater than sign). This method moves the XmlTextReader to the end
/// of the element tag.
/// </summary>
Location GetEmptyElementEnd()
{
reader.ReadStartElement();
int line = reader.LineNumber - 1;
// Take off two as we have moved passed the end tag
// column.
int column = reader.LinePosition - 2;
return new Location(column, line);
}
/// <summary>
/// Determines the end of the end element including the final end tag marker
/// (the greater than sign). This method moves the XmlTextReader to the end of
/// the end tag.
/// </summary>
Location GetEndElementEnd()
{
reader.ReadEndElement();
int line = reader.LineNumber - 1;
// Take off two as we have moved passed the end tag column.
int column = reader.LinePosition - 2;
// If ReadEndElement has moved to the start of another element
// take off one from the column value otherwise the column
// value includes the start tag of the next element.
if (reader.NodeType == XmlNodeType.Element) {
--column;
}
return new Location(column, line);
}
}
}

47
src/AddIns/BackendBindings/WixBinding/Project/Src/WixElementBase.cs

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using System.Text;
using System.Xml;
namespace ICSharpCode.WixBinding
{
public abstract class WixElementBase : XmlElement
{
public WixElementBase(string localName, WixDocument document)
: base(document.GetWixNamespacePrefix(), localName, WixNamespaceManager.Namespace, document)
{
}
public string Id {
get { return GetAttribute("Id"); }
set { SetAttribute("Id", value); }
}
public string GetXml(WixTextWriter wixWriter)
{
StringBuilder xml = new StringBuilder();
StringWriter stringWriter = new StringWriter(xml);
using (XmlWriter xmlWriter = wixWriter.Create(stringWriter)) {
WriteTo(xmlWriter);
}
return RemoveWixNamespace(xml.ToString());
}
string RemoveWixNamespace(string xml)
{
string namespaceDeclaration = String.Concat(" xmlns=\"", WixNamespaceManager.Namespace, "\"");
return xml.Replace(namespaceDeclaration, String.Empty);
}
protected WixDocument OwnerWixDocument {
get { return (WixDocument)OwnerDocument; }
}
}
}

231
src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs

@ -17,28 +17,104 @@ namespace ICSharpCode.WixBinding @@ -17,28 +17,104 @@ namespace ICSharpCode.WixBinding
/// <summary>
/// Represents a Wix File element in a Wix XML document.
/// </summary>
public class WixFileElement : XmlElement
public class WixFileElement : WixElementBase
{
public const string FileElementName = "File";
WixComponentElement parentComponent;
public WixFileElement(WixDocument document)
: base(document.WixNamespacePrefix, FileElementName, WixNamespaceManager.Namespace, document)
: base(FileElementName, document)
{
}
public WixFileElement(WixDocument document, string fileName) : this(document)
public WixFileElement(WixDocument document, string fileName)
: this(document)
{
Init(fileName);
}
public WixFileElement(WixComponentElement component, string fileName) : this((WixDocument)component.OwnerDocument)
public WixFileElement(WixComponentElement component, string fileName)
: this((WixDocument)component.OwnerDocument)
{
parentComponent = component;
Init(fileName);
}
/// <summary>
/// Initialises a new Wix File element with the specified
/// <paramref name="fileName"/>.
/// </summary>
/// <remarks>
/// The element generated will have an Id, LongName and Name
/// all set and derived from the <paramref name="fileName"/>
/// </remarks>
void Init(string fileName)
{
Id = GenerateUniqueId(fileName);
FileName = Path.GetFileName(fileName);
Source = OwnerWixDocument.GetRelativePath(fileName);;
}
string GenerateUniqueId(string fileName)
{
string fileNameWithoutPath = Path.GetFileName(fileName);
return GenerateUniqueId(Path.GetDirectoryName(fileName), fileNameWithoutPath);
}
/// <summary>
/// Generates a unique id for the entire document that this file element
/// belongs to.
/// </summary>
/// <param name="parentDirectory">The full path of the parent directory
/// for the filename.</param>
/// <param name="fileName">The name of the file to generate a unique
/// id for. This does not include any path.</param>
string GenerateUniqueId(string parentDirectory, string fileName)
{
string id = GenerateId(fileName);
if (!OwnerWixDocument.FileIdExists(id)) {
return id;
}
id = GenerateIdFromParentDirectory(parentDirectory, id);
if (!OwnerWixDocument.FileIdExists(id)) {
return id;
}
return GenerateUniqueIdByAppendingNumberToFileNameId(id);
}
string GenerateIdFromParentDirectory(string parentDirectory, string fileNameId)
{
string id = GenerateIdFromParentDirectory(parentDirectory);
if (!String.IsNullOrEmpty(id)) {
return String.Concat(id, ".", fileNameId);
}
return fileNameId;
}
string GenerateIdFromParentDirectory(string parentDirectory)
{
string parentDirectoryName = WixDirectoryElement.GetLastFolderInDirectoryName(parentDirectory);
if (parentDirectoryName.Length > 0) {
return WixFileElement.GenerateId(parentDirectoryName);
}
return String.Empty;
}
string GenerateUniqueIdByAppendingNumberToFileNameId(string fileNameId)
{
string id = String.Empty;
int count = 0;
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileNameId);
string extension = Path.GetExtension(fileNameId);
do {
++count;
id = String.Concat(fileNameWithoutExtension, count, extension);
} while (OwnerWixDocument.FileIdExists(id));
return id;
}
/// <summary>
/// Generates an id from the filename.
/// </summary>
@ -60,51 +136,22 @@ namespace ICSharpCode.WixBinding @@ -60,51 +136,22 @@ namespace ICSharpCode.WixBinding
}
/// <summary>
/// Gets the filename where the resource being added to the setup
/// package can be found. Typically this is relative to the Wix document the
/// File element is a part of.
/// </summary>
public string Source {
get { return GetAttribute("Source"); }
set { SetAttribute("Source", value); }
}
public string Id {
get { return GetAttribute("Id"); }
set { SetAttribute("Id", value); }
}
/// <summary>
/// Gets whether the file is the KeyPath for its parent component.
/// </summary>
public string KeyPath {
get { return GetAttribute("KeyPath"); }
set { SetAttribute("KeyPath", value); }
}
/// <summary>
/// Gets the name of the file without any path information.
/// This is the name that will be used when installing the file.
/// </summary>
public string FileName {
get { return GetAttribute("Name"); }
set { SetAttribute("Name", value); }
}
/// <summary>
/// Gets the full path to the file. If the parent WixDocument
/// has no filename then the relative path as stored in the
/// wix document is returned.
/// Returns a valid id character for the given position. If the
/// character is an invalid character it is replaced with an underscore.
/// </summary>
public string SourceFullPath {
get {
WixDocument document = OwnerDocument as WixDocument;
if (document != null && !String.IsNullOrEmpty(document.FileName)) {
string directory = Path.GetDirectoryName(document.FileName);
return Path.GetFullPath(Path.Combine(directory, Source));
static char GetIdCharacter(char ch, int index)
{
if (IsValidIdCharacter(ch)) {
// First char must be a letter or underscore.
if (index == 0) {
if (IsLetterOrUnderscore(ch)) {
return ch;
}
} else {
return ch;
}
return Source;
}
}
return '_';
}
/// <summary>
@ -133,82 +180,48 @@ namespace ICSharpCode.WixBinding @@ -133,82 +180,48 @@ namespace ICSharpCode.WixBinding
/// </summary>
static bool IsLetter(char ch)
{
return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
return ((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z'));
}
/// <summary>
/// Returns a valid id character for the given position. If the
/// character is an invalid character it is replaced with an underscore.
/// Gets the filename where the resource being added to the setup
/// package can be found. Typically this is relative to the Wix document the
/// File element is a part of.
/// </summary>
static char GetIdCharacter(char ch, int index)
{
if (IsValidIdCharacter(ch)) {
// First char must be a letter or underscore.
if (index > 0 || IsLetterOrUnderscore(ch)) {
return ch;
}
}
return '_';
public string Source {
get { return GetAttribute("Source"); }
set { SetAttribute("Source", value); }
}
/// <summary>
/// Initialises a new Wix File element with the specified
/// <paramref name="fileName"/>.
/// Gets whether the file is the KeyPath for its parent component.
/// </summary>
/// <remarks>
/// The element generated will have an Id, LongName and Name
/// all set and derived from the <paramref name="fileName"/>
/// </remarks>
void Init(string fileName)
{
WixDocument document = (WixDocument)OwnerDocument;
string baseDirectory = Path.GetDirectoryName(document.FileName);
string sourceFileName = FileUtility.GetRelativePath(baseDirectory, fileName);
Source = sourceFileName;
FileName = Path.GetFileName(fileName);
// Generate a unique id from the filename.
string id = FileName;
Id = GenerateUniqueId(Path.GetDirectoryName(fileName), id);
public string KeyPath {
get { return GetAttribute("KeyPath"); }
set { SetAttribute("KeyPath", value); }
}
/// <summary>
/// Generates a unique id for the entire document that this file element
/// belongs to.
/// Gets the name of the file without any path information.
/// This is the name that will be used when installing the file.
/// </summary>
/// <param name="parentDirectory">The full path of the parent directory
/// for the filename.</param>
/// <param name="fileName">The name of the file to generate a unique
/// id for. This does not include any path.</param>
string GenerateUniqueId(string parentDirectory, string fileName)
public string FileName {
get { return GetAttribute("Name"); }
set { SetAttribute("Name", value); }
}
/// <summary>
/// Gets the full path to the file. If the parent WixDocument
/// has no filename then the relative path as stored in the
/// wix document is returned.
/// </summary>
public string GetSourceFullPath()
{
string id = GenerateId(fileName);
WixDocument document = (WixDocument)OwnerDocument;
if (!document.FileIdExists(id)) {
return id;
if (!String.IsNullOrEmpty(OwnerWixDocument.FileName)) {
string directory = Path.GetDirectoryName(OwnerWixDocument.FileName);
return Path.GetFullPath(Path.Combine(directory, Source));
}
// Add the file's parent directory to the id.
string parentDirectoryName = WixDirectoryElement.GetLastDirectoryName(parentDirectory);
if (parentDirectoryName.Length > 0) {
id = String.Concat(WixFileElement.GenerateId(parentDirectoryName), ".", id);
if (!document.FileIdExists(id)) {
return id;
}
fileName = id;
}
// Add a number to the file name until we get a unique id.
int count = 0;
string idStart = Path.GetFileNameWithoutExtension(fileName);
string extension = Path.GetExtension(fileName);
do {
++count;
id = String.Concat(idStart, count, extension);
} while (document.FileIdExists(id));
return id;
return Source;
}
}
}

49
src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileName.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
namespace ICSharpCode.WixBinding
{
public class WixFileName
{
public const string WixSourceFileExtension = ".wxs";
public const string WixIncludeFileExtension = ".wxi";
WixFileName()
{
}
/// <summary>
/// Checks the file extension to see if the file is a Wix file. The file
/// can either be a Wix source file (.wxs) or a Wix include file (.wxi).
/// </summary>
public static bool IsWixFileName(string fileName)
{
if (String.IsNullOrEmpty(fileName)) {
return false;
}
string extension = Path.GetExtension(fileName.ToLowerInvariant());
switch (extension) {
case WixSourceFileExtension:
return true;
case WixIncludeFileExtension:
return true;
}
return false;
}
/// <summary>
/// Checks whether the file extension is for a Wix source file (.wxs).
/// </summary>
public static bool IsWixSourceFileName(string fileName)
{
return String.Compare(Path.GetExtension(fileName), WixSourceFileExtension, true) == 0;
}
}
}

2
src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesDiff.cs

@ -124,7 +124,7 @@ namespace ICSharpCode.WixBinding @@ -124,7 +124,7 @@ namespace ICSharpCode.WixBinding
{
List<string> fileNames = new List<string>();
foreach (WixFileElement fileElement in fileElements) {
fileNames.Add(fileElement.SourceFullPath);
fileNames.Add(fileElement.GetSourceFullPath());
}
return fileNames;
}

39
src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs

@ -193,7 +193,7 @@ namespace ICSharpCode.WixBinding @@ -193,7 +193,7 @@ namespace ICSharpCode.WixBinding
WixDirectoryElement parentElement = (WixDirectoryElement)view.SelectedElement;
// Add directory.
string directoryName = WixDirectoryElement.GetLastDirectoryName(directory);
string directoryName = WixDirectoryElement.GetLastFolderInDirectoryName(directory);
WixDirectoryElement directoryElement = AddDirectory(parentElement, directoryName);
AddFiles(directoryElement, directory);
@ -216,14 +216,14 @@ namespace ICSharpCode.WixBinding @@ -216,14 +216,14 @@ namespace ICSharpCode.WixBinding
/// the Wix document and the files on the file system and
/// shows the differences.
/// </summary>
public void ShowDiff()
public void CalculateDiff()
{
WixPackageFilesDiff diff = new WixPackageFilesDiff(directoryReader);
diff.ExcludedFileNames.Add(excludedNames);
WixDirectoryElementBase directoryElement = view.SelectedElement as WixDirectoryElementBase;
if (directoryElement == null) {
directoryElement = RootDirectoryElement;
directoryElement = GetRootDirectoryElement();
}
// Directory element selected?
@ -314,7 +314,7 @@ namespace ICSharpCode.WixBinding @@ -314,7 +314,7 @@ namespace ICSharpCode.WixBinding
WixDirectoryElement AddDirectory(WixDirectoryElementBase parentElement, string name)
{
if (parentElement == null) {
parentElement = RootDirectoryElement;
parentElement = GetRootDirectoryElement();
if (parentElement == null) {
parentElement = document.AddRootDirectory();
}
@ -327,13 +327,12 @@ namespace ICSharpCode.WixBinding @@ -327,13 +327,12 @@ namespace ICSharpCode.WixBinding
/// Takes into account whether the WixDocument is using a
/// DirectoryRef element.
/// </summary>
WixDirectoryElementBase RootDirectoryElement {
get {
if (usingRootDirectoryRef) {
return document.RootDirectoryRef;
}
return document.RootDirectory;
WixDirectoryElementBase GetRootDirectoryElement()
{
if (usingRootDirectoryRef) {
return document.GetRootDirectoryRef();
}
return document.GetRootDirectory();
}
/// <summary>
@ -359,12 +358,11 @@ namespace ICSharpCode.WixBinding @@ -359,12 +358,11 @@ namespace ICSharpCode.WixBinding
/// <summary>
/// Adds a new component element to the directory element.
/// </summary>
/// <param name="id">The id attribute the component element will have.</param>
WixComponentElement AddComponent(WixDirectoryElement parentElement, string id)
WixComponentElement AddComponent(WixDirectoryElement parentDirectory, string fileName)
{
if (parentElement != null) {
WixComponentElement element = parentElement.AddComponent(id);
return element;
if (parentDirectory != null) {
WixComponentElement component = parentDirectory.AddComponent(fileName);
return component;
}
return null;
}
@ -382,15 +380,15 @@ namespace ICSharpCode.WixBinding @@ -382,15 +380,15 @@ namespace ICSharpCode.WixBinding
/// </summary>
FindRootDirectoryResult FindRootDirectory(WixDocument currentDocument)
{
if (currentDocument.IsProductDocument) {
WixDirectoryElement rootDirectory = currentDocument.RootDirectory;
if (currentDocument.HasProduct) {
WixDirectoryElement rootDirectory = currentDocument.GetRootDirectory();
if (rootDirectory != null) {
view.AddDirectories(rootDirectory.GetDirectories());
}
document = currentDocument;
return FindRootDirectoryResult.RootDirectoryFound;
} else {
WixDirectoryRefElement rootDirectoryRef = currentDocument.RootDirectoryRef;
WixDirectoryRefElement rootDirectoryRef = currentDocument.GetRootDirectoryRef();
if (rootDirectoryRef != null) {
view.AddDirectories(rootDirectoryRef.GetDirectories());
document = currentDocument;
@ -421,8 +419,7 @@ namespace ICSharpCode.WixBinding @@ -421,8 +419,7 @@ namespace ICSharpCode.WixBinding
/// </summary>
WixComponentElement AddFileWithParentComponent(WixDirectoryElement directoryElement, string fileName)
{
string id = WixComponentElement.GenerateIdFromFileName(document, fileName);
WixComponentElement component = AddComponent(directoryElement, id);
WixComponentElement component = AddComponent(directoryElement, fileName);
AddFile(component, fileName, true);
return component;
}
@ -440,7 +437,7 @@ namespace ICSharpCode.WixBinding @@ -440,7 +437,7 @@ namespace ICSharpCode.WixBinding
void AddDirectoryContents(WixDirectoryElement directoryElement, string directory)
{
foreach (string subDirectory in DirectoryReader.GetDirectories(directory)) {
string subDirectoryName = WixDirectoryElement.GetLastDirectoryName(subDirectory);
string subDirectoryName = WixDirectoryElement.GetLastFolderInDirectoryName(subDirectory);
if (!excludedNames.IsExcluded(subDirectoryName)) {
WixDirectoryElement subDirectoryElement = AddDirectory(directoryElement, subDirectoryName);
AddFiles(subDirectoryElement, subDirectory);

18
src/AddIns/BackendBindings/WixBinding/Project/Src/WixPropertyParser.cs

@ -10,21 +10,6 @@ using System.Text; @@ -10,21 +10,6 @@ using System.Text;
namespace ICSharpCode.WixBinding
{
/// <summary>
/// Interface that allows a class to convert a Wix property name into a value.
/// </summary>
public interface IWixPropertyValueProvider
{
/// <summary>
/// Gets the property value for the specified name. Wix property names are
/// case sensitive.
/// </summary>
/// <returns>
/// The original null if the name cannot be found.
/// </returns>
string GetValue(string name);
}
/// <summary>
/// Parses a string of Wix property values (e.g. "$(var.DATAPATH)") it also
/// handles MSBuild property values (e.g. "$(SharpDevelopBinPath)").
@ -42,9 +27,6 @@ namespace ICSharpCode.WixBinding @@ -42,9 +27,6 @@ namespace ICSharpCode.WixBinding
{
}
/// <summary>
/// Expands the Wix property values using the IWixPropertyValueProvider
/// </summary>
public static string Parse(string input, IWixPropertyValueProvider valueProvider)
{
StringBuilder output = new StringBuilder();

58
src/AddIns/BackendBindings/WixBinding/Project/Src/WixTextWriter.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using System.Xml;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.WixBinding
{
public class WixTextWriter
{
ITextEditorOptions textEditorOptions;
public WixTextWriter(ITextEditorOptions textEditorOptions)
{
this.textEditorOptions = textEditorOptions;
}
public XmlWriterSettings CreateXmlWriterSettings()
{
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.CloseOutput = true;
xmlWriterSettings.Indent = true;
xmlWriterSettings.NewLineChars = "\r\n";
xmlWriterSettings.OmitXmlDeclaration = true;
if (textEditorOptions.ConvertTabsToSpaces) {
string space = " ";
xmlWriterSettings.IndentChars = space.PadRight(textEditorOptions.IndentationSize);
} else {
xmlWriterSettings.IndentChars = "\t";
}
return xmlWriterSettings;
}
public XmlWriter Create(TextWriter textWriter)
{
XmlWriterSettings settings = CreateXmlWriterSettings();
return XmlTextWriter.Create(textWriter, settings);
}
public XmlWriter Create(string fileName)
{
XmlWriterSettings settings = CreateXmlWriterSettings();
return Create(fileName, settings);
}
protected virtual XmlWriter Create(string fileName, XmlWriterSettings settings)
{
return XmlTextWriter.Create(fileName, settings);
}
}
}

4
src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin

@ -217,7 +217,7 @@ @@ -217,7 +217,7 @@
class = "ICSharpCode.WixBinding.AddDirectoryCommand"/>
<MenuItem id = "AddFilesToDirectory"
label = "${res:ICSharpCode.WixBinding.PackagesFilesView.ContextMenu.AddFiles}"
class = "ICSharpCode.WixBinding.AddFilesToDirectoryCommand"/>
class = "ICSharpCode.WixBinding.AddFilesCommand"/>
<MenuItem id = "Diff"
label = "Diff"
class = "ICSharpCode.WixBinding.ShowDiffCommand"/>
@ -227,7 +227,7 @@ @@ -227,7 +227,7 @@
<Path name = "/AddIns/WixBinding/PackageFilesView/ContextMenu/ComponentTreeNode">
<MenuItem id = "AddFiles"
label = "${res:ICSharpCode.WixBinding.PackagesFilesView.ContextMenu.AddFiles}"
class = "ICSharpCode.WixBinding.AddFilesToComponentCommand"/>
class = "ICSharpCode.WixBinding.AddFilesCommand"/>
<Include path = "/AddIns/WixBinding/PackageFilesView/ContextMenu/Common"/>
</Path>

43
src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -36,19 +37,45 @@ @@ -36,19 +37,45 @@
<OutputPath>..\..\..\..\..\AddIns\AddIns\BackendBindings\WixBinding\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Design" />
<Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Src\Commands\AddFilesToDirectoryCommand.cs" />
<Compile Include="Src\Commands\AbstractActivePackageFilesViewCommand.cs" />
<Compile Include="Src\Commands\AddFilesCommand.cs" />
<Compile Include="Src\Commands\AddWixExtensionToProject.cs" />
<Compile Include="Src\Commands\AddWixItemToProjectBaseCommand.cs" />
<Compile Include="Src\DefaultFileLoader.cs" />
<Compile Include="Src\Gui\ActivePackageFilesView.cs" />
<Compile Include="Src\Gui\IFormsDesignerView.cs" />
<Compile Include="Src\Gui\OpenTextEditors.cs" />
<Compile Include="Src\Gui\WixDocumentWindow.cs" />
<Compile Include="Src\IPackageFilesViewFactory.cs" />
<Compile Include="Src\IWixPackageFilesControl.cs" />
<Compile Include="Src\IWixPropertyValueProvider.cs" />
<Compile Include="Src\PackageFilesViewFactory.cs" />
<Compile Include="Src\Project\WixExtensionFolderNode.cs" />
<Compile Include="Src\Project\WixExtensionNode.cs" />
<Compile Include="Src\WixDialogElement.cs" />
<Compile Include="Src\WixDocumentReader.cs" />
<Compile Include="Src\WixElementBase.cs" />
<Compile Include="Src\WixFileName.cs" />
<Compile Include="Src\WixProjectBinding.cs" />
<Compile Include="Src\Project\WixProject.cs" />
<Compile Include="Src\Gui\CompilerParametersPanel.cs" />
@ -96,6 +123,7 @@ @@ -96,6 +123,7 @@
<Compile Include="Src\WixPackageFilesEditor.cs" />
<Compile Include="Src\Gui\WixDocumentEditor.cs" />
<Compile Include="Src\ITextFileReader.cs" />
<Compile Include="Src\WixTextWriter.cs" />
<Compile Include="Src\WixXmlAttribute.cs" />
<Compile Include="Src\WixXmlAttributeType.cs" />
<EmbeddedResource Include="..\..\..\..\..\data\schemas\wix.xsd">
@ -123,7 +151,6 @@ @@ -123,7 +151,6 @@
<Compile Include="Src\Gui\WixPackageFilesTreeView.cs" />
<Compile Include="Src\Commands\AddElementCommand.cs" />
<Compile Include="Src\Commands\RemoveElementCommand.cs" />
<Compile Include="Src\Commands\AddFilesToComponentCommand.cs" />
<Compile Include="Src\WixComponentElement.cs" />
<Compile Include="Src\WixDirectoryRefElement.cs" />
<Compile Include="Src\WixDirectoryElementBase.cs" />
@ -167,6 +194,11 @@ @@ -167,6 +194,11 @@
<Content Include="WixBinding.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<ProjectReference Include="..\..\..\..\Libraries\AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj">
<Project>{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}</Project>
<Name>ICSharpCode.AvalonEdit</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>
@ -188,6 +220,11 @@ @@ -188,6 +220,11 @@
<Name>ICSharpCode.TextEditor</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\DisplayBindings\AvalonEdit.AddIn\AvalonEdit.AddIn.csproj">
<Project>{0162E499-42D0-409B-AA25-EED21F75336B}</Project>
<Name>AvalonEdit.AddIn</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\DisplayBindings\FormsDesigner\Project\FormsDesigner.csproj">
<Project>{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}</Project>
<Name>FormsDesigner</Name>

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapFromProjectTestFixture.cs

@ -49,7 +49,7 @@ namespace WixBinding.Tests.Document @@ -49,7 +49,7 @@ namespace WixBinding.Tests.Document
doc.FileName = docFileName;
doc.LoadXml(GetMainWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog", this);
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", this);
using (Form dialog = wixDialog.CreateDialog(this)) {
PictureBox pictureBox = (PictureBox)dialog.Controls[0];
hasImage = (pictureBox.Image != null);

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapTestFixture.cs

@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading
WixProject project = WixBindingTestsHelper.CreateEmptyWixProject();
WixDocument doc = new WixDocument(project, this);
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
PictureBox pictureBox = (PictureBox)dialog.Controls[0];
hasImage = (pictureBox.Image != null);

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonFontTestFixture.cs

@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
Button button = (Button)dialog.Controls[0];
fontName = button.Font.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonTextTestFixture.cs

@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
Button nextButton = (Button)dialog.Controls[0];
nextButtonText = nextButton.Text;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonsTestFixture.cs

@ -38,7 +38,7 @@ namespace WixBinding.Tests.DialogLoading @@ -38,7 +38,7 @@ namespace WixBinding.Tests.DialogLoading
doc.LoadXml(GetWixXml());
controlsAddedCount = 0;
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
foreach (Control control in dialog.Controls) {
++controlsAddedCount;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/CheckBoxTestFixture.cs

@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
CheckBox checkBox = (CheckBox)dialog.Controls[0];
name = checkBox.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ComboBoxTestFixture.cs

@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading @@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ComboBox comboBox = (ComboBox)dialog.Controls[0];
name = comboBox.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DefaultUIFontTestFixture.cs

@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
Button button = (Button)dialog.Controls[0];
fontName = button.Font.Name;

3
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogMinimizeBoxTestFixture.cs

@ -12,6 +12,7 @@ using System.Drawing; @@ -12,6 +12,7 @@ using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogLoading
{
@ -28,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading @@ -28,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form simpleDialog = wixDialog.CreateDialog()) {
minimizeBox = simpleDialog.MinimizeBox;
}

3
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogTitleTestFixture.cs

@ -11,6 +11,7 @@ using System; @@ -11,6 +11,7 @@ using System;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogLoading
{
@ -28,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading @@ -28,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog()) {
dialogTitle = dialog.Text;
}

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DirectoryListTestFixture.cs

@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ListBox listBox = (ListBox)dialog.Controls[0];
name = listBox.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DisabledButtonTestFixture.cs

@ -29,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading @@ -29,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
Button backButton = (Button)dialog.Controls[0];
disabled = !backButton.Enabled;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/GroupBoxTestFixture.cs

@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
GroupBox groupBox = (GroupBox)dialog.Controls[0];
name = groupBox.Name;

7
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidLocationTests.cs

@ -28,8 +28,7 @@ namespace WixBinding.Tests.DialogLoading @@ -28,8 +28,7 @@ namespace WixBinding.Tests.DialogLoading
[TestFixtureSetUp]
public void SetupFixture()
{
ResourceManager rm = new ResourceManager("WixBinding.Tests.Strings", GetType().Assembly);
ResourceService.RegisterNeutralStrings(rm);
WixBindingTestsHelper.RegisterResourceStringsWithSharpDevelopResourceManager();
}
[Test]
@ -47,7 +46,7 @@ namespace WixBinding.Tests.DialogLoading @@ -47,7 +46,7 @@ namespace WixBinding.Tests.DialogLoading
"\t</Fragment>\r\n" +
"</Wix>";
doc.LoadXml(xml);
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
try {
wixDialog.CreateDialog();
Assert.Fail("Expected an exception before this line.");
@ -73,7 +72,7 @@ namespace WixBinding.Tests.DialogLoading @@ -73,7 +72,7 @@ namespace WixBinding.Tests.DialogLoading
"\t</Fragment>\r\n" +
"</Wix>";
doc.LoadXml(xml);
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
try {
wixDialog.CreateDialog();
Assert.Fail("Expected an exception before this line.");

11
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidSizeTests.cs

@ -28,8 +28,7 @@ namespace WixBinding.Tests.DialogLoading @@ -28,8 +28,7 @@ namespace WixBinding.Tests.DialogLoading
[TestFixtureSetUp]
public void SetupFixture()
{
ResourceManager rm = new ResourceManager("WixBinding.Tests.Strings", GetType().Assembly);
ResourceService.RegisterNeutralStrings(rm);
WixBindingTestsHelper.RegisterResourceStringsWithSharpDevelopResourceManager();
}
[Test]
@ -45,7 +44,7 @@ namespace WixBinding.Tests.DialogLoading @@ -45,7 +44,7 @@ namespace WixBinding.Tests.DialogLoading
"\t</Fragment>\r\n" +
"</Wix>";
doc.LoadXml(xml);
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
try {
wixDialog.CreateDialog();
Assert.Fail("Expected an exception before this line.");
@ -69,7 +68,7 @@ namespace WixBinding.Tests.DialogLoading @@ -69,7 +68,7 @@ namespace WixBinding.Tests.DialogLoading
"\t</Fragment>\r\n" +
"</Wix>";
doc.LoadXml(xml);
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
try {
wixDialog.CreateDialog();
Assert.Fail("Expected an exception before this line.");
@ -93,7 +92,7 @@ namespace WixBinding.Tests.DialogLoading @@ -93,7 +92,7 @@ namespace WixBinding.Tests.DialogLoading
"\t</Fragment>\r\n" +
"</Wix>";
doc.LoadXml(xml);
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
try {
wixDialog.CreateDialog();
Assert.Fail("Expected an exception before this line.");
@ -117,7 +116,7 @@ namespace WixBinding.Tests.DialogLoading @@ -117,7 +116,7 @@ namespace WixBinding.Tests.DialogLoading
"\t</Fragment>\r\n" +
"</Wix>";
doc.LoadXml(xml);
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
try {
wixDialog.CreateDialog();
Assert.Fail("Expected an exception before this line.");

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelFontFromPropertyTestFixture.cs

@ -35,7 +35,7 @@ namespace WixBinding.Tests.DialogLoading @@ -35,7 +35,7 @@ namespace WixBinding.Tests.DialogLoading
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
Label titleLabel = (Label)dialog.Controls[0];
titleLabelFontName = titleLabel.Font.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelTestFixture.cs

@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading @@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
Label label = (Label)dialog.Controls[0];
labelName = label.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LineTestFixture.cs

@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
Label line = (Label)dialog.Controls[0];
lineName = line.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListBoxTestFixture.cs

@ -35,7 +35,7 @@ namespace WixBinding.Tests.DialogLoading @@ -35,7 +35,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ListBox listBox = (ListBox)dialog.Controls[0];
name = listBox.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListViewTestFixture.cs

@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading @@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ListView listView = (ListView)dialog.Controls[0];
name = listView.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MaskedEditTestFixture.cs

@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
MaskedTextBox textBox = (MaskedTextBox)dialog.Controls[0];
name = textBox.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingBitmapBinaryTestFixture.cs

@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading @@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading
WixProject project = WixBindingTestsHelper.CreateEmptyWixProject();
WixDocument doc = new WixDocument(project, this);
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
// Should be the last control added to the dialog appears behind all
// the other controls. This is what happens when you call SendToBack

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingRadioButtonGroupTestFixture.cs

@ -34,7 +34,7 @@ namespace WixBinding.Tests.DialogLoading @@ -34,7 +34,7 @@ namespace WixBinding.Tests.DialogLoading
doc.LoadXml(GetWixXml());
controlsAddedCount = 0;
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("AcceptLicenseDialog");
WixDialog wixDialog = doc.CreateWixDialog("AcceptLicenseDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
foreach (Control control in dialog.Controls) {
++controlsAddedCount;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/NullComponentCreatorTestFixture.cs

@ -29,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading @@ -29,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading
WixProject project = WixBindingTestsHelper.CreateEmptyWixProject();
WixDocument doc = new WixDocument(project);
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
try {
wixDialog.CreateDialog(null);
Assert.Fail("Expected an ArgumentException");

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/PathEditTestFixture.cs

@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
TextBox textBox = (TextBox)dialog.Controls[0];
name = textBox.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ProgressBarTestFixture.cs

@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ProgressBar progressBar = (ProgressBar)dialog.Controls[0];
name = progressBar.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/RadioButtonTestFixture.cs

@ -41,7 +41,7 @@ namespace WixBinding.Tests.DialogLoading @@ -41,7 +41,7 @@ namespace WixBinding.Tests.DialogLoading
doc.LoadXml(GetWixXml());
controlsAddedCount = 0;
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("AcceptLicenseDialog");
WixDialog wixDialog = doc.CreateWixDialog("AcceptLicenseDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
foreach (Control control in dialog.Controls) {
++controlsAddedCount;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ScrollableTextTestFixture.cs

@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
RichTextBox textBox = (RichTextBox)dialog.Controls[0];
name = textBox.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SelectionTreeTestFixture.cs

@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
TreeView treeView = (TreeView)dialog.Controls[0];
name = treeView.Name;

5
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogTestFixture.cs

@ -12,6 +12,7 @@ using System.Drawing; @@ -12,6 +12,7 @@ using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogLoading
{
@ -34,7 +35,7 @@ namespace WixBinding.Tests.DialogLoading @@ -34,7 +35,7 @@ namespace WixBinding.Tests.DialogLoading
{
doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form simpleDialog = wixDialog.CreateDialog()) {
dialogName = simpleDialog.Name;
borderStyle = simpleDialog.FormBorderStyle;
@ -85,7 +86,7 @@ namespace WixBinding.Tests.DialogLoading @@ -85,7 +86,7 @@ namespace WixBinding.Tests.DialogLoading
[Test]
public void DialogIdWithSingleQuote()
{
Assert.IsNull(doc.GetDialog("Test'Id"));
Assert.IsNull(doc.CreateWixDialog("Test'Id", new MockTextFileReader()));
}
string GetWixXml()

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogUsingObjectCreatorTestFixture.cs

@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
formComponent = CreatedComponents[0];
formName = dialog.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextBoxTestFixture.cs

@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
TextBox textBox = (TextBox)dialog.Controls[0];
name = textBox.Name;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextStyleNameWithSpecialXmlCharsTestFixture.cs

@ -24,7 +24,7 @@ namespace WixBinding.Tests.DialogLoading @@ -24,7 +24,7 @@ namespace WixBinding.Tests.DialogLoading
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
}
}

2
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TransparentLabelsTestFixture.cs

@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading
CreatedComponents.Clear();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
Label titleLabel = (Label)dialog.Controls[0];
titleLabelColor = titleLabel.BackColor;

3
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/AddAcceptAndCancelButtonTestFixture.cs

@ -12,6 +12,7 @@ using System.Drawing; @@ -12,6 +12,7 @@ using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogXmlGeneration
{
@ -31,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -31,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog()) {
Button nextButton = (Button)dialog.Controls[0];
dialog.AcceptButton = nextButton;

3
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonAddedTestFixture.cs

@ -12,6 +12,7 @@ using System.Drawing; @@ -12,6 +12,7 @@ using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogXmlGeneration
{
@ -30,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -30,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog()) {
Button nextButton = new Button();
nextButton.Left = 200;

3
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonChangedTestFixture.cs

@ -12,6 +12,7 @@ using System.Drawing; @@ -12,6 +12,7 @@ using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogXmlGeneration
{
@ -31,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -31,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog()) {
Button nextButton = (Button)dialog.Controls[0];
nextButton.Left = 200;

3
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonRemovedTestFixture.cs

@ -12,6 +12,7 @@ using System.Drawing; @@ -12,6 +12,7 @@ using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogXmlGeneration
{
@ -30,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -30,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog()) {
Button nextButton = (Button)dialog.Controls[0];
dialog.Controls.Remove(nextButton);

8
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonTextRemovedTestFixture.cs

@ -5,12 +5,14 @@ @@ -5,12 +5,14 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.Windows.Forms;
using System.Xml;
using ICSharpCode.WixBinding;
using NUnit.Framework;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogXmlGeneration
{
/// <summary>
@ -29,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -29,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog()) {
Button nextButton = (Button)dialog.Controls[0];
nextButton.Text = String.Empty;

2
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxItemAddedTestFixture.cs

@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ComboBox comboBox = (ComboBox)dialog.Controls[0];

2
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxPropertyWithSpecialXmlCharsTestFixture.cs

@ -25,7 +25,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -25,7 +25,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
XmlElement dialogElement = wixDialog.UpdateDialogElement(dialog);
}

42
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/DialogXmlWritingTestFixture.cs

@ -5,24 +5,25 @@ @@ -5,24 +5,25 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.Xml;
using ICSharpCode.WixBinding;
using NUnit.Framework;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogXmlGeneration
{
[TestFixture]
public class DialogXmlWritingTestFixture
{
XmlElement dialogElement;
WixDialogElement dialogElement;
[TestFixtureSetUp]
public void SetUpFixture()
{
XmlDocument doc = new XmlDocument();
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
dialogElement = (XmlElement)doc.SelectSingleNode("//w:Dialog", new WixNamespaceManager(doc.NameTable));
dialogElement = (WixDialogElement)doc.SelectSingleNode("//w:Dialog", new WixNamespaceManager(doc.NameTable));
dialogElement.SetAttribute("Id", "id");
dialogElement.SetAttribute("Title", "title");
XmlElement controlElement = doc.CreateElement("Control", WixNamespaceManager.Namespace);
@ -30,28 +31,43 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -30,28 +31,43 @@ namespace WixBinding.Tests.DialogXmlGeneration
}
[Test]
public void Tabs()
public void WixDocumentGetXmlWithTabs()
{
string outputXml = WixDocument.GetXml(dialogElement, "\r\n", false, 4);
string expectedXml = "<Dialog Id=\"id\" Height=\"270\" Width=\"370\" Title=\"title\">\r\n" +
MockTextEditorOptions options = new MockTextEditorOptions();
options.ConvertTabsToSpaces = false;
options.IndentationSize = 4;
WixTextWriter wixWriter = new WixTextWriter(options);
string outputXml = dialogElement.GetXml(wixWriter);
string expectedXml =
"<Dialog Id=\"id\" Height=\"270\" Width=\"370\" Title=\"title\">\r\n" +
"\t<Control />\r\n" +
"</Dialog>";
Assert.AreEqual(expectedXml, outputXml);
}
[Test]
public void Spaces()
public void WixDocumentGetXmlWithSpaces()
{
string outputXml = WixDocument.GetXml(dialogElement, "\n", true, 4);
string expectedXml = "<Dialog Id=\"id\" Height=\"270\" Width=\"370\" Title=\"title\">\n" +
" <Control />\n" +
MockTextEditorOptions options = new MockTextEditorOptions();
options.ConvertTabsToSpaces = true;
options.IndentationSize = 4;
WixTextWriter wixWriter = new WixTextWriter(options);
string outputXml = dialogElement.GetXml(wixWriter);
string expectedXml =
"<Dialog Id=\"id\" Height=\"270\" Width=\"370\" Title=\"title\">\r\n" +
" <Control />\r\n" +
"</Dialog>";
Assert.AreEqual(expectedXml, outputXml);
}
string GetWixXml()
{
return "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>\r\n" +
return
"<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>\r\n" +
"\t<Fragment>\r\n" +
"\t\t<UI>\r\n" +
"\t\t\t<Dialog Id='WelcomeDialog' Height='270' Width='370' Title='Welcome Dialog Title'/>\r\n" +

3
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/GroupBoxContainingControlsTestFixture.cs

@ -12,6 +12,7 @@ using System.Drawing; @@ -12,6 +12,7 @@ using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogXmlGeneration
{
@ -35,7 +36,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -35,7 +36,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog()) {
GroupBox groupBox = new GroupBox();
groupBox.Name = "NewGroupBox";

2
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxAddedTestFixture.cs

@ -34,7 +34,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -34,7 +34,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ListBox listBox = new ListBox();

2
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemAddedTestFixture.cs

@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ListBox listBox = (ListBox)dialog.Controls[0];

2
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemRemovedTestFixture.cs

@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ListBox listBox = (ListBox)dialog.Controls[0];

2
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxPropertyWithSpecialXmlCharsTestFixture.cs

@ -25,7 +25,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -25,7 +25,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
XmlElement dialogElement = wixDialog.UpdateDialogElement(dialog);
}

2
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxUpdatedTestFixture.cs

@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ListBox listBox = (ListBox)dialog.Controls[0];

2
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewAddedTestFixture.cs

@ -34,7 +34,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -34,7 +34,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ListView listView = new ListView();

2
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemAddedTestFixture.cs

@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ListView listView = (ListView)dialog.Controls[0];

2
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemRemovedTestFixture.cs

@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
ListView listView = (ListView)dialog.Controls[0];

4
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewPropertyWithSpecialXmlCharsTestFixture.cs

@ -25,8 +25,8 @@ namespace WixBinding.Tests.DialogXmlGeneration @@ -25,8 +25,8 @@ namespace WixBinding.Tests.DialogXmlGeneration
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
using (Form dialog = wixDialog.CreateDialog(this)) {
WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader());
using (Form dialog = wixDialog.CreateDialog(this)) {
XmlElement dialogElement = wixDialog.UpdateDialogElement(dialog);
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save