private void LoadCompletableFunctions(IEnumerable <IFdoFunctionDefintion> funcs)
 {
     foreach (var func in funcs)
     {
         var sigs = ExpressionEditor.MakeUniqueSignatures(func);
         foreach (var sig in sigs)
         {
             var args = new List <string>();
             foreach (var argDef in sig.Arguments)
             {
                 args.Add(argDef.Name.Trim());
             }
             string expr = $"{func.Name}({FdoExpressionCompletionDataProvider.StringifyFunctionArgs(args)})"; //NOXLATE
             if (!_autoCompleteItems.ContainsKey(func.Name))
             {
                 _autoCompleteItems[func.Name] = new List <AutoCompleteItem>();
             }
             _autoCompleteItems[func.Name].Add(new FunctionItem(func, sig, expr));
         }
     }
 }
        /// <summary>
        /// Initializes the dialog.
        /// </summary>
        /// <param name="edSvc">The editor service.</param>
        /// <param name="caps">The provider capabilities.</param>
        /// <param name="cls">The class definition.</param>
        /// <param name="featureSourceId">The features source id.</param>
        /// <param name="mode">The editor mode</param>
        /// <param name="attachStylizationFunctions">If true, Stylization FDO functions will be included</param>
        public void Initialize(IEditorService edSvc, IFdoProviderCapabilities caps, ClassDefinition cls, string featureSourceId, ExpressionEditorMode mode, bool attachStylizationFunctions)
        {
            try
            {
                _caps  = caps;
                _mode  = mode;
                _cls   = cls;
                _edSvc = edSvc;
                if (_edSvc != null)
                {
                    _featSvc = _edSvc.CurrentConnection.FeatureService;
                    insertThemeExpressionToolStripMenuItem.Enabled = true;
                }
                else
                {
                    insertThemeExpressionToolStripMenuItem.Enabled = false;
                }
                m_featureSource = featureSourceId;

                insertThemeExpressionToolStripMenuItem.Enabled = attachStylizationFunctions;

                //TODO: Perhaps add column type and indication of primary key
                SortedList <string, PropertyDefinition> sortedCols = new SortedList <string, PropertyDefinition>();
                foreach (var col in _cls.Properties)
                {
                    sortedCols.Add(col.Name, col);
                }

                ColumnName.Items.Clear();
                ColumnName.Tag = sortedCols;

                foreach (var col in sortedCols.Values)
                {
                    string          name = col.Name;
                    ToolStripButton btn  = new ToolStripButton();
                    btn.Name   = name;
                    btn.Text   = name;
                    btn.Click += delegate
                    {
                        InsertText(name);
                    };
                    btnProperties.DropDown.Items.Add(btn);

                    ColumnName.Items.Add(name);
                }

                if (ColumnName.Items.Count > 0)
                {
                    ColumnName.SelectedIndex = 0;
                }

                LoadCompletableProperties(_cls.Properties);

                //TODO: Figure out how to translate the enums into something usefull

                //Functions
                var sortedFuncs = new SortedList <string, IFdoFunctionDefintion>();
                foreach (var func in caps.Expression.SupportedFunctions)
                {
                    sortedFuncs.Add(func.Name, func);
                }

                if (attachStylizationFunctions)
                {
                    foreach (var func in Utility.GetStylizationFunctions())
                    {
                        sortedFuncs.Add(func.Name, func);
                    }
                }

                foreach (var func in sortedFuncs.Values)
                {
                    string name = func.Name;
                    string desc = func.Description;

                    ToolStripItemCollection parent = btnFunctions.DropDown.Items;
                    var sigs = ExpressionEditor.MakeUniqueSignatures(func);
                    if (sigs.Length > 1)
                    {
                        ToolStripMenuItem btn = new ToolStripMenuItem();
                        btn.Name        = string.Format(Strings.MultiSigFunction, name, sigs.Length);
                        btn.Text        = string.Format(Strings.MultiSigFunction, name, sigs.Length);
                        btn.ToolTipText = desc;

                        btnFunctions.DropDown.Items.Add(btn);
                        parent = btn.DropDown.Items;
                    }

                    foreach (var sig in sigs)
                    {
                        ToolStripMenuItem btn = new ToolStripMenuItem();
                        btn.Name        = name;
                        btn.ToolTipText = desc;

                        List <string> args = new List <string>();
                        foreach (var argDef in sig.Arguments)
                        {
                            args.Add(argDef.Name.Trim());
                        }
                        string expr = $"{name}({FdoExpressionCompletionDataProvider.StringifyFunctionArgs(args)})"; //NOXLATE
                        btn.Text   = $"{expr} : {sig.ReturnType}";                                                  //NOXLATE
                        btn.Click += (s, e) =>
                        {
                            InsertText(expr);
                        };
                        parent.Add(btn);
                    }
                }
                LoadCompletableFunctions(caps.Expression.SupportedFunctions);
                if (attachStylizationFunctions)
                {
                    LoadCompletableFunctions(Utility.GetStylizationFunctions());
                }

                //Spatial Operators
                foreach (var op in caps.Filter.SpatialOperations)
                {
                    string          name = op.ToUpper();
                    ToolStripButton btn  = new ToolStripButton();
                    btn.Name   = btn.Text = btn.ToolTipText = op;
                    btn.Click += delegate
                    {
                        InsertFilter(name);
                    };
                    btnSpatial.DropDown.Items.Add(btn);
                }

                //Distance Operators
                foreach (var op in caps.Filter.DistanceOperations)
                {
                    string          name = op.ToUpper();
                    ToolStripButton btn  = new ToolStripButton();
                    btn.Name   = btn.Text = btn.ToolTipText = op;
                    btn.Click += delegate
                    {
                        InsertFilter(name);
                    };
                    btnDistance.DropDown.Items.Add(btn);
                }

                //Conditional Operators
                foreach (var op in caps.Filter.ConditionTypes)
                {
                    string          name = op.ToUpper();
                    ToolStripButton btn  = new ToolStripButton();
                    btn.Name   = btn.Text = btn.ToolTipText = op;
                    btn.Click += delegate
                    {
                        InsertFilter(name);
                    };
                    btnCondition.DropDown.Items.Add(btn);
                }

                /*try
                 * {
                 *  /*FdoProviderCapabilities cap = m_connection.GetProviderCapabilities(m_providername);
                 *  foreach (FdoProviderCapabilitiesFilterType cmd in cap.Filter.Condition)
                 *      FunctionCombo.Items.Add(cmd.ToString());
                 *
                 *  FunctionLabel.Enabled = FunctionCombo.Enabled = true;
                 * }
                 * catch
                 * {
                 *  FunctionLabel.Enabled = FunctionCombo.Enabled = false;
                 * }*/
            }
            catch
            {
            }
        }