Beispiel #1
0
        protected override void OnLoad(EventArgs args)
        {
            base.OnLoad(args);

            _DesignSurface         = new DesignSurface();
            _DesignSurface.Loaded += new LoadedEventHandler(OnDesignSurfaceLoaded);

            _ToolboxControl.AddToolboxItem(new ToolboxItem()
            {
                TypeName = NameConsts.Pointer, DisplayName = Properties.Resources.Tool_Pointer, Bitmap = new Bitmap(1, 1)
            });
            ToolMap.All(pair =>
            {
                _ToolboxControl.AddToolboxItem(new ToolboxItem(pair.Key)
                {
                    DisplayName = pair.Value
                });
                return(true);
            });

            DesignerHost = _DesignSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
            DesignerHost.AddService(typeof(IToolboxService), _ToolboxControl.ToolboxService);
            //DesignerHost.AddService( typeof( IPropertyValueUIService ), new GlyphService() );

            SelectionService = _DesignSurface.GetService(typeof(ISelectionService)) as ISelectionService;
            SelectionService.SelectionChanged += OnDesignerSurfaceView_SelectionChanged;

            // Initialise the DesignSurface class
            _DesignSurface.BeginLoad(typeof(RootDesignedComponent));
        }
Beispiel #2
0
        //
        public DiagramDesignerHolder()
        {
            InitializeComponent();
            btOK.BringToFront();
            btCancel.BringToFront();
            _undoEngine = new UndoEngine2();
            //
            dsf = new DesignSurface(typeof(DiagramViewer));
            Control control = dsf.View as Control;             //DesignerFrame

            splitContainer1.Panel2.Controls.Add(control);
            control.Dock    = DockStyle.Fill;
            control.Visible = true;
            splitContainer1.SplitterMoved += new SplitterEventHandler(splitContainer1_SplitterMoved);
            this.Resize += new EventHandler(designview_Resize);
            splitContainer1.SplitterWidth = 3;
            //
            IDesignerHost host = (IDesignerHost)dsf.GetService(typeof(IDesignerHost));

            root      = (DiagramViewer)host.RootComponent;
            root.Dock = DockStyle.Fill;
            root.AssignHolder(this);
            //
            host.AddService(typeof(PropertyGrid), propertyGrid1);
            host.AddService(typeof(INameCreationService), new NameCreation());
            //
            selectionService = (ISelectionService)dsf.GetService(typeof(ISelectionService));
            if (selectionService != null)
            {
                selectionService.SelectionChanged += new EventHandler(selectionService_SelectionChanged);
            }
            IComponentChangeService componentChangeService = (IComponentChangeService)dsf.GetService(typeof(IComponentChangeService));

            componentChangeService.ComponentAdded    += new ComponentEventHandler(componentChangeService_ComponentAdded);
            componentChangeService.ComponentRemoving += new ComponentEventHandler(componentChangeService_ComponentRemoving);
            componentChangeService.ComponentRemoved  += new ComponentEventHandler(componentChangeService_ComponentRemoved);
            componentChangeService.ComponentChanged  += new ComponentChangedEventHandler(componentChangeService_ComponentChanged);
            //
            root.ControlRemoved += new ControlEventHandler(root_ControlRemoved);
            //
            _msgFilter = new DesignMessageFilter(dsf);
            Application.AddMessageFilter(_msgFilter);
            //
            propertyGrid1.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid1_PropertyValueChanged);
            propertyGrid1.HelpVisible           = false;
            propertyGrid1.PropertySort          = PropertySort.Alphabetical;
            propertyGrid1.SelectedObject        = root;
            //
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add table layout panel.
                TableLayoutPanel tableLayoutPanel1 = (TableLayoutPanel)host.CreateComponent(typeof(TableLayoutPanel), "tableLayoutPanel1");
                tableLayoutPanel1.ColumnCount = 2;
                tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F));
                tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 60F));
                tableLayoutPanel1.Location = new Point(0, 0);
                tableLayoutPanel1.RowCount = 2;
                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F));
                tableLayoutPanel1.Size     = new Size(200, 100);
                tableLayoutPanel1.TabIndex = 0;

                form.Controls.Add(tableLayoutPanel1);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            MockTextEditorProperties textEditorProperties = new MockTextEditorProperties();

            generator       = new DerivedPythonDesignerGenerator();
            mockViewContent = new MockTextEditorViewContent();
            viewContent     = new FormsDesignerViewContent(mockViewContent, new MockOpenedFile("Test.py"));
            viewContent.DesignerCodeFileContent = GetTextEditorCode();
            generator.Attach(viewContent);
            viewContentAttached = generator.GetViewContent();

            ParseInformation parseInfo             = new ParseInformation();
            PythonParser     parser                = new PythonParser();
            ICompilationUnit parserCompilationUnit = parser.Parse(new DefaultProjectContent(), "Test.py", GetTextEditorCode());

            parseInfo.SetCompilationUnit(parserCompilationUnit);
            generator.ParseInfoToReturnFromParseFileMethod = parseInfo;

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(499, 309);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    generator.MergeRootComponentChanges(host, serializationManager);
                    generator.Detach();
                }
            }
        }
