!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Tools / LuaRemoteDebugger / Aga.Controls / Tree / TreeViewAdv.Editor.cs
blob615026744f0a9b8627f18b7592c20fb5dc4f1817
1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 using System;
4 using System.Collections.Generic;
5 using System.Text;
6 using System.Windows.Forms;
7 using Aga.Controls.Tree.NodeControls;
8 using System.Drawing;
10 namespace Aga.Controls.Tree
12 partial class TreeViewAdv
14 private TreeNodeAdv _editingNode;
16 public EditableControl CurrentEditorOwner { get; private set; }
17 public Control CurrentEditor { get; private set; }
19 public void HideEditor()
21 if (CurrentEditorOwner != null)
22 CurrentEditorOwner.EndEdit(false);
25 internal void DisplayEditor(Control editor, EditableControl owner)
27 if (editor == null || owner == null || CurrentNode == null)
28 throw new ArgumentNullException();
30 HideEditor(false);
32 CurrentEditor = editor;
33 CurrentEditorOwner = owner;
34 _editingNode = CurrentNode;
36 editor.Validating += EditorValidating;
37 UpdateEditorBounds();
38 UpdateView();
39 editor.Parent = this;
40 editor.Focus();
41 owner.UpdateEditor(editor);
44 internal bool HideEditor(bool applyChanges)
46 if (CurrentEditor != null)
48 if (applyChanges)
50 if (!ApplyChanges())
51 return false;
54 //Check once more if editor was closed in ApplyChanges
55 if (CurrentEditor != null)
57 CurrentEditor.Validating -= EditorValidating;
58 CurrentEditorOwner.DoDisposeEditor(CurrentEditor);
60 CurrentEditor.Parent = null;
61 CurrentEditor.Dispose();
63 CurrentEditor = null;
64 CurrentEditorOwner = null;
65 _editingNode = null;
68 return true;
71 private bool ApplyChanges()
73 try
75 CurrentEditorOwner.ApplyChanges(_editingNode, CurrentEditor);
76 _errorProvider.Clear();
77 return true;
79 catch (ArgumentException ex)
81 _errorProvider.SetError(CurrentEditor, ex.Message);
82 /*CurrentEditor.Validating -= EditorValidating;
83 MessageBox.Show(this, ex.Message, "Value is not valid", MessageBoxButtons.OK, MessageBoxIcon.Warning);
84 CurrentEditor.Focus();
85 CurrentEditor.Validating += EditorValidating;*/
86 return false;
90 void EditorValidating(object sender, System.ComponentModel.CancelEventArgs e)
92 e.Cancel = !ApplyChanges();
95 public void UpdateEditorBounds()
97 if (CurrentEditor != null)
99 EditorContext context = new EditorContext();
100 context.Owner = CurrentEditorOwner;
101 context.CurrentNode = CurrentNode;
102 context.Editor = CurrentEditor;
103 context.DrawContext = _measureContext;
104 SetEditorBounds(context);
108 private void SetEditorBounds(EditorContext context)
110 foreach (NodeControlInfo info in GetNodeControls(context.CurrentNode))
112 if (context.Owner == info.Control && info.Control is EditableControl)
114 Point p = info.Bounds.Location;
115 p.X += info.Control.LeftMargin;
116 p.X -= OffsetX;
117 p.Y -= (_rowLayout.GetRowBounds(FirstVisibleRow).Y - ColumnHeaderHeight);
118 int width = DisplayRectangle.Width - p.X;
119 if (UseColumns && info.Control.ParentColumn != null && Columns.Contains(info.Control.ParentColumn))
121 Rectangle rect = GetColumnBounds(info.Control.ParentColumn.Index);
122 width = rect.Right - OffsetX - p.X;
124 context.Bounds = new Rectangle(p.X, p.Y, width, info.Bounds.Height);
125 ((EditableControl)info.Control).SetEditorBounds(context);
126 return;
131 private Rectangle GetColumnBounds(int column)
133 int x = 0;
134 for (int i = 0; i < Columns.Count; i++)
136 if (Columns[i].IsVisible)
138 if (i < column)
139 x += Columns[i].Width;
140 else
141 return new Rectangle(x, 0, Columns[i].Width, 0);
144 return Rectangle.Empty;