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();
                }
            }
        }
        public void GenerateEventHandlerWithNullMethodBody()
        {
            DerivedPythonDesignerGenerator generator = new DerivedPythonDesignerGenerator();
            string eventHandler         = generator.CallCreateEventHandler("button2_click", null, String.Empty);
            string expectedEventHandler = "def button2_click(self, sender, e):\r\n" +
                                          "\tpass";

            Assert.AreEqual(expectedEventHandler, eventHandler);
        }
        public void GetMethodReplaceRegion()
        {
            MockMethod method     = new MockMethod();
            DomRegion  bodyRegion = new DomRegion(0, 4, 1, 4);

            method.BodyRegion = bodyRegion;
            DomRegion expectedRegion = new DomRegion(bodyRegion.BeginLine + 1, 1, bodyRegion.EndLine + 1, 1);
            DerivedPythonDesignerGenerator generator = new DerivedPythonDesignerGenerator();

            Assert.AreEqual(expectedRegion, PythonDesignerGenerator.GetBodyRegionInDocument(method));
        }
        public void SetUpFixture()
        {
            textEditorOptions = new MockTextEditorOptions();
            generator         = new DerivedPythonDesignerGenerator(textEditorOptions);
            mockViewContent   = new MockTextEditorViewContent();
            viewContent       = new DerivedFormDesignerViewContent(mockViewContent, new MockOpenedFile(fileName));
            generator.Attach(viewContent);
            viewContent.DesignerCodeFileContent = GetTextEditorCode();

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

            generator.ParseInfoToReturnFromParseFileMethod = parseInfo;

            AfterSetUpFixture();
        }
Esempio n. 5
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);
                    }
                }
            }
        }
Esempio n. 6
0
        public void SetUpFixture()
        {
            DerivedPythonDesignerGenerator generator       = new DerivedPythonDesignerGenerator();
            MockTextEditorViewContent      mockViewContent = new MockTextEditorViewContent();
            DerivedFormDesignerViewContent viewContent     = new DerivedFormDesignerViewContent(mockViewContent, new MockOpenedFile("Test.py"));

            viewContent.DesignerCodeFileContent = GetTextEditorCode();

            // Create parse info.
            PythonParser     parser    = new PythonParser();
            ICompilationUnit unit      = parser.Parse(new MockProjectContent(), @"C:\Projects\MyProject\test.py", GetTextEditorCode());
            ParseInformation parseInfo = new ParseInformation();

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

            // Attach view content to generator.
            generator.Attach(viewContent);

            // Get compatible methods for event.
            MockEventDescriptor eventDescriptor = new MockEventDescriptor("Click");

            compatibleMethods = generator.GetCompatibleMethods(eventDescriptor);
        }