Ejemplo n.º 1
0
        public override void Execute()
        {
            var textDocument = AddIn.TextDocument;
            var cursor       = AddIn.Cursor;

            if (cursor.Row == textDocument.EndPoint.Line)
            {
                return;
            }

            var line = AddIn.CurrentLine;

            textDocument.Selection.LineDown();
            var otherLine = AddIn.CurrentLine;

            textDocument.Selection.SelectLine();
            AddIn.InsertText(line + Environment.NewLine, true);

            textDocument.Selection.Cancel();
            textDocument.Selection.LineUp();

            textDocument.Selection.SelectLine();
            AddIn.InsertText(otherLine + Environment.NewLine, true);

            textDocument.Selection.Cancel();
            textDocument.Selection.LineDown();
            textDocument.Selection.CharRight(false, cursor.Column - 1);
        }
Ejemplo n.º 2
0
        public override void Execute()
        {
            var textDocument = AddIn.TextDocument;

            if (AddIn.CurrentSelection.Length == 0)
            {
                textDocument.Selection.Insert("/");
            }
            else
            {
                var ranges = textDocument.Selection.TextRanges
                             .OfType <TextRange>()
                             .Select(tr => new
                {
                    Start      = new Cursor(tr.StartPoint.DisplayColumn, tr.StartPoint.Line),
                    End        = new Cursor(tr.EndPoint.DisplayColumn, tr.EndPoint.Line),
                    StartPoint = tr.StartPoint,
                    EndPoint   = tr.EndPoint
                })
                             .Where(r => !r.Start.Equals(r.End))
                             .ToList();

                if (ranges.Any(r => r.StartPoint.AtStartOfLine))
                {
                    var text = textDocument.Selection.Text;
                    if (ranges.Count > 1)
                    {
                        var trailingNewLine = textDocument.Selection.ActivePoint.AtStartOfLine ? Environment.NewLine : String.Empty;
                        AddIn.InsertText(String.Format("/*{0}{1}{0}*/{2}", Environment.NewLine, text.Trim(), trailingNewLine), true);
                    }
                    else
                    {
                        AddIn.InsertText(String.Format("/* {0} */" + Environment.NewLine, text.TrimEnd()), true);
                    }
                }
                else
                {
                    foreach (var range in ranges)
                    {
                        var editPoint = range.StartPoint.CreateEditPoint();
                        var text      = editPoint.GetText(range.EndPoint);

                        editPoint.ReplaceText(
                            range.EndPoint,
                            String.Format(@"/* {0} */", text),
                            (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat
                            );
                    }
                }

                textDocument.Selection.CharRight(false, textDocument.Selection.AnchorPoint.DisplayColumn);
            }
        }
Ejemplo n.º 3
0
        public override void Execute()
        {
            var textDocument = AddIn.TextDocument;
            var cursor       = textDocument.Selection.ActivePoint;
            var startPoint   = cursor.CreateEditPoint();

            var line = AddIn.CurrentLine;

            textDocument.Selection.StartOfLine();
            AddIn.InsertText(line + Environment.NewLine);
            textDocument.Selection.Cancel();

            textDocument.Selection.MoveToPoint(startPoint);
        }
Ejemplo n.º 4
0
        public override void Execute()
        {
            var textDocument = AddIn.TextDocument;

            if (AddIn.CurrentSelection.Length == 0)
            {
                textDocument.Selection.Insert("[");
            }
            else
            {
                var text = textDocument.Selection.Text;
                AddIn.InsertText(String.Format("[{0}]", text), true);
                textDocument.Selection.CharRight(false, text.Length);
            }
        }
Ejemplo n.º 5
0
        public override void Execute()
        {
            var textDocument = AddIn.TextDocument;

            if (textDocument.Selection.IsEmpty)
            {
                textDocument.Selection.SelectAll();
            }

            try
            {
                AddIn.InsertText(_engine.Execute(textDocument.Selection.Text + Environment.NewLine));
            }
            finally
            {
                textDocument.Selection.Cancel();
            }
        }
Ejemplo n.º 6
0
        public void Expand(string word)
        {
            try
            {
                AddIn.SelectCurrentWord();
                string   padding       = new string(' ', 4);
                Template foundTemplate = Templates.First(t => String.Compare(t.Code, word, true) == 0);

                if (foundTemplate == null)
                {
                    return;
                }

                var raw = foundTemplate
                          .Body
                          .Split('\n')
                          .Select(line => line.Replace("\t", padding))
                          .ToList();

                string offset = new string(' ', AddIn.Cursor.Column - 1);

                // add lines, indenting as required, except the first
                var lines = new List <String>();
                lines.Add(raw.FirstOrDefault());
                for (int index = 1; index < raw.Count; index++)
                {
                    lines.Add((raw[index] == String.Empty ? String.Empty : offset) + raw[index]);
                }

                Cursor cursor = DetermineCursorFromBar(raw);
                if (cursor.Row < lines.Count)
                {
                    lines[cursor.Row] = lines[cursor.Row].Replace("|", "");
                }

                AddIn.InsertText(String.Join(Environment.NewLine, lines.ToArray()));
                AddIn.Cursor = cursor;
            }
            finally
            {
                AddIn.CancelSelection();
            }
        }