Beispiel #5
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add month calendar.
                MonthCalendar calendar = (MonthCalendar)host.CreateComponent(typeof(MonthCalendar), "monthCalendar1");
                calendar.TabIndex = 0;
                calendar.Location = new Point(0, 0);
                calendar.AddMonthlyBoldedDate(new DateTime(2009, 1, 2));
                calendar.AddMonthlyBoldedDate(new DateTime(0));

                form.Controls.Add(calendar);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Bootstrap method - loads a blank Form
        /// </summary>
        /// <returns></returns>
        protected override CodeCompileUnit Parse( )
        {
            CodeCompileUnit ccu = null;



            if (String.IsNullOrWhiteSpace(SourceCodeToPasrse))
            {
                DesignSurface ds = new DesignSurface();
                ds.BeginLoad(typeof(ABCControls.ABCView));
                IDesignerHost idh = (IDesignerHost)ds.GetService(typeof(IDesignerHost));
                idh.RootComponent.Site.Name = "Form1";

                ccu = new CodeGen().GetCodeCompileUnit(idh);
            }
            else
            {
                //    ccu=ConvertToCodeComlieUnit( SourceCodeToPasrse );
                ccu = DeSerializationCodeCompileUnit();
            }

            AssemblyName[] names = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
            for (int i = 0; i < names.Length; i++)
            {
                Assembly assembly = Assembly.Load(names[i]);
                ccu.ReferencedAssemblies.Add(assembly.Location);
            }

            codeCompileUnit = ccu;



            return(ccu);
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                Button button = (Button)host.CreateComponent(typeof(Button), "button1");
                button.Location = new Point(0, 0);
                button.Size     = new Size(10, 10);
                button.Text     = "button1";
                button.UseCompatibleTextRendering = false;

                button.FlatAppearance.BorderSize         = 2;
                button.FlatAppearance.BorderColor        = Color.Red;
                button.FlatAppearance.MouseOverBackColor = Color.Yellow;

                form.Controls.Add(button);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(284, 264);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                TextBox textBox = (TextBox)host.CreateComponent(typeof(TextBox), "textBox1");
                textBox.Size     = new Size(110, 20);
                textBox.TabIndex = 1;
                textBox.Location = new Point(10, 10);

                form.Controls.Add(textBox);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add combo box.
                ComboBox comboBox = (ComboBox)host.CreateComponent(typeof(ComboBox), "comboBox1");
                comboBox.TabIndex = 0;
                comboBox.Location = new Point(0, 0);
                comboBox.Size     = new System.Drawing.Size(121, 21);
                comboBox.Items.Add("aaa");
                comboBox.Items.Add("bbb");
                comboBox.Items.Add("ccc");

                form.Controls.Add(comboBox);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add timer. This checks that the components Container is only created once in the
                // generated code.
                Timer timer = (Timer)host.CreateComponent(typeof(Timer), "timer1");

                // Add menu strip.
                ContextMenuStrip menuStrip = (ContextMenuStrip)host.CreateComponent(typeof(ContextMenuStrip), "contextMenuStrip1");

                // Set the context menu strip OwnerItem to simulate leaving the context menu
                // open in the designer before generating the source code. We do not want the
                // OwnerItem to be serialized.
                menuStrip.OwnerItem   = new DerivedToolStripMenuItem();
                menuStrip.RightToLeft = RightToLeft.No;
                menuStripSize         = menuStrip.Size;

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            resourceWriter  = new MockResourceWriter();
            resourceService = new MockResourceService();
            resourceService.SetResourceWriter(resourceWriter);

            AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor();
            document        = textEditor.Document;
            textEditor.Text = GetTextEditorCode();

            RubyParser       parser          = new RubyParser();
            ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.rb", document.Text);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(499, 309);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyDesignerGenerator generator = new RubyDesignerGenerator(new MockTextEditorOptions());
                    generator.Merge(host, new AvalonEditDocumentAdapter(document, null), compilationUnit, serializationManager);
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Parses a source code and creates a new design surface.
        /// </summary>
        /// <param name="serviceContainer"></param>
        /// <param name="surfaceManager"></param>
        /// <param name="file">The source file to deserialize.</param>
        /// <returns></returns>
        public DesignSurface Deserialize(DesignSurfaceManager surfaceManager, IServiceContainer serviceContainer, OpenedFile file)
        {
            DesignSurface surface      = surfaceManager.CreateDesignSurface(serviceContainer);
            IDesignerHost designerHost = surface.GetService(typeof(IDesignerHost)) as IDesignerHost;

            Type componentType = CompileTypeFromFile(file);

            // load base type.
            surface.BeginLoad(componentType.BaseType);

            // get instance to copy components and properties from.
            Control instance = Activator.CreateInstance(componentType) as Control;

            // add components
            var components = CreateComponents(componentType, instance, designerHost);

            InitializeComponents(components, designerHost);

            Control rootControl = designerHost.RootComponent as Control;

            Control parent = rootControl.Parent;
            ISite   site   = rootControl.Site;

            // copy instance properties to root control.
            CopyProperties(instance, designerHost.RootComponent);

            rootControl.AllowDrop = true;
            rootControl.Parent    = parent;
            rootControl.Visible   = true;
            rootControl.Site      = site;
            designerHost.RootComponent.Site.Name = instance.Name;
            return(surface);
        }
Beispiel #13
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(284, 264);

                PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           descriptor  = descriptors.Find("MinimumSize", false);
                descriptor.SetValue(form, new Size(100, 200));
                descriptor = descriptors.Find("AutoScrollMinSize", false);
                descriptor.SetValue(form, new Size(10, 20));
                descriptor = descriptors.Find("AutoScrollMargin", false);
                descriptor.SetValue(form, new Size(11, 22));
                descriptor = descriptors.Find("AutoScroll", false);
                descriptor.SetValue(form, false);

                PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            resourceWriter   = new MockResourceWriter();
            componentCreator = new MockComponentCreator();
            componentCreator.SetResourceWriter(resourceWriter);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                host.AddService(typeof(IResourceService), componentCreator);

                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add ImageList.
                icon = new Icon(typeof(GenerateFormResourceTestFixture), "App.ico");
                ImageList imageList = (ImageList)host.CreateComponent(typeof(ImageList), "imageList1");
                imageList.Images.Add("App.ico", icon);
                imageList.Images.Add("", icon);
                imageList.Images.Add("", icon);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, "RootNamespace", 1);
                }
            }
        }
        public void SetUpFixture()
        {
            resourceWriter   = new MockResourceWriter();
            componentCreator = new MockComponentCreator();
            componentCreator.SetResourceWriter(resourceWriter);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                host.AddService(typeof(IResourceService), componentCreator);

                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Set bitmap as form background image.
                bitmap = new Bitmap(10, 10);
                form.BackgroundImage = bitmap;

                icon      = new Icon(typeof(GenerateFormResourceTestFixture), "App.ico");
                form.Icon = icon;

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, "RootNamespace", 1);
                }
            }
        }
