diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AbstractActivePackageFilesViewCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AbstractActivePackageFilesViewCommand.cs
new file mode 100644
index 0000000000..beb9c1491d
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AbstractActivePackageFilesViewCommand.cs
@@ -0,0 +1,40 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+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);
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs
index 94488731ca..1807895300 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs
@@ -6,7 +6,7 @@
//
using System;
-using ICSharpCode.Core;
+using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
@@ -14,11 +14,20 @@ namespace ICSharpCode.WixBinding
/// Adds a directory and all its contents to the currently selected directory
/// node.
///
- 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();
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddElementCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddElementCommand.cs
index dbd64e09b3..aafdfe5bf1 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddElementCommand.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddElementCommand.cs
@@ -7,6 +7,7 @@
using System;
using System.Windows.Forms;
+using ICSharpCode.SharpDevelop.Gui;
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);
+ }
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesCommand.cs
new file mode 100644
index 0000000000..2be1582f0d
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesCommand.cs
@@ -0,0 +1,30 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+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();
+ }
+ }
+}
+
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/HideDiffCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/HideDiffCommand.cs
index c4986b3764..a22a99ec33 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/HideDiffCommand.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/HideDiffCommand.cs
@@ -6,18 +6,27 @@
//
using System;
-using ICSharpCode.Core;
+using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
///
/// Hides the diff control from the Setup Files window.
///
- 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();
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/RemoveElementCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/RemoveElementCommand.cs
index cac5de603c..81639038c6 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/RemoveElementCommand.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/RemoveElementCommand.cs
@@ -6,18 +6,27 @@
//
using System;
-using ICSharpCode.Core;
+using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WixBinding
{
///
/// Remove the selected element from the Wix document.
///
- 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();
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ShowDiffCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ShowDiffCommand.cs
index 8d3db88f82..e05225f1bc 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ShowDiffCommand.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ShowDiffCommand.cs
@@ -6,15 +6,24 @@
//
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();
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewDialogXmlCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewDialogXmlCommand.cs
index 5cb00cb648..dceeb2ab29 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewDialogXmlCommand.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewDialogXmlCommand.cs
@@ -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);
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewSetupFilesCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewSetupFilesCommand.cs
index c434951d52..e4e9c34311 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewSetupFilesCommand.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewSetupFilesCommand.cs
@@ -17,12 +17,54 @@ namespace ICSharpCode.WixBinding
///
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;
+ }
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/DefaultFileLoader.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/DefaultFileLoader.cs
new file mode 100644
index 0000000000..ef40fc921f
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/DefaultFileLoader.cs
@@ -0,0 +1,28 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+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;
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/ActivePackageFilesView.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/ActivePackageFilesView.cs
new file mode 100644
index 0000000000..508ab37a58
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/ActivePackageFilesView.cs
@@ -0,0 +1,27 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+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;
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToComponentCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/IFormsDesignerView.cs
similarity index 63%
rename from src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToComponentCommand.cs
rename to src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/IFormsDesignerView.cs
index 06dbadcba2..752837629a 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToComponentCommand.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/IFormsDesignerView.cs
@@ -6,15 +6,12 @@
//
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; }
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/OpenTextEditors.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/OpenTextEditors.cs
new file mode 100644
index 0000000000..37fdd535b5
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/OpenTextEditors.cs
@@ -0,0 +1,42 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+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);
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs
index 9c04ca082b..a036215aaa 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs
@@ -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
{
///
/// Displays the setup package files.
///
- 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;
}
- ///
- /// Gets the project that this view is associated with.
- ///
- 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
}
public override bool IsDirty {
- get {
- return packageFilesControl.IsDirty;
- }
- }
-
- ///
- /// Shows the view for the specified project.
- ///
- 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
public void ShowFiles()
{
- packageFilesControl.ShowFiles(project, this, this);
+ packageFilesControl.ShowFiles(project, new WorkbenchTextFileReader(), this);
}
///
@@ -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
packageFilesControl.IsDiffVisible = false;
}
- ///
- /// Gets the package files view that is already open and displaying the files
- /// for the specified project.
- ///
- 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;
- }
-
- ///
- /// Merges the changes to the Wix document to the file currently open in
- /// SharpDevelop.
- ///
- 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;
}
///
@@ -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
}
}
- ///
- /// Checks whether the active window is the Wix document window.
- ///
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); }
}
- ///
- /// Checks whether the active window is this window.
- ///
- 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);
- }
-
- ///
- /// Gets the Wix xml for the specified element.
- ///
- string GetWixXml(XmlElement element)
- {
- ITextEditorProperties properties = SharpDevelopTextEditorProperties.Instance;
- return WixDocument.GetXml(element, properties.LineTerminator, properties.ConvertTabsToSpaces, properties.IndentationSize);
- }
-
- ///
- /// Tries to replace the element defined by element name and its Id attribute in the
- /// text editor with the specified xml.
- ///
- /// The Id attribute of the element.
- /// The name of the element.
- /// The text area control to update.
- /// The replacement xml.
- 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);
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs
index 9e026deabe..cea941cc5c 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs
@@ -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());
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs
index 492ee0fc7e..6eba959202 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs
@@ -5,7 +5,6 @@
// $Revision$
//
-using ICSharpCode.SharpDevelop.Refactoring;
using System;
using System.Collections.ObjectModel;
using System.IO;
@@ -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
// 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
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
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
/// Gets the Wix document filename.
///
public string DocumentFileName {
- get {
- return this.PrimaryFileName;
- }
+ get { return this.PrimaryFileName; }
}
///
/// Gets the wix project containing the document open in the designer.
///
public WixProject Project {
- get {
- return wixProject;
- }
+ get { return wixProject; }
}
///
@@ -203,9 +198,11 @@ namespace ICSharpCode.WixBinding
///
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
///
string GetFirstDialogIdInTextEditor()
{
- TextAreaControl textArea = ActiveTextAreaControl;
- if (textArea != null) {
- StringReader reader = new StringReader(textArea.Document.TextContent);
- ReadOnlyCollection ids = WixDocument.GetDialogIds(reader);
+ ITextEditor textEditor = ActiveTextEditor;
+ if (textEditor != null) {
+ StringReader reader = new StringReader(textEditor.Document.Text);
+ WixDocumentReader wixReader = new WixDocumentReader(reader);
+ ReadOnlyCollection ids = wixReader.GetDialogIds();
if (ids.Count > 0) {
return ids[0];
}
@@ -229,11 +227,11 @@ namespace ICSharpCode.WixBinding
///
/// Gets the active text area control.
///
- 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
{
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
public override object ToolsContent {
- get {
- return SetupDialogControlsToolBox;
- }
+ get { return SetupDialogControlsToolBox; }
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerDisplayBinding.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerDisplayBinding.cs
index f9b9e069af..e310f39bd0 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerDisplayBinding.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerDisplayBinding.cs
@@ -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
}
public bool ReattachWhenParserServiceIsReady {
- get {
- return false;
- }
+ get { return false; }
}
///
/// Wix dialog designer can attach to Wix source files (.wxs) and
/// Wix include files (.wxi).
///
- 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;
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs
index ad7cb07854..3a3fca65d1 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs
@@ -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
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 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
///
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)
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerLoader.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerLoader.cs
index 76b1b53d80..1fd0f0d7b2 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerLoader.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerLoader.cs
@@ -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
IWixDialogDesigner designer;
public WixDialogDesignerLoader(IWixDialogDesigner designer, IWixDialogDesignerGenerator generator)
- : this(designer, generator, null)
+ : this(designer, generator, new DefaultFileLoader())
{
}
@@ -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");
}
}
- ///
- /// Gets the designer used by the loader.
- ///
public IWixDialogDesigner Designer {
- get {
- return designer;
- }
+ get { return designer; }
}
- ///
- /// Gets the designer generator used by the loader.
- ///
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);
}
///
@@ -103,28 +136,24 @@ namespace ICSharpCode.WixBinding
///
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);
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs
index 8662453d86..59afb3d720 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs
@@ -6,24 +6,45 @@
//
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
{
///
/// A utility class that can replace xml in a Wix document currently open
/// in the text editor.
- ///
+ ///
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;
+ }
+
+
+ ///
+ /// Tries to replace the element defined by element name and its Id attribute in the
+ /// text editor with the specified xml.
+ ///
+ /// The Id attribute of the element.
+ /// The name of the element.
+ /// The replacement xml.
+ 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;
}
///
@@ -32,92 +53,146 @@ namespace ICSharpCode.WixBinding
///
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);
+ }
}
- ///
- /// Inserts and indents the xml at the specified location.
- ///
- 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);
}
///
- /// Selects the specified text range.
+ /// Inserts and indents the xml at the specified location.
///
- static void SelectText(SelectionManager selectionManager, IDocument document, int startOffset, int length)
+ ///
+ /// Lines and columns are zero based.
+ ///
+ 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);
+ }
}
-
+
///
/// Indents the lines and returns the total number of extra characters added.
///
- 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;
+ }
+
///
/// Gets the current indentation for the specified line.
///
- 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";
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentWindow.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentWindow.cs
new file mode 100644
index 0000000000..a6023d3028
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentWindow.cs
@@ -0,0 +1,34 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+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;
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs
index 6150e4e023..172094ffa8 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs
@@ -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
InitializeComponent();
diffControl.ContextMenuStrip = MenuService.CreateContextMenu(this, "/AddIns/WixBinding/WixPackageFilesDiffControl/ContextMenu");
}
-
- public delegate void DirtyChangedEventHandler(object source, EventArgs e);
-
+
///
/// Raised when the files are changed and require saving.
///
- public event DirtyChangedEventHandler DirtyChanged;
+ public event EventHandler DirtyChanged;
///
/// Gets or sets the error message that will be displayed instead of the
/// property grid.
///
public string ErrorMessage {
- get {
- return errorMessageTextBox.Text;
- }
- set {
- errorMessageTextBox.Text = value;
- }
+ get { return errorMessageTextBox.Text; }
+ set { errorMessageTextBox.Text = value; }
}
///
@@ -58,9 +52,7 @@ namespace ICSharpCode.WixBinding
/// error message text box replaces the property grid.
///
public bool IsErrorMessageTextBoxVisible {
- get {
- return errorMessageTextBoxVisible;
- }
+ get { return errorMessageTextBoxVisible; }
set {
errorMessageTextBoxVisible = value;
if (value) {
@@ -75,9 +67,7 @@ namespace ICSharpCode.WixBinding
/// Shows or hides the diff panel.
///
public bool IsDiffVisible {
- get {
- return diffVisible;
- }
+ get { return diffVisible; }
set {
if (diffVisible != value) {
diffVisible = value;
@@ -94,9 +84,7 @@ namespace ICSharpCode.WixBinding
/// Gets the project that is currently being displayed.
///
public WixProject Project {
- get {
- return project;
- }
+ get { return project; }
}
///
@@ -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
}
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
/// Gets the attributes for the selected xml element.
///
public WixXmlAttributeCollection Attributes {
- get {
- return wixXmlAttributes;
- }
+ get { return wixXmlAttributes; }
}
///
@@ -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
/// Wix document and the files on the file system and displays
/// the results.
///
- public void ShowDiff()
+ public void CalculateDiff()
{
- editor.ShowDiff();
+ editor.CalculateDiff();
}
///
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs
index 6a2898c35c..27d7c901e4 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs
@@ -46,18 +46,14 @@ namespace ICSharpCode.WixBinding
/// initialized then all the child nodes have been added to this node.
///
public bool IsInitialized {
- get {
- return isInitialized;
- }
+ get { return isInitialized; }
}
///
/// Can delete all Wix tree nodes.
///
public override bool EnableDelete {
- get {
- return true;
- }
+ get { return true; }
}
public override void Delete()
@@ -70,15 +66,11 @@ namespace ICSharpCode.WixBinding
/// Gets the XmlElement associated with this tree node.
///
public XmlElement XmlElement {
- get {
- return element;
- }
+ get { return element; }
}
public WixPackageFilesTreeView WixPackageFilesTreeView {
- get {
- return (WixPackageFilesTreeView)TreeView;
- }
+ get { return (WixPackageFilesTreeView)TreeView; }
}
///
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/IFileLoader.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/IFileLoader.cs
index 9e99d96d56..b063e5277b 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/IFileLoader.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/IFileLoader.cs
@@ -21,6 +21,6 @@ namespace ICSharpCode.WixBinding
///
/// if the file does not exist.
///
- Bitmap GetBitmap(string fileName);
+ Bitmap LoadBitmap(string fileName);
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToDirectoryCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/IPackageFilesViewFactory.cs
similarity index 60%
rename from src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToDirectoryCommand.cs
rename to src/AddIns/BackendBindings/WixBinding/Project/Src/IPackageFilesViewFactory.cs
index 885f912276..e0bc64c21d 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToDirectoryCommand.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/IPackageFilesViewFactory.cs
@@ -1,4 +1,4 @@
-//
+//
//
//
//
@@ -6,16 +6,12 @@
//
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);
}
}
-
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPackageFilesControl.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPackageFilesControl.cs
new file mode 100644
index 0000000000..c50dbf47cf
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPackageFilesControl.cs
@@ -0,0 +1,31 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+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; }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPropertyValueProvider.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPropertyValueProvider.cs
new file mode 100644
index 0000000000..797d1e849d
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPropertyValueProvider.cs
@@ -0,0 +1,23 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using System;
+
+namespace ICSharpCode.WixBinding
+{
+ ///
+ /// Interface that allows a class to convert a Wix property name into a value.
+ ///
+ public interface IWixPropertyValueProvider
+ {
+ ///
+ /// Gets the property value for the specified name. Wix property names are
+ /// case sensitive.
+ ///
+ string GetValue(string name);
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/PackageFilesViewFactory.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/PackageFilesViewFactory.cs
new file mode 100644
index 0000000000..0dfe9f4c2a
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/PackageFilesViewFactory.cs
@@ -0,0 +1,24 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+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);
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Project/WixProject.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Project/WixProject.cs
index 0f3074359c..26a47c28ce 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Project/WixProject.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Project/WixProject.cs
@@ -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
/// Gets the full path to the installer file that will be generated by
/// the Wix compiler and linker.
///
- 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);
}
-
+
///
/// Adds a set of Wix libraries (.wixlib) to the project.
///
- public void AddWixLibraries(string[] files)
+ public void AddWixLibraries(string[] fileNames)
{
- foreach (string fileName in files) {
+ foreach (string fileName in fileNames) {
AddWixLibrary(fileName);
}
}
- ///
- /// Adds a Wix library (.wixlib) to the project.
- ///
public void AddWixLibrary(string fileName)
{
WixLibraryProjectItem projectItem = new WixLibraryProjectItem(this);
projectItem.FileName = fileName;
ProjectService.AddProjectItem(this, projectItem);
}
-
- ///
- /// Adds a set of Wix extensions to the project.
- ///
- public void AddWixExtensions(string[] files)
+
+ public void AddWixExtensions(string[] fileNames)
{
- foreach (string fileName in files) {
+ foreach (string fileName in fileNames) {
AddWixExtension(fileName);
}
}
- ///
- /// Adds a Wix extension to the project.
- ///
public void AddWixExtension(string fileName)
{
WixExtensionProjectItem projectItem = new WixExtensionProjectItem(this);
@@ -166,14 +156,14 @@ namespace ICSharpCode.WixBinding
/// their filename.
///
public ReadOnlyCollection WixFiles {
- get { return GetMatchingFiles(WixDocument.IsWixFileName); }
+ get { return GetMatchingFiles(WixFileName.IsWixFileName); }
}
///
/// Returns the file project items that are Wix source files (.wxs).
///
public ReadOnlyCollection WixSourceFiles {
- get { return GetMatchingFiles(WixDocument.IsWixSourceFileName); }
+ get { return GetMatchingFiles(WixFileName.IsWixSourceFileName); }
}
///
@@ -189,9 +179,7 @@ namespace ICSharpCode.WixBinding
///
/// TODO: This can be configuration specific.
///
- /// The preprocessor variable name.
- /// An empty string if the name cannot be found.
- 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
///
/// Gets the MSBuild Property value for the given name.
///
- 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
/// in MSBuildBasedProject is called.
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);
}
///
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs
index 9d44bc4acb..3df1f438ef 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs
@@ -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) {
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaryElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaryElement.cs
index 63648c387d..b73018aeb8 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaryElement.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaryElement.cs
@@ -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
///
/// The full path is generated by using the WixDocument's filename.
///
- 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;
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs
index e18511e9aa..6554313e45 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs
@@ -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
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); }
}
- ///
- /// Checks whether the disk id has already been set for this component.
- ///
public bool HasDiskId {
get { return HasAttribute("DiskId"); }
}
- ///
- /// Generates a new guid for this component element.
- ///
public void GenerateNewGuid()
{
Guid = System.Guid.NewGuid().ToString().ToUpperInvariant();
}
+ public WixFileElement[] GetFiles()
+ {
+ List files = new List();
+ foreach (XmlNode childNode in ChildNodes) {
+ WixFileElement childElement = childNode as WixFileElement;
+ if (childElement != null) {
+ files.Add(childElement);
+ }
+ }
+ return files.ToArray();
+ }
+
///
/// Creates a new file element with the specified filename.
///
public WixFileElement AddFile(string fileName)
{
WixFileElement fileElement = new WixFileElement(this, fileName);
- return (WixFileElement)AppendChild(fileElement);
+ AppendChild(fileElement);
+ return fileElement;
}
- ///
- /// Creates an id from the filename.
- ///
///
/// Takes the filename, removes all periods, and
/// capitalises the first character and first extension character.
///
- /// The Wix document is used to make sure the
- /// id generated is unique for that document.
- /// The full filename including the directory to
- /// use when generating the id.
- 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);
}
///
@@ -105,44 +88,77 @@ namespace ICSharpCode.WixBinding
/// Takes the filename, removes all periods, and
/// capitalises the first character and first extension character.
///
- 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;
}
- ///
- /// Gets any child file elements.
- ///
- public WixFileElement[] GetFiles()
+ string UpperCaseFirstCharacter(string s)
{
- List files = new List();
- 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;
}
- ///
- /// Upper cases first character of string.
- ///
- 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;
}
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs
index 9d2e64bae7..9884b2c2dd 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs
@@ -52,8 +52,8 @@ namespace ICSharpCode.WixBinding
///
/// The dialog XML element loaded from
/// the Wix document
- 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
{
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)
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialogElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialogElement.cs
new file mode 100644
index 0000000000..752cdb08fb
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialogElement.cs
@@ -0,0 +1,22 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using System;
+using System.Xml;
+
+namespace ICSharpCode.WixBinding
+{
+ public class WixDialogElement : WixElementBase
+ {
+ public const string DialogElementName = "Dialog";
+
+ public WixDialogElement(WixDocument document)
+ : base(DialogElementName, document)
+ {
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs
index b039f6f1cb..63775d60d7 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs
@@ -24,18 +24,10 @@ namespace ICSharpCode.WixBinding
{
}
- ///
- /// Determines whether the specified element name refers to a Directory element.
- ///
- public static bool IsDirectoryElement(string name)
- {
- return name == DirectoryElementName;
- }
-
///
/// Returns the last directory specified in the path
///
- 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
///
/// Adds a new component element to this directory element.
///
- 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 {
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs
index 2fc70357f3..a10e7e3f1d 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs
@@ -17,18 +17,13 @@ namespace ICSharpCode.WixBinding
/// Common base class for the WixDirectoryElement and WixDirectoryRefElement
/// classes.
///
- 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); }
- }
-
///
/// Gets any child directory elements.
///
@@ -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
WixDirectoryElement directoryElement = new WixDirectoryElement((WixDocument)OwnerDocument);
directoryElement.Id = WixFileElement.GenerateId(name);
directoryElement.DirectoryName = name;
- return (WixDirectoryElement)AppendChild(directoryElement);
- }
+ AppendChild(directoryElement);
+ return directoryElement;
+ }
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs
index 0cfff9e7f3..7aeb4a4803 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs
@@ -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
/// A Wix document (.wxs or .wxi).
///
public class WixDocument : XmlDocument, IWixPropertyValueProvider
- {
- public const string WixSourceFileExtension = ".wxs";
- public const string WixIncludeFileExtension = ".wxi";
-
- ///
- /// Class used to store the line number and dialog id of the
- /// dialog element start tag.
- ///
- 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;
- }
- }
- }
-
- ///
- /// Default IFileLoader implementation which tries to load
- /// the bitmap from the specified filename. If the file does
- /// not exist the bitmap is not loaded.
- ///
- 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
{
this.project = project;
this.fileLoader = fileLoader;
+
if (fileLoader == null) {
- throw new ArgumentException("Cannot be null.", "fileLoader");
+ throw new ArgumentNullException("fileLoader");
}
+
namespaceManager = new WixNamespaceManager(NameTable);
}
- ///
- /// Gets the project that this document belongs to.
- ///
public WixProject Project {
- get {
- return project;
- }
+ get { return project; }
}
- ///
- /// Gets or sets the filename for the Wix Document.
- ///
public string FileName {
- get {
- return fileName;
- }
- set {
- fileName = value;
- }
+ get { return fileName; }
+ set { fileName = value; }
}
///
- /// Gets the dialogs from a Wix file.
- ///
- public static ReadOnlyCollection GetDialogIds(string fileName)
- {
- using (XmlTextReader reader = new XmlTextReader(new FileStream(fileName, FileMode.Open, FileAccess.Read))) {
- return GetDialogIds(reader);
- }
- }
-
- ///
- /// Gets the dialogs from a Wix file.
- ///
- public static ReadOnlyCollection GetDialogIds(TextReader reader)
- {
- XmlTextReader xmlReader = new XmlTextReader(reader);
- return GetDialogIds(xmlReader);
- }
-
- ///
- /// Gets the dialog Ids in a Wix file.
- ///
- public static ReadOnlyCollection GetDialogIds(XmlTextReader reader)
- {
- using (reader) {
- List dialogIds = new List();
- 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(dialogIds);
- }
- }
-
- ///
- /// Gets the line and column where the specified element starts. The column
- /// returned is the column containing the opening tag (<).
- ///
- /// The element name.
- /// The id attribute value.
- public static Location GetStartElementLocation(TextReader reader, string name, string id)
- {
- XmlTextReader xmlReader = new XmlTextReader(reader);
- return GetStartElementLocation(xmlReader, name, id);
- }
-
- ///
- /// Gets the line and column where the specified element starts. The column
- /// returned is the column containing the opening tag (<).
- ///
- /// The element name.
- /// The id attribute value.
- 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;
- }
-
- ///
- /// Gets the line and column where the specified element ends. The column
- /// returned is the column containing the opening tag (<) of the end element.
- ///
- /// The element name.
- /// The id attribute value.
- public static Location GetEndElementLocation(TextReader reader, string name, string id)
- {
- XmlTextReader xmlReader = new XmlTextReader(reader);
- return GetEndElementLocation(xmlReader, name, id);
- }
-
- ///
- /// Gets the line and column where the specified element ends. The column
- /// returned is the column containing the opening tag (<) of the end element.
- ///
- /// The element name.
- /// The id attribute value.
- 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;
- }
-
- ///
- /// Gets the dialog id at the specified line.
- ///
- /// Line numbers start from zero.
- /// The dialog id found at the specified line;
- /// if no dialog found.
- public static string GetDialogId(TextReader reader, int line)
- {
- XmlTextReader xmlReader = new XmlTextReader(reader);
- return GetDialogId(xmlReader, line);
- }
-
- ///
- /// Gets the dialog id at the specified line.
+ /// Gets a WixDialog object for the specified dialog id.
///
- /// Line numbers start from zero.
- /// The dialog id found at the specified line;
- /// if no dialog found.
- 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;
}
-
- ///
- /// 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).
- ///
- 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;
- }
-
- ///
- /// Checks whether the file extension is for a Wix source file (.wxs).
- ///
- public static bool IsWixSourceFileName(string fileName)
- {
- return String.Compare(Path.GetExtension(fileName), WixSourceFileExtension, true) == 0;
- }
- ///
- /// Converts a DomRegion to an ISegment for the given document.
- ///
- 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);
}
- ///
- /// Creates an XML fragment string for the specified element.
- ///
- /// The line terminator.
- /// Indicates whether tabs will be converted to spaces.
- /// The indent to be used when converting tabs to spaces.
- /// An XML fragment string without any Wix namespace attributes.
- 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));
}
- ///
- /// 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.
- ///
- /// The name of the element.
- /// The id attribute value of the element.
- 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));
}
- ///
- /// 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.
- ///
- /// The name of the element.
- /// The id attribute value of the element.
- 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);
}
- ///
- /// Gets a WixDialog object for the specified dialog id.
- ///
- /// The id of the dialog.
- /// A for the dialog id
- /// found; otherwise if no dialog
- /// with the specified id can be found.
- 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);
}
- ///
- /// Gets a WixDialog object for the specified dialog id.
- ///
- /// The id of the dialog.
- /// The text file reader to use when looking up
- /// binary filenames.
- /// A for the dialog id
- /// found; otherwise if no dialog
- /// with the specified id can be found.
- 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);
}
- ///
- /// Gets the binary filename for the specified id.
- ///
- /// if the id cannot be found.
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;
}
- ///
- /// Loads the bitmap using the Wix Bitmap id.
- ///
- public Bitmap GetBitmapFromId(string id)
- {
- string bitmapFileName = GetBinaryFileName(id);
- return GetBitmapFromFileName(bitmapFileName);
- }
-
- ///
- /// Loads the bitmap.
- ///
- 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
///
/// Gets a property value defined in the Wix document.
///
- /// The property value if it is found; an empty string otherwise.
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;
}
- ///
- /// Gets the preprocessor variable value from the WixProject.
- ///
- 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
///
/// Gets the top SOURCEDIR directory.
///
- 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);
}
///
/// Gets a reference to the root directory.
///
- 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);
}
- ///
- /// The Wix document contains the Product element.
- ///
- public bool IsProductDocument {
- get {
- return Product != null;
- }
+ public bool HasProduct {
+ get { return GetProduct() != null; }
}
- ///
- /// Gets the prefix used for the Wix namespace.
- ///
- 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;
}
- ///
- /// Adds a new root directory.
- ///
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);
}
- ///
- /// Creates a new Xml element belonging to the Wix namespace.
- ///
- public XmlElement CreateWixElement(string name)
+ XmlElement AddProduct()
{
- return CreateElement(WixNamespacePrefix, name, WixNamespaceManager.Namespace);
+ XmlElement productElement = CreateWixElement("Product");
+ DocumentElement.AppendChild(productElement);
+ return productElement;
}
- ///
- /// Saves the document to the location specified by WixDocument.FileName.
- ///
- 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);
- }
- }
-
- ///
- /// Gets the Product element.
- ///
- public XmlElement Product {
- get {
- return (XmlElement)SelectSingleNode("w:Wix/w:Product", namespaceManager);
- }
+ WixDirectoryElement rootDirectory = WixDirectoryElement.CreateRootDirectory(this);
+ return (WixDirectoryElement)parentProductElement.AppendChild(rootDirectory);
}
- ///
- /// Gets the binary elements defined in this document.
- ///
- public WixBinaryElement[] GetBinaries()
+ public XmlElement CreateWixElement(string name)
{
- List binaries = new List();
- foreach (WixBinaryElement element in SelectNodes("//w:Binary", namespaceManager)) {
- binaries.Add(element);
- }
- return binaries.ToArray();
+ return CreateElement(GetWixNamespacePrefix(), name, WixNamespaceManager.Namespace);
}
///
@@ -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
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;
+ }
+
///
/// Checks to see if a Component element exists with the specified id in this
/// document.
@@ -673,7 +263,7 @@ namespace ICSharpCode.WixBinding
///
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
///
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;
}
- ///
- /// Reads the dialog id and adds it to the list of dialogs found so far.
- ///
- /// An XmlReader which is currently at the dialog start element.
- static void AddDialogId(XmlReader reader, List dialogIds)
+ public XmlElement GetProduct()
{
- string id = GetIdFromCurrentNode(reader);
- if (id.Length > 0) {
- dialogIds.Add(id);
- }
+ return SelectSingleElement("w:Wix/w:Product");
}
- ///
- /// Gets the id for the current element.
- ///
- /// An XmlReader which is currently at the start element.
- static string GetIdFromCurrentNode(XmlReader reader)
- {
- if (reader.MoveToAttribute("Id")) {
- if (reader.Value != null) {
- return reader.Value;
- }
- }
- return String.Empty;
- }
-
- ///
- /// Checks that the atomised element names match.
- ///
- static bool IsElementMatch(object elementName, object currentElementName)
- {
- return elementName == currentElementName;
- }
-
- ///
- /// 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.
- ///
- /// A dialog id.
- /// An XmlTextReader currently at the dialog start element.
- /// if the dialog id does not match.
- static Location GetStartElementLocationIfMatch(XmlTextReader reader, string id)
- {
- // Store the column and line position since the call to GetDialogId will
- // move to the