Example #1
0
        public override void Draw(IPlatformDrawer platform, float scale)
        {
            DrawBackground(platform, scale);
            var b = new Rect(Bounds);

            b.x     += 10;
            b.width -= 20;
            //base.Draw(platform, scale);
            platform.DrawColumns(b.Scale(scale), new float[] { _typeSize.x + 5, _nameSize.x },
                                 _ =>
            {
                platform.DoButton(_, _cachedTypeName, CachedStyles.ClearItemStyle, OptionClicked, OptionRightClicked);
            },
                                 _ =>
            {
                DrawName(_, platform, scale, DrawingAlignment.MiddleRight);
                platform.DoButton(_, "", CachedStyles.ClearItemStyle, () =>
                {
                    if (ItemViewModel.IsSelected)
                    {
                        //TODO: Eliminate hack: due to the inconsistent input mechanisms, I cannot fix: when clicking on type, type window appear, then click on the property,
                        //editing will begin, but type window will stay there. So here is a hack of signaling HideSelection event.

                        InvertApplication.SignalEvent <IHideSelectionMenu>(__ => __.HideSelection());

                        ItemViewModel.BeginEditing();
                    }
                    else
                    {
                        ItemViewModel.Select();
                    }
                }, OptionRightClicked);
            });
        }
Example #2
0
        protected CodeConstructor RenderConstructor(object instance, KeyValuePair <MethodInfo, GenerateConstructor> templateMethod, IDiagramNodeItem data)
        {
            var info = templateMethod.Key;
            var dom  = templateMethod.Key.ToCodeConstructor();

            CurrentAttribute   = templateMethod.Value;
            CurrentConstructor = dom;
            PushStatements(dom.Statements);
            //            CurrentStatements = dom.Statements;
            var args       = new List <object>();
            var parameters = info.GetParameters();

            foreach (var arg in parameters)
            {
                args.Add(GetDefault(arg.ParameterType));
            }
            foreach (var item in templateMethod.Value.BaseCallArgs)
            {
                dom.BaseConstructorArgs.Add(new CodeSnippetExpression(item));
            }


            info.Invoke(instance, args.ToArray());
            PopStatements();
            CurrentDeclaration.Members.Add(dom);
            InvertApplication.SignalEvent <ICodeTemplateEvents>(_ => _.ConstructorAdded(instance, this, dom));
            return(dom);
        }
Example #3
0
        public virtual void OptionRightClicked()
        {
            if (!this.ItemViewModel.Enabled)
            {
                return;
            }
            // TODO 2.0 Quick Types Right Click menu
            InvertApplication.SignalEvent <IShowContextMenu>(_ => _.Show(null, this.ViewModelObject));
            //var menu = InvertGraphEditor.CreateCommandUI<ContextMenuUI>(true, typeof(IDiagramNodeItemCommand));

            //var types = InvertGraphEditor.TypesContainer.ResolveAll<GraphTypeInfo>();
            //foreach (var type in types)
            //{
            //    var type1 = type;
            //    menu.AddCommand(new SimpleEditorCommand<GenericTypedChildItem>((_) =>
            //    {
            //        _.RelatedType = type1.Name;
            //    },type1.Label,type1.Group));
            //}
            //foreach (var type in InvertGraphEditor.CurrentDiagramViewModel.CurrentNodes)
            //{
            //    var type1 = type;
            //    menu.AddCommand(new SimpleEditorCommand<GenericTypedChildItem>((_) =>
            //    {
            //        _.RelatedType = type1.Identifier;
            //    }, type1.Label, type1.Group));
            //}

            //menu.Go();
        }
Example #4
0
        public void Execute(BackgroundTaskCommand command)
        {
            BackgroundWorker worker = new BackgroundWorker()
            {
                WorkerSupportsCancellation = true,
                WorkerReportsProgress      = true
            };

            InvertApplication.Log("Creating background task");
            worker.DoWork += (sender, args) =>
            {
                InvertApplication.Log("Executing background task");
                var bgCommand = args.Argument as BackgroundTaskCommand;

                if (bgCommand != null)
                {
                    bgCommand.Command.Worker = sender as BackgroundWorker;
                    bgCommand.Action(bgCommand.Command);
                }
            };
            worker.ProgressChanged += (sender, args) =>
            {
                InvertApplication.Log("PROGRESS");
                InvertApplication.SignalEvent <ICommandProgressEvent>(_ => _.Progress(null, args.UserState.ToString(), args.ProgressPercentage));
            };
            command.Task = new BackgroundTask(worker);
            worker.RunWorkerAsync(command);
        }