Beispiel #16
0
        public override void Flush()
        {
            PerformFlushWorker();
            IDesignerHost idh = (IDesignerHost)ds.GetService(typeof(IDesignerHost));

            codeCompileUnit = cg.GetCodeCompileUnit(idh);
        }
Beispiel #17
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(284, 264);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                Button button = (Button)host.CreateComponent(typeof(Button), "button1");
                button.Location = new Point(0, 0);
                button.Size     = new Size(10, 10);
                button.Text     = "button1";
                button.TabIndex = 0;
                button.UseCompatibleTextRendering = false;
                form.Controls.Add(button);

                RadioButton radioButton = (RadioButton)host.CreateComponent(typeof(RadioButton), "radioButton1");
                radioButton.Location = new Point(20, 0);
                radioButton.Size     = new Size(10, 10);
                radioButton.Text     = "radioButton1";
                radioButton.TabIndex = 1;
                radioButton.UseCompatibleTextRendering = false;
                form.Controls.Add(radioButton);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, 1);
                }
            }
        }
Beispiel #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="designer"></param>
        /// <param name="rootComponentType">it can be null. if not null then it must be a type derived from Diagram</param>
        public ItemDesignerHost(IXDesignerHost designer, Type rootComponentType)
        {
            InitializeComponent();
            _undoEngine = new UndoEngine2();
            if (rootComponentType == null)
            {
                dsf = new DesignSurface(typeof(Diagram));
            }
            else
            {
                dsf = new DesignSurface(rootComponentType);
            }
            Control control = dsf.View as Control;

            this.Controls.Add(control);
            control.Dock    = DockStyle.Fill;
            control.Visible = true;
            //
            IDesignerHost host = (IDesignerHost)dsf.GetService(typeof(IDesignerHost));

            root      = (Diagram)host.RootComponent;
            root.Dock = DockStyle.Fill;
            //
            DesignMessageFilter filter = new DesignMessageFilter(dsf);

            Application.AddMessageFilter(filter);
        }
