Example #1
0
        public CommandEditorControl(Type commandType, Command value)
        {
            InitializeComponent();

            foreach (Type type in Assembly.GetCallingAssembly().GetTypes())
            {
                if (commandType.IsAssignableFrom(type))
                {
                    try
                    {
                        Command c = (Command)Activator.CreateInstance(type);
                        Image image = c.MenuImage ?? c.ToolBarImage;
                        string text = c.GetType().Name;
                        ListViewItem item = new ListViewItem(text);
                        item.Tag = c;

                        if (image != null)
                        {
                            imageList.Images.Add(text, image);
                            item.ImageKey = text;
                        }

                        listView.Items.Add(item);

                        item.Selected = value != null && value.GetType() == c.GetType();
                    }
                    catch (MissingMethodException)
                    {
                    }
                }
            }

            foreach (ColumnHeader ch in listView.Columns)
            {
                ch.Width = -2;
            }

            listView.ListViewItemSorter = new Sorter();
        }
Example #2
0
 private CommandTreeNode FillTreeNode(CommandTreeNode node, Command command, CommandTreeNode nodeAfter)
 {
     Type type = command.GetType();
     var commandAttr = type.GetCustomAttributes(false).OfType<GinNameAttribute>().FirstOrDefault();
     CommandTreeNode commandNode;
     if (nodeAfter == null)
     {
         commandNode = node.AppendChild(command, commandAttr);
     }
     else
     {
         commandNode = node.InsertAfter(command, commandAttr, nodeAfter);
     }
     var properties = type.GetProperties();
     foreach (PropertyInfo property in properties)
     {
         var propertyAttr = (GinArgumentCommandAttribute)property.GetCustomAttributes(typeof(GinArgumentCommandAttribute), false).FirstOrDefault();
         if (propertyAttr != null)
         {
             CommandTreeNode argumentNode = commandNode.AppendChild(command, commandAttr, property, propertyAttr);
             object nestedCommand = property.GetValue(command, null);
             if (nestedCommand != null)
             {
                 Type nestedType = nestedCommand.GetType();
                 bool isEnumerable = propertyAttr.IsEnumerable;
                 if (isEnumerable)
                 {
                     IEnumerable iEnum = (IEnumerable)nestedCommand;
                     foreach (var item in iEnum)
                     {
                         FillTreeNode(argumentNode, (Command)item, null);
                     }
                 }
                 else
                 {
                     FillTreeNode(argumentNode, (Command)nestedCommand, null);
                 }
             }
         }
     }
     return commandNode;
 }
Example #3
0
 private void ClearAllNestedCommands(Command command)
 {
     Type commandType = command.GetType();
     var properties = commandType.GetProperties();
     foreach (var property in properties)
     {
         bool isNestedCommand = property.GetCustomAttributes(typeof(GinArgumentCommandAttribute), false).Count() == 1;
         if (isNestedCommand)
         {
             object defaultValue = null;
             property.SetValue(command, defaultValue, null);
         }
     }
 }
 private bool AddCommand(Command c)
 {
     if (c == null)
     {
         DebugLog("WARNING: Cannot use NULL command");
         return false;
     }
     string cName = c.Name;
     if (string.IsNullOrEmpty(cName))
     {
         DebugLog("WARNING: Cannot use no-name command " + c.GetType());
         return false;
     }
     if (cName.StartsWith("!"))
     {
         //DebugLog("WARNING: Skipping command " + cName);
         return false;
     }
     if (c.Parameters == null)
     {
         // DebugLog("WARNING: Skipping non-paramerized command " + cName);
         return false;
     }
     int i = 0;
     while (i < c.Parameters.Parameters.Length)
     {
         Type from = (Type)c.Parameters.Parameters[i].SourceType;
         Type use = (Type)c.Parameters.Parameters[i].DestinationType;
         AddCommand(c, from, use);
         i++;
     }
     return true;
 }
 private void RegisterConextAction(Command t, CommandContextAction cca)
 {            
     String subDir = t.GetType().Namespace;
     var ccc = GetCommandContextMenu(subDir);
     ccc.AddSubCommand(cca);
     var ccc2 = GetCommandContextMenu(t.Category.ToString());
     if (ccc2!=ccc) ccc2.AddSubCommand(cca);
     //instance.TabConsole.RegisterContextAction(cca);
 }
        private void FillProperties(Command cmd)
        {
            pnlProperties.Controls.Clear();

            if (!cmd.AllowUserProperties)
                return;

            foreach (var prop in cmd.GetType().GetProperties())
            {
                if (prop.GetCustomAttributes(typeof(UserPropertyAttribute), true).Count() == 0)
                    continue;

                var setterControl = ServiceLocator.GetPropertyUI(prop.PropertyType);

                PropertySetterConfiguration setterConfig = new PropertySetterConfiguration();
                setterConfig.Property = prop.Name;
                setterConfig.Value = null;
                setterControl.Initialize(setterConfig);
                pnlProperties.Controls.Add((Control)setterControl);
            }
        }