bool UpdateOpenFileWithRootDirectoryChanges(WixDocument wixDocument, TextAreaControl textAreaControl)
        {
            // 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);
            }

            // Find the product end element location.
            IDocument document = textAreaControl.Document;
            Location  location = WixDocument.GetEndElementLocation(new StringReader(document.TextContent), "Product", wixDocument.Product.GetAttribute("Id"));

            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);
            }
            return(false);
        }
		public void Init()
		{
			originalXml = 
				"<root>\r\n" +
				"    <child>\r\n" +
				"    </child>\r\n" +
				"</root>";
			
			textEditor = new MockTextEditor();
			textEditor.OptionsConvertTabsToSpaces = true;
			textEditor.OptionsIndentationSize = 4;
			textEditor.OptionsIndentationString = " ";
			
			textEditor.Document.Text = originalXml;
					
			// Insert new xml as child element of <child>.
			// Insert position is just before the start of </root> end element.
			WixDocumentEditor editor = new WixDocumentEditor(textEditor);
			
			string xmlToInsert = 
				"<new-child>\r\n" +
				"</new-child>\r\n";
			
			int line = 3;
			int column = 5;
			editor.InsertIndented(line, column, xmlToInsert);
			
			document = textEditor.Document;
		}
        void UpdateOpenTextEditorWithRootDirectoryRefChanges(ITextEditor textEditor, WixDocument document)
        {
            WixDirectoryRefElement rootDirectoryRef = document.GetRootDirectoryRef();
            string xml = rootDirectoryRef.GetXml(wixTextWriter);

            WixDocumentEditor documentEditor = new WixDocumentEditor(textEditor);

            documentEditor.ReplaceElement(rootDirectoryRef.Id, WixDirectoryRefElement.DirectoryRefElementName, xml);
        }
		public void Init()
		{
			textEditor = new MockTextEditor();
			textEditor.Document.Text = GetWixXml();
			
			string replacementXml = 
				"<NewElement>\r\n" +
				"</NewElement>";
			
			wixDocumentEditor = new WixDocumentEditor(textEditor);
			replacementRegion = wixDocumentEditor.ReplaceElement("TARGETDIR", "Directory", replacementXml);
		}
        /// <summary>
        /// Tries to replace the element defined by element name and its Id attribute in the
        /// text editor with the specified xml.
        /// </summary>
        /// <param name="id">The Id attribute of the element.</param>
        /// <param name="elementName">The name of the element.</param>
        /// <param name="textAreaControl">The text area control to update.</param>
        /// <param name="xml">The replacement xml.</param>
        bool ReplaceElement(string id, string elementName, TextAreaControl textAreaControl, string xml)
        {
            WixDocumentEditor documentEditor = new WixDocumentEditor(textAreaControl);
            IDocument         document       = textAreaControl.Document;
            DomRegion         region         = WixDocument.GetElementRegion(new StringReader(document.TextContent), elementName, id);

            if (!region.IsEmpty)
            {
                documentEditor.Replace(region, xml);
                return(true);
            }
            return(false);
        }
		/// <summary>
		/// Merges the changes made to the wix document by overwriting the dialog element.
		/// </summary>
		void IWixDialogDesignerGenerator.MergeFormChanges(string dialogId, XmlElement dialogElement)
		{
			DomRegion region = GetTextEditorRegionForDialogElement(dialogId);
			if (region.IsEmpty) {
				ThrowDialogElementCouldNotBeFoundError(dialogId);
			}
			
			WixTextWriter writer = new WixTextWriter(textEditor.Options);
			WixDialogElement wixDialogElement = (WixDialogElement)dialogElement;
			string newDialogXml = wixDialogElement.GetXml(writer);
			
			WixDocumentEditor editor = new WixDocumentEditor(textEditor);
			editor.Replace(region, newDialogXml);
		}
示例#7
0
        /// <summary>
        /// Merges the changes made to the wix document by overwriting the dialog element.
        /// </summary>
        void IWixDialogDesignerGenerator.MergeFormChanges(string dialogId, XmlElement dialogElement)
        {
            DomRegion region = GetTextEditorRegionForDialogElement(dialogId);

            if (region.IsEmpty)
            {
                ThrowDialogElementCouldNotBeFoundError(dialogId);
            }

            WixTextWriter    writer           = new WixTextWriter(textEditor.Options);
            WixDialogElement wixDialogElement = (WixDialogElement)dialogElement;
            string           newDialogXml     = wixDialogElement.GetXml(writer);

            WixDocumentEditor editor = new WixDocumentEditor(textEditor);

            editor.Replace(region, newDialogXml);
        }
