public void DrawActionDialog(IPlatformDrawer platform, Rect bounds, ActionItem item, Action cancel = null)
        {
            if (item == null) return;

            platform.DrawStretchBox(bounds, CachedStyles.WizardSubBoxStyle, 13);

            bounds = bounds.PadSides(15);

            var descriptionHeight = string.IsNullOrEmpty(item.Description) ? 50 : platform.CalculateTextHeight(item.Description, CachedStyles.BreadcrumbTitleStyle, bounds.width) + 60;

            var headerRect = bounds.WithHeight(40);
            var iconRect = bounds.WithSize(41, 41);
            
            var descriptionRect = headerRect.Below(headerRect).Translate(0,-22).WithHeight(descriptionHeight);
            var inspectorRect = bounds.Below(descriptionRect).Clip(bounds);
            var executeButtonRect = new Rect()
                .WithSize(100, 30)
                .InnerAlignWithBottomRight(bounds);

            if (!_inspectors.ContainsKey(item))
            {
                var uFrameMiniInspector = new uFrameMiniInspector(item.Command);
                _inspectors.Add(item, uFrameMiniInspector);
            }
            var inspector = _inspectors[item];
            var inspectorHeight = inspector.Height;


            _scrollPosition = GUI.BeginScrollView(bounds.AddHeight(-30).AddWidth(15), _scrollPosition,
                bounds.WithHeight(headerRect.height + iconRect.height + descriptionRect.height + inspectorHeight));

            platform.DrawLabel(headerRect, item.Title, CachedStyles.WizardSubBoxTitleStyle, DrawingAlignment.MiddleCenter);
            platform.DrawImage(iconRect, string.IsNullOrEmpty(item.Icon) ? "CreateEmptyDatabaseIcon" : item.Icon, true);
            platform.DrawLabel(descriptionRect, item.Description, CachedStyles.BreadcrumbTitleStyle, DrawingAlignment.MiddleLeft);

            inspector.Draw(descriptionRect.WithHeight(inspectorHeight).Pad(0,0,10,0).Below(descriptionRect));

            //Draw generic inspector


                GUI.EndScrollView();
            if ( cancel != null)
            {
                platform.DoButton(executeButtonRect.InnerAlignWithBottomLeft(bounds), "Cancel", ElementDesignerStyles.DarkButtonStyle, cancel);
            }

            platform.DoButton(executeButtonRect, string.IsNullOrEmpty(item.Verb) ? "Create" : item.Verb, ElementDesignerStyles.DarkButtonStyle, () =>
            {
                InvertApplication.Execute(item.Command);
            });
        }
        public void DrawWorkspacesList(IPlatformDrawer platform, Rect bounds, List<WorkspacesListItem> items)
        {
            platform.DrawStretchBox(bounds, CachedStyles.WizardSubBoxStyle, 13);

            var scrollBounds = bounds.Translate(15, 0).Pad(0, 0, 15, 0);
            bounds = bounds.PadSides(15);


            var headerRect = bounds.WithHeight(40);

            platform.DrawLabel(headerRect, "Workspaces", CachedStyles.WizardSubBoxTitleStyle, DrawingAlignment.TopCenter);

            var unpaddedItemRect = bounds.Below(headerRect).WithHeight(100);

            var workspaces = items.ToArray();
         
            var position = scrollBounds.Below(headerRect).Clip(scrollBounds).Pad(0, 0, 0, 55);
            var usedRect = position.Pad(0, 0, 15, 0).WithHeight((unpaddedItemRect.height + 1) * workspaces.Length);
            _scrollPos = GUI.BeginScrollView(position, _scrollPos, usedRect);
            foreach (var db in workspaces)
            {
                var workspace = db;
                platform.DrawStretchBox(unpaddedItemRect, CachedStyles.WizardListItemBoxStyle, 2);
                var itemRect = unpaddedItemRect.PadSides(15);
                var titleRect = itemRect.WithHeight(40);

                platform.DrawLabel(titleRect, db.Workspace.Title, CachedStyles.WizardSubBoxTitleStyle, DrawingAlignment.TopLeft);

                var infoRect = itemRect.Below(titleRect).WithHeight(30);
                //(platform as UnityDrawer).DrawInfo(infoRect, string.Format("Namespace: {0}\nPath: {1}", db.GraphConfiguration.Namespace ?? "-", db.GraphConfiguration.FullPath));


                var openButton = new Rect().WithSize(80, 25).InnerAlignWithBottomRight(itemRect);
                var configButton = openButton.LeftOf(openButton).Translate(-2, 0);
                var deleteButton = configButton.LeftOf(configButton).Translate(-2, 0);

                platform.DoButton(openButton, "Open", ElementDesignerStyles.DarkButtonStyle, () =>
                {
                    Execute(new OpenWorkspaceCommand() { Workspace = workspace.Workspace });
                    EnableWizard = false;
                });
                var db1 = db;
                platform.DoButton(configButton, "Config", ElementDesignerStyles.DarkButtonStyle, () => InvokeConfigFor(db1));
                platform.DoButton(deleteButton, "Remove", ElementDesignerStyles.DarkButtonStyle, () => { Execute(new RemoveWorkspaceCommand() { Workspace = workspace.Workspace }); });
                //platform.DoButton(showButton, "Show In Explorer", ElementDesignerStyles.ButtonStyle, () => { });


                unpaddedItemRect = unpaddedItemRect.Below(unpaddedItemRect).Translate(0, 1);

            }

            GUI.EndScrollView(true);

        }
        public void DrawProblemInspector(Rect bounds, Problem problem)
        {
            var headerRect = bounds.WithHeight(30);
            PlatformDrawer.DrawLabel(headerRect, problem.Exception.Message, CachedStyles.WizardActionTitleStyle, DrawingAlignment.MiddleCenter);

            var stackFrames = problem.StackTrace.GetFrames();
            if (stackFrames == null) return;

            var lastLineRect = headerRect;
            
            foreach (var frame in stackFrames)
            {
                var lineRect = bounds.WithHeight(15).Below(lastLineRect);

                PlatformDrawer.DrawLabel(lineRect ,frame.GetMethod().DeclaringType.Name+"."+frame.GetMethod().Name + " at " +frame.GetFileName(), CachedStyles.ListItemTitleStyle, DrawingAlignment.MiddleCenter);


                lastLineRect = lineRect;
            }

        }
        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 DrawGraphsList(Rect bounds, List<IGraphData> items)
        {

            PlatformDrawer.DrawStretchBox(bounds, CachedStyles.WizardSubBoxStyle, 13);
            
            var scrollBounds = bounds.Translate(15,0).Pad(0,0,15,0);
            
            bounds = bounds.PadSides(15);


            var headerRect = bounds.WithHeight(40);
             
            PlatformDrawer.DrawLabel(headerRect, string.Format("{0} Graphs", WorkspaceService.CurrentWorkspace.Title), CachedStyles.WizardSubBoxTitleStyle, DrawingAlignment.TopCenter);

            var unpaddedItemRect = bounds.Below(headerRect).WithHeight(50);

            var databasesListItems = items.ToArray();
         
            var position = scrollBounds.Below(headerRect).Clip(scrollBounds).Pad(0, 0, 0, 55);
            var usedRect = position.Pad(0, 0, 15, 0).WithHeight((unpaddedItemRect.height + 1)*databasesListItems.Length);
            
            _scrollPos = GUI.BeginScrollView(position, _scrollPos, usedRect);

            foreach (var db in databasesListItems)
            {

                var db1 = db;
                var isGraphInWorkspace = WorkspaceService.CurrentWorkspace != null && WorkspaceService.CurrentWorkspace.Graphs.Contains(db1);
                var cColor = GUI.color;
                var mColor = new Color(cColor.r, cColor.g, cColor.b, 0.3f);
                if (!isGraphInWorkspace) GUI.color = mColor;

                PlatformDrawer.DrawStretchBox(unpaddedItemRect,CachedStyles.WizardListItemBoxStyle,2);
               
                if(isGraphInWorkspace)
                PlatformDrawer.DoButton(unpaddedItemRect.TopHalf(),"",CachedStyles.ClearItemStyle, () =>
                {
                    Execute(new LambdaCommand("Open Graph", () =>
                    {
                        WorkspaceService.CurrentWorkspace.AddGraph(db1);
                        WorkspaceService.CurrentWorkspace.CurrentGraphId = db1.Identifier;
                        EnableGraphManagementhWizard = false;
                    }));
                });
                
                var itemRect = unpaddedItemRect.PadSides(15);
                var titleRect = itemRect.WithHeight(40);

                PlatformDrawer.DrawLabel(titleRect,db.Title,CachedStyles.WizardSubBoxTitleStyle,DrawingAlignment.TopLeft);

                var infoRect = itemRect.Below(titleRect).WithHeight(38);
                //(PlatformDrawer as UnityDrawer).DrawInfo(infoRect, string.Format("Namespace: {0}\nPath: {1}", db.GraphConfiguration.Namespace ?? "-", db.GraphConfiguration.FullPath));


                var openButton = new Rect().WithSize(80,25).InnerAlignWithBottomRight(itemRect).AlignHorisonallyByCenter(itemRect);
                var configButton = openButton.LeftOf(openButton).Translate(-2,0);
                var exportButton = openButton.LeftOf(configButton).Translate(-2, 0);
                var deleteButton = openButton.LeftOf(exportButton).Translate(-2, 0);


                GUI.color = cColor;
                PlatformDrawer.DoButton(openButton, isGraphInWorkspace ? "Open" : "Import", ElementDesignerStyles.DarkButtonStyle, () =>
                {
                    
                    /* OPEN DATABASE */
                    Execute(new LambdaCommand("Open Graph", () =>
                    {
                        WorkspaceService.CurrentWorkspace.AddGraph(db1);
                        WorkspaceService.CurrentWorkspace.CurrentGraphId = db1.Identifier;
                        EnableGraphManagementhWizard = false;
                    }));
                    //DatabaseListWindow.Init(new Vector2(Screen.currentResolution.width / 2 - 200, Screen.currentResolution.height/2- 300));

                });
                //PlatformDrawer.DoButton(configButton, "Config", ElementDesignerStyles.ButtonStyle, () => { /* CONFIG DATABASE */ });
                //PlatformDrawer.DoButton(deleteButton, "Delete", ElementDesignerStyles.ButtonStyle, () => { /* SHOW DATABASE IN EXPLORER */ });
                //PlatformDrawer.DoButton(exportButton, "Export", ElementDesignerStyles.ButtonStyle, () => { /* SHOW DATABASE IN EXPLORER */ });
               
                unpaddedItemRect = unpaddedItemRect.Below(unpaddedItemRect).Translate(0,1);

            }
            GUI.EndScrollView(true);
        }
        //TODO WIZARDS: Add scrolling (drawer needs to be extended to support scrolling / or use native unity stuff)
        public void DrawActionsPanel(IPlatformDrawer platform, Rect bounds, List<ActionItem> actions, Action<ActionItem,Vector2> primaryAction,
            Action<ActionItem,Vector2> secondaryAction = null)
        {
            platform.DrawStretchBox(bounds, CachedStyles.WizardSubBoxStyle, 13);

            bounds = bounds.PadSides(15);
            var headerRect = new Rect(bounds.WithHeight(40));

            platform.DrawLabel(headerRect, "Actions", CachedStyles.WizardSubBoxTitleStyle, DrawingAlignment.TopCenter);

            bounds = bounds.Below(headerRect).Clip(bounds);

            var buttonSize = 100;
            var buttonsPerRow = (int)bounds.width / (int)buttonSize;
            var buttonIndex = 0;
            var padding = (bounds.width % buttonSize) / (buttonsPerRow - 1);
            var itemRect = new Rect().Align(bounds).WithSize(buttonSize, buttonSize);

            foreach (var action in actions)
            {

                platform.DrawStretchBox(itemRect, CachedStyles.WizardActionButtonStyle, 0);

                var action1 = action;
                platform.DoButton(itemRect,"",CachedStyles.ClearItemStyle, m =>
                {
                    primaryAction(action1, m);
                }, m =>
                {
                    if (secondaryAction != null)
                    {
                        secondaryAction(action1, m);
                    }
                });

                var imageRect = itemRect
                    .WithSize(41, 41)
                    .CenterInsideOf(itemRect)
                    .AlignHorisontally(itemRect)
                    .Translate(0, 10);

                var titleRect = itemRect
                    .Below(imageRect)
                    .Clip(itemRect)
                    .Pad(5, 0, 10, 0)
                    .Translate(0, -2);

                platform.DrawImage(imageRect, string.IsNullOrEmpty(action.Icon) ? "CreateEmptyDatabaseIcon" : action.Icon, true);
                platform.DrawLabel(titleRect, action.Title, CachedStyles.ListItemTitleStyle, DrawingAlignment.MiddleCenter);

                buttonIndex++;

                if (buttonIndex % buttonsPerRow == 0)
                {
                    itemRect = itemRect.Below(itemRect).AlignVertically(bounds).Translate(0, 10);
                }
                else
                {
                    itemRect = itemRect.RightOf(itemRect).Translate(padding, 0);
                }

            }
        }
        public void Draw(Rect bouds)
        {

            if (TreeModel == null) return;

            HandleInput(bouds);

            if (!EnableContent ) return;

            var searcbarRect = bouds.WithHeight(30).PadSides(5);

            var leftHeight = bouds.height - searcbarRect.height;

            var listRect = bouds.Below(searcbarRect).WithHeight(leftHeight * 0.6f).PadSides(5);

            var searchIconRect = new Rect().WithSize(30, 30).InnerAlignWithBottomRight(searcbarRect).AlignHorisonallyByCenter(searcbarRect).PadSides(10);

            var descriptionRect = bouds.Below(listRect).Clip(bouds).PadSides(5);

            GUI.SetNextControlName("SelectionMenu_Search");
            EditorGUI.BeginChangeCheck();
            var newSearchCrit = GUI.TextField(searcbarRect, SearchCriteria ?? "",ElementDesignerStyles.SearchBarTextStyle);
            PlatformDrawer.DrawImage(searchIconRect, "SearchIcon", true);
            if (EditorGUI.EndChangeCheck())
            {
                if (newSearchCrit != SearchCriteria)
                {
                    SearchCriteria = newSearchCrit;
                    TreeModel.SelectedIndex = -1;
                    if (string.IsNullOrEmpty(SearchCriteria))
                    {
                        TreeModel.Predicate = null;
                    }
                    else
                    {
                        var sc = SearchCriteria.ToLower();
                        TreeModel.Predicate = i =>
                        {
                            if (string.IsNullOrEmpty(i.Title)) return false;

                            if (
                                CultureInfo.CurrentCulture.CompareInfo.IndexOf(i.Title, SearchCriteria,
                                    CompareOptions.IgnoreCase) != -1) return true;

                            if (!string.IsNullOrEmpty(i.SearchTag) &&
                                CultureInfo.CurrentCulture.CompareInfo.IndexOf(i.SearchTag, SearchCriteria,
                                    CompareOptions.IgnoreCase) != -1) return true;

                            return false;
                        };
                    }
                    TreeModel.IsDirty = true;
                }
            }

            if (TreeModel.IsDirty) TreeModel.Refresh();

            InvertApplication.SignalEvent<IDrawTreeView>(_ =>
            {
                _.DrawTreeView(listRect, TreeModel, (m, i) => { SelectItem(i); });
            });

            if (TreeModel == null) return;

            var selectedItem = TreeModel.SelectedData as IItem;
            if (selectedItem != null)
            {
                PlatformDrawer.DrawStretchBox(descriptionRect, CachedStyles.WizardSubBoxStyle, 10);

                if (string.IsNullOrEmpty(selectedItem.Description))
                {
                    var textRect = descriptionRect;
                    var cacheColor = GUI.color;
                    GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 0.4f);
                    PlatformDrawer.DrawLabel(textRect, string.Format("{0}\nNo Description", selectedItem.Title), CachedStyles.WizardSubBoxTitleStyle, DrawingAlignment.MiddleCenter);
                    GUI.color = cacheColor;
                }
                else
                {
                    var titleRect = descriptionRect.WithHeight(40).PadSides(10);
                    var desctTextRect = descriptionRect.Below(titleRect).Clip(descriptionRect).PadSides(10);
                    PlatformDrawer.DrawLabel(titleRect, selectedItem.Title, CachedStyles.WizardActionTitleStyle, DrawingAlignment.TopLeft);
                    PlatformDrawer.DrawLabel(desctTextRect, selectedItem.Description ?? "Please add description to the item", CachedStyles.WizardActionTitleStyle, DrawingAlignment.TopLeft);
                }


            }

            if (_focusNeeded)
            {
                GUI.FocusControl("SelectionMenu_Search");
                _focusNeeded = false;
            }
        }
        public Rect CalculateBounds(Rect diagramRect)
        {
            if (RequestPosition.HasValue)
            {

                if (TreeModel == null) return new Rect(0,0,0,0);
                var selectedItem = TreeModel.SelectedData as IItem;

                var rect = new Rect().WithSize(QuickAccessWidth, selectedItem == null ? QuickAccessHeigth - 200 : QuickAccessHeigth).WithOrigin(RequestPosition.Value.x, RequestPosition.Value.y);
                if (rect.height > diagramRect.height) rect = rect.WithHeight(Mathf.Max(diagramRect.height, 230));

                if (rect.yMax > diagramRect.yMax) rect = rect.WithOrigin(rect.x, diagramRect.yMax - rect.height - 15 );
                if (rect.xMax > diagramRect.xMax) rect = rect.WithOrigin(diagramRect.xMax - rect.width - 15, rect.y);

                return rect;


            }
            var rectNorm =  new Rect().WithSize(QuickAccessWidth, QuickAccessHeigth).CenterInsideOf(diagramRect);
            if (rectNorm.height > diagramRect.height) rectNorm = rectNorm.WithHeight(Mathf.Max(diagramRect.height, 230));
            return rectNorm;

        }
        public void DrawDatabasesList(IPlatformDrawer Drawer, Rect bounds, List<DatabasesListItem> items)
        {

            Drawer.DrawStretchBox(bounds, CachedStyles.WizardSubBoxStyle, 13);
            
            var scrollBounds = bounds.Translate(15,0).Pad(0,0,15,0);
            
            bounds = bounds.PadSides(15);


            var headerRect = bounds.WithHeight(40);
             
            Drawer.DrawLabel(headerRect, "Databases", CachedStyles.WizardSubBoxTitleStyle, DrawingAlignment.TopCenter);

            var unpaddedItemRect = bounds.Below(headerRect).WithHeight(150);

            var databasesListItems = items.ToArray();
         
            var position = scrollBounds.Below(headerRect).Clip(scrollBounds).Pad(0, 0, 0, 55);
            var usedRect = position.Pad(0, 0, 15, 0).WithHeight((unpaddedItemRect.height + 1)*databasesListItems.Length);
            
            _scrollPos = GUI.BeginScrollView(position, _scrollPos, usedRect);

            foreach (var db in databasesListItems)
            {

                Drawer.DrawStretchBox(unpaddedItemRect,CachedStyles.WizardListItemBoxStyle,2);
                var itemRect = unpaddedItemRect.PadSides(15);
                var titleRect = itemRect.WithHeight(40);

                Drawer.DrawLabel(titleRect,db.GraphConfiguration.Title,CachedStyles.WizardSubBoxTitleStyle,DrawingAlignment.TopLeft);

                var infoRect = itemRect.Below(titleRect).WithHeight(50);
                (Drawer as UnityDrawer).DrawInfo(infoRect,string.Format("Namespace: {0}\nPath: {1}",db.GraphConfiguration.Namespace ?? "-",db.GraphConfiguration.FullPath));


                var openButton = new Rect().WithSize(80,25).InnerAlignWithBottomRight(itemRect);
                var configButton = openButton.LeftOf(openButton).Translate(-2,0);
                var showButton = configButton.WithWidth(120).InnerAlignWithBottomLeft(itemRect);

                Drawer.DoButton(openButton, "Open", ElementDesignerStyles.DarkButtonStyle, () =>
                {
                    Signal<IChangeDatabase>(_=>_.ChangeDatabase(db.GraphConfiguration));
                });

                Drawer.SetTooltipForRect(openButton,"Open this database.");

                var db1 = db;
                Drawer.DoButton(configButton, "Config", ElementDesignerStyles.DarkButtonStyle, () =>
                {
                    SelectedItem = new ActionItem()
                    {
                        Command = new EditDatabaseCommand()
                        {
                            Namespace = db1.GraphConfiguration.Namespace,
                            CodePath = db1.GraphConfiguration.CodeOutputPath,
                            Configuration = db1.GraphConfiguration as uFrameDatabaseConfig
                        },

                        Description = "Configuration",
                        Title = string.Format("Configure {0}", db1.GraphConfiguration.Title),
                        Verb = "Apply"
                    };
                });
                Drawer.DoButton(showButton, "Show In Explorer", ElementDesignerStyles.DarkButtonStyle, () =>
                {
                    EditorUtility.RevealInFinder(db1.GraphConfiguration.FullPath);
                });

                unpaddedItemRect = unpaddedItemRect.Below(unpaddedItemRect).Translate(0,1);

            }
            GUI.EndScrollView(true);
        }