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();
                }
            }
        }
Esempio n. 2
0
        public void SetUpFixture()
        {
            using (FormsDesignerViewContent viewContent = new FormsDesignerViewContent(null, new MockOpenedFile("Test.py"))) {
                viewContent.DesignerCodeFileContent = "class MainForm(Form):\r\n" +
                                                      " def __init__(self):\r\n" +
                                                      "  self.InitializeComponent()\r\n" +
                                                      "\r\n" +
                                                      " def InitializeComponent(self):\r\n" +
                                                      "  pass\r\n";

                document = viewContent.DesignerCodeFileDocument;

                ParseInformation parseInfo       = new ParseInformation();
                PythonParser     parser          = new PythonParser();
                ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.py", document.TextContent);
                parseInfo.SetCompilationUnit(compilationUnit);

                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");

                    MockTextEditorProperties textEditorProperties = new MockTextEditorProperties();
                    textEditorProperties.ConvertTabsToSpaces = true;
                    textEditorProperties.IndentationSize     = 1;

                    DerivedPythonDesignerGenerator generator = new DerivedPythonDesignerGenerator(textEditorProperties);
                    generator.ParseInfoToReturnFromParseFileMethod = parseInfo;
                    generator.Attach(viewContent);
                    DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                    using (serializationManager.CreateSession()) {
                        generator.MergeRootComponentChanges(host, serializationManager);
                    }
                }
            }
        }