Ejemplo n.º 1
0
        public bool TakeSelection()
        {
            bool       openAgain = false;
            Suggestion s         = theList.SelectedItem as Suggestion;

            if (s != null)
            {
                openAgain = s.openImmediatelyAfter;
                if (suggestionList.queryMode)
                {
                    if (s.dbColumn != null)
                    {
                        SqlBuilder b = new SqlBuilder(suggestionList.query);
                        b.AddColumn(suggestionList.keyword as Keyword, s.dbColumn, suggestionList.includeAliases);
                        string sql = b.Render();
                        editor.Text = sql;
                    }
                    else if (s.dbTable != null)
                    {
                        SqlBuilder b = new SqlBuilder(suggestionList.query);
                        b.AddTable(s.dbTable, suggestionList.includeAliases);
                        string sql = b.Render();
                        editor.Text = sql;
                    }
                }
                else
                {
                    string txt = s.expr;
                    if (txt != "")
                    {
                        txt = txt.Trim() + " ";

                        editor.Focus();
                        editor.DeleteRange(suggestionList.wordStartPosition, suggestionList.currentPos - suggestionList.wordStartPosition);
                        editor.InsertText(suggestionList.wordStartPosition, txt);
                        int pos = suggestionList.wordStartPosition + txt.Length;
                        while (editor.Text.Length > pos + 1 && editor.Text[pos - 1] == ' ' && editor.Text[pos] == ' ')
                        {
                            editor.DeleteRange(pos, 1);
                        }
                        if (s.dbColumn != null)
                        {
                            A.db.ColumnUsed(s.dbColumn);
                            A.db.TableUsed(s.dbColumn.table.name);
                            if (s.tableAlias != null && S.Get("RememberAliases", true))
                            {
                                A.db.AliasUsed(s.tableAlias, s.dbColumn.table.name);
                            }

                            if (S.Get("AutocompleteInsertTables", false))
                            {
                                AddTables(s.dbColumn);
                            }
                        }

                        editor.CurrentPosition = editor.SelectionStart = editor.SelectionEnd = pos;
                    }
                }
            }



            Hide();
            editor.Focus();
            return(openAgain);
        }