Example #1
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();
            }
        }