private static void ExtractOperators(SqlParseTree tree) { List <OperatorColor> operatorColors = new List <OperatorColor>(ViewerSettings.Instance.OperatorColors); Dictionary <string, OperatorColor> index = new Dictionary <string, OperatorColor>(); operatorColors.ForEach(o => { if (index.ContainsKey(o.OperatorName) == false) { index.Add(o.OperatorName, o); } }); List <SqlParseTreeNode> nodes = new List <SqlParseTreeNode>() { tree.RootNode }; while (nodes.Count > 0) { foreach (SqlParseTreeNode node in nodes) { if (string.IsNullOrEmpty(node.OperationName) == false && index.ContainsKey(node.OperationName) == false) { OperatorColor operatorColor = new OperatorColor(); operatorColor.OperatorName = node.OperationName; operatorColor.DisplayColor = GetColorForOperator(node.OperationName); index.Add(node.OperationName, operatorColor); ViewerSettings.Instance.AddOperatorColor(node.OperationName, operatorColor.DisplayColor); } } nodes = nodes.SelectMany(n => n.Children).ToList(); } }
private void StandardColorComboBox_SelectedIndexChanged(object sender, EventArgs e) { OperatorColor operatorColor = operatorsListView.SelectedItem as OperatorColor; if (operatorColor != null) { operatorColor.DisplayColor = (Color)standardColorComboBox.SelectedItem; } }
private void DeleteButton_Click(object sender, EventArgs e) { OperatorColor operatorColor = operatorsListView.SelectedItem as OperatorColor; if (operatorColor != null) { ViewerSettings.Clone.DeleteOperatorColor(operatorColor.OperatorName); operatorsListView.Items.Remove(operatorColor); } }
public Color?GetOperatorColor(string operatorName) { if (string.IsNullOrEmpty(operatorName)) { throw new ArgumentNullException(nameof(operatorName)); } OperatorColor operatorColor = _operatorColors.FirstOrDefault(o => o.OperatorName == operatorName); return(operatorColor?.DisplayColor); }
private void OperatorsListView_SelectedIndexChanged(object sender, EventArgs e) { OperatorColor operatorColor = operatorsListView.SelectedItem as OperatorColor; if (operatorColor != null) { standardColorComboBox.Items.Clear(); standardColorComboBox.Items.Add(operatorColor.DisplayColor); Type colorType = typeof(Color); List <PropertyInfo> colorProperties = colorType.GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public).ToList(); colorProperties.Sort((a, b) => a.Name.CompareTo(b.Name)); foreach (PropertyInfo property in colorProperties) { Color color = (Color)property.GetMethod.Invoke(null, null); standardColorComboBox.Items.Add(color); } standardColorComboBox.SelectedIndex = 0; } }
private void CustomColorButton_Click(object sender, EventArgs e) { if (standardColorComboBox.Items.Count > 0) { using (ColorDialog dialog = new ColorDialog()) { dialog.AnyColor = true; dialog.FullOpen = true; dialog.Color = (Color)standardColorComboBox.Items[0]; if (dialog.ShowDialog() == DialogResult.OK) { standardColorComboBox.Items[0] = dialog.Color; OperatorColor operatorColor = operatorsListView.SelectedItem as OperatorColor; if (operatorColor != null) { operatorColor.DisplayColor = dialog.Color; } } } } }
public void AddOperatorColor(string operatorName, Color color) { if (string.IsNullOrEmpty(operatorName)) { throw new ArgumentNullException(nameof(operatorName)); } OperatorColor operatorColor = _operatorColors.FirstOrDefault(o => o.OperatorName == operatorName); if (operatorColor == null) { operatorColor = new OperatorColor(); operatorColor.OperatorName = operatorName; operatorColor.DisplayColor = color; _operatorColors.Add(operatorColor); } else { operatorColor.DisplayColor = color; } }