Beispiel #19
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                Button button = (Button)host.CreateComponent(typeof(Button), "button1");
                button.Location = new Point(0, 0);
                button.Size     = new Size(10, 10);
                button.Text     = "button1";
                button.UseCompatibleTextRendering = false;
                form.Controls.Add(button);

                PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           acceptButtonPropertyDescriptor = descriptors.Find("AcceptButton", false);
                acceptButtonPropertyDescriptor.SetValue(form, button);

                PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    IScriptingCodeDomSerializer serializer = CreateSerializer();
                    generatedCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager);
                }
            }
        }
Beispiel #20
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                host.AddService(typeof(IEventBindingService), eventBindingService);

                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Simulate giving a name to the Load event handler in the property grid.
                EventDescriptorCollection events            = TypeDescriptor.GetEvents(form);
                EventDescriptor           loadEvent         = events.Find("Load", false);
                PropertyDescriptor        loadEventProperty = eventBindingService.GetEventProperty(loadEvent);
                loadEventProperty.SetValue(form, "MainFormLoad");

                // Add a second event handler method.
                EventDescriptor    closedEvent         = events.Find("FormClosed", false);
                PropertyDescriptor closedEventProperty = eventBindingService.GetEventProperty(closedEvent);
                closedEventProperty.SetValue(form, "MainFormClosed");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                DataGridView dataGridView = (DataGridView)host.CreateComponent(typeof(DataGridView), "dataGridView1");
                dataGridView.Location = new Point(0, 0);
                dataGridView.Size     = new Size(100, 100);
                form.Controls.Add(dataGridView);

                DataSet dataSet = (DataSet)host.CreateComponent(typeof(DataSet), "dataSet1");
                dataGridView.DataSource = dataSet;

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
        /// <summary>
        /// Bootstrap method - loads a blank Form
        /// </summary>
        /// <returns></returns>
        protected override CodeCompileUnit Parse()
        {
            CodeCompileUnit ccu = null;

            DesignSurface ds = new DesignSurface();

            ds.BeginLoad(typeof(Form));



            IDesignerHost idh = (IDesignerHost)ds.GetService(typeof(IDesignerHost));


            idh.RootComponent.Site.Name = "Form1";



            cg  = new CodeGen();
            ccu = cg.GetCodeCompileUnit(idh);

            AssemblyName[] names = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
            for (int i = 0; i < names.Length; i++)
            {
                Assembly assembly = Assembly.Load(names[i]);
                ccu.ReferencedAssemblies.Add(assembly.Location);
            }

            codeCompileUnit = ccu;
            return(ccu);
        }