示例#8
0
        /// <summary>
        /// Merges the changes made to the wix document by overwriting the dialog element.
        /// </summary>
        void IWixDialogDesignerGenerator.MergeFormChanges(string dialogId, XmlElement dialogElement)
        {
            // Get the text region we are replacing.
            IDocument document = view.DesignerCodeFileDocument;
            DomRegion region   = WixDocument.GetElementRegion(new StringReader(document.TextContent), "Dialog", dialogId);

            if (region.IsEmpty)
            {
                throw new FormsDesignerLoadException(String.Format(StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}"), dialogId));
            }
            // Get the replacement dialog xml.
            TextEditorControl     textEditorControl = ((ITextEditorControlProvider)view.PrimaryViewContent).TextEditorControl;
            ITextEditorProperties 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);
        }
        void UpdateOpenTextEditorWithRootDirectoryChanges(ITextEditor textEditor, WixDocument document)
        {
            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;
            }

            Location location = FindProductElementEndLocation(textEditor, document);

            if (!location.IsEmpty)
            {
                documentEditor.InsertIndented(location, String.Concat(xml, "\r\n"));
            }
        }
		public void Init()
		{
			originalXml = 
				"<root>\r\n" +
				"\t<child>\r\n" +
				"\t</child>\r\n" +
				"</root>";
			
			textEditor = new MockTextEditor();
			textEditor.OptionsConvertTabsToSpaces = false;
			textEditor.OptionsIndentationSize = 4;
			textEditor.OptionsIndentationString = "\t";
			
			document = textEditor.Document;

			textEditor.Document.Text = originalXml;
					
			// Replace the <child> element
			WixDocumentEditor editor = new WixDocumentEditor(textEditor);
			
			string xmlToInsert = 
				"<new-child>\r\n" +
				"</new-child>";
			
			int line = 2;
			int column = 2;
			int endLine = 3;
			
			// End column is the column containing the '>' of the </child> element.
			int endColumn = 9;
			
			DomRegion region = new DomRegion(line, column, endLine, endColumn);
			
			WixDocumentLineSegment lineSegment = WixDocumentLineSegment.ConvertRegionToSegment(textEditor.Document, region);
			initialDocumentRegionText = textEditor.Document.GetText(lineSegment.Offset, lineSegment.Length);

			editor.Replace(region, xmlToInsert);			
		}
示例#11
0
		void UpdateOpenTextEditorWithRootDirectoryRefChanges(ITextEditor textEditor, WixDocument document)
		{
			WixDirectoryRefElement rootDirectoryRef = document.GetRootDirectoryRef();
			string xml = rootDirectoryRef.GetXml(wixTextWriter);
			
			WixDocumentEditor documentEditor = new WixDocumentEditor(textEditor);
			documentEditor.ReplaceElement(rootDirectoryRef.Id, WixDirectoryRefElement.DirectoryRefElementName, xml);
		}
示例#12
0
		void UpdateOpenTextEditorWithRootDirectoryChanges(ITextEditor textEditor, WixDocument document)
		{
			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;
			}
			
			TextLocation location = FindProductElementEndLocation(textEditor, document);
			if (!location.IsEmpty) {
				documentEditor.InsertIndented(location, String.Concat(xml, "\r\n"));
			}
		}
		/// <summary>
		/// Tries to replace the element defined by element name and its Id attribute in the
		/// text editor with the specified xml.
		/// </summary>
		/// <param name="id">The Id attribute of the element.</param>
		/// <param name="elementName">The name of the element.</param>
		/// <param name="textAreaControl">The text area control to update.</param>
		/// <param name="xml">The replacement xml.</param>
		bool ReplaceElement(string id, string elementName, TextAreaControl textAreaControl, string xml)
		{
			WixDocumentEditor documentEditor = new WixDocumentEditor(textAreaControl);
			IDocument document = textAreaControl.Document;
			DomRegion region = WixDocument.GetElementRegion(new StringReader(document.TextContent), elementName, id);
			if (!region.IsEmpty) {
				documentEditor.Replace(region, xml);
				return true;
			}
			return false;
		}
		bool UpdateOpenFileWithRootDirectoryChanges(WixDocument wixDocument, TextAreaControl textAreaControl)
		{
			// 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;
			}
			
			// Find the product end element location.
			IDocument document = textAreaControl.Document;
			Location location = WixDocument.GetEndElementLocation(new StringReader(document.TextContent), "Product", wixDocument.Product.GetAttribute("Id"));
			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;
			}
			return false;
		}
		/// <summary>
		/// Merges the changes made to the wix document by overwriting the dialog element.
		/// </summary>
		void IWixDialogDesignerGenerator.MergeFormChanges(string dialogId, XmlElement dialogElement)
		{
			// Get the text region we are replacing.
			IDocument document = view.DesignerCodeFileDocument;
			DomRegion region = WixDocument.GetElementRegion(new StringReader(document.TextContent), "Dialog", dialogId);
			if (region.IsEmpty) {
				throw new FormsDesignerLoadException(String.Format(StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}"), dialogId));
			}
			// Get the replacement dialog xml.
			TextEditorControl textEditorControl = ((ITextEditorControlProvider)view.PrimaryViewContent).TextEditorControl;
			ITextEditorProperties 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);
		}