Example #5
0
        public IEnumerator AddGraphItems(IEnumerable <IDiagramNode> items)
        {
            var dictionary = new Dictionary <string, IFilterItem>();

            foreach (var item in GraphData.CurrentFilter.FilterItems)
            {
                if (dictionary.ContainsKey(item.NodeId))
                {
                    item.Repository.Remove(item);
                    continue;
                }
                dictionary.Add(item.NodeId, item);
            }

            FilterItems = dictionary;



            IsLoading = true;
            var connectors = new List <ConnectorViewModel>();

            // var time = DateTime.Now;
            foreach (var item in items)
            {
                // Get the ViewModel for the data
                //InvertApplication.Log("B-A" + DateTime.Now.Subtract(time).TotalSeconds.ToString());
                var mapping = InvertApplication.Container.RelationshipMappings[item.GetType(), typeof(ViewModel)];
                if (mapping == null)
                {
                    continue;
                }
                var vm = Activator.CreateInstance(mapping, item, this) as GraphItemViewModel;
                //var vm =
                //    InvertApplication.Container.ResolveRelation<ViewModel>(item.GetType(), item, this) as
                //        GraphItemViewModel;
                //InvertApplication.Log("B-B" + DateTime.Now.Subtract(time).TotalSeconds.ToString());
                if (vm == null)
                {
                    if (InvertGraphEditor.Platform.MessageBox("Node Error", string.Format("Couldn't find view-model for {0} would you like to remove this item?", item.GetType()), "Yes", "No"))
                    {
                        CurrentRepository.Remove(item);
                    }
                    continue;
                }
                vm.DiagramViewModel = this;
                GraphItems.Add(vm);
                //// Clear the connections on the view-model
                //vm.Connectors.Clear();
                //vm.GetConnectors(vm.Connectors);
                //connectors.AddRange(vm.Connectors);
                yield return(new TaskProgress(string.Format("Loading..."), 95f));
            }
            IsLoading = false;
            RefreshConnectors();
            //AddConnectors(connectors);
            InvertApplication.SignalEvent <IGraphLoaded>(_ => _.GraphLoaded());
            yield break;
        }
 public void ManagerRefreshed(IDataRecordManager manager)
 {
     InvertApplication.SignalEvent <IDataRecordManagerRefresh>(_ =>
     {
         if (_ != this)
         {
             _.ManagerRefreshed(manager);
         }
     });
 }
Example #7
0
        protected CodeMemberMethod RenderMethod(object instance, KeyValuePair <MethodInfo, GenerateMethod> templateMethod, IDiagramNodeItem data)
        {
            MethodInfo info;
            var        dom = TemplateType.MethodFromTypeMethod(templateMethod.Key.Name, out info, false);

            CurrentMember    = dom;
            CurrentAttribute = templateMethod.Value;
            PushStatements(dom.Statements);

            var args       = new List <object>();
            var parameters = info.GetParameters();

            foreach (var arg in parameters)
            {
                args.Add(GetDefault(arg.ParameterType));
            }

            CurrentDeclaration.Members.Add(dom);

            var result = info.Invoke(instance, args.ToArray());
            var a      = result as IEnumerable;

            if (a != null)
            {
                var dummyIteraters = a.Cast <object>().ToArray();
                foreach (var item in dummyIteraters)
                {
                }
            }

            PopStatements();

            //var isOverried = false;
            //if (!IsDesignerFile && dom.Attributes != MemberAttributes.Final && templateMethod.Value.Location == TemplateLocation.Both)
            //{
            //    dom.Attributes |= MemberAttributes.Override;
            //    isOverried = true;
            //}
            //if ((info.IsVirtual && !IsDesignerFile) || (info.IsOverride() && !info.GetBaseDefinition().IsAbstract && IsDesignerFile))
            //{
            //    if (templateMethod.Value.CallBase)
            //    {
            //        //if (!info.IsOverride() || !info.GetBaseDefinition().IsAbstract && IsDesignerFile)
            //        //{
            //        dom.invoke_base(true);
            //        //}

            //    }
            //}
            InvertApplication.SignalEvent <ICodeTemplateEvents>(_ => _.MethodAdded(instance, this, dom));
            return(dom);
        }
 public void BeforePropertyChanged(IDataRecord record, string name, object previousValue, object nextValue)
 {
     if (SilentMode)
     {
         return;
     }
     InvertApplication.SignalEvent <IDataRecordPropertyBeforeChange>(_ =>
     {
         if (_ != this)
         {
             _.BeforePropertyChanged(record, name, previousValue, nextValue);
         }
     });
 }
 public void RecordRemoving(IDataRecord record)
 {
     if (SilentMode)
     {
         return;
     }
     InvertApplication.SignalEvent <IDataRecordRemoving>(_ =>
     {
         if (_ != this)
         {
             _.RecordRemoving(record);
         }
     });
 }