Beispiel #23
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add menu strip.
                MenuStrip menuStrip = (MenuStrip)host.CreateComponent(typeof(MenuStrip), "menuStrip1");
                menuStrip.Text     = "menuStrip1";
                menuStrip.TabIndex = 0;
                menuStrip.Location = new Point(0, 0);
                form.Controls.Add(menuStrip);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
Beispiel #24
0
        public void SetUpFixture()
        {
            AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor();
            document        = textEditor.Document;
            textEditor.Text = GetTextEditorCode();

            RubyParser       parser          = new RubyParser();
            ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.py", document.Text);

            using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) {
                IDesignerHost host        = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                UserControl   userControl = (UserControl)host.RootComponent;
                userControl.ClientSize = new Size(489, 389);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(userControl);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(userControl, "userControl1");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    AvalonEditDocumentAdapter docAdapter = new AvalonEditDocumentAdapter(document, null);
                    RubyDesignerGenerator     generator  = new RubyDesignerGenerator(new MockTextEditorOptions());
                    generator.Merge(host, docAdapter, compilationUnit, serializationManager);
                }
            }
        }
Beispiel #25
0
        public DesignForm(Form originalForm, System.Collections.ObjectModel.Collection <string> propertiesToDesign)
        {
            // Copy parameters to fields
            _originalForm       = originalForm;
            _propertiesToDesign = propertiesToDesign;

            // Create hashtables
            _reparentedControls    = new Hashtable();
            _customTypeDescriptors = new Hashtable();

            // Create the DesignSurface and get the View from it;
            _surface = new DesignSurface(typeof(Form));

            // Setup UI, note, this can't be called until _surface is non-null
            SetupUI();

            // Get the IDesignerHost for the surface
            _host = _surface.GetService(typeof(IDesignerHost)) as IDesignerHost;

            // Get the ISelectionService and hook the SelectionChanged event
            _selection = _surface.GetService(typeof(ISelectionService)) as ISelectionService;

            if (_selection != null)
            {
                _selection.SelectionChanged += new EventHandler(SelectionChanged);
            }

            // Get the rootForm from the IDesignerHost
            Form rootForm = _host.RootComponent as Form;

            if (rootForm != null)
            {
                //  Clone the Form's properties
                CloneControlProperties(_originalForm, rootForm);

                // Now that a customTypeDescriptor is around for the Form, use it
                SampleCustomTypeDescriptor formDesc = _customTypeDescriptors[rootForm] as SampleCustomTypeDescriptor;
                if (formDesc != null)
                {
                    _grid.SelectedObject = formDesc;
                }

                // Clone the controls on the Form
                CloneControlsRecursive(_originalForm.Controls, rootForm);
            }
        }
        public void ExtenderProviderService_AddExtenderProvider_NullProvider_ThrowsArgumentNullException()
        {
            var    surface = new DesignSurface();
            object service = surface.GetService(typeof(IExtenderListService));
            IExtenderProviderService providerService = Assert.IsAssignableFrom <IExtenderProviderService>(service);

            Assert.Throws <ArgumentNullException>("provider", () => providerService.AddExtenderProvider(null));
        }
        public void ExtenderProviderService_GetExtenderProviders_Invoke_ReturnsEmpty()
        {
            var    surface = new DesignSurface();
            object service = surface.GetService(typeof(IExtenderListService));
            IExtenderListService listService = Assert.IsAssignableFrom <IExtenderListService>(service);

            Assert.Empty(listService.GetExtenderProviders());
        }
        private void SetupDesigner()
        {
            try
            {
                var snapshot = _language.CreateSourceSnapshot(AssociatedFile.GetContentsAsString()) as NetSourceSnapshot;
                _includeBaseType = !string.IsNullOrEmpty(snapshot.Types[0].ValueType);
                _namespace       = snapshot.Namespaces.Length == 0 ? string.Empty : snapshot.Namespaces[0].Name;

                _serviceContainer.AddService(typeof(INameCreationService), new NameCreationService());
                _surface = _codeReader.Deserialize(_surfaceManager, _serviceContainer, AssociatedFile);

                _viewControl      = _surface.View as Control;
                _viewControl.Dock = DockStyle.Fill;
                this.Control      = _viewControl;

                _designerHost = _surface.GetService <IDesignerHost>();

                var selectionService = _surface.GetService <ISelectionService>();
                selectionService.SelectionChanged += selectionService_SelectionChanged;

                var changeService = _designerHost.GetService <IComponentChangeService>();
                changeService.OnComponentChanging(_designerHost.RootComponent, TypeDescriptor.GetProperties(_designerHost.RootComponent)["Controls"]);
                changeService.ComponentChanging += changeService_ComponentChanging;
                changeService.ComponentAdded    += changeService_ComponentsChanged;
                changeService.ComponentRemoved  += changeService_ComponentsChanged;

                _serviceContainer.AddService(typeof(IMenuCommandService), new Services.MenuCommandService(_extensionHost, _designerHost));
                _serviceContainer.AddService(typeof(IEventBindingService), new Services.EventBindingService(_designerHost));
                _toolboxService = new Services.FormsToolBoxService((ParentExtension as FormsDesignerExtension).ToolBoxBuilder);
                _toolboxService.SelectedItemChanged += toolBoxService_SelectedItemChanged;
                _toolboxService.SelectedItemUsed    += toolBoxService_SelectedItemUsed;
                _serviceContainer.AddService(typeof(IToolboxService), _toolboxService);
            }
            catch (BuildException ex)
            {
                _errorControl.SetBuildErrors(ex.Result.Errors);
                this.Control = _errorControl;
            }
            catch (Exception ex)
            {
                _errorControl.SetException(ex);
                this.Control = _errorControl;
            }
        }
