/// <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);
		}
示例#3
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);
        }
示例#4
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);
        }
		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);			
		}
		/// <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)
		{
			// 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);
		}