Esempio n. 1
0
        public override void Execute(CancellationToken cancellationToken)
        {
            var vs = new VisualStudioTextManipulation(ProjectHelpers.Dte);

            vs.StartSingleUndoOperation(this.UndoOperationName);
            try
            {
                var lineNumber = this.Tag.Snapshot.GetLineNumberFromPosition(this.Tag.InsertPosition) + 1;

                string toInsert;
                if (this.Tag.GridNeedsExpanding)
                {
                    vs.RemoveInActiveDocOnLine(" />", lineNumber);

                    toInsert = $">{Environment.NewLine}{this.InjectedXaml}";

                    toInsert = toInsert.Replace("\n", "\n" + this.Tag.LeftPad);

                    string shortPad = this.Tag.LeftPad.EndsWith("\t")
                        ? this.Tag.LeftPad.Substring(0, this.Tag.LeftPad.Length - 1)
                        : this.Tag.LeftPad.Substring(0, this.Tag.LeftPad.Length - 4);

                    toInsert += $"{Environment.NewLine}{shortPad}</Grid>";
                }
                else
                {
                    toInsert = Environment.NewLine + this.InjectedXaml;
                    toInsert = toInsert.Replace("\n", "\n" + this.Tag.LeftPad);
                }

                vs.InsertAtEndOfLine(lineNumber, toInsert);

                RapidXamlDocumentCache.TryUpdate(this.File);
            }
            finally
            {
                vs.EndSingleUndoOperation();
            }
        }
Esempio n. 2
0
        public override void Execute(CancellationToken cancellationToken)
        {
            var vs = new VisualStudioTextManipulation(ProjectHelpers.Dte);

            vs.StartSingleUndoOperation(StringRes.Info_UndoContextAddRowDefinitions);

            try
            {
                var insert = string.Empty;

                const string def = "<RowDefinition Height=\"*\" />";

                var leftPad = this.Tag.LeftPad.Contains("\t") ? this.Tag.LeftPad + "\t" : this.Tag.LeftPad + "    ";

                for (var i = 0; i <= this.Tag.TotalDefsRequired - this.Tag.ExistingDefsCount; i++)
                {
                    insert += $"{Environment.NewLine}{leftPad}{def}";
                }

                var insertLine = this.Tag.Snapshot.GetLineNumberFromPosition(this.Tag.InsertPosition);

                if (!this.Tag.HasSomeDefinitions)
                {
                    insert = $"{Environment.NewLine}{this.Tag.LeftPad}<Grid.RowDefinitions>{insert}{Environment.NewLine}{this.Tag.LeftPad}</Grid.RowDefinitions>";

                    // Account for different reference position - end-of-start vs start-of-end
                    insertLine += 1;
                }

                vs.InsertAtEndOfLine(insertLine, insert);

                RapidXamlDocumentCache.TryUpdate(this.File);
            }
            finally
            {
                vs.EndSingleUndoOperation();
            }
        }