コード例 #1
0
        private void ListBoxKeyDown(object sender, Form.KeyEventArgs e)
        {
            Form.ListBox lb = (Form.ListBox)sender;

            if (e.KeyCode == Form.Keys.Escape || lb.SelectedIndex < 0)
            {
                Done();
            }
            else
            if (e.KeyCode == Form.Keys.Enter)
            {
                ExecuteItem((Item)lb.Items[lb.SelectedIndex]);
                AddIn.CancelSelection();
                Done();
            }
        }
コード例 #2
0
ファイル: SqlTemplating.cs プロジェクト: meikeric/sqlformat
        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();
            }
        }