Example #10
0
        public void Load(bool async = false)
        {
            GraphItems.Clear();
            //GraphItems.Add(InspectorViewModel);

            // var graphItems = new List<GraphItemViewModel>();
            //// var time = DateTime.Now;
            // foreach (var item in CurrentNodes)
            // {

            //     // Get the ViewModel for the data
            //     //InvertApplication.Log("B-A" + DateTime.Now.Subtract(time).TotalSeconds.ToString());
            //     var mapping = InvertApplication.Container.RelationshipMappings[item.GetType(), typeof(ViewModel)];
            //     if (mapping == null) continue;
            //     var vm = Activator.CreateInstance(mapping, item, this) as GraphItemViewModel;
            //     //var vm =
            //     //    InvertApplication.Container.ResolveRelation<ViewModel>(item.GetType(), item, this) as
            //     //        GraphItemViewModel;
            //     //InvertApplication.Log("B-B" + DateTime.Now.Subtract(time).TotalSeconds.ToString());
            //     if (vm == null)
            //     {
            //         if (InvertGraphEditor.Platform.MessageBox("Node Error", string.Format("Couldn't find view-model for {0} would you like to remove this item?", item.GetType()), "Yes", "No"))
            //         {
            //             CurrentRepository.Remove(item);
            //         }
            //         continue;
            //     }
            //     vm.DiagramViewModel = this;
            //     GraphItems.Add(vm);
            //     // Clear the connections on the view-model
            //     vm.Connectors.Clear();
            //     vm.GetConnectors(vm.Connectors);
            //     connectors.AddRange(vm.Connectors);
            // }
            CurrentNodes = GraphData.CurrentFilter.FilterNodes.Distinct().ToArray();
            NavigationViewModel.Refresh();
            //if (async)
            //{
            InvertApplication.SignalEvent <ITaskHandler>(_ => _.BeginBackgroundTask(AddGraphItems(CurrentNodes)));
            //}
            //else
            //{
            //var e = AddGraphItems();
            //while (e.MoveNext())
            //{

            //}
            //}
        }
 public void RecordRemoved(IDataRecord record)
 {
     //TODO Check already invoked in JsonFileRecordManager and FastJsonFileRecordManager
     if (SilentMode)
     {
         return;
     }
     InvertApplication.SignalEvent <IDataRecordRemoved>(_ =>
     {
         if (_ != this)
         {
             _.RecordRemoved(record);
         }
     });
 }
Example #12
0
        public void Execute(CreateWorkspaceCommand command)
        {
            var workspace = Activator.CreateInstance(command.WorkspaceType) as Workspace;

            if (workspace == null)
            {
                throw new Exception("Workspace cannot be created! If you are using custom workspace type, make sure it derives from Workspace class.");
            }
            workspace.Name = command.Name;
            command.Result = workspace;
            Repository.Add(workspace);
            Execute(new OpenWorkspaceCommand()
            {
                Workspace = workspace
            });

            InvertApplication.SignalEvent <INotify>(_ => _.Notify(command.Name + " workspace has been created!", NotificationIcon.Info));
        }
Example #13
0
        public override void OnRightClick(MouseEvent mouseEvent)
        {
            DiagramViewModel.LastMouseEvent = mouseEvent;
            BubbleEvent(d => d.OnRightClick(mouseEvent), mouseEvent);
            if (DrawersAtMouse == null)
            {
                ShowAddNewContextMenu(mouseEvent);
                return;
            }
            //var item = DrawersAtMouse.OrderByDescending(p=>p.ZOrder).FirstOrDefault();
            IDrawer item = DrawersAtMouse.OfType <ConnectorDrawer>().FirstOrDefault();

            if (item != null)
            {
                InvertApplication.SignalEvent <IShowContextMenu>(_ => _.Show(mouseEvent, item.ViewModelObject));
                return;
            }
            item = DrawersAtMouse.OfType <ItemDrawer>().FirstOrDefault();
            if (item != null)
            {
                if (item.Enabled)
                {
                    ShowItemContextMenu(mouseEvent);
                }
                return;
            }
            item = DrawersAtMouse.OfType <DiagramNodeDrawer>().FirstOrDefault();
            if (item == null)
            {
                item = DrawersAtMouse.OfType <HeaderDrawer>().FirstOrDefault();
            }
            if (item != null)
            {
                if (!item.ViewModelObject.IsSelected)
                {
                    item.ViewModelObject.Select();
                }
                ShowContextMenu(mouseEvent);
                return;
            }
            ShowAddNewContextMenu(mouseEvent);
        }