Beispiel #29
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add list view.
                ListView listView = (ListView)host.CreateComponent(typeof(ListView), "listView1");
                listView.TabIndex   = 0;
                listView.Location   = new Point(0, 0);
                listView.ClientSize = new Size(200, 100);
                descriptors         = TypeDescriptor.GetProperties(listView);
                PropertyDescriptor descriptor = descriptors.Find("UseCompatibleStateImageBehavior", false);
                descriptor.SetValue(listView, true);
                descriptor = descriptors.Find("View", false);
                descriptor.SetValue(listView, View.Details);
                form.Controls.Add(listView);

                // Add ImageList.
                Icon      icon      = new Icon(typeof(GenerateFormResourceTestFixture), "App.ico");
                ImageList imageList = (ImageList)host.CreateComponent(typeof(ImageList), "imageList1");
                imageList.Images.Add("App.ico", icon);
                imageList.Images.Add("b.ico", icon);
                imageList.Images.Add("c.ico", icon);

                DesignerSerializationManager  designerSerializationManager = new DesignerSerializationManager(host);
                IDesignerSerializationManager serializationManager         = (IDesignerSerializationManager)designerSerializationManager;
                using (designerSerializationManager.CreateSession()) {
                    // Add list view items.
                    ListViewItem item = (ListViewItem)serializationManager.CreateInstance(typeof(ListViewItem), new object[] { "aaa" }, "listViewItem1", false);
                    item.ImageIndex = 1;
                    listView.Items.Add(item);

                    ListViewItem item2 = (ListViewItem)serializationManager.CreateInstance(typeof(ListViewItem), new object[] { "bbb" }, "listViewItem2", false);
                    item2.ImageKey = "App.ico";
                    listView.Items.Add(item2);

                    ListViewItem item3 = (ListViewItem)serializationManager.CreateInstance(typeof(ListViewItem), new object[0], "listViewItem3", false);
                    item3.ImageIndex = 2;
                    listView.Items.Add(item3);

                    ListViewItem item4 = (ListViewItem)serializationManager.CreateInstance(typeof(ListViewItem), new object[0], "listViewItem4", false);
                    item4.ImageKey = "b.ico";
                    listView.Items.Add(item4);

                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager);
                }
            }
        }
