Exemplo n.º 1
0
        public void QueryContextMenu(ContextMenuUI ui, MouseEvent evt, params object[] obj)
        {
            var typedItem = obj.FirstOrDefault() as TypedItemViewModel;

            if (typedItem != null)
            {
                foreach (var item in TypesInfo)
                {
                    var item1 = item;
                    ui.AddCommand(new ContextMenuItem()
                    {
                        Title   = item1.Name,
                        Group   = item.Group,
                        Command = new LambdaCommand("Change Type", () =>
                        {
                            typedItem.RelatedType = item1.Name;
                        })
                    });
                }
            }
            var nodeItem = obj.FirstOrDefault() as ItemViewModel;

            if (nodeItem != null)
            {
                ui.AddCommand(new ContextMenuItem()
                {
                    Title   = "Delete",
                    Command = new DeleteCommand()
                    {
                        Title = "Delete Item",
                        Item  = new[] { nodeItem.DataObject as IDataRecord }
                    }
                });
            }
        }
Exemplo n.º 2
0
        public void QueryContextMenu(ContextMenuUI ui, MouseEvent evt, params object[] obj)
        {
            var exportUI = obj.OfType <ExportUICommand>().FirstOrDefault();

            if (exportUI != null)
            {
                var ws = InvertApplication.Container.Resolve <WorkspaceService>();
                if (ws != null && ws.CurrentWorkspace != null)
                {
                    ui.AddCommand(new ContextMenuItem()
                    {
                        Title   = "Export Database",
                        Group   = "Export",
                        Command = new ExportDatabaseCommand()
                        {
                            Database = Container.Resolve <DatabaseService>().CurrentConfiguration
                        },
                    });
                    ui.AddCommand(new ContextMenuItem()
                    {
                        Title   = "Export Workspace",
                        Group   = "Export",
                        Command = new ExportWorkspaceCommand()
                        {
                            Workspace = ws.CurrentWorkspace
                        },
                    });
                    // ui.AddSeparator();
                    if (ws.CurrentWorkspace.CurrentGraph != null)
                    {
                        ui.AddCommand(new ContextMenuItem()
                        {
                            Title   = "Export Current Graph",
                            Group   = "Export",
                            Command = new ExportGraphCommand()
                            {
                                Graph = ws.CurrentWorkspace.CurrentGraph
                            },
                        });
                    }
                }
            }

            var diagram = obj.OfType <DiagramViewModel>().FirstOrDefault();

            if (diagram == null)
            {
                return;
            }
            //var graph = diagram.GraphData;
            //ui.AddCommand(new ContextMenuItem()
            //{
            //    Title = "Export this graph",
            //    Command = new LambdaCommand("Export Graph", () =>
            //    {

            //    })
            //});
        }