Example #14
0
        public void DeselectAll()
        {
            if (InspectorViewModel != null)
            {
                InspectorViewModel.TargetViewModel = null;
            }

            foreach (var item in AllViewModels.ToArray())
            {
                var ivm = item as ItemViewModel;
                if (ivm != null)
                {
                    if (ivm.IsEditing)
                    {
                        ivm.EndEditing();
                        break;
                    }
                }
                var nvm = item as DiagramNodeViewModel;
                if (nvm != null)
                {
                    if (nvm.IsEditing)
                    {
                        nvm.EndEditing();
                        break;
                    }
                }


                if (item.IsSelected)
                {
                    item.IsSelected = false;
                }
            }


            InvertApplication.SignalEvent <INothingSelectedEvent>(_ => _.NothingSelected());
#if UNITY_EDITOR
            UnityEngine.GUI.FocusControl("");
#endif
        }
Example #15
0
        public void Select(GraphItemViewModel viewModelObject)
        {
            if (viewModelObject == null)
            {
                return;
            }

            InspectorViewModel.TargetViewModel = viewModelObject;

            if (viewModelObject.IsSelected)
            {
                return;
            }
            if (LastMouseEvent != null && LastMouseEvent.ModifierKeyStates != null && !LastMouseEvent.ModifierKeyStates.Alt)
            {
                DeselectAll();
            }

            viewModelObject.IsSelected = true;
            InvertApplication.SignalEvent <IGraphSelectionEvents>(
                _ => _.SelectionChanged(viewModelObject));
        }
        public void Execute(CreateDatabaseCommand command)
        {
            if (Directory.Exists(command.Name))
            {
                throw new Exception(string.Format("Database {0} already exists.", command.Name));
            }
            var dbDir  = Directory.CreateDirectory(Path.Combine(DbRootPath, command.Name + ".db"));
            var db     = new TypeDatabase(new JsonRepositoryFactory(dbDir.FullName));
            var config = GetConfig(db, command.Name);

            config.Namespace      = command.Namespace;
            config.Title          = command.Name;
            config.CodeOutputPath = command.CodePath;
            config.Namespace      = command.Namespace ?? config.Namespace;
            config.FullPath       = dbDir.FullName;
            config.Database       = db;
            db.Commit();
            CurrentDatabaseIdentifier   = config.Identifier;
            InvertApplication.Container = null;
            if (InvertApplication.Container != null)
            {
                InvertApplication.SignalEvent <INotify>(_ => _.Notify(command.Name + " Database " + " has been created!", NotificationIcon.Info));
            }
        }
        public void SelectItem()
        {
            var menu = new SelectionMenu();

            menu.AddItem(new SelectionMenuItem(string.Empty, "[None]", () =>
            {
                ReferenceItem.SetInput(null);
            }));
            menu.ConvertAndAdd(ReferenceItem.GetAllowed().OfType <IItem>(), _ =>
            {
                var item = _ as IValueItem;
                if (item == null)
                {
                    return;
                }
                if (IsInput)
                {
                    ReferenceItem.SetInput(item);
                }
                else
                {
                    ReferenceItem.SetOutput(item);
                }
            });

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

//            InvertGraphEditor.WindowManager.InitItemWindow(ReferenceItem.GetAllowed().ToArray(), _ =>
//            {
//                InvertApplication.Execute(new LambdaCommand("Set Item", () =>
//                {
//
//
//                }));
//            });
        }
Example #18
0
 public void Execute(SaveAndCompileCommand command)
 {
     InvertApplication.SignalEvent <ITaskHandler>(_ => { _.BeginTask(Generate(command)); });
 }
Example #19
0
 public void ShowContextMenu(MouseEvent mouseEvent)
 {
     InvertApplication.SignalEvent <IShowContextMenu>(_ => _.Show(mouseEvent, DiagramViewModel.SelectedNodes.Cast <object>().ToArray()));
 }
Example #20
0
 public virtual void OnMouseDown(MouseEvent mouseEvent)
 {
     InvertApplication.SignalEvent <IOnMouseDownEvent>(_ => _.OnMouseDown(this, mouseEvent));
 }
Example #21
0
 public virtual void OnRightClick(MouseEvent mouseEvent)
 {
     InvertApplication.SignalEvent <IOnRightClickEvent>(_ => _.OnRightClick(this, mouseEvent));
 }
Example #22
0
 public virtual void OnMouseUp(MouseEvent e)
 {
     InvertApplication.SignalEvent <IOnMouseUpEvent>(_ => _.OnMouseUp(this, e));
 }