Beispiel #30
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add list view.
                ListView listView = (ListView)host.CreateComponent(typeof(ListView), "listView1");
                listView.TabIndex   = 0;
                listView.Location   = new Point(0, 0);
                listView.ClientSize = new Size(200, 100);
                descriptors         = TypeDescriptor.GetProperties(listView);
                PropertyDescriptor descriptor = descriptors.Find("UseCompatibleStateImageBehavior", false);
                descriptor.SetValue(listView, true);
                descriptor = descriptors.Find("View", false);
                descriptor.SetValue(listView, View.Details);
                form.Controls.Add(listView);

                // Add column headers.
                columnHeader1 = (ColumnHeader)host.CreateComponent(typeof(ColumnHeader), "columnHeader1");
                descriptors   = TypeDescriptor.GetProperties(columnHeader1);
                descriptor    = descriptors.Find("Text", false);
                descriptor.SetValue(columnHeader1, "columnHeader1");
                listView.Columns.Add(columnHeader1);

                columnHeader2 = (ColumnHeader)host.CreateComponent(typeof(ColumnHeader), "columnHeader2");
                descriptors   = TypeDescriptor.GetProperties(columnHeader2);
                descriptor    = descriptors.Find("Text", false);
                descriptor.SetValue(columnHeader2, "columnHeader2");
                listView.Columns.Add(columnHeader2);

                // Add list view items.
                DesignerSerializationManager  designerSerializationManager = new DesignerSerializationManager(host);
                IDesignerSerializationManager serializationManager         = (IDesignerSerializationManager)designerSerializationManager;
                using (designerSerializationManager.CreateSession()) {
                    ListViewItem item = (ListViewItem)serializationManager.CreateInstance(typeof(ListViewItem), new object[] { "aaa" }, "listViewItem1", false);
                    item.ToolTipText = "tooltip";
                    listView.Items.Add(item);

                    item = (ListViewItem)serializationManager.CreateInstance(typeof(ListViewItem), new object[] { "bbb" }, "listViewItem2", false);
                    listView.Items.Add(item);

                    item = (ListViewItem)serializationManager.CreateInstance(typeof(ListViewItem), new object[0], "listViewItem3", false);
                    listView.Items.Add(item);

                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, 1);
                }
            }
        }
		private void InitializeRunner ()
		{
			StartGuiThread ();
			RunMWFThread ();
            while (_mwfContainer == null) {}
			while (!_mwfContainer.IsHandleCreated) { } // wait for the mwf handle


			// Hopefully by the time LoadGui is done the MWF Application.Run
			// will be done with whatever it's doing, because else strange things
			// might happen.
			Gtk.Application.Invoke (delegate { 
				InitializeGTK ();
			});
            while (_gtkContainer == null) {}
			while (_gtkContainer.Handle == IntPtr.Zero) { } // wait for the gtk handle

			bool parented = false;
			Gtk.Application.Invoke ( delegate { 
				Gdk.Window window = Gdk.Window.ForeignNew ((uint) _mwfContainer.Handle);
				window.Reparent (_gtkContainer.GdkWindow, 0, 0);
				parented = true;
			});
			while (!parented) { }

			EventHandler loadSurfaceDelegate = delegate {
				DesignSurface surface = new DesignSurface ();
				((IServiceContainer)surface.GetService (typeof (IServiceContainer))).AddService (typeof (ITypeResolutionService),
																								 new TypeResolutionService ());
				surface.BeginLoad (new MDDesignerLoader (_designerFile));
				if (surface.IsLoaded) {
					_mwfContainer.Controls.Add ((Control)surface.View);
					_mwfContainer.Refresh ();
				}
			};
			_mwfContainer.Invoke (loadSurfaceDelegate);

			_gtkContainer.SizeAllocated += delegate (object o, SizeAllocatedArgs args) {
				EventHandler resizeDelegate = delegate {
					_mwfContainer.Width = args.Allocation.Width;
					_mwfContainer.Height = args.Allocation.Height;
				};
				_mwfContainer.Invoke (resizeDelegate);
			};	

			EventHandler resizeNow = delegate {
				_mwfContainer.Width = _gtkContainer.Allocation.Width;
				_mwfContainer.Height = _gtkContainer.Allocation.Height;
			};
			_mwfContainer.Invoke (resizeNow);
		}
		private void OnDesignSurfaceCreated (DesignSurface surface)
		{
			if (DesignSurfaceCreated != null)
				DesignSurfaceCreated (this, new DesignSurfaceEventArgs (surface));
			
			// monitor disposing
			surface.Disposed += new EventHandler (OnDesignSurfaceDisposed);
			
			DesignerEventService eventService = GetService (typeof (IDesignerEventService)) as DesignerEventService;
			if (eventService != null)
				eventService.RaiseDesignerCreated (surface.GetService (typeof (IDesignerHost)) as IDesignerHost);
		}