public override void Initialize(IComponent component) { base.Initialize(component); this.inheritanceService = new InheritanceService(); ISite provider = component.Site; IContainer container = null; IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); IExtenderProviderService ex = (IExtenderProviderService)this.GetService(typeof(IExtenderProviderService)); if (ex != null) { this.designerExtenders = new DesignerExtenders(ex); } if (host != null) { this.eventHandlerService = new EventHandlerService(null); this.selectionUIService = new SelectionUIService(host); host.AddService(typeof(IInheritanceService), this.inheritanceService); host.AddService(typeof(IEventHandlerService), this.eventHandlerService); host.AddService(typeof(ISelectionUIService), this.selectionUIService); this.compositionUI = new CompositionUI(this, provider); host.AddService(typeof(ComponentTray), this.compositionUI); IComponentChangeService service2 = (IComponentChangeService)this.GetService(typeof(IComponentChangeService)); if (service2 != null) { service2.ComponentAdded += new ComponentEventHandler(this.OnComponentAdded); service2.ComponentRemoved += new ComponentEventHandler(this.OnComponentRemoved); } ISelectionService service3 = (ISelectionService)this.GetService(typeof(ISelectionService)); if (service3 != null) { service3.SetSelectedComponents(new object[] { component }, SelectionTypes.Auto); } } if (provider != null) { this.commandSet = new CompositionCommandSet(this.compositionUI, provider); container = provider.Container; } this.pbrsFwd = new PbrsForward(this.compositionUI, provider); this.inheritanceService.AddInheritedComponents(component, container); IServiceContainer service = (IServiceContainer)this.GetService(typeof(IServiceContainer)); if (service != null) { this.delegateFilterService = (ITypeDescriptorFilterService)this.GetService(typeof(ITypeDescriptorFilterService)); if (this.delegateFilterService != null) { service.RemoveService(typeof(ITypeDescriptorFilterService)); } service.AddService(typeof(ITypeDescriptorFilterService), this); } }
public void SetUpFixture() { resourceWriter = new MockResourceWriter(); componentCreator = new MockComponentCreator(); componentCreator.SetResourceWriter(resourceWriter); resourceWriter2 = new MockResourceWriter(); componentCreator2 = new MockComponentCreator(); componentCreator2.SetResourceWriter(resourceWriter2); 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 picture box PictureBox pictureBox = (PictureBox)host.CreateComponent(typeof(PictureBox), "pictureBox1"); pictureBox.Location = new Point(0, 0); bitmap = new Bitmap(10, 10); pictureBox.Image = bitmap; pictureBox.Size = new Size(100, 120); pictureBox.TabIndex = 0; form.Controls.Add(pictureBox); // Add bitmap to form. form.BackgroundImage = new Bitmap(10, 10); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" "); generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1); } // Check that calling the GenerateInitializeComponentMethodBody also generates a resource file. host.RemoveService(typeof(IResourceService)); host.AddService(typeof(IResourceService), componentCreator2); serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" "); serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1); } } }
// 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); 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); } } }
// Loads a ButtonDesignerFilterService ITypeDescriptorFilterService // to add ColorCycleButtonDesigner designers to each button. private void LoadService() { // If no custom ITypeDescriptorFilterService is loaded, // loads it now. if (!serviceloaded) { // Stores the current ITypeDescriptorFilterService // to restore later. ITypeDescriptorFilterService tdfs = (ITypeDescriptorFilterService)this.Component.Site.GetService(typeof(ITypeDescriptorFilterService)); if (tdfs != null) { oldservice = tdfs; } // Retrieves an IDesignerHost interface to use to // remove and add services. IDesignerHost dh = (IDesignerHost)this.Component.Site.GetService(typeof(IDesignerHost)); if (dh == null) { throw new Exception("Could not obtain IDesignerHost interface."); } // Removes standard ITypeDescriptorFilterService. dh.RemoveService(typeof(ITypeDescriptorFilterService)); // Adds new custom ITypeDescriptorFilterService. dh.AddService(typeof(ITypeDescriptorFilterService), new ButtonDesignerFilterService()); serviceloaded = true; } }
private void SetupServices() { IDesignerHost designerHost = base.GetService(typeof(IDesignerHost)) as IDesignerHost; designerHost.AddService(typeof(INameCreationService), new DetailsTemplatesNameCreationService()); this.detailsTemplatesMenuService = new DetailsTemplatesMenuService(this); this.detailsTemplatesMenuService.Enabled = false; designerHost.AddService(typeof(IMenuCommandService), this.detailsTemplatesMenuService); designerHost.AddService(typeof(IDesignerSerializationService), new DetailsTemplatesSerializationService(this)); designerHost.AddService(typeof(ComponentSerializationService), new CodeDomComponentSerializationService(this)); UndoEngine undoEngine = new DetailsTemplateUndoEngine(this); undoEngine.Enabled = false; designerHost.AddService(typeof(UndoEngine), undoEngine); Application.AddMessageFilter(this); }
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); } } }
/// <summary> /// 初始化具有HostDesign类的对象,加载当前所选控件变化时的事件服务和消息处理。 /// 得到的服务:属性控件、上下文菜单、状态栏、标签控件(TabControl)、菜单栏、 /// 添加的服务:撤消/重复 /// </summary> internal void Initialize() { host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (host == null) { return; } try { selectionService = (ISelectionService)(this.GetService(typeof(ISelectionService))); selectionService.SelectionChanged += new EventHandler(selectionService_SelectionChanged); if (host.RootComponent != null) { ((Control)host.RootComponent).Resize += new EventHandler(CassView_Resize); } cassPropertyGrid = (FilteredPropertyGrid)(this.GetService(typeof(FilteredPropertyGrid))); operateMenu = (ContextMenuStrip)(this.GetService(typeof(ContextMenuStrip))); designMousePosition = (ToolStripStatusLabel)(this.GetService(typeof(ToolStripStatusLabel))); editToolMenuItem = (ToolStripMenuItem)this.GetService(typeof(ToolStripMenuItem)); //添加撤消/重复操作服务 IServiceContainer serviceContainer = host.GetService(typeof(ServiceContainer)) as IServiceContainer; undoEngine = new UndoEngineImplication(serviceContainer); undoEngine.Enabled = false; //关闭撤消和重复功能 host.AddService(typeof(UndoEngineImplication), undoEngine); } catch (Exception ex) { } }
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); } } }
protected bool IsItemContainerSupported(ToolboxItemContainer container, IDesignerHost host) { if (container == null) { throw new ArgumentNullException("container"); } if (host == null) { throw new ArgumentNullException("host"); } ICollection creatorCollection = this.GetCreatorCollection(host); this._lastState = host.GetService(typeof(DesignerToolboxInfo)) as DesignerToolboxInfo; if (this._lastState == null) { this._lastState = new DesignerToolboxInfo(this, host); host.AddService(typeof(DesignerToolboxInfo), this._lastState); } switch (GetFilterSupport(container.GetFilter(creatorCollection), this._lastState.Filter)) { case FilterSupport.NotSupported: return(false); case FilterSupport.Supported: return(true); case FilterSupport.Custom: if (this._lastState.ToolboxUser == null) { break; } return(this._lastState.ToolboxUser.GetToolSupported(container.GetToolboxItem(creatorCollection))); } return(false); }
public static void Initialize(IDesignerHost service, LayoutPanelDesigner layoutPanelDesigner) { if (service.GetService <MoreDesignerServices>() == null) { service.AddService(typeof(MoreDesignerServices), new MoreDesignerServices()); service.AddService(typeof(IDebugOutputPane), (container, type) => new DebugOutputPane(container)); service.SubstituteService <ITypeDescriptorFilterService>((container, originalService) => new ExtendedTypeDescriptorFilterService(originalService)); } var compositionContainer = new CompositionContainer(); compositionContainer.ComposeExportedValue(service.GetService <IDesignerHost>()); compositionContainer.ComposeExportedValue(service.GetService <BehaviorService>()); compositionContainer.ComposeExportedValue(service.GetService <ISelectionService>()); compositionContainer.ComposeExportedValue(service.GetService <IComponentChangeService>()); compositionContainer.ComposeExportedValue(service.GetService <IDebugOutputPane>()); compositionContainer.SatisfyImportsOnce(layoutPanelDesigner); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if ((service == null) || (context.Instance == null)) { return(value); } IDesignerHost host = (IDesignerHost)provider.GetService(typeof(IDesignerHost)); if (host == null) { return(value); } //if (this.dataGridViewColumnCollectionDialog == null) //{ // this.dataGridViewColumnCollectionDialog = new DataGridViewColumnCollectionDialog(((DataGridView)context.Instance).Site); //} if (this.dataGridViewColumnCollectionDialog == null) { Type type = Type.GetType("System.Windows.Forms.Design.DataGridViewColumnCollectionDialog"); this.dataGridViewColumnCollectionDialog = Activator.CreateInstance( type, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { provider }, CultureInfo.CurrentCulture) as Form; } //this.dataGridViewColumnCollectionDialog.SetLiveDataGridView((DataGridView)context.Instance); MethodInfo methodInfo = this.dataGridViewColumnCollectionDialog.GetType().GetMethod("SetLiveDataGridView", BindingFlags.NonPublic | BindingFlags.Instance); methodInfo.Invoke(this.dataGridViewColumnCollectionDialog, new object[] { context.Instance }); //using (DesignerTransaction transaction = host.CreateTransaction(System.Design.SR.GetString("DataGridViewColumnCollectionTransaction"))) using (DesignerTransaction transaction = host.CreateTransaction()) { host.RemoveService(typeof(ITypeDiscoveryService)); host.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService()); ITypeDiscoveryService service2 = (ITypeDiscoveryService)host.GetService(typeof(ITypeDiscoveryService)); if (service.ShowDialog(this.dataGridViewColumnCollectionDialog) == DialogResult.OK) { transaction.Commit(); return(value); } transaction.Cancel(); } } return(value); }
internal DesignerActionUIService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; if (serviceProvider != null) { _serviceProvider = serviceProvider; IDesignerHost host = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost)); host.AddService(typeof(DesignerActionUIService), this); _designerActionService = serviceProvider.GetService(typeof(DesignerActionService)) as DesignerActionService; Debug.Assert(_designerActionService != null, "we should have created and registered the DAService first"); } }
// Removes the custom service and reloads any stored, // preexisting service. private void RemoveService() { IDesignerHost dh = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (dh == null) { throw new Exception("Could not obtain IDesignerHost interface."); } dh.RemoveService(typeof(ITypeDescriptorFilterService)); if (oldservice != null) { dh.AddService(typeof(ITypeDescriptorFilterService), oldservice); } serviceloaded = false; }
/// <summary> /// The constructor for this class which takes the serviceprovider used to get the selectionservice. This ToolStripInSituService is ToolStrip specific. /// </summary> public ToolStripInSituService(IServiceProvider provider) { _sp = provider; _designerHost = (IDesignerHost)provider.GetService(typeof(IDesignerHost)); Debug.Assert(_designerHost != null, "ToolStripKeyboardHandlingService relies on the selection service, which is unavailable."); if (_designerHost != null) { _designerHost.AddService(typeof(ISupportInSituService), this); } _componentChangeSvc = (IComponentChangeService)_designerHost.GetService(typeof(IComponentChangeService)); Debug.Assert(_componentChangeSvc != null, "ToolStripKeyboardHandlingService relies on the componentChange service, which is unavailable."); if (_componentChangeSvc != null) { _componentChangeSvc.ComponentRemoved += new ComponentEventHandler(OnComponentRemoved); } }
public override void Initialize(System.ComponentModel.IComponent component) { base.Initialize(component); IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); if (host == null) { return; } IInheritanceService inheritanceService = (IInheritanceService)GetService(typeof(IInheritanceService)); m_inheritanceService = new InlineInheritanceService(this, inheritanceService); host.RemoveService(typeof(IInheritanceService)); host.AddService(typeof(IInheritanceService), m_inheritanceService); }
private void DesignMdiController_DesignPanelLoaded(object sender, DevExpress.XtraReports.UserDesigner.DesignerLoadedEventArgs e) { XRDesignPanel panel = (XRDesignPanel)sender; if (panel == null) { return; } IDesignerHost host = panel.GetService(typeof(IDesignerHost)) as IDesignerHost; if (host == null) { return; } ITypeDescriptorFilterService serv = host.GetService(typeof(ITypeDescriptorFilterService)) as ITypeDescriptorFilterService; host.RemoveService(typeof(ITypeDescriptorFilterService)); host.AddService(typeof(ITypeDescriptorFilterService), new TypeDescriptorFilterService(serv)); }
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(284, 264); PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); namePropertyDescriptor.SetValue(form, "MainForm"); Panel panel = (Panel)host.CreateComponent(typeof(Panel), "panel1"); panel.Location = new Point(10, 15); panel.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; panel.TabIndex = 0; panel.Size = new Size(100, 120); TextBox textBox = (TextBox)host.CreateComponent(typeof(TextBox), "textBox1"); textBox.Location = new Point(5, 5); textBox.TabIndex = 0; textBox.Size = new Size(110, 20); panel.Controls.Add(textBox); // Add an event handler to the panel to check that this code is generated // before the text box is initialized. EventDescriptorCollection events = TypeDescriptor.GetEvents(panel); EventDescriptor clickEvent = events.Find("Click", false); PropertyDescriptor clickEventProperty = eventBindingService.GetEventProperty(clickEvent); clickEventProperty.SetValue(panel, "Panel1Click"); form.Controls.Add(panel); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { RubyCodeDomSerializer serializer = new RubyCodeDomSerializer(" "); generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, 1); } } }
protected override void Dispose(bool disposing) { if (disposing) { IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); if (host != null) { if (m_inheritanceService != null) { host.RemoveService(typeof(IInheritanceService)); if (m_inheritanceService.m_parentService != null) { host.AddService(typeof(IInheritanceService), m_inheritanceService.m_parentService); } m_inheritanceService.Dispose(); m_inheritanceService = null; } } } base.Dispose(disposing); }
/// <summary> /// Standard constructor. A Service Provider is necessary for monitoring selection and component changes. /// </summary> public DesignerActionService(IServiceProvider serviceProvider) { if (serviceProvider != null) { _serviceProvider = serviceProvider; IDesignerHost host = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost)); host.AddService(typeof(DesignerActionService), this); IComponentChangeService cs = (IComponentChangeService)serviceProvider.GetService(typeof(IComponentChangeService)); if (cs != null) { cs.ComponentRemoved += new ComponentEventHandler(OnComponentRemoved); } _selSvc = (ISelectionService)serviceProvider.GetService(typeof(ISelectionService)); if (_selSvc == null) { Debug.Fail("Either BehaviorService or ISelectionService is null, cannot continue."); } } _designerActionLists = new Hashtable(); _componentToVerbsEventHookedUp = new Hashtable(); }
public ILimnorDesignPane CreateDesigner(ClassData classData) { ILimnorDesignPane limnorXmlPane = null; try { DesignUtil.LogIdeProfile("Create designer loader"); LimnorXmlDesignerLoader2 designerLoader = new LimnorXmlDesignerLoader2(classData); DesignUtil.LogIdeProfile("Create designer surface"); HostSurface designSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer); IDesignerHost dh = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); dh.AddService(typeof(INameCreationService), new NameCreationService()); IServiceContainer serviceContainer = dh.GetService(typeof(ServiceContainer)) as IServiceContainer; DesignUtil.LogIdeProfile("Load designer surface"); designSurface.Loader = designerLoader; designSurface.BeginLoad(designerLoader); if (VPLUtil.Shutingdown) { return(null); } DesignUtil.LogIdeProfile("Add designer services"); XMenuCommandService menuServices = new XMenuCommandService(serviceContainer); dh.AddService(typeof(IMenuCommandService), menuServices); menuServices.AddVerb(new DesignerVerb("Cut", null, StandardCommands.Cut)); menuServices.AddVerb(new DesignerVerb("Copy", null, StandardCommands.Copy)); menuServices.AddVerb(new DesignerVerb("Paste", null, StandardCommands.Paste)); menuServices.AddVerb(new DesignerVerb("Delete", null, StandardCommands.Delete)); menuServices.AddVerb(new DesignerVerb("Undo", null, StandardCommands.Undo)); menuServices.AddVerb(new DesignerVerb("Redo", null, StandardCommands.Redo)); if (dh.GetService(typeof(IDesignerSerializationService)) == null) { dh.AddService(typeof(IDesignerSerializationService), new DesignerSerializationService(serviceContainer)); } if (dh.GetService(typeof(ComponentSerializationService)) == null) { //DesignerSerializationService uses CodeDomComponentSerializationService CodeDomComponentSerializationService codeDomComponentSerializationService = new CodeDomComponentSerializationService(serviceContainer); dh.AddService(typeof(ComponentSerializationService), codeDomComponentSerializationService); } VOB.UndoEngineImpl undoEngine = new VOB.UndoEngineImpl(serviceContainer); undoEngine.Enabled = false; dh.AddService(typeof(UndoEngine), undoEngine); designerLoader.AddComponentChangeEventHandler(); DesignUtil.LogIdeProfile("Create designer pane"); limnorXmlPane = new LimnorXmlPane2(designSurface, designerLoader); if (designerLoader.IsSetup) { } else { DesignUtil.LogIdeProfile("Apply config"); if (limnorXmlPane.Loader.ObjectMap != null) { limnorXmlPane.BeginApplyConfig(); } } DesignUtil.LogIdeProfile("Initialize designer surface"); designSurface.Initialize(); ILimnorToolbox toolbox = (ILimnorToolbox)GetService(typeof(IToolboxService)); toolbox.Host = dh; this.ActiveDesignSurface = designSurface; // } catch (Exception ex) { MathNode.Log(TraceLogClass.MainForm, ex); // Just rethrow for now throw; } DesignUtil.LogIdeProfile("Finish creating designer"); return(limnorXmlPane); }
void CreateDesigner(bool New, string XmlCode) { ModUi.ResetEventHandlers(); //Create a new DesignSurface ModDesignSurface MDS = new ModDesignSurface(); MDS.SetUpSelectionService(); MDS.BeginLoad(typeof(Form)); IDH = (IDesignerHost)MDS.GetService(typeof(IDesignerHost)); try { IDH.RemoveService(typeof(ITypeDescriptorFilterService)); }catch {} try { IDH.RemoveService(typeof(IToolboxService)); }catch {} try { IDH.RemoveService(typeof(PropertyGrid)); }catch { } //Read XML and update the Form control if (!New) { ModCodeAndControlHolder Code = ModUiTools.XmlToCode(XmlCode, (Form)IDH.RootComponent); } //Panel P = (Panel)IDH.CreateComponent(typeof(Panel)); //P.Location = ModUiTools.GetLocationDefinition(20, 20); //P.Size = ModUiTools.GetSizeDefinition(100, 100); //Button B = (Button)IDH.CreateComponent(typeof(Button), "TestButton"); //B.Text = "123"; //P.Controls.Add(B); //P.Parent = (Form)IDH.RootComponent; try { this.BaseSplit.Panel2.Controls.RemoveAt(0); } catch { } Control C = MDS.View as Control; C.Parent = this.BaseSplit.Panel2; C.Dock = DockStyle.Fill; IDH.AddService(typeof(ITypeDescriptorFilterService), new CustomFilterService()); ModToolBox TB = new ModToolBox(); TB.Parent = this.ToolboxTab; TB.Dock = DockStyle.Fill; IDH.AddService(typeof(IToolboxService), TB); PropertyGrid PG = new PropertyGrid(); PG.Parent = this.PropertiesPropertySubTab; PG.Dock = DockStyle.Fill; IDH.AddService(typeof(PropertyGrid), PG); // Use ComponentChangeService to announce changing of the // Form's Controls collection */ IComponentChangeService ICC = (IComponentChangeService)IDH.GetService(typeof(IComponentChangeService)); ICC.OnComponentChanging(IDH.RootComponent, TypeDescriptor.GetProperties(IDH.RootComponent)["Controls"]); }
/// <summary> /// ��ʼ������HostDesign��Ķ����ص�ǰ��ѡ�ؼ��仯ʱ���¼��������Ϣ����� /// �õ��ķ������Կؼ��������IJ˵���״̬������ǩ�ؼ���TabControl�����˵����� /// ��ӵķ�����/�ظ� /// </summary> internal void Initialize() { host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (host == null) { return; } try { selectionService = (ISelectionService)(this.GetService(typeof(ISelectionService))); selectionService.SelectionChanged += new EventHandler(selectionService_SelectionChanged); if (host.RootComponent != null) { ((Control)host.RootComponent).Resize += new EventHandler(CassView_Resize); } cassPropertyGrid = (FilteredPropertyGrid)(this.GetService(typeof(FilteredPropertyGrid))); operateMenu = (ContextMenuStrip)(this.GetService(typeof(ContextMenuStrip))); designMousePosition = (ToolStripStatusLabel)(this.GetService(typeof(ToolStripStatusLabel))); editToolMenuItem = (ToolStripMenuItem)this.GetService(typeof(ToolStripMenuItem)); //��ӳ���/�ظ��������� IServiceContainer serviceContainer = host.GetService(typeof(ServiceContainer)) as IServiceContainer; undoEngine = new UndoEngineImplication(serviceContainer); undoEngine.Enabled = false; //�رճ������ظ����� host.AddService(typeof(UndoEngineImplication), undoEngine); } catch (Exception ex) { } }
void CreateDesigner(bool New, string XmlCode) { ModUi.ResetEventHandlers(); //Create a new DesignSurface ModDesignSurface MDS = new ModDesignSurface(); MDS.SetUpSelectionService(); MDS.BeginLoad(typeof(Form)); IDH = (IDesignerHost)MDS.GetService(typeof(IDesignerHost)); try { IDH.RemoveService(typeof(ITypeDescriptorFilterService)); }catch{} try { IDH.RemoveService(typeof(IToolboxService)); }catch{} try { IDH.RemoveService(typeof(PropertyGrid)); }catch { } //Read XML and update the Form control if (!New) { ModCodeAndControlHolder Code = ModUiTools.XmlToCode(XmlCode, (Form)IDH.RootComponent); } //Panel P = (Panel)IDH.CreateComponent(typeof(Panel)); //P.Location = ModUiTools.GetLocationDefinition(20, 20); //P.Size = ModUiTools.GetSizeDefinition(100, 100); //Button B = (Button)IDH.CreateComponent(typeof(Button), "TestButton"); //B.Text = "123"; //P.Controls.Add(B); //P.Parent = (Form)IDH.RootComponent; try { this.BaseSplit.Panel2.Controls.RemoveAt(0); } catch { } Control C = MDS.View as Control; C.Parent = this.BaseSplit.Panel2; C.Dock = DockStyle.Fill; IDH.AddService(typeof(ITypeDescriptorFilterService), new CustomFilterService()); ModToolBox TB = new ModToolBox(); TB.Parent = this.ToolboxTab; TB.Dock = DockStyle.Fill; IDH.AddService(typeof(IToolboxService), TB); PropertyGrid PG = new PropertyGrid(); PG.Parent = this.PropertiesPropertySubTab; PG.Dock = DockStyle.Fill; IDH.AddService(typeof(PropertyGrid), PG); // Use ComponentChangeService to announce changing of the // Form's Controls collection */ IComponentChangeService ICC = (IComponentChangeService)IDH.GetService(typeof(IComponentChangeService)); ICC.OnComponentChanging(IDH.RootComponent, TypeDescriptor.GetProperties(IDH.RootComponent)["Controls"]); }
/// <include file='doc\CompositionDesigner.uex' path='docs/doc[@for="ComponentDocumentDesigner.Initialize"]/*' /> /// <devdoc> /// <para> /// Initializes the designer with the specified component.</para> /// </devdoc> public override void Initialize(IComponent component) { base.Initialize(component); inheritanceService = new InheritanceService(); ISite site = component.Site; IContainer container = null; IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); IExtenderProviderService exps = (IExtenderProviderService)GetService(typeof(IExtenderProviderService)); if (exps != null) { designerExtenders = new DesignerExtenders(exps); } Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || host != null, "IDesignerHost not found"); if (host != null) { eventHandlerService = new EventHandlerService(null); selectionUIService = new SelectionUIService(host); host.AddService(typeof(IInheritanceService), inheritanceService); host.AddService(typeof(IEventHandlerService), eventHandlerService); host.AddService(typeof(ISelectionUIService), selectionUIService); compositionUI = new CompositionUI(this, site); host.AddService(typeof(ComponentTray), compositionUI); IComponentChangeService cs = (IComponentChangeService)GetService(typeof(IComponentChangeService)); Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || cs != null, "IComponentChangeService not found"); if (cs != null) { cs.ComponentAdded += new ComponentEventHandler(OnComponentAdded); cs.ComponentRemoved += new ComponentEventHandler(OnComponentRemoved); } // Select this component. // ISelectionService ss = (ISelectionService)GetService(typeof(ISelectionService)); if (ss != null) { ss.SetSelectedComponents(new object[] { component }, SelectionTypes.Normal); } } // Set up our menu command set // if (site != null) { commandSet = new CompositionCommandSet(compositionUI, site); container = site.Container; } this.pbrsFwd = new PbrsForward(compositionUI, site); // Hook up our inheritance service and do a scan for inherited components. // inheritanceService.AddInheritedComponents(component, container); // Hook yourself up to the ITypeDescriptorFilterService so we can hide the // location property on all components being added to the designer. // IServiceContainer serviceContainer = (IServiceContainer)GetService(typeof(IServiceContainer)); if (serviceContainer != null) { delegateFilterService = (ITypeDescriptorFilterService)GetService(typeof(ITypeDescriptorFilterService)); if (delegateFilterService != null) { serviceContainer.RemoveService(typeof(ITypeDescriptorFilterService)); } serviceContainer.AddService(typeof(ITypeDescriptorFilterService), this); } }
private IntPtr CreateDesignerView(IVsHierarchy hierarchy, uint itemid, IVsTextLines textLines, ref string editorCaption, ref Guid cmdUI, string documentMoniker) { // Request the Designer Service IVSMDDesignerService designerService = (IVSMDDesignerService)GetService(typeof(IVSMDDesignerService)); try { // Get the service provider IOleServiceProvider provider = serviceProvider.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; IObjectWithSite ows = (IObjectWithSite)textLines; ows.SetSite(provider); // Create loader for the designer LimnorXmlDesignerLoader2 designerLoader = new LimnorXmlDesignerLoader2(documentMoniker, itemid); // Create the designer using the provider and the loader IVSMDDesigner designer = designerService.CreateDesigner(provider, designerLoader); designerLoader.AddComponentChangeEventHandler(); // Retrieve the design surface DesignSurface designSurface = (DesignSurface)designer; IDesignerHost dh = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); dh.AddService(typeof(INameCreationService), new NameCreationService()); IServiceContainer serviceContainer = dh.GetService(typeof(ServiceContainer)) as IServiceContainer; dh.AddService(typeof(IDesignerSerializationService), new DesignerSerializationService(serviceContainer)); //DesignerSerializationService uses CodeDomComponentSerializationService CodeDomComponentSerializationService codeDomComponentSerializationService = new CodeDomComponentSerializationService(serviceContainer); dh.AddService(typeof(ComponentSerializationService), codeDomComponentSerializationService); //LimnorUndoEngine undoEngine = new LimnorUndoEngine(serviceContainer); //undoEngine.Enabled = false;//not use undo during loading //dh.AddService(typeof(UndoEngine), undoEngine); //object v = dh.GetService(typeof(IOleUndoManager)); //if (v != null) //{ // object v2 = dh.GetService(typeof(UndoEngine)); // if (v2 == null) // { // dh.AddService(typeof(UndoEngine), v); // } //} // Create pane with this surface LimnorXmlPane2 limnorXmlPane = new LimnorXmlPane2(designSurface);//, winControlPME); // Get command guid from designer cmdUI = limnorXmlPane.CommandGuid; editorCaption = " [Design]"; if (designerLoader.IsSetup) { } else { if (limnorXmlPane.Loader.ObjectMap != null) { limnorXmlPane.BeginApplyConfig(); } } // Return LimnorXmlPane return(Marshal.GetIUnknownForObject(limnorXmlPane)); } catch (Exception ex) { MathNode.Log(ex); //Trace.WriteLine("Exception: " + ex.Message); // Just rethrow for now throw; } }
public void AddService(Type t, object service) { IDesignerHost host = (IDesignerHost)dsf.GetService(typeof(IDesignerHost)); host.AddService(t, service); }