示例#1
0
        private void Setup_Panels()
        {
            if (IsNotSave())
            {
                return;
            }
            if (_panelMain == null)
            {
                // Lets try to get the main panel
                "No Main Panel assigned.".zOk();
                _formHost = UIDesigner_Service.IDesignerHost_FromComponent(this);
                var panels = UIDesigner_Tools.Host_Controls_All <Panel>(_formHost);
                foreach (Panel panel in panels)
                {
                    if (panel.Tag.ToString() == "MainPanel")
                    {
                        _panelMain = panel;
                    }
                }
                if (panels.Count == 0)
                {
                    Setup_PanelMain();
                }

                if (_panelMain == null)
                {
                    "Cannot change panels if Panel_Main is not assigned!".zOk();
                    return;
                }
            }
            UIDesigner_Generate.Form_PanelSetup(this, Panel_Setup, Panel_Main, out _panel1, out _panel2, out _panel3);
        }
示例#2
0
        // This method creates a Timer component using the
        // IDesignerHost.CreateComponent method. It also
        // creates an event handler for the Timer component's
        // tick event.
        private void CreateTimer()
        {
            if (_host != null)
            {
                IEventBindingService    eventBindingService     = UIDesigner_Service.IEventBindingService_FromHost(_host);
                DesignerActionUIService designerActionUIService = UIDesigner_Service.DesignerActionUIService_FromHost(_host);

                //if (this.relatedDesigner.createdTimer == null)
                {
                    // Create and configure the Timer object.
                    _createdTimer = _host.CreateComponent(typeof(Timer)) as Timer;
                    if (_createdTimer == null)
                    {
                        return;                        // ================================================
                    }
                    Timer t = _createdTimer;
                    t.Interval = 1000;
                    t.Enabled  = true;

                    EventDescriptorCollection eventColl = TypeDescriptor.GetEvents(t, new Attribute[0]);
                    if (eventColl != null)
                    {
                        var eventDescriptor = eventColl["Tick"] as EventDescriptor;
                        if (eventDescriptor != null)
                        {
                            PropertyDescriptor propertyDescriptor = eventBindingService.GetEventProperty(eventDescriptor);
                            propertyDescriptor.SetValue(t, "timer_Tick");
                        }
                    }

                    designerActionUIService.Refresh(_createdTimer);
                }
            }
        }
示例#3
0
        /// <summary>Generates the controls on the designer panels.</summary>
        /// <param name="form">The form</param>
        /// <param name="classObject">The class objectect</param>
        /// <param name="panel1">The panel1</param>
        /// <param name="panel2">The panel to setting. Default value = null.</param>
        /// <param name="panel3">The panel3 setting. Default value = null.</param>
        /// <param name="onValueChange">The on valueue change setting. Default value = null.</param>
        /// <returns>bool</returns>
        public bool Generate_Controls(Form form, IObjectModel classObject, Panel panel1, Panel panel2 = null, Panel panel3 = null, EventHandler <onInputControl_EventArgs> onValueChange = null)
        {
            var type = classObject.GetType();
            BlueprintData_TableAttribute attribute;

            LamedalCore_.Instance.Types.Class.ClassAttributes.Find_Class(type, out attribute, new BlueprintData_TableAttribute());

            stateForm state = form.zzState();

            state.onValueChange   = onValueChange;
            state.FormObjectModel = classObject;
            state.DoEventsFlag    = false;

            IDesignerHost host   = UIDesigner_Service.IDesignerHost_FromForm(form);
            int           height = Lamedal_WinForms.Instance.libUI.WinForms.FormGenerate.Generate_Controls(host, type, attribute, panel1, panel2, panel3, OnValueChangeEvent);

            form.Height = height;
            if (attribute != null)
            {
                if (attribute.Caption != "")
                {
                    form.Text = attribute.Caption;
                }
            }

            state.DoEventsFlag = true;
            return(true);
        }
 public FormClassDesigner_ActionList(IComponent component)
     : base(component)
 {
     // Cache a reference to DesignerActionUIService, so the DesigneractionList can be refreshed.
     this._Control = component as FormCreator_;
     this._designerActionUIService = UIDesigner_Service.DesignerActionUIService_FromActionList(this);
 }
示例#5
0
        private void button_Generate_Click(object sender, EventArgs e)
        {
            if (input_Panel1.Field_Value == "")
            {
                "You need to setup panel1 before you can generate code!".zOk();
                return;
            }
            try
            {
                // Select the first panel
                var panelName = input_Panel1.Field_Value;
                listBox_Components.zListBox_SearchItem(panelName); // This will select the panel

                Control controlPanel = UIDesigner_Tools.Host_Controls_SelectedFirst(_host);
                var     panel        = controlPanel as Panel;
                var     group        = controlPanel as GroupBox;
                var     form         = controlPanel as System.Windows.Forms.Form;
                if (panel == null && group == null && form == null)
                {
                    "Please select a parent control".zOk();
                }
                else
                {
                    var input = UIDesigner_Tools.Host_Controls_Add2Form <Input_Control>(_host, controlPanel);
                    if (input == null)
                    {
                        "Unable to create control!".zOk();
                        return;
                    }
                    input.Parent        = controlPanel;
                    input.Top           = 10;
                    input.Left          = 10;
                    input.Dock          = DockStyle.Top;
                    input.Text          = "It works!";
                    input.Field_Caption = "Field Caption:";
                    input.Field_Name    = "Field_Name";

                    // Add Event handler
                    // input.Event_OnValueChange
                    IEventBindingService      eventBindingService = UIDesigner_Service.IEventBindingService_FromHost(_host);
                    EventDescriptorCollection eventColl           = TypeDescriptor.GetEvents(input, new Attribute[0]);
                    if (eventColl != null)
                    {
                        var eventDescriptor = eventColl["Event_OnValueChange"] as EventDescriptor;
                        if (eventDescriptor != null)
                        {
                            PropertyDescriptor propertyDescriptor = eventBindingService.GetEventProperty(eventDescriptor);
                            propertyDescriptor.SetValue(input, "OnValueChangeEvent");
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                exception.Message.zOk();
            }
        }
        public void Setup(Component designer, stateAssemblyFilters AssemblyFilters)
        {
            _designer        = designer;
            _AssemblyFilters = AssemblyFilters;
            _host            = UIDesigner_Service.IDesignerHost_FromComponent(designer);
            if (_host != null)
            {
                // Set event
                UIDesigner_Tools.Host_Controls_SelectionChange(_host, OnselectionChanged);
                this.Closed -= OnFormClosed;
                this.Closed += OnFormClosed;

                this.TopMost = true;
                this.Show();
                500.zExecute_Async(Setup_EnumTypes);
                tabControl1.SelectedIndex = 1;
            }
        }
示例#7
0
        public void Setup(FormCreator_ designer)
        {
            _SetupFlag = true;
            _designer  = designer;

            // Form Size & Form Panels
            typeof(enForm_Size).zEnum_To_IList(comboBox_FormSize.Items);
            //IamWindows.libUI.WinForms.Controls.ComboBox.SearchItem(comboBox_FormSize, designer.FormSize.ToString());

            typeof(enForm_Panels).zEnum_To_IList(comboBox_FormPanels.Items);
            IamWindows.libUI.WinForms.Controls.ComboBox.SearchItem(comboBox_FormPanels, designer.Panel_Setup.ToString());

            // Panel setup
            input_Panel1.Field_Value = UIDesigner_Component.Component_AsStr(_designer.Panel_Main, true, true);

            listBox_Components.Items.Clear();
            _host = UIDesigner_Service.IDesignerHost_FromComponent(designer);
            if (_host != null)
            {
                // Set event
                UIDesigner_Tools.Host_Controls_SelectionChange(_host, OnselectionChanged);
                this.Closed -= OnFormClosed;
                this.Closed += OnFormClosed;

                // Find all controls on the form
                _components = UIDesigner_Tools.Host_Components_All(_host);
                _controls   = UIDesigner_Tools.Host_Controls_All(_host);
                UIDesigner_Component.ControlNames(_components).zTo_IList(listBox_Components.Items);

                // Populate the list of classes that can be generated
                Assembly      assembly = LamedalCore_.Instance.Types.Assembly.From_Object(designer);
                List <string> typeNameList;
                if (IamWindows.libUI.WinForms.FormGenerate.AssemblyTypes(assembly, out typeNameList, out _typeAttributeDictionary))
                {
                    typeNameList.zTo_IList(listBox_Classes.Items);
                    listBox_Classes.SelectedIndex = 0;
                }

                this.TopMost = true;
                this.Show();
            }

            _SetupFlag = false;
        }
示例#8
0
        private void AddCode()
        {
            //Add method "Form1_Load" on Form1
            //---------------------------------------------------------------------------
            var member = new CodeMemberMethod();

            member.Name = "Form1_Load";
            member.Parameters.Add(new CodeParameterDeclarationExpression("System.Object", "sender"));
            member.Parameters.Add(new CodeParameterDeclarationExpression("System.EventArgs", "e"));
            CodeSnippetExpression sn;

            sn = new CodeSnippetExpression("MessageBox.Show(\"Hello world\")");
            member.Statements.Add(sn);
            member.Attributes = MemberAttributes.Private;
            var typedecl = UIDesigner_Service.CodeTypeDeclaration_FromHost(_host);

            typedecl.Members.Add(member);
            //---------------------------------------------------------------------------
        }
示例#9
0
        // This method uses the IEventBindingService.ShowCode
        // method to start the Code Editor. It places the caret
        // in the timer_tick method created by the CreateTimer method.
        private void ShowEventHandlerCode()
        {
            if (_createdTimer == null)
            {
                return;                        // ================================================
            }
            Timer timer = _createdTimer;

            if (timer != null)
            {
                EventDescriptorCollection eventColl =
                    TypeDescriptor.GetEvents(timer, new Attribute[0]);
                if (eventColl != null)
                {
                    var eventDescriptor = eventColl["Tick"] as EventDescriptor;
                    if (eventDescriptor != null)
                    {
                        var eventBindingService = UIDesigner_Service.IEventBindingService_FromHost(_host);
                        eventBindingService.ShowCode(timer, eventDescriptor);
                    }
                }
            }
        }
        public void Setup(Component designer)
        {
            _designer = designer;
            listBox_Components.Items.Clear();
            _host = UIDesigner_Service.IDesignerHost_FromComponent(designer);
            if (_host != null)
            {
                UIDesigner_Tools.Host_Controls_SelectionChange(_host, OnselectionChanged);  // Set the events

                _components = UIDesigner_Tools.Host_Components_All(_host);
                // Load the controls
                foreach (Component component in _components)
                {
                    string name = UIDesigner_Component.Component_AsStr(component, true, true);
                    if (name != "")
                    {
                        listBox_Components.Items.Add(name);
                    }
                }

                this.TopMost = true;
                this.Show();
            }
        }
示例#11
0
 protected void Setup_MainForm()
 {
     _formHost = UIDesigner_Service.IDesignerHost_FromComponent(this);
     _formName = UIDesigner_Form.Form_Main(this);
     if (_formName == null)
     {
         return;                     // If we do not know what the form name is -> we cannot go past this point.
     }
     try
     {
         if (_formHost != null)
         {
             // Basic setup of the form
             _formControls = UIDesigner_Tools.Host_Controls_All(_formHost);
             Setup_();
         }
     }
     catch (Exception)
     {
         _Form_Startup = false;
         throw;
     }
     _Form_Startup = false;
 }
示例#12
0
        private void Setup_Go(bool showMsg = true)
        {
            if (_FormCreator_StartupFlag)
            {
                return;                             // Prevent actions during construction
            }
            if (Generator_Class.zIsNullOrEmpty())
            {
                "Error! No class was specified for generation.".zOk();
                return;
            }

            if (Panel_Main == null)
            {
                "Error! Cannot generate form if Panel_Main is not assigned!".zOk();
                return;
            }

            if (Panel_1 == null)
            {
                ("Error! Cannot generate controls if Panel_1 is unknown.".NL() + " (Set the 'Panel_Setup' property)").zOk();
                return;
            }

            // Final Check
            // =================================================================================
            var msg = "This will generate the class '{0}'. Continue...".zFormat(_generatorClass);

            if (msg.zDialog().MessageBox_YesNo() == false)
            {
                return;
            }
            // =================================================================================

            #region Back-end
            // ==================
            // Backend generation
            // ==================
            if (_host == null)
            {
                _host = UIDesigner_Service.IDesignerHost_FromComponent(this);
            }
            CodeTypeDeclaration codeBackend = UIDesigner_Service.CodeTypeDeclaration_FromHost(_host);
            if (codeBackend == null)
            {
                "Error! Can not generate backend because a CodeTypeDeclaration service was not available.".zOk();
                return;
            }

            CodeMemberMethod method1;
            if (UIDesigner_Code.Method_Find(codeBackend, out method1, "Model_Setup", true, MemberAttributes.Public) == false)
            {
                UIDesigner_Code.Method_AddParameter(method1, Generator_Class, "model");

                UIDesigner_Code.Method_AddCode(method1, "// Todo: Create the following fields in the form ");
                UIDesigner_Code.Method_AddCode(method1, "// private readonly UIWindows _lamedalWin = Lamedal_WinForms.Instance; // Set reference to Blueprint Windows lib");
                UIDesigner_Code.Method_AddCode(method1, "// private " + Generator_Class + " _model;");
                UIDesigner_Code.Method_AddCode(method1, "_model = model;");
                codeBackend.Members.Add(method1);
            }

            CodeMemberMethod method2;
            if (UIDesigner_Code.Method_Find(codeBackend, out method2, "Model_RefreshForm", true, MemberAttributes.Public) == false)
            {
                UIDesigner_Code.Method_AddCode(method2, "// Update the form from the object.");
                UIDesigner_Code.Method_AddCode(method2, "_lamedalWin.libUI.WinForms.FormGenerate.Form_FromObject(this, _model);");
                codeBackend.Members.Add(method2);
            }
            // private void Model_OnFormValueChangeEvent(object sender, evInput_Control_EventArgs e)
            CodeMemberMethod method3;
            if (UIDesigner_Code.Method_Find(codeBackend, out method3, "Model_OnFormValueChangeEvent") == false)
            {
                UIDesigner_Code.Method_AddParameter(method3, "System.Object", "sender");
                UIDesigner_Code.Method_AddParameter(method3, "evInput_Control_EventArgs", "e");

                codeBackend.Members.Add(method3);
            }
            // ReAdd the code as expression
            UIDesigner_Code.Method_AddCode(method3, "// When the value on the form is updted -> sync changes to the object.", true);
            UIDesigner_Code.Method_AddCode(method3, "// Wait 1 second then sync from the object back to the form. (This ensure that the object is the master of the data", true);
            UIDesigner_Code.Method_AddCode(method3, "_lamedalWin.libUI.WinForms.FormGenerate.Form_ToObject(e, _model)", true);
            UIDesigner_Code.Method_AddCode(method3, "1000.zExecute_Async(Model_RefreshForm, \"formRefresh\", true)", true);

            #endregion

            #region Front-end

            // ======================
            // Generate the front-end
            // ======================
            // Find the type to generate
            Tuple <Type, Attribute> typeAttribute;
            if (ClassTypeDef(this, out typeAttribute))
            {
                //UIDesigner_Generate.Form_PanelSetup(this, Panel_Setup, Panel_Main, out _panel1, out _panel2, out _panel3, showMsg);   // Reset the panels
                _lamedalWin.libUI.WinForms.FormGenerate.Generate_Controls(_host, typeAttribute.Item1, (BlueprintData_TableAttribute)typeAttribute.Item2, Panel_1, Panel_2, Panel_3, null);   // Generate the controls
            }
            else
            {
                "Error! No fields were marked with the BlueprintData_FieldAttribute".zOk();
            }

            #endregion

            "Finish generating form. Please remove the generator component.".zOk();
        }
示例#13
0
        //private ImageSetup_Form _frmImageResouce;

        public ImageSetup_ActionList(IComponent component) : base(component)
        {
            // Cache a reference to DesignerActionUIService, so the DesigneractionList can be refreshed.
            this._Control = component as ImageSetup;
            this._designerActionUIService = UIDesigner_Service.DesignerActionUIService_FromActionList(this);
        }
示例#14
0
        //private void OnValueChangeEvent(object sender, Input_Control_EventArgs e)
        //{
        //    if (_GenerateStartFlag) return;  // Do not pass this point when generating code

        //    IamWindows.libUI.WinForms.FormGenerate.Form_ToObject(e, _sample);
        //    1000.zExecute_Async(RefreshObj, "formRefresh", true);
        //}

        //private void RefreshObj()
        //{
        //    // Update the generated the form from the object.
        //    IamWindows.libUI.WinForms.FormGenerate.Form_FromObject(this, _sample);
        //}

        private void AddCode2()
        {
            CodeTypeDeclaration codeTypeDeclaration = UIDesigner_Service.CodeTypeDeclaration_FromHost(_host);


            // private bool _GenerateStartFlag = false;
            var field1 = new CodeMemberField("bool", "_GenerateStartFlag");

            field1.InitExpression = new CodePrimitiveExpression(false);
            field1.Attributes     = MemberAttributes.Private;
            codeTypeDeclaration.Members.Add(field1);

            //// private readonly Lamedal_WinForms IamWindows = Lamedal_WinForms.Instance; // Set reference to Blueprint Windows lib
            //var field2 = new CodeMemberField("LaMedalUI_Windows_", "IamWindows");
            //field2.InitExpression = new CodeSnippetExpression("LaMedalUI_Windows_.Instance; // Set reference to Blueprint Windows lib");
            //field2.Attributes = MemberAttributes.Private;
            //codeTypeDeclaration.Members.Add(field2);

            // Add OnValueChangeEvent()
            // ==============================
            var member1   = new CodeMemberMethod();
            var newMethod = true;
            var members   = codeTypeDeclaration.Members;

            foreach (var member in members)
            {
                var member01 = member as CodeMemberMethod;
                if (member01 == null)
                {
                    continue;
                }
                if (member01.Name == "OnValueChangeEvent")
                {
                    member1   = member01;
                    newMethod = false;
                    break;
                }
            }
            if (newMethod)
            {
                member1.Name = "OnValueChangeEvent";
                member1.Parameters.Add(new CodeParameterDeclarationExpression("System.Object", "sender"));
                member1.Parameters.Add(new CodeParameterDeclarationExpression("Input_Control_EventArgs", "e"));
                member1.Attributes = MemberAttributes.Private;
            }
            var code1 = new CodeSnippetExpression("if (_GenerateStartFlag) return;  // Do not pass this point when generating code");
            var code2 = new CodeSnippetExpression("IamWindows.libUI.WinForms.FormGenerate.Form_ToObject(e, _sample);");
            var code3 = new CodeSnippetExpression("1000.zExecute_Async(RefreshObj, \"formRefresh\", true);");

            member1.Statements.Add(code1);
            member1.Statements.Add(code2);
            member1.Statements.Add(code3);
            codeTypeDeclaration.Members.Add(member1);

            var member2 = new CodeMemberMethod();

            member2.Name = "RefreshObj";
            var code_1 = new CodeSnippetExpression("// Update the generated the form from the object.");
            var code_2 = new CodeSnippetExpression("IamWindows.libUI.WinForms.FormGenerate.Form_FromObject(this, _sample);");

            member2.Statements.Add(code_1);
            member2.Statements.Add(code_2);
            member2.Attributes = MemberAttributes.Private;
            codeTypeDeclaration.Members.Add(member2);
        }