Exemplo n.º 3
0
        public void QueryContextMenu(ContextMenuUI ui, MouseEvent evt, params object[] obj)
        {
            var node = obj.FirstOrDefault() as DiagramNodeViewModel;

            if (node != null)
            {
                var config         = InvertGraphEditor.Container.Resolve <IGraphConfiguration>();
                var fileGenerators = InvertGraphEditor.GetAllFileGenerators(config, new[] { node.DataObject as IDataRecord }, true).ToArray();
                foreach (var file in fileGenerators)
                {
                    var file1 = file;
                    if (File.Exists(file1.SystemPath))
                    {
                        ui.AddCommand(new ContextMenuItem()
                        {
                            Title   = "Open " + (file.AssetPath.Replace("/", "\\")),
                            Group   = "Open",
                            Command = new LambdaCommand("Open File", () =>
                            {
                                InvertGraphEditor.Platform.OpenScriptFile(file1.AssetPath);
                            })
                        });
                    }
                }

                foreach (var file in fileGenerators)
                {
                    var file1     = file;
                    var outputGen = file1.Generators.FirstOrDefault();
                    if (outputGen == null)
                    {
                        continue;
                    }
                    var templateClassGen = outputGen as ITemplateClassGenerator;
                    if (templateClassGen != null && typeof(IOnDemandTemplate).IsAssignableFrom(templateClassGen.TemplateType))
                    {
                        ui.AddCommand(new ContextMenuItem()
                        {
                            Title   = "Create Editable " + Path.GetFileName(file.AssetPath),
                            Group   = "Open",
                            Command = new LambdaCommand("Create Editable File", () =>
                            {
                                GenerateFile(new FileInfo(file1.SystemPath), file1);
                                AssetDatabase.Refresh();
                                InvertGraphEditor.Platform.OpenScriptFile(file1.AssetPath);
                            })
                        });
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void QueryContextMenu(ContextMenuUI ui, MouseEvent evt, params object[] obj)
        {
            var item = obj.OfType <GraphItemViewModel>().FirstOrDefault();

            if (item == null)
            {
                return;
            }

            foreach (var flag in FlagByName.Values)
            {
                var flag1 = flag;
                if (flag.For.GetType().IsAssignableFrom(item.DataObject.GetType()) || flag.For == item.DataObject.GetType())
                {
                    var value = flag.GetValue(item.DataObject as IDiagramNodeItem);
                    ui.AddCommand(new ContextMenuItem()
                    {
                        Title   = flag.FlagName,
                        Checked = value,
                        Group   = "Flags",
                        Command = new LambdaCommand("Set Flag", () =>
                        {
                            flag1.SetValue(item.DataObject as IDiagramNodeItem, !value);
                        })
                    });
                }
            }
        }
Exemplo n.º 5
0
        public void QueryContextMenu(ContextMenuUI ui, MouseEvent evt, params object[] obj)
        {
            var connector = obj.FirstOrDefault() as ConnectorViewModel;

            if (connector != null)
            {
                var connections =
                    InvertGraphEditor.CurrentDiagramViewModel.GraphItems.OfType <ConnectionViewModel>()
                    .Where(p => p.ConnectorA == connector || p.ConnectorB == connector).ToArray();

                foreach (var connection in connections)
                {
                    ConnectionViewModel connection1 = connection;
                    ui.AddCommand(new ContextMenuItem()
                    {
                        Title   = string.Format("Remove {0}", connection1.Name),
                        Group   = "Remove",
                        Command = new LambdaCommand("Remove Connection", () => { connection1.Remove(connection1); })
                    });
                }
            }
        }
Exemplo n.º 6
0
        public void QueryContextMenu(ContextMenuUI ui, MouseEvent evt, params object[] objs)
        {
            var diagramNodeItem = objs.FirstOrDefault() as ItemViewModel;

            if (diagramNodeItem != null)
            {
                var item = diagramNodeItem.DataObject as IDiagramNodeItem;
                if (item != null)
                {
                    ui.AddCommand(new ContextMenuItem()
                    {
                        Title   = "Move Up",
                        Command = new MoveItemUpCommand()
                        {
                            Item = item
                        }
                    });
                    ui.AddCommand(new ContextMenuItem()
                    {
                        Title   = "Move Down",
                        Command = new MoveItemDownCommand()
                        {
                            Item = item
                        }
                    });
                }
            }
            var diagramNode = objs.FirstOrDefault() as DiagramNodeViewModel;

            if (diagramNode != null)
            {
                ui.AddCommand(new ContextMenuItem()
                {
                    Title   = "Rename",
                    Group   = "Node",
                    Command = new RenameCommand()
                    {
                        ViewModel = diagramNode
                    }
                });
                ui.AddCommand(new ContextMenuItem()
                {
                    Title   = "Hide",
                    Group   = "Node",
                    Command = new HideCommand()
                    {
                        Node   = objs.OfType <DiagramNodeViewModel>().Select(p => p.GraphItemObject).ToArray(),
                        Filter = diagramNode.DiagramViewModel.GraphData.CurrentFilter
                    }
                });
                ui.AddCommand(new ContextMenuItem()
                {
                    Title   = "Delete",
                    Group   = "Careful",
                    Command = new DeleteCommand()
                    {
                        Item = objs.OfType <DiagramNodeViewModel>().Select(p => p.GraphItemObject).ToArray()
                    }
                });
                if (diagramNode.IsExternal)
                {
                    ui.AddCommand(new ContextMenuItem()
                    {
                        Title   = "Pull",
                        Group   = "Node",
                        Command = new PullNodeCommand()
                        {
                            Node = objs.OfType <DiagramNodeViewModel>().Select(p => p.GraphItemObject).ToArray(),
                        }
                    });
                }
            }

            var diagram = objs.FirstOrDefault() as DiagramViewModel;

            if (diagram != null)
            {
                var filter = diagram.GraphData.CurrentFilter;
                foreach (var nodeType in FilterExtensions.AllowedFilterNodes[filter.GetType()].OrderBy(p => p.FullName))
                {
                    if (nodeType.IsAbstract)
                    {
                        continue;
                    }
                    var config = Container.GetNodeConfig(nodeType);
                    if (config.AllowAddingInMenu)
                    {
                        ui.AddCommand(new ContextMenuItem()
                        {
                            Title   = "Create " + Container.GetNodeConfig(nodeType).Name,
                            Group   = "Create",
                            Command = new CreateNodeCommand()
                            {
                                NodeType  = nodeType,
                                GraphData = diagram.GraphData,
                                Position  = diagram.LastMouseEvent.MouseDownPosition
                            }
                        });
                    }
                }

                if (filter.AllowExternalNodes)
                {
                    foreach (var item in filter.GetAllowedDiagramItems().OfType <GenericNode>().OrderBy(p => p.Name))
                    {
                        ui.AddCommand(new ContextMenuItem()
                        {
                            Title   = "Show/" + item.Config.Name + "/" + item.Name,
                            Group   = "Show",
                            Command = new ShowCommand()
                            {
                                Node = item, Filter = filter, Position = evt.MousePosition
                            }
                        });
                    }
                }
            }
        }