public void AddRegisterDirective(RegisterDirective directive, TextEditorData editor, bool preserveCaretPosition)
        {
            var node = GetRegisterInsertionPointNode();

            if (node == null)
            {
                return;
            }

            Doc.Info.RegisteredTags.Add(directive);

            var line = Math.Max(node.Location.EndLine, node.Location.BeginLine);
            var pos  = editor.Document.LocationToOffset(line, editor.Document.GetLine(line - 1).Length);

            if (pos < 0)
            {
                return;
            }

            using (var undo = editor.OpenUndoGroup())
            {
                var oldCaret = editor.Caret.Offset;

                var inserted = editor.Insert(pos, editor.EolMarker + directive.ToString());
                if (preserveCaretPosition)
                {
                    editor.Caret.Offset = (pos < oldCaret)? oldCaret + inserted : oldCaret;
                }
            }
        }
        /// <summary>
        /// Gets a tag prefix, also returning the directive that would have to be added if necessary.
        /// </summary>
        public string GetTagPrefixWithNewDirective(IType control, string assemblyName, string desiredPrefix,
                                                   out RegisterDirective directiveNeededToAdd)
        {
            directiveNeededToAdd = null;
            string existingPrefix = GetTagPrefix(control);

            if (existingPrefix != null)
            {
                return(existingPrefix);
            }

            //TODO: detect control name conflicts
            string prefix = desiredPrefix;

            if (desiredPrefix == null)
            {
                prefix = GetPrefix(control);
            }

            var an = MonoDevelop.Core.Assemblies.SystemAssemblyService.ParseAssemblyName(assemblyName);

            directiveNeededToAdd = new AssemblyRegisterDirective(prefix, control.Namespace, an.Name);

            return(prefix);
        }
        public void AddRegisterDirective(RegisterDirective directive, TextEditor editor, bool preserveCaretPosition)
        {
            var node = GetRegisterInsertionPointNode();

            if (node == null)
            {
                return;
            }

            Doc.Info.RegisteredTags.Add(directive);

            var line = Math.Max(node.Location.EndLine, node.Location.BeginLine);
            var pos  = editor.GetPositionFromLineColumn(line, editor.GetLineLength(line) + 1);

            if (pos < 0)
            {
                return;
            }

            editor.BeginAtomicUndo();
            var oldCaret = editor.CursorPosition;

            var inserted = editor.InsertText(pos, editor.NewLine + directive.ToString());

            if (preserveCaretPosition)
            {
                editor.CursorPosition = (pos < oldCaret)? oldCaret + inserted : oldCaret;
            }
            editor.EndAtomicUndo();
        }
		public void AddRegisterDirective (RegisterDirective directive, TextEditorData editor, bool preserveCaretPosition)
		{
			var node = GetRegisterInsertionPointNode ();
			if (node == null)
				return;
			
			Doc.Info.RegisteredTags.Add (directive);
			
			var line = Math.Max (node.Region.EndLine, node.Region.BeginLine);
			var pos = editor.Document.LocationToOffset (line, editor.Document.GetLine (line - 1).Length);
			if (pos < 0)
				return;
			
			using (var undo = editor.OpenUndoGroup ()) {
				var oldCaret = editor.Caret.Offset;
				
				var inserted = editor.Insert (pos, editor.EolMarker + directive.ToString ());
				if (preserveCaretPosition) {
					editor.Caret.Offset = (pos < oldCaret)? oldCaret + inserted : oldCaret;
				}
			}
		}
		/// <summary>
		/// Gets a tag prefix, also returning the directive that would have to be added if necessary.
		/// </summary>
		public string GetTagPrefixWithNewDirective (IType control, string assemblyName, string desiredPrefix, 
		                                            out RegisterDirective directiveNeededToAdd)
		{
			directiveNeededToAdd = null;
			string existingPrefix = GetTagPrefix (control);
			if (existingPrefix != null)
				return existingPrefix;
			
			//TODO: detect control name conflicts 
			string prefix = desiredPrefix;
			if (desiredPrefix == null)
				prefix = GetPrefix (control);
			
			var an = MonoDevelop.Core.Assemblies.SystemAssemblyService.ParseAssemblyName (assemblyName);
			
			directiveNeededToAdd = new AssemblyRegisterDirective (prefix, control.Namespace, an.Name);
			
			return prefix;
		}
		public void AddRegisterDirective (RegisterDirective directive, TextEditor editor, bool preserveCaretPosition)
		{
			var node = GetRegisterInsertionPointNode ();
			if (node == null)
				return;
			
			Doc.Info.RegisteredTags.Add (directive);
			
			var line = Math.Max (node.Location.EndLine, node.Location.BeginLine);
			var pos = editor.GetPositionFromLineColumn (line, editor.GetLineLength (line) + 1);
			if (pos < 0)
				return;
			
			editor.BeginAtomicUndo ();
			var oldCaret = editor.CursorPosition;
			
			var inserted = editor.InsertText (pos, editor.NewLine + directive.ToString ());
			if (preserveCaretPosition) {
				editor.CursorPosition = (pos < oldCaret)? oldCaret + inserted : oldCaret;
			}
			editor.EndAtomicUndo ();
		}