Example #23
0
 public virtual void OnMouseEnter(MouseEvent e)
 {
     ViewModelObject.IsMouseOver = true;
     InvertApplication.SignalEvent <IOnMouseEnterEvent>(_ => _.OnMouseEnter(this, e));
 }
Example #24
0
 public virtual void OnMouseExit(MouseEvent e)
 {
     InvertApplication.SignalEvent <IOnMouseExitEvent>(_ => _.OnMouseExit(this, e));
     ViewModelObject.IsMouseOver = false;
 }
Example #25
0
        public override void OnMouseUp(MouseEvent e)
        {
            base.OnMouseUp(e);
            if (CurrentConnection != null)
            {
                InvertApplication.Execute(new LambdaCommand("Create Connection", () =>
                {
                    CurrentConnection.Apply(CurrentConnection);
                }));
            }
            else
            {
                var mouseData = e;
                InvertApplication.SignalEvent <IShowConnectionMenu>(
                    _ => _.Show(DiagramViewModel, StartConnector, mouseData.MouseUpPosition));

                //var allowedFilterNodes = FilterExtensions.AllowedFilterNodes[this.DiagramViewModel.CurrentRepository.CurrentFilter.GetType()];
                //var menu = InvertGraphEditor.CreateCommandUI<ContextMenuUI>();
                //foreach (var item in allowedFilterNodes)
                //{
                //    if (item.IsInterface) continue;
                //    if (item.IsAbstract) continue;

                //    var node = Activator.CreateInstance(item) as IDiagramNode;
                //    node.Graph = this.DiagramViewModel.GraphData;
                //    var vm = InvertGraphEditor.Container.GetNodeViewModel(node, this.DiagramViewModel) as DiagramNodeViewModel;


                //    if (vm == null) continue;
                //    vm.IsCollapsed = false;
                //    var connectors = new List<ConnectorViewModel>();
                //    vm.GetConnectors(connectors);

                //    var config = InvertGraphEditor.Container.Resolve<NodeConfigBase>(item.Name);
                //    var name = config == null ? item.Name : config.Name;
                //    foreach (var connector in connectors)
                //    {
                //        foreach (var strategy in InvertGraphEditor.ConnectionStrategies)
                //        {
                //            var connection = strategy.Connect(this.DiagramViewModel, StartConnector, connector);
                //            if (connection == null) continue;
                //            var node1 = node;
                //            var message = string.Format("Create {0}", name);
                //            if (!string.IsNullOrEmpty(connector.Name))
                //            {
                //                message += string.Format(" and connect to {0}", connector.Name);
                //            }
                //            var value = new KeyValuePair<IDiagramNode, ConnectionViewModel>(node1, connection);
                //            menu.AddCommand(
                //             new SimpleEditorCommand<DiagramViewModel>(delegate(DiagramViewModel n)
                //             {


                //                 //UnityEditor.EditorWindow.FocusWindowIfItsOpen(typeof (ElementsDesigner));

                //                 InvertGraphEditor.ExecuteCommand(_ =>
                //                 {
                //                     this.DiagramViewModel.AddNode(value.Key,e.MouseUpPosition);
                //                     connection.Apply(value.Value as ConnectionViewModel);
                //                     value.Key.IsSelected = true;
                //                     value.Key.IsEditing = true;
                //                     value.Key.Name = "";
                //                 });
                //             },message));
                //        }

                //    }

                //}
                //menu.Go();
            }


            foreach (var a in PossibleConnections)
            {
                a.IsMouseOver = false;
                a.IsSelected  = false;
            }
            e.Cancel();
        }
