private void ComboBoxEdit_SelectedValueChanged(object sender, EventArgs e) { var comboBox = (ComboBox)sender; var itemControlInfo = (ItemControlInfo)comboBox.Tag; var property = itemControlInfo.Property; foreach (var enumItem in property.EnumItems) { if (enumItem.Name == comboBox.Text) { if (Values == null) { property.Value = enumItem.Value; } else { Values[property.Name] = enumItem.Value; } OnPropertyValueChanged?.Invoke(this, new PropertyValueChangeEventArgs() { Property = property, Value = property.Value }); break; } } }
private object GetPropertyEditor(object o, PropertyInfo p) { var allRules = Enumerable.Concat(_editorRules, EditableDumpContainer.GlobalEditorRules); foreach (var editor in allRules) { if (editor.Match(o, p)) { return(editor.Editor(o, p, () => p.GetValue(o), (v) => { SetValue(o, p, v); if (!editor.DisableAutomaticRefresh) { SetContent(); } var newVal = p.GetValue(o); if (_changeHandlers.TryGetValue(p, out var handler)) { handler.Invoke((T)o, newVal); } OnPropertyValueChanged?.Invoke((T)o, p, newVal); OnChanged?.Invoke(); })); } } return(p.GetValue(o)); }
private void properties_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) { OnPropertyValueChanged?.Invoke(this, e); //SetObjectCollection(); //update label in treeview list.SelectedNode.Text = properties.SelectedObject.ToString(); }
private void ButtonEdit_OnButtonClick(object sender, ButtonPressedEventArgs e) { var buttonEdit = (ButtonEdit)sender; var itemControlInfo = (ItemControlInfo)buttonEdit.Tag; var property = itemControlInfo.Property; if (e.ButtonInfo.Tag == null) { var dialog = new FolderBrowserDialog() { Description = property.PathDescription, SelectedPath = Convert.ToString(property.Value) }; if (dialog.ShowDialog() == DialogResult.OK) { if (Values == null) { property.Value = dialog.SelectedPath; } else { Values[property.Name] = dialog.SelectedPath; } buttonEdit.Text = dialog.SelectedPath; OnPropertyValueChanged?.Invoke(this, new PropertyValueChangeEventArgs() { Property = property, Value = property.Value }); } } else { var buttonName = (string)e.ButtonInfo.Tag; if (buttonName == "clear") { buttonEdit.Text = Convert.ToString(property.Value); if (Values == null) { property.Value = property.DefaultValue; } else { Values[property.Name] = property.DefaultValue; } OnPropertyValueChanged?.Invoke(this, new PropertyValueChangeEventArgs() { Property = property, Value = property.Value }); } } }
/// <summary> /// Move element /// </summary> /// <param name="move">define movement +1 move down -1 move up </param> /// <param name="top">if set to true element is moved to the top of collection</param> /// <param name="bottom">if set to true element is moved to the botom of collection</param> void moveObject(int move, bool top, bool bottom) { CollectionType parentCollection = getParentCollection(SelectedObject); if (parentCollection != null && parentCollection.MoveItemInCollection(SelectedObject, move, top, bottom)) { SetObjectCollection(CurrentContext.CurrentView, true); OnPropertyValueChanged?.Invoke(this, null); } }
private void CheckEdit_CheckedChanged(object sender, EventArgs e) { var checkEdit = (CheckBox)sender; var itemControlInfo = (ItemControlInfo)checkEdit.Tag; var property = itemControlInfo.Property; if (Values == null) { property.Value = Convert.ToBoolean(checkEdit.Checked); } else { Values[property.Name] = Convert.ToBoolean(checkEdit.Checked); } OnPropertyValueChanged?.Invoke(this, new PropertyValueChangeEventArgs() { Property = property, Value = property.Value }); }
private void SpinEdit_Float_ValueChanged(object sender, EventArgs e) { var spinEdit = (NumericUpDown)sender; var itemControlInfo = (ItemControlInfo)spinEdit.Tag; var property = itemControlInfo.Property; if (Values == null) { property.Value = spinEdit.Value; } else { Values[property.Name] = spinEdit.Value; } OnPropertyValueChanged?.Invoke(this, new PropertyValueChangeEventArgs() { Property = property, Value = property.Value }); }
private void TextBox_TextChanged(object sender, EventArgs e) { var textBox = (TextBox)sender; var itemControlInfo = (ItemControlInfo)textBox.Tag; var property = itemControlInfo.Property; if (Values == null) { property.Value = textBox.Text; } else { Values[property.Name] = textBox.Text; } OnPropertyValueChanged?.Invoke(this, new PropertyValueChangeEventArgs() { Property = property, Value = property.Value }); }
private void EditorPath_OnTextChanged(object sender, EventArgs e) { var buttonEdit = (ButtonEdit)sender; var itemControlInfo = (ItemControlInfo)buttonEdit.Tag; var property = itemControlInfo.Property; if (Values == null) { property.Value = buttonEdit.Text; } else { Values[property.Name] = buttonEdit.Text; } OnPropertyValueChanged?.Invoke(this, new PropertyValueChangeEventArgs() { Property = property, Value = property.Value }); }
private void EditorColor_ColorChanged(object sender, EventArgs e) { var colorEdit = (ColorEdit)sender; var itemControlInfo = (ItemControlInfo)colorEdit.Tag; var property = itemControlInfo.Property; if (Values == null) { property.Value = colorEdit.Color; } else { Values[property.Name] = colorEdit.Color; } OnPropertyValueChanged?.Invoke(this, new PropertyValueChangeEventArgs() { Property = property, Value = property.Value }); }
private void CheckBox_CheckedChanged(object sender, EventArgs e) { var checkBox = (CheckBox)sender; var property = (GenericProperty)checkBox.Tag; bool value = checkBox.Checked; if (Values != null) { Values[property.Name] = value; } else { property.Value = value; } OnPropertyValueChanged?.Invoke(this, new Quantum.Framework.GenericProperties.GenericPropertyCheckListBox.Events.PropertyValueChangedEventArgs() { Property = property, Value = value }); }
private void OnNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Node == null) { return; } EditorTreeView.SelectedNode = e.Node; if (e.Node.Nodes.Count > 0) { if (e.Node.IsExpanded) { e.Node.Collapse(); } else { e.Node.Expand(); } return; } if (string.IsNullOrEmpty(e.Node.Name)) { return; // Node has no name, nothing to do } if (e.Node.Name.StartsWith("*")) { return; // Node is a folder, nothing to do } if (e.Node.Name.StartsWith("#")) // Node is an array element { // Array of enums or DBEntries, treat as a checkbox if (GetTreeViewPropertyAttribute(e.Node.Parent.Name).DataSourceType.IsEnum || GetTreeViewPropertyAttribute(e.Node.Parent.Name).DataSourceType.IsSubclassOf(typeof(DBEntry))) { if (e.Button != MouseButtons.Left) { return; // Only left clicks can toggle checkboxes } string checkImage = (e.Node.ImageKey == "checkbox0") ? "checkbox1" : "checkbox0"; e.Node.ImageKey = checkImage; e.Node.SelectedImageKey = checkImage; object selectedValues = null; PropertyInfo propertyInfo = GetPropertyInfo(e.Node.Parent.Name); Type elementType = propertyInfo.PropertyType.GetElementType(); if (elementType == typeof(string)) { selectedValues = (from TreeNode n in e.Node.Parent.Nodes where n.ImageKey == "checkbox1" select n.Name.Substring(1)).ToArray(); } else if (elementType == typeof(RealismOption)) { selectedValues = (from TreeNode n in e.Node.Parent.Nodes where n.ImageKey == "checkbox1" select(RealismOption) Enum.Parse(elementType, n.Name.Substring(1))).ToArray(); } if (selectedValues != null) { propertyInfo.SetValue(SelectedObject, selectedValues); } UpdateNode(e.Node.Parent); // Update parent because sometimes enabling an option will disable others OnPropertyValueChanged?.Invoke(EditorTreeView, new EventArgs()); } else if (GetTreeViewPropertyAttribute(e.Node.Parent.Name).DataSourceType. IsSubclassOf(typeof(ContextMenuExpandable))) // Array of ContextMenuExpandables { ContextMenu.Items.Clear(); Array arrayValues = (Array)GetPropertyValue(e.Node.Parent.Name); int arrayIndex = (int)e.Node.Tag; ((ContextMenuExpandable)arrayValues.GetValue(arrayIndex)).CreateContextMenu(ContextMenu, OnContextMenuItemClicked); ContextMenu.Items.Add(new ToolStripSeparator()); if (GetTreeViewPropertyAttribute(e.Node.Parent.Name).DataSourceType == typeof(MissionTemplateFlightGroup)) { ContextMenu.Items.Add("Add another flight group").Tag = "*add"; if (e.Node.Parent.Nodes.Count > 1) { ContextMenu.Items.Add("Remove flight group").Tag = "*remove"; } } foreach (ToolStripItem item in ContextMenu.Items) { if ((item is ToolStripMenuItem) && (((ToolStripMenuItem)item).DropDownItems.Count > 0)) { ((ToolStripMenuItem)item).DropDownItemClicked += OnContextMenuItemClicked; } } ContextMenu.Show(EditorTreeView, e.Location); } return; } if (GetPropertyInfo(e.Node.Name).PropertyType.IsArray) { return; } ContextMenu.Items.Clear(); TreeViewPropertyAttribute tvpa = GetTreeViewPropertyAttribute(e.Node.Name); if (tvpa.DataSourceType.IsEnum) { foreach (object enumValue in Enum.GetValues(tvpa.DataSourceType)) { GUITools.GetDisplayStrings(tvpa.DataSourceType, enumValue, out string enumDisplayName, out string enumDescription); ToolStripMenuItem enumMenuItem = new ToolStripMenuItem { Tag = enumValue, Text = enumDisplayName, ToolTipText = enumDescription }; ContextMenu.Items.Add(enumMenuItem); } } else if (tvpa.DataSourceType == typeof(int)) { TreeViewPropertyIntAttribute tvpia = GetPropertyAttribute <TreeViewPropertyIntAttribute>(e.Node.Name); if (tvpia != null) { for (int i = tvpia.IntValueMin; i <= tvpia.IntValueMax; i += tvpia.IntValueIncrement) { ContextMenu.Items.Add(tvpia.FormatIntValue(i)).Tag = i; } } } else if (tvpa.DataSourceType.IsSubclassOf(typeof(DBEntry))) { GUITools.PopulateToolStripMenuWithDBEntries( ContextMenu.Items, tvpa.DataSourceType, OnContextMenuItemClicked, tvpa.Flags.HasFlag(TreeViewPropertyAttributeFlags.EmptyIsRandom)); } ContextMenu.Show(EditorTreeView, e.Location); }
private void OnContextMenuItemClicked(object sender, ToolStripItemClickedEventArgs e) { if (EditorTreeView.SelectedNode == null) { return; // No selected node } if (e.ClickedItem.Tag == null) { return; // Node has no tag (probably a folder) } if (e.ClickedItem.Tag.ToString() == "*add") // Special case: adding a new item to a ContextMenuExpandable array { Array arrayValues = (Array)GetPropertyValue(EditorTreeView.SelectedNode.Parent.Name); if (GetTreeViewPropertyAttribute(EditorTreeView.SelectedNode.Parent.Name).DataSourceType == typeof(MissionTemplateFlightGroup)) { List <MissionTemplateFlightGroup> list = new List <MissionTemplateFlightGroup>(); for (int i = 0; i < arrayValues.Length; i++) { list.Add((MissionTemplateFlightGroup)arrayValues.GetValue(i)); } list.Add(new MissionTemplateFlightGroup()); SetPropertyValue(EditorTreeView.SelectedNode.Parent.Name, list.ToArray()); } UpdateNode(EditorTreeView.SelectedNode.Parent); OnPropertyValueChanged?.Invoke(EditorTreeView, new EventArgs()); return; } else if (e.ClickedItem.Tag.ToString() == "*remove") // Special case: revove an item to a ContextMenuExpandable array { Array arrayValues = (Array)GetPropertyValue(EditorTreeView.SelectedNode.Parent.Name); int index = (int)EditorTreeView.SelectedNode.Tag; if (GetTreeViewPropertyAttribute(EditorTreeView.SelectedNode.Parent.Name).DataSourceType == typeof(MissionTemplateFlightGroup)) { List <MissionTemplateFlightGroup> list = new List <MissionTemplateFlightGroup>(); for (int i = 0; i < arrayValues.Length; i++) { if (i == index) { continue; } list.Add((MissionTemplateFlightGroup)arrayValues.GetValue(i)); } SetPropertyValue(EditorTreeView.SelectedNode.Parent.Name, list.ToArray()); } UpdateNode(EditorTreeView.SelectedNode.Parent); OnPropertyValueChanged?.Invoke(EditorTreeView, new EventArgs()); return; } // Property is a ContextMenuExpandable, call the class's own OnContextMenuItemClicked method if ((EditorTreeView.SelectedNode.Parent != null) && (GetTreeViewPropertyAttribute(EditorTreeView.SelectedNode.Parent.Name) != null) && GetTreeViewPropertyAttribute(EditorTreeView.SelectedNode.Parent.Name).DataSourceType.IsSubclassOf(typeof(ContextMenuExpandable))) { Array arrayValues = (Array)GetPropertyValue(EditorTreeView.SelectedNode.Parent.Name); int arrayIndex = (int)EditorTreeView.SelectedNode.Tag; ((ContextMenuExpandable)arrayValues.GetValue(arrayIndex)).OnContextMenuItemClicked(e.ClickedItem.Tag); UpdateNode(EditorTreeView.SelectedNode.Parent); OnPropertyValueChanged?.Invoke(EditorTreeView, new EventArgs()); return; } SetPropertyValue(EditorTreeView.SelectedNode.Name, e.ClickedItem.Tag); UpdateNode(EditorTreeView.SelectedNode); OnPropertyValueChanged?.Invoke(EditorTreeView, new EventArgs()); }
private void list_DragDrop(object sender, DragEventArgs e) { if (!EnableMove) { return; } // Retrieve the client coordinates of the drop location. var targetPoint = list.PointToClient(new Point(e.X, e.Y)); // Retrieve the node at the drop location. var targetNode = list.GetNodeAt(targetPoint); if (string.IsNullOrEmpty(ChildPropertyName))//not multi level { targetNode = null; } // Retrieve the node that was dragged. var draggedNode = (TreeNode)e.Data.GetData(typeof(TreeNode)); // Confirm that the node at the drop location is not // the dragged node and that target node isn't null // (for example if you drag outside the control) if (draggedNode.Equals(targetNode)) { return; //|| targetNode == null } // Remove the node from its current // location and add it to the node at the drop location. var item = (ObjectType)draggedNode.Tag; // remove item from original collection var parentCollection = getParentCollection(item); parentCollection.Remove(item); //remove node from previous location draggedNode.Remove(); //future Parent ObjectType targetObject; CollectionType targetObjectCollection; var insertPos = -1; if (_dragdroppos.SelectedNode != null) {//drop before or after var node = _dragdroppos.SelectedNode; var parent = node.Parent; var addToRoot = parent == null || string.IsNullOrEmpty(ChildPropertyName); var parentCollectionNode = addToRoot ? list.Nodes : parent.Nodes; targetObject = addToRoot ? null : (ObjectType)parent.Tag; targetObjectCollection = addToRoot ? ConfigurationElementCollection(CurrentContext.CurrentView) : getChild((ObjectType)parent.Tag); insertPos = _dragdroppos.Up ? node.Index : node.Index + 1; parentCollectionNode.Insert(node.Index, draggedNode); } else { //drop on node if (targetNode == null) { //add to root list.Nodes.Add(draggedNode); targetObject = null; targetObjectCollection = ConfigurationElementCollection(CurrentContext.CurrentView); } else {//add to a child targetNode.Nodes.Add(draggedNode); targetObject = (ObjectType)targetNode.Tag; targetObjectCollection = getChild(targetObject); targetNode.Expand(); } } setParent(item, targetObject); if (insertPos == -1) { //targetObjectCollection.Add(item); targetObjectCollection.Insert(targetObjectCollection.Count, item); } else { targetObjectCollection.Insert(insertPos, item); } OnPropertyValueChanged?.Invoke(this, null); }