public IControl Build(object data)
        {
            Type type = null;

            if (data is BaseToolWindow toolWindow)
            {
                ToolWindowAttribute toolWindowAttribute =
                    toolWindow.GetType().GetCustomAttribute <ToolWindowAttribute>();

                type = toolWindowAttribute.ViewType;
            }
            else
            {
                // I take no responsibility for the code in this else statement.
                // Avalonia's default project generated this.
                // ~Russell

                var name = data.GetType().FullName.Replace("ViewModel", "View");
                type = Type.GetType(name);
            }


            if (type != null)
            {
                return((Control)Activator.CreateInstance(type));
            }
            else
            {
                return(new TextBlock {
                    Text = "Not Found: " + data.GetType().FullName
                });
            }
        }
Example #2
0
        public void CreateToolWindows()
        {
            this.CreateHandle();

            foreach (Assembly assembly in Manager.Assemblies)
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (typeof(ToolWindow).IsAssignableFrom(type) && type.IsClass)
                    {
                        ToolWindowAttribute attr = ToolWindowAttribute.ForType(type);
                        if (attr == null)
                        {
                            continue;
                        }

                        ToolWindow panel  = Activator.CreateInstance(type, new object[] { Manager }) as ToolWindow;
                        IntPtr     handle = panel.Handle;                       // Make sure we can call Invoke(), even if it isn't opened
                        mToolWindows.Add(panel);

                        ToolStripMenuItem parent;
                        if (attr.Group == "")
                        {
                            parent = viewToolStripMenuItem;
                        }
                        else
                        {
                            ToolStripItem [] candidates = viewToolStripMenuItem.DropDownItems.Find(attr.Group, false);
                            if (candidates.Length > 0)
                            {
                                parent = (ToolStripMenuItem)candidates[0];
                            }
                            else
                            {
                                parent      = new ToolStripMenuItem(attr.Group);
                                parent.Name = attr.Group;
                                viewToolStripMenuItem.DropDownItems.Add(parent);
                            }
                        }

                        ToolStripMenuItem menu = new ToolStripMenuItem(panel.TabText);
                        menu.Tag    = panel;
                        menu.Click += new EventHandler(ToolMenu_Click);
                        parent.DropDownItems.Add(menu);
                    }
                }
            }
        }
Example #3
0
        private void AddToolWindow(Type toolType)
        {
            if (!CanInjectToolConstructor(toolType))
            {
                return;
            }

            ToolWindowAttribute toolWindowAttribute =
                toolType.GetCustomAttribute <ToolWindowAttribute>();

            DefaultToolWindowAttribute defaultToolWindowAttribute =
                toolType.GetCustomAttribute <DefaultToolWindowAttribute>();

            ToolWindowFactoryInfo info = new ToolWindowFactoryInfo();

            info.Type = toolType;
            info.ToolWindowAttribute        = toolWindowAttribute;
            info.DefaultToolWindowAttribute = defaultToolWindowAttribute;
            info.Instances = new List <BaseToolWindow>();

            if (toolWindowAttribute.ToolWindowType == ToolWindowType.Floating)
            {
                _floatingToolWindows.Add(toolWindowAttribute.DisplayName, info);
            }
            else
            {
                _documentToolWindows.Add(toolWindowAttribute.DisplayName, info);
            }

            if (defaultToolWindowAttribute != null)
            {
                if (toolWindowAttribute.ToolWindowType == ToolWindowType.Floating)
                {
                    _defaultFloatingTools.Add(toolWindowAttribute.DisplayName, info);
                }
                else
                {
                    _defaultDocumentTools.Add(toolWindowAttribute.DisplayName, info);
                }
            }
        }