Exemple #1
0
        static MenuHelper()
        {
            /*
             * Create one instance of guiControllerCommand for each existing public command.
             * This instance is later used in every context menu (instances of commands are shared
             * among the existing menus)
             */
            foreach (List <CommandDescriptor> scopeCommands in PublicCommandsHelper.publicCommandsByScope.Values)
            {
                foreach (CommandDescriptor commandDescriptor in scopeCommands)
                {
                    guiControllerCommand guiC       = new guiControllerCommand();
                    CommandDescriptor    descriptor = commandDescriptor;
                    guiC.ControllerCommandFactoryMethod =
                        delegate
                    {
                        return(CommandSerializer.CreateCommandObject(descriptor.CommandType));
                    };
                    guiC.ControllerCommandType        = commandDescriptor.CommandType;
                    guiC.ControllerCommandDescription = commandDescriptor.CommandDescription;
                    guiCommandsForControllerCommands[commandDescriptor.CommandType] = guiC;
                }
            }

            foreach (Type t in typeof(guiScopeCommand).Assembly.GetTypes())
            {
                if (t.IsSubclassOf(typeof(guiScopeCommand)))
                {
                    ScopeAttribute a = (ScopeAttribute)t.GetCustomAttributes(typeof(ScopeAttribute), true).FirstOrDefault();
                    if (a != null)
                    {
                        #if SILVERLIGHT
                        foreach (ScopeAttribute.EScope scope in EnumHelper.GetValues(typeof(ScopeAttribute.EScope)))
                        #else
                        foreach (ScopeAttribute.EScope scope in Enum.GetValues(typeof(ScopeAttribute.EScope)))
                        #endif
                        {
                            if (scope == ScopeAttribute.EScope.None)
                            {
                                continue;
                            }
                            if (a.Scope.HasFlag(scope))
                            {
                                localCommandsByScope.CreateSubCollectionIfNeeded(scope);
                                localCommandsByScope[scope].Add((guiScopeCommand)t.GetConstructor(Type.EmptyTypes).Invoke(null));
                            }
                        }
                        if (a.Scope == ScopeAttribute.EScope.None)
                        {
                            localCommandsByScope.CreateSubCollectionIfNeeded(a.Scope);
                            localCommandsByScope[a.Scope].Add((guiScopeCommand)t.GetConstructor(Type.EmptyTypes).Invoke(null));
                        }
                    }
                }
            }
        }
Exemple #2
0
        private static void PrepareCommandScope(ExolutioContextMenu contextMenu, ContextMenuItem contextMenuItem)
        {
            guiControllerCommand guiControllerCommand = contextMenuItem.Command as guiControllerCommand;

            if (guiControllerCommand != null)
            {
                guiControllerCommand.Diagram = (Diagram)contextMenu.Diagram;

                if (!guiControllerCommand.NoScope)
                {
                    guiControllerCommand.ScopeObject = contextMenu.ScopeObject;
                    SetScopeForCommand(guiControllerCommand.ControllerCommand, contextMenu.ScopeObject);
                }
                guiControllerCommand.ProjectVersion = Current.ProjectVersion;
            }
        }
Exemple #3
0
        private static ContextMenuItem CreateMenuItem(CommandDescriptor commandDescriptor)
        {
            ContextMenuItem menuItem = new ContextMenuItem(commandDescriptor.CommandDescription);
            //change.Icon = ExolutioResourceNames.GetResourceImageSource(ExolutioResourceNames.pencil);

            guiControllerCommand guiCommandForControllerCommand = guiCommandsForControllerCommands[commandDescriptor.CommandType];

            menuItem.Command = guiCommandForControllerCommand;

            guiCommandForControllerCommand.OpenDialog = commandDescriptor.Parameters.Count(p => p.CreateControlInEdtors) > 1;
            guiCommandForControllerCommand.NoScope    = commandDescriptor.Scope == ScopeAttribute.EScope.None;

            if (guiCommandForControllerCommand.OpenDialog)
            {
                menuItem.Header = commandDescriptor.CommandDescription + "...";
            }

            return(menuItem);
        }