Example #26
0
        public void Draw(float width, float height, Vector2 scrollPosition, float scale)
        {
            DiagramDrawer.IsEditingField = false;
            if (Drawer == null)
            {
                InvertApplication.Log("DRAWER IS NULL");
                return;
            }
            var diagramRect = new Rect();

            if (DrawToolbar)
            {
                var toolbarTopRect  = new Rect(0, 0, width, 18);
                var tabsRect        = new Rect(0, toolbarTopRect.height, width, 31);
                var breadCrumbsRect = new Rect(0, tabsRect.y + tabsRect.height, width, 30);

                diagramRect = new Rect(0f, breadCrumbsRect.y + breadCrumbsRect.height, width,
                                       height - ((toolbarTopRect.height * 2)) - breadCrumbsRect.height - 31);
                var toolbarBottomRect = new Rect(0f, diagramRect.y + diagramRect.height, width,
                                                 toolbarTopRect.height);


                List <DesignerWindowModalContent> modalItems = new List <DesignerWindowModalContent>();
                Signal <IQueryDesignerWindowModalContent>(_ => _.QueryDesignerWindowModalContent(modalItems));

                List <DesignerWindowOverlayContent> overlayItems = new List <DesignerWindowOverlayContent>();
                Signal <IQueryDesignerWindowOverlayContent>(_ => _.QueryDesignerWindowOverlayContent(overlayItems));

                //Disable diagram input if any modal content presents or if mouse is over overlay content
                _shouldProcessInputFromDiagram = !modalItems.Any() && overlayItems.All(i => !i.Drawer.CalculateBounds(diagramRect).Contains(Event.current.mousePosition));

                Drawer.DrawStretchBox(toolbarTopRect, CachedStyles.Toolbar, 0f);

                Drawer.DoToolbar(toolbarTopRect, this, ToolbarPosition.Left);
                //drawer.DoToolbar(toolbarTopRect, this, ToolbarPosition.Right);

                Drawer.DrawRect(tabsRect, InvertGraphEditor.Settings.GridLinesColor);

                //Drawer.DoTabs(Drawer,tabsRect, this);
                DiagramRect = diagramRect;

                /*
                 * DRAW DIAGRAM
                 * Using GUI.color hack to avoid transparent diagram on disabled input (Thanks Unity :( )
                 */

                if (!_shouldProcessInputFromDiagram)
                {
                    Drawer.DisableInput();
                }

                if (DiagramDrawer != null)
                {
                    DiagramDrawer.DrawTabs(Drawer, tabsRect);
                    DiagramDrawer.DrawBreadcrumbs(Drawer, breadCrumbsRect.y);
                }

                var fpsCounterRect = tabsRect.WithWidth(80).RightOf(tabsRect).Translate(-100, 0);

                if (ShowFPS)
                {
                    if ((DateTime.Now - _lastFpsUpdate).TotalMilliseconds > 1000)
                    {
                        _fpsShown      = _framesLastSec;
                        _lastFpsUpdate = DateTime.Now;
                        _framesLastSec = 0;
                    }
                    else
                    {
                        _framesLastSec++;
                    }
                    Drawer.DrawLabel(fpsCounterRect, string.Format("FPS: {0}", _fpsShown), CachedStyles.WizardSubBoxTitleStyle);
                }

                Drawer.DrawRect(diagramRect, InvertGraphEditor.Settings.BackgroundColor);

                DiagramRect = diagramRect;

                DrawDiagram(Drawer, scrollPosition, scale, diagramRect);

                Drawer.EnableInput();

                /*
                 * DRAW OVERLAY CONTENT
                 */

                if (modalItems.Any())
                {
                    Drawer.DisableInput();
                }

                foreach (var item in overlayItems)
                {
                    var bounds      = item.Drawer.CalculateBounds(diagramRect);
                    var isMouseOver = bounds.Contains(Event.current.mousePosition);

                    var colorCache = GUI.color;

                    if (!isMouseOver && !item.DisableTransparency)
                    {
                        GUI.color = new Color(colorCache.r, colorCache.g, colorCache.b, colorCache.a / 4);
                    }

                    item.Drawer.Draw(bounds);

                    GUI.color = colorCache;
                }

                Drawer.EnableInput();

                /*
                 * DRAW MODAL CONTENT
                 */

                if (modalItems.Any())
                {
                    var modalBackgroundRect = new Rect().Cover(breadCrumbsRect, tabsRect, diagramRect);
                    var modalContentRect    = new Rect().WithSize(800, 500).CenterInsideOf(modalBackgroundRect);
                    var activeModal         = modalItems.OrderBy(i => i.ZIndex).Last();

                    Drawer.DisableInput();

                    foreach (var source in modalItems.OrderBy(i => i.ZIndex).Except(new[] { activeModal }))
                    {
                        source.Drawer(modalContentRect);
                    }

                    Drawer.EnableInput();

                    Drawer.DrawRect(modalBackgroundRect, new Color(0, 0, 0, 0.8f));

                    activeModal.Drawer(modalContentRect);
                }


                DrawToolip(breadCrumbsRect);

                Drawer.DoToolbar(toolbarBottomRect, this, ToolbarPosition.BottomLeft);
                //drawer.DoToolbar(toolbarBottomRect, this, ToolbarPosition.BottomRight);
            }
            else
            {
                diagramRect = new Rect(0f, 0f, width, height);
                DiagramRect = diagramRect;
                DrawDiagram(Drawer, scrollPosition, scale, diagramRect);
            }

            InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.AfterDrawDesignerWindow(new Rect(0, 0, width, height)));
            InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.DrawComplete());
        }
