Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit bec633d

Browse files
committed
Fix #333: Unable to save WiX file.
Allow saving of an updated WiX file when it has been edited in the Setup - Files view.
1 parent ad3a588 commit bec633d

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ public ITextEditor FindTextEditorForDocument(WixDocument document)
3737
{
3838
foreach (IViewContent view in workbench.ViewContentCollection) {
3939
ITextEditor textEditor = view.GetService<ITextEditor>();
40-
if (AreFileNamesEqual(view.PrimaryFileName, document.FileName)) {
41-
return textEditor;
40+
if (textEditor != null) {
41+
if (AreFileNamesEqual(view.PrimaryFileName, document.FileName)) {
42+
return textEditor;
43+
}
4244
}
4345
}
4446
return null;

src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/OpenTextEditorsTestFixture.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
using System;
2020
using ICSharpCode.SharpDevelop;
21+
using ICSharpCode.SharpDevelop.Editor;
2122
using ICSharpCode.WixBinding;
2223
using NUnit.Framework;
2324
using WixBinding.Tests.Utils;
@@ -37,7 +38,7 @@ public void Init()
3738
{
3839
SD.InitializeForUnitTests();
3940
existingTextEditor = new MockTextEditor();
40-
MockTextEditorViewContent viewContent = new MockTextEditorViewContent();
41+
var viewContent = new MockTextEditorViewContent();
4142
viewContent.TextEditor = existingTextEditor;
4243
viewContent.SetFileName(@"d:\projects\test\file.wxs");
4344

@@ -64,5 +65,19 @@ public void CannotFindTextEditorForUnknownWixDocumentFileName()
6465
unknownDocument.FileName = @"d:\unknown-file.wxs";
6566
Assert.IsNull(openEditors.FindTextEditorForDocument(unknownDocument));
6667
}
68+
69+
[Test]
70+
public void FindTextEditorForDocument_FirstViewContentHasNoTextEditorAndNoPrimaryFileName_DoesNotThrowNullReferenceException()
71+
{
72+
var viewContent = new MockViewContent();
73+
viewContent.PrimaryFile = null;
74+
workbench.ViewContentCollection.Add(viewContent);
75+
var unknownDocument = new WixDocument();
76+
unknownDocument.FileName = @"d:\unknown-file.wxs";
77+
78+
ITextEditor textEditor = openEditors.FindTextEditorForDocument(unknownDocument);
79+
80+
Assert.IsNull(textEditor);
81+
}
6782
}
6883
}

src/AddIns/BackendBindings/WixBinding/Test/Utils/MockViewContent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public IList<OpenedFile> Files {
6565

6666
public OpenedFile PrimaryFile {
6767
get { return primaryFile; }
68+
set { primaryFile = value; }
6869
}
6970

7071
public FileName PrimaryFileName {

0 commit comments

Comments
 (0)