private void DrawGraphManagementWizard(Rect obj)
        {
            var listRect = obj.RightHalf().PadSides(2);
            var controlRect = obj.LeftHalf().BottomHalf().PadSides(2);
            var actionRect = obj.LeftHalf().TopHalf().PadSides(2);

            var actions = new List<ActionItem>();
            Signal<IQueryGraphsActions>(_=>_.QueryGraphsAction(actions));

            DrawGraphsList(listRect, Repository.AllOf<IGraphData>()
                .OrderBy(_ => WorkspaceService.CurrentWorkspace != null && !WorkspaceService.CurrentWorkspace.Graphs.Contains(_))
                .ThenBy(_=>_.Name)
                .ToList());
     
            Signal<IDrawActionsPanel>(_=>_.DrawActionsPanel(PlatformDrawer,actionRect,actions, (i, m) =>
            {
                SelectedAction = i;
            }));

            if (SelectedAction != null)
            {
                Signal<IDrawActionDialog>(_=>_.DrawActionDialog(PlatformDrawer,controlRect,SelectedAction, () =>
                {
                    SelectedAction = null;
                }));
            }

            var closeButtonBounds = new Rect().WithSize(80, 30).InnerAlignWithBottomRight(listRect.PadSides(15));
            PlatformDrawer.DoButton(closeButtonBounds, "Close", ElementDesignerStyles.ButtonStyle, () => EnableGraphManagementhWizard = false);
        }
        public void DrawDatabasesWizard(Rect bounds)
        {

           // platform.DrawStretchBox(bounds, CachedStyles.WizardBoxStyle, 13);

            var actions = new List<ActionItem>();
            var items = new List<DatabasesListItem>();
            var databasesActionsBounds = bounds.LeftHalf().TopHalf().PadSides(2);
            var databasesListBounds = bounds.RightHalf().PadSides(2);
            var databasesActionInspectorBounds = bounds.LeftHalf().BottomHalf().PadSides(2);
            var closeButtonBounds = new Rect().WithSize(80, 30).InnerAlignWithBottomRight(databasesListBounds.PadSides(15));

            Signal<IQueryDatabasesActions>(_ => _.QueryDatabasesActions(actions));
            Signal<IQueryDatabasesListItems>(_ => _.QueryDatabasesListItems(items));
            Signal<IDrawActionsPanel>(_ => _.DrawActionsPanel(Drawer, databasesActionsBounds, actions,(a,m)=> SelectedItem = a));
            Signal<IDrawActionDialog>(_ => _.DrawActionDialog(Drawer, databasesActionInspectorBounds,SelectedItem,()=> SelectedItem = null));
            Signal<IDrawDatabasesList>(_ => _.DrawDatabasesList(Drawer, databasesListBounds, items));

            Drawer.DoButton(closeButtonBounds, "Close", ElementDesignerStyles.DarkButtonStyle, () => EnableWizard = false);
        }
        public virtual void DrawInspector(Rect rect, PropertyFieldViewModel d, GUIStyle labelStyle)
        {
            var colorCache = GUI.color;
            GUI.color = Color.white;
            var labelArea = rect.LeftHalf();
            var fieldArea = rect.RightHalf();
            var labelWidtho = GUILayout.Width(140);

            if (d.InspectorType == InspectorType.GraphItems)
            {
                var item = d.CachedValue as IGraphItem;
                var text = "--Select--";
                if (item != null)
                {
                    text = item.Label;
                }
                //GUILayout.BeginHorizontal();

                if (GUI.Button(rect, d.Label + ": " + text, ElementDesignerStyles.ButtonStyle))
                {
                    var type = d.Type;

                    var items = InvertGraphEditor.CurrentDiagramViewModel.CurrentRepository.AllOf<IGraphItem>().Where(p => type.IsAssignableFrom(p.GetType()));

                    var menu = new SelectionMenu();
                    menu.AddItem(new SelectionMenuItem(string.Empty,"[None]", () =>
                    {
                        InvertApplication.Execute(() =>
                        {
                            d.Setter(d.DataObject, null);
                        });
                    }));
                    foreach (var graphItem in items)
                    {
                        var graphItem1 = graphItem;
                        menu.AddItem(new SelectionMenuItem(graphItem1, () =>
                        {
                            InvertApplication.Execute(() =>
                            {
                                d.Setter(d.DataObject, graphItem1);
                            });
                        }));
                    }

                    InvertApplication.SignalEvent<IShowSelectionMenu>(_ => _.ShowSelectionMenu(menu));



                    //
                    //                    InvertGraphEditor.WindowManager.InitItemWindow(items, 
                    //                        
                    //                    },true);

                }
                SetTooltipForRect(rect, d.InspectorTip);

                GUI.color = colorCache;
                //GUILayout.EndHorizontal();
                return;
            }


            if (d.Type == typeof(string))
            {
                if (d.InspectorType == InspectorType.TextArea)
                {
                    labelArea = rect.WithHeight(17).InnerAlignWithUpperRight(rect);
                    fieldArea = rect.Below(labelArea).Clip(rect).PadSides(2);
                    EditorGUI.LabelField(labelArea, d.Name, labelStyle);
                    SetTooltipForRect(rect, d.InspectorTip);
                    EditorGUI.BeginChangeCheck();
                    d.CachedValue = EditorGUI.TextArea(fieldArea, (string)d.CachedValue, TextWrappingTextArea);
                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                    if (Event.current.isKey && Event.current.keyCode == KeyCode.Return)
                    {
                        InvertApplication.Execute(() =>
                        {

                        });
                    }
                }
                else if (d.InspectorType == InspectorType.TypeSelection)
                {

                    if (GUI.Button(rect, (string)d.CachedValue))
                    {
                        d.NodeViewModel.Select();
                        // TODO 2.0 Open Selection?
                    }
                    SetTooltipForRect(rect, d.InspectorTip);


                }

                else
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.LabelField(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.TextField(fieldArea, (string)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }

            }
            else
            {
                if (d.Type == typeof(int))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.IntField(fieldArea, (int)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(float))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.FloatField(fieldArea, (float)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(Vector2))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Vector2Field(fieldArea, string.Empty, (Vector2)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }

                else if (d.Type == typeof(Vector3))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Vector3Field(fieldArea, string.Empty, (Vector3)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }

                }
                else if (d.Type == typeof(Color))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.ColorField(fieldArea, (Color)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }

                }
                else if (d.Type == typeof(Vector4))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Vector4Field(fieldArea, string.Empty, (Vector4)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (d.Type == typeof(bool))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.Toggle(fieldArea, (bool)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {

                        d.Setter(d.DataObject, d.CachedValue);
                    }
                }
                else if (typeof(Enum).IsAssignableFrom(d.Type))
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.Label(labelArea, d.Name, labelStyle);
                    d.CachedValue = EditorGUI.EnumPopup(fieldArea, (Enum)d.CachedValue);
                    SetTooltipForRect(rect, d.InspectorTip);

                    if (EditorGUI.EndChangeCheck())
                    {
                        InvertApplication.Execute(() =>
                        {
                            d.Setter(d.DataObject, d.CachedValue);
                        });

                    }
                }
                else if (d.Type == typeof(Type))
                {
                    //InvertGraphEditor.WindowManager.InitTypeListWindow();
                }
            }

            GUI.color = colorCache;

        }
        public void DrawBreadcrumbs(IPlatformDrawer platform,  float y)
        {

            var navPanelRect = new Rect(4, y, 60, 30f);
            var breadcrumbsRect = new Rect(64, y, Bounds.width-44, 30f);
            platform.DrawRect(Bounds.WithOrigin(0,y).WithHeight(30), InvertGraphEditor.Settings.BackgroundColor);

            var back = new Rect().WithSize(30, 30).PadSides(2).CenterInsideOf(navPanelRect.LeftHalf());
            platform.DoButton(back, "", ElementDesignerStyles.WizardActionButtonStyleSmall,
                () =>
                {
                    InvertApplication.Execute(new NavigateBackCommand());
                });
            platform.DrawImage(back.PadSides(4), "BackIcon", true);

            var forward = new Rect().WithSize(30, 30).PadSides(2).CenterInsideOf(navPanelRect.RightHalf());
            platform.DoButton(forward, "", ElementDesignerStyles.WizardActionButtonStyleSmall,
                () =>
                {
                    InvertApplication.Execute(new NavigateForwardCommand());
                });
            platform.DrawImage(forward.PadSides(4),"ForwardIcon",true);

            //var color = new Color(InvertGraphEditor.Settings.BackgroundColor.r * 0.8f, InvertGraphEditor.Settings.BackgroundColor.g * 0.8f, InvertGraphEditor.Settings.BackgroundColor.b * 0.8f, 1f);
            //platform.DrawRect(rect, color);
            
//            var lineRect = new Rect(rect);
//            lineRect.height = 2;
//            lineRect.y = y + 38f;
//            platform.DrawRect(lineRect, new Color(InvertGraphEditor.Settings.BackgroundColor.r * 0.6f, InvertGraphEditor.Settings.BackgroundColor.g * 0.6f, InvertGraphEditor.Settings.BackgroundColor.b * 0.6f, 1f));
//            
//            
//            var first = true;
//            if (_cachedPaths != null)
//            foreach (var item in _cachedPaths)
//            {
//                var item1 = item;
//                platform.DoButton(new Rect(x, rect.y + 20 - (item.Value.y / 2), item.Value.x, item.Value.y), first ? item.Key.Name : "< " + item.Key.Name, first ? CachedStyles.GraphTitleLabel : CachedStyles.ItemTextEditingStyle,
//                    () =>
//                    {
//                        InvertApplication.Execute(new LambdaCommand(() =>
//                        {
//                            DiagramViewModel.GraphData.PopToFilter(item1.Key);
//                        }));
//                    });
//                x += item.Value.x + 15;
//                first = false;
//            }


            var x = 1f;

            var styles = DiagramViewModel.NavigationViewModel.BreadcrumbsStyle;
            var iconsTine = new Color(1, 1, 1, 0.5f);

            foreach (var usitem in DiagramViewModel.NavigationViewModel.Breadcrubs.ToArray())
            {
                var item = usitem;
                var textSize = platform.CalculateTextSize(usitem.Title, CachedStyles.BreadcrumbTitleStyle);
                float buttonContentPadding = 5;
                float buttonIconsPadding= 5;
                bool useSpecIcon = !string.IsNullOrEmpty(item.SpecializedIcon);
                var buttonWidth = textSize.x + buttonContentPadding*2 + 8;
                if (!string.IsNullOrEmpty(item.Icon)) buttonWidth += buttonIconsPadding + 16;
                if (useSpecIcon) buttonWidth += buttonIconsPadding + 16;
               
                var buttonRect = new Rect()
                    .AlignAndScale(breadcrumbsRect)
                    .WithWidth(buttonWidth)
                    .PadSides(3)
                    .Translate(x, 0);

                var icon1Rect = new Rect()
                    .WithSize(16, 16)
                    .AlignTopRight(buttonRect)
                    .AlignHorisonallyByCenter(buttonRect)
                    .Translate(-buttonContentPadding, 0);

                var icon2Rect = new Rect()
                    .WithSize(16, 16)
                    .Align(buttonRect)
                    .AlignHorisonallyByCenter(buttonRect)
                    .Translate(buttonContentPadding, 0);

                var textRect = new Rect()
                    .WithSize(textSize.x, textSize.y)
                    .Align(useSpecIcon ? icon2Rect : buttonRect)
                    .AlignHorisonallyByCenter(buttonRect)
                    .Translate(useSpecIcon ? buttonIconsPadding + 16 : buttonContentPadding, -1);

                var dotRect = new Rect()
                    .WithSize(16, 16)
                    .RightOf(buttonRect)
                    .AlignHorisonallyByCenter(buttonRect)
                    .Translate(-3,0);

                platform.DoButton(buttonRect, "", item.State == NavigationItemState.Current ? CachedStyles.BreadcrumbBoxActiveStyle : CachedStyles.BreadcrumbBoxStyle, item.NavigationAction);
                platform.DrawLabel(textRect, item.Title, CachedStyles.BreadcrumbTitleStyle, DrawingAlignment.MiddleCenter);
                platform.DrawImage(icon1Rect, styles.GetIcon(item.Icon,iconsTine), true);

                if (useSpecIcon) platform.DrawImage(icon2Rect, styles.GetIcon(item.SpecializedIcon, iconsTine), true);
                if (item.State != NavigationItemState.Current) platform.DrawImage(dotRect, styles.GetIcon("DotIcon", iconsTine), true);

                x += buttonRect.width + 16 - 6;

            }



        }
        public void DrawWorkspacesWizard( Rect bounds)
        {
            var actions = new List<ActionItem>();
            var items = new List<WorkspacesListItem>();
            var databasesActionsBounds = bounds.LeftHalf().TopHalf().PadSides(2);
            var databasesListBounds = bounds.RightHalf().PadSides(2);
            var databasesActionInspectorBounds = bounds.LeftHalf().BottomHalf().PadSides(2);
            var closeButtonBounds = new Rect().WithSize(80, 30).InnerAlignWithBottomRight(databasesListBounds.PadSides(15));

            Signal<IQueryWorkspacesActions>(_ => _.QueryWorkspacesActions(actions));
            Signal<IQueryWorkspacesListItems>(_ => _.QueryWorkspacesListItems(items));
            Signal<IDrawActionsPanel>(_ => _.DrawActionsPanel(Drawer, databasesActionsBounds, actions, (a, m) => SelectedAction = a));
            Signal<IDrawActionDialog>(_ => _.DrawActionDialog(Drawer, databasesActionInspectorBounds, SelectedAction, () => SelectedAction = null));
            Signal<IDrawWorkspacesList>(_ => _.DrawWorkspacesList(Drawer, databasesListBounds, items));

            Drawer.DoButton(closeButtonBounds, "Close", ElementDesignerStyles.DarkButtonStyle, () =>
            {
                if (WorkspaceService.CurrentWorkspace == null)
                {
                    Signal<INotify>(_ => _.Notify("You need to select or create a Workspace!", NotificationIcon.Info));
                }
                else
                {
                    EnableWizard = false;
                }
            });

        }