Example #27
0
        public void DrawTabs(IPlatformDrawer platform, Rect tabsRect)
        {
            var designerWindow = DiagramViewModel.NavigationViewModel.DesignerWindow;

            if (designerWindow != null && designerWindow.Designer != null)
            {
                var x = 1f;
                foreach (var tab in DiagramViewModel.NavigationViewModel.Tabs.ToArray())
                {
                    if (tab == null)
                    {
                        continue;
                    }
                    if (tab.Title == null)
                    {
                        continue;
                    }

                    var textSize = platform.CalculateTextSize(tab.Title, CachedStyles.TabTitleStyle);

                    var buttonRect = new Rect()
                                     .AlignAndScale(tabsRect)
                                     .WithWidth(Math.Max(textSize.x + 21 + 16, 60))
                                     .Translate(x, 0);

                    var buttonBoxRect = new Rect().AlignAndScale(buttonRect)
                                        .WithWidth(textSize.x + 10);

                    var textRect = new Rect()
                                   .AlignAndScale(buttonRect)
                                   .Pad(7, 0, 7, 0);

                    var closeButton = new Rect()
                                      .WithSize(16, 16)
                                      .AlignTopRight(buttonRect)
                                      .AlignHorisonallyByCenter(buttonRect)
                                      .Translate(-7, 1);


                    platform.DrawStretchBox(buttonRect, tab.State == NavigationItemState.Current ? CachedStyles.TabBoxActiveStyle : CachedStyles.TabBoxStyle, 10);

                    platform.DrawLabel(textRect, tab.Title, CachedStyles.TabTitleStyle);

                    var tab1 = tab;
                    platform.DoButton(buttonBoxRect, "", CachedStyles.ClearItemStyle, m =>
                    {
                        if (tab1.NavigationAction != null)
                        {
                            tab1.NavigationAction(m);
                        }
                    }, m =>
                    {
                        if (tab1.NavigationActionSecondary != null)
                        {
                            tab1.NavigationActionSecondary(m);
                        }
                    });

                    platform.DoButton(closeButton, "", CachedStyles.TabCloseButton, m =>
                    {
                        if (tab1.CloseAction != null)
                        {
                            tab1.CloseAction(m);
                        }
                    });

                    x += buttonRect.width + 2;
                }

                var newTabButtonRect =
                    new Rect().WithSize(27, 27).Align(tabsRect).AlignHorisonallyByCenter(tabsRect).Translate(x + 2, 0);

                platform.SetTooltipForRect(newTabButtonRect, "Create or import new graphs");

                platform.DoButton(newTabButtonRect, "", ElementDesignerStyles.WizardActionButtonStyleSmall, () => { InvertApplication.SignalEvent <INewTabRequested>(_ => _.NewTabRequested()); });

                platform.DrawImage(newTabButtonRect.PadSides(6), "PlusIcon_Micro", true);
            }
        }
Example #28
0
 public void ShowItemContextMenu(MouseEvent mouseEvent)
 {
     InvertApplication.SignalEvent <IShowContextMenu>(_ => _.Show(mouseEvent, DiagramViewModel.SelectedNodeItem));
 }
Example #29
0
        private bool DrawDiagram(IPlatformDrawer drawer, Vector2 scrollPosition, float scale, Rect diagramRect)
        {
            var screen = new Vector2(Screen.width, Screen.height);


            if (DiagramDrawer == null)
            {
                if (Workspace != null)
                {
                    if (Workspace.CurrentGraph != null)
                    {
                        LoadDiagram(Workspace.CurrentGraph);
                    }
                }
            }

            if (DiagramDrawer != null && DiagramViewModel != null && InvertGraphEditor.Settings.UseGrid)
            {
                if (_cachedLines == null || _cachedScroll != scrollPosition || _cachedScreen != screen)
                {
                    var lines = new List <CachedLineItem>();

                    var softColor = InvertGraphEditor.Settings.GridLinesColor;
                    var hardColor = InvertGraphEditor.Settings.GridLinesColorSecondary;
                    var x         = -scrollPosition.x;

                    var every10 = 0;

                    while (x < DiagramRect.x + DiagramRect.width + scrollPosition.x)
                    {
                        var color = softColor;
                        if (every10 == 10)
                        {
                            color   = hardColor;
                            every10 = 0;
                        }
                        if (x > diagramRect.x)
                        {
                            lines.Add(new CachedLineItem()
                            {
                                Lines = new[] { new Vector3(x, diagramRect.y), new Vector3(x, diagramRect.x + diagramRect.height + scrollPosition.y + 85) },
                                Color = color
                            });
                        }

                        x += DiagramViewModel.Settings.SnapSize * scale;
                        every10++;
                    }
                    var y = -scrollPosition.y + 80;
                    every10 = 10;
                    while (y < DiagramRect.y + DiagramRect.height + scrollPosition.y)
                    {
                        var color = softColor;
                        if (every10 == 10)
                        {
                            color   = hardColor;
                            every10 = 0;
                        }
                        if (y > diagramRect.y)
                        {
                            lines.Add(new CachedLineItem()
                            {
                                Lines = new[] { new Vector3(diagramRect.x, y), new Vector3(diagramRect.x + diagramRect.width + scrollPosition.x, y) },
                                Color = color
                            });
                        }

                        y += DiagramViewModel.Settings.SnapSize * scale;
                        every10++;
                    }
                    _cachedLines  = lines.ToArray();
                    _cachedScreen = screen;
                    _cachedScroll = scrollPosition;
                }

                for (int i = 0; i < _cachedLines.Length; i++)
                {
                    Drawer.DrawLine(_cachedLines[i].Lines, _cachedLines[i].Color);
                }
            }
            if (DiagramDrawer != null)
            {
                InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.BeforeDrawGraph(diagramRect));
                DiagramDrawer.Bounds = new Rect(0f, 0f, diagramRect.width, diagramRect.height);

                DiagramDrawer.Draw(drawer, 1f);

                if (_shouldProcessInputFromDiagram)
                {
                    InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.ProcessInput());
                }
                InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.AfterDrawGraph(DiagramDrawer.Bounds));
            }
            return(false);
        }
Example #30
0
        public IEnumerator Generate(SaveAndCompileCommand command)
        {
            var repository = InvertGraphEditor.Container.Resolve <IRepository>();

            var remove = repository.AllOf <IClassNode>().Where(p => string.IsNullOrEmpty(p.Name)).ToArray();

            foreach (var item in remove)
            {
                repository.Remove(item);
            }

            repository.Commit();
            var config = InvertGraphEditor.Container.Resolve <IGraphConfiguration>();
            var items  = GetItems(repository, command.ForceCompileAll).Distinct().ToArray();

            yield return
                (new TaskProgress(0f, "Validating"));

            var a = ValidationSystem.ValidateNodes(items.OfType <IDiagramNode>().ToArray());

            while (a.MoveNext())
            {
                yield return(a.Current);
            }
            if (ValidationSystem.ErrorNodes.SelectMany(n => n.Errors).Any(e => e.Siverity == ValidatorType.Error))
            {
                Signal <INotify>(_ => _.Notify("Please, fix all errors before compiling.", NotificationIcon.Error));
                yield break;
            }
            Signal <IUpgradeDatabase>(_ => _.UpgradeDatabase(config as uFrameDatabaseConfig));
            Signal <ICompilingStarted>(_ => _.CompilingStarted(repository));
            // Grab all the file generators
            var fileGenerators = InvertGraphEditor.GetAllFileGenerators(config, items, true).ToArray();

            var length = 100f / (fileGenerators.Length + 1);
            var index  = 0;

            foreach (var codeFileGenerator in fileGenerators)
            {
                index++;
                yield return(new TaskProgress(length * index, "Generating " + System.IO.Path.GetFileName(codeFileGenerator.AssetPath)));

                // Grab the information for the file
                var fileInfo = new FileInfo(codeFileGenerator.SystemPath);
                // Make sure we are allowed to generate the file
                if (!codeFileGenerator.CanGenerate(fileInfo))
                {
                    var fileGenerator = codeFileGenerator;
                    InvertApplication.SignalEvent <ICompileEvents>(_ => _.FileSkipped(fileGenerator));

                    if (codeFileGenerator.Generators.All(p => p.AlwaysRegenerate))
                    {
                        if (File.Exists(fileInfo.FullName))
                        {
                            File.Delete(fileInfo.FullName);
                        }
                    }

                    continue;
                }

                GenerateFile(fileInfo, codeFileGenerator);
                CodeFileGenerator generator = codeFileGenerator;
                InvertApplication.SignalEvent <ICompileEvents>(_ => _.FileGenerated(generator));
            }
            ChangedRecrods.Clear();
            InvertApplication.SignalEvent <ICompileEvents>(_ => _.PostCompile(config, items));
            foreach (var item in items.OfType <IGraphData>())
            {
                item.IsDirty = false;
            }
            yield return
                (new TaskProgress(100f, "Complete"));

#if UNITY_EDITOR
            repository.Commit();
            if (InvertGraphEditor.Platform != null) // Testability
            {
                InvertGraphEditor.Platform.RefreshAssets();
            }
#endif
        }