コード例 #1
0
        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;
            }
        }
コード例 #2
0
 private void changeService_ComponentChanging(object sender, ComponentChangingEventArgs e)
 {
     AssociatedFile.GiveUnsavedData();
     _propertyContainer.SelectedObjects = new object[] { e.Component };
 }
コード例 #3
0
 private void changeService_ComponentsChanged(object sender, ComponentEventArgs e)
 {
     AssociatedFile.GiveUnsavedData();
 }