Beispiel #1
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);
        }
Beispiel #2
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);
            });
        }
Beispiel #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();
        }
Beispiel #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);
        }
Beispiel #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;
        }
Beispiel #6
0
 public void ManagerRefreshed(IDataRecordManager manager)
 {
     InvertApplication.SignalEvent <IDataRecordManagerRefresh>(_ =>
     {
         if (_ != this)
         {
             _.ManagerRefreshed(manager);
         }
     });
 }
Beispiel #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);
        }
Beispiel #8
0
 public void BeforePropertyChanged(IDataRecord record, string name, object previousValue, object nextValue)
 {
     if (SilentMode)
     {
         return;
     }
     InvertApplication.SignalEvent <IDataRecordPropertyBeforeChange>(_ =>
     {
         if (_ != this)
         {
             _.BeforePropertyChanged(record, name, previousValue, nextValue);
         }
     });
 }
Beispiel #9
0
 public void RecordRemoving(IDataRecord record)
 {
     if (SilentMode)
     {
         return;
     }
     InvertApplication.SignalEvent <IDataRecordRemoving>(_ =>
     {
         if (_ != this)
         {
             _.RecordRemoving(record);
         }
     });
 }
Beispiel #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())
            //{

            //}
            //}
        }
Beispiel #11
0
 public void RecordRemoved(IDataRecord record)
 {
     //TODO Check already invoked in JsonFileRecordManager and FastJsonFileRecordManager
     if (SilentMode)
     {
         return;
     }
     InvertApplication.SignalEvent <IDataRecordRemoved>(_ =>
     {
         if (_ != this)
         {
             _.RecordRemoved(record);
         }
     });
 }
Beispiel #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));
        }
Beispiel #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);
        }
Beispiel #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
        }
Beispiel #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));
        }
Beispiel #16
0
        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", () =>
//                {
//
//
//                }));
//            });
        }
Beispiel #18
0
        public IEnumerable <CodeMemberProperty> RenderTemplateProperty(object instance, KeyValuePair <PropertyInfo, GenerateProperty> templateProperty)
        {
            CurrentAttribute = templateProperty.Value;
            var attributes = templateProperty.Key.GetCustomAttributes(typeof(TemplateAttribute), true).OfType <TemplateAttribute>().OrderBy(p => p.Priority).ToArray();

            bool success = true;

            foreach (var attribute in attributes)
            {
                if (!attribute.CanGenerate(instance, templateProperty.Key, this))
                {
                    success = false;
                }
            }
            if (!success)
            {
                yield break;
            }

            // Default to designer file only
            if (!attributes.OfType <Inside>().Any())
            {
                if (!IsDesignerFile)
                {
                    yield break;
                }
            }

            if (Iterators.ContainsKey(templateProperty.Key.Name))
            {
                var iterator = Iterators[templateProperty.Key.Name];
                var items    = iterator(Data).OfType <IDiagramNodeItem>().ToArray();

                foreach (var item in items)
                {
                    if (ItemFilter != null && !ItemFilter(item))
                    {
                        continue;
                    }
                    Item = item;

                    var domObject = RenderProperty(instance, templateProperty);
                    foreach (var attribute in attributes)
                    {
                        attribute.Modify(instance, templateProperty.Key, this);
                    }
                    CurrentDeclaration.Members.Add(domObject);
                    yield return(domObject);

                    InvertApplication.SignalEvent <ICodeTemplateEvents>(_ => _.PropertyAdded(instance, this, domObject));
                }
                Item = null;
            }
            else
            {
                Item = Data as IDiagramNodeItem;
                if (ItemFilter != null && !ItemFilter(Item))
                {
                    yield break;
                }
                var domObject = RenderProperty(instance, templateProperty);
                foreach (var attribute in attributes)
                {
                    attribute.Modify(instance, templateProperty.Key, this);
                }
                CurrentDeclaration.Members.Add(domObject);
                yield return(domObject);

                InvertApplication.SignalEvent <ICodeTemplateEvents>(_ => _.PropertyAdded(instance, this, domObject));
                Item = null;
            }
        }
Beispiel #19
0
 public void Signal <TInterface>(Action <TInterface> invoke) where TInterface : class
 {
     InvertApplication.SignalEvent <TInterface>(invoke);
 }
Beispiel #20
0
 public virtual void OnMouseExit(MouseEvent e)
 {
     InvertApplication.SignalEvent <IOnMouseExitEvent>(_ => _.OnMouseExit(this, e));
     ViewModelObject.IsMouseOver = false;
 }
Beispiel #21
0
 public virtual void OnRightClick(MouseEvent mouseEvent)
 {
     InvertApplication.SignalEvent <IOnRightClickEvent>(_ => _.OnRightClick(this, mouseEvent));
 }
Beispiel #22
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 (mCachedLines == null || mCachedScroll != scrollPosition || mCachedScreen != 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++;
                    }
                    mCachedLines  = lines.ToArray();
                    mCachedScreen = screen;
                    mCachedScroll = scrollPosition;
                }

                for (int i = 0; i < mCachedLines.Length; i++)
                {
                    Drawer.DrawLine(mCachedLines[i].Lines, mCachedLines[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 (mShouldProcessInputFromDiagram)
                {
                    InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.ProcessInput());
                }
                InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.AfterDrawGraph(DiagramDrawer.Bounds));
            }
            return(false);
        }
Beispiel #23
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);


                var modalItems = new List <DesignerWindowModalContent>();

                var overlayItems = new List <DesignerWindowOverlayContent>();

                //Disable diagram input if any modal content presents or if mouse is over overlay content
                mShouldProcessInputFromDiagram = !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 (!mShouldProcessInputFromDiagram)
                {
                    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 - mLastFpsUpdate).TotalMilliseconds > 1000)
                    {
                        mFpsShown      = mFramesLastSec;
                        mLastFpsUpdate = DateTime.Now;
                        mFramesLastSec = 0;
                    }
                    else
                    {
                        mFramesLastSec++;
                    }
                    Drawer.DrawLabel(fpsCounterRect, string.Format("FPS: {0}", mFpsShown), 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());
        }
Beispiel #24
0
 public virtual void OnMouseUp(MouseEvent e)
 {
     InvertApplication.SignalEvent <IOnMouseUpEvent>(_ => _.OnMouseUp(this, e));
 }
Beispiel #25
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
        }
Beispiel #26
0
 public virtual void OnMouseEnter(MouseEvent e)
 {
     ViewModelObject.IsMouseOver = true;
     InvertApplication.SignalEvent <IOnMouseEnterEvent>(_ => _.OnMouseEnter(this, e));
 }
Beispiel #27
0
 public void Execute(SaveAndCompileCommand command)
 {
     InvertApplication.SignalEvent <ITaskHandler>(_ => { _.BeginTask(Generate(command)); });
 }
Beispiel #28
0
 public virtual void OnMouseDown(MouseEvent mouseEvent)
 {
     InvertApplication.SignalEvent <IOnMouseDownEvent>(_ => _.OnMouseDown(this, mouseEvent));
 }
        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();
        }
Beispiel #30
0
        public void ProcessTemplate()
        {
            // Initialize the template
            TemplateContext.Iterators.Clear();
            TemplateClass.TemplateSetup();

            foreach (
                var item in
                TemplateClass.GetType()
                .GetCustomAttributes(typeof(TemplateAttribute), true)
                .OfType <TemplateAttribute>().OrderBy(p => p.Priority))
            {
                item.Modify(TemplateClass, null, TemplateContext);
            }

            var initializeMethods = TemplateClass.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public).Where(p => p.IsDefined(typeof(TemplateSetup), true)).ToArray();

            foreach (var item in initializeMethods)
            {
                item.Invoke(TemplateClass, null);
            }

            InvertApplication.SignalEvent <ICodeTemplateEvents>(_ => _.TemplateGenerating(TemplateClass, TemplateContext));


            foreach (var templateProperty in TemplateProperties)
            {
                if (FilterToMembers != null && !FilterToMembers.Contains(templateProperty.Key.Name))
                {
                    continue;
                }
                foreach (var item in TemplateContext.RenderTemplateProperty(TemplateClass, templateProperty))
                {
                    Results.Add(new TemplateMemberResult(this, templateProperty.Key, templateProperty.Value, item, Decleration));
                }
            }

            foreach (var templateMethod in TemplateMethods)
            {
                if (FilterToMembers != null && !FilterToMembers.Contains(templateMethod.Key.Name))
                {
                    continue;
                }
                foreach (var item in TemplateContext.RenderTemplateMethod(TemplateClass, templateMethod))
                {
                    Results.Add(new TemplateMemberResult(this, templateMethod.Key, templateMethod.Value, item, Decleration));
                }
            }

            foreach (var templateConstructor in TemplateConstructors)
            {
                if (FilterToMembers != null && !FilterToMembers.Contains(templateConstructor.Key.Name))
                {
                    continue;
                }
                foreach (var item in TemplateContext.RenderTemplateConstructor(TemplateClass, templateConstructor))
                {
                    Results.Add(new TemplateMemberResult(this, templateConstructor.Key, templateConstructor.Value, item, Decleration));
                }
            }
            var postMethods = TemplateClass.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public).Where(p => p.IsDefined(typeof(TemplateComplete), true)).ToArray();

            foreach (var item in postMethods)
            {
                item.Invoke(TemplateClass, null);
            }

            var list = new List <CodeNamespaceImport>();

            foreach (var item in TemplateContext.Namespace.Imports)
            {
                list.Add((CodeNamespaceImport)item);
            }
            TemplateContext.Namespace.Imports.Clear();
            foreach (var item in list.OrderBy(p => p.Namespace))
            {
                TemplateContext.Namespace.Imports.Add(item);
            }
        }