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

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

                if (!string.IsNullOrEmpty(this.Tag.ExistingBindingMode))
                {
                    vs.ReplaceInActiveDocOnLine(this.Tag.ExistingBindingMode, "Mode=TwoWay", lineNumber);
                }
                else
                {
                    vs.ReplaceInActiveDocOnLine("}", ", Mode=TwoWay}", lineNumber);
                }

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

            if (resPath == null)
            {
                return;
            }

            var vs = new VisualStudioTextManipulation(ProjectHelpers.Dte);

            vs.StartSingleUndoOperation(StringRes.Info_UndoContextMoveStringToResourceFile);

            try
            {
                // If the resource file is open with unsaved changes VS will prompt about data being lost.
                this.AddResource(resPath, $"{this.Tag.UidValue}.{this.Tag.AttributeName}", this.Tag.Value);

                if (this.Tag.AttributeType == AttributeType.Inline)
                {
                    var currentAttribute = $"{this.Tag.AttributeName}=\"{this.Tag.Value}\"";

                    if (this.Tag.UidExists)
                    {
                        vs.RemoveInActiveDocOnLine(currentAttribute, this.Tag.GetDesignerLineNumber());
                    }
                    else
                    {
                        var uidTag = $"x:Uid=\"{this.Tag.UidValue}\"";
                        vs.ReplaceInActiveDocOnLine(currentAttribute, uidTag, this.Tag.GetDesignerLineNumber());
                    }
                }
                else if (this.Tag.AttributeType == AttributeType.Element)
                {
                    var currentAttribute = $"<{this.Tag.ElementName}.{this.Tag.AttributeName}>{this.Tag.Value}</{this.Tag.ElementName}.{this.Tag.AttributeName}>";

                    vs.RemoveInActiveDocOnLine(currentAttribute, this.Tag.GetDesignerLineNumber());

                    if (!this.Tag.UidExists)
                    {
                        var uidTag = $"<{this.Tag.ElementName} x:Uid=\"{this.Tag.UidValue}\"";
                        vs.ReplaceInActiveDocOnLineOrAbove($"<{this.Tag.ElementName}", uidTag, this.Tag.GetDesignerLineNumber());
                    }
                }
                else if (this.Tag.AttributeType == AttributeType.DefaultValue)
                {
                    var current     = $">{this.Tag.Value}</{this.Tag.ElementName}>";
                    var replaceWith = this.Tag.UidExists ? " />" : $" x:Uid=\"{this.Tag.UidValue}\" />";

                    vs.ReplaceInActiveDocOnLine(current, replaceWith, this.Tag.GetDesignerLineNumber());
                }

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

            vs.StartSingleUndoOperation(this.UndoText);
            try
            {
                vs.ReplaceInActiveDocOnLine(this.Original, this.Replace, this.LineNo);

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

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

                string newName;

                if (this.Tag.ExistingName.ToLowerInvariant().Contains("checked"))
                {
                    if (this.Tag.ExistingIsChecked)
                    {
                        newName = this.Tag.ExistingName.Replace("Checked", "UnChecked").Replace("checked", "Unchecked");
                    }
                    else
                    {
                        newName = this.Tag.ExistingName.Replace("UnChecked", "Checked").Replace("unchecked", "checked");
                    }
                }
                else
                {
                    if (this.Tag.ExistingIsChecked)
                    {
                        newName = "OnCheckBoxUnchecked";
                    }
                    else
                    {
                        newName = "OnCheckBoxChecked";
                    }
                }

                var newEvent = this.Tag.ExistingIsChecked
                    ? $"Unchecked=\"{newName}\""
                    : $"Checked=\"{newName}\"";

                vs.ReplaceInActiveDocOnLine("<CheckBox", $"<CheckBox {newEvent} ", lineNumber);

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

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

                vs.ReplaceInActiveDocOnLine("<Entry ", $"<Entry Keyboard=\"{this.KeyBoardName}\" ", lineNumber);

                RapidXamlDocumentCache.TryUpdate(this.File);
            }
            finally
            {
                vs.EndSingleUndoOperation();
            }
        }
Esempio n. 6
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. 7
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();
            }
        }