⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formdesignerdisplaybindingbase.cs

📁 全功能c#编译器
💻 CS
📖 第 1 页 / 共 2 页
字号:
			}
			switch (Path.GetExtension(fileName)) {
				case ".cs":
					new CodeDOMGenerator(host, new Microsoft.CSharp.CSharpCodeProvider()).ConvertContentDefinition(fileName);
					break;
				case ".vb":
					new CodeDOMGenerator(host, new Microsoft.VisualBasic.VBCodeProvider()).ConvertContentDefinition(fileName);
					break;
				default:
					doc.Save(fileName);
					break;
			}
			IsDirty = false;
		}
		/*
		// todo : complete CodeDOM writing
		void SaveCSharp(string fileName, XmlDocument doc)
		{
			
			
			
			foreach (XmlNode node in doc.DocumentElement.ChildNodes) {
				if (node.Attributes["value"] != null) {
				}
			}
			
			co.Members.Add(cm);
			
			
			StreamWriter writer = File.CreateText(fileName);
			cg.GenerateCodeFromNamespace(cnamespace, writer, null);
			writer.Close();
		}*/
		
		public override void Load(string fileName)
		{
		}
		
		
		protected virtual void CreateDesignerHost()
		{
			host = new DefaultDesignerHost();
			
			ComponentChangeService changeService = new ComponentChangeService();
			host.AddService(typeof(System.ComponentModel.Design.IComponentChangeService),      changeService);
			host.AddService(typeof(System.Windows.Forms.Design.IUIService),                    new UIService());
			host.AddService(typeof(System.ComponentModel.Design.IDesignerOptionService),       new ICSharpCode.SharpDevelop.FormDesigner.Services.DesignerOptionService());
			host.AddService(typeof(System.ComponentModel.Design.ITypeDescriptorFilterService), new TypeDescriptorFilterService());
			
			host.AddService(typeof(System.Drawing.Design.IToolboxService), ToolboxProvider.ToolboxService);
			host.AddService(typeof(System.Drawing.Design.IPropertyValueUIService), new PropertyValueUIService());
			
			ExtenderService extenderService = new ExtenderService(host);
			host.AddService(typeof(System.ComponentModel.Design.IExtenderListService),    extenderService);
			host.AddService(typeof(System.ComponentModel.Design.IExtenderProviderService), extenderService);
			
			host.AddService(typeof(System.ComponentModel.Design.IDesignerHost),        host);
			host.AddService(typeof(System.ComponentModel.IContainer),                  host.Container);
			host.AddService(typeof(System.ComponentModel.Design.IDictionaryService),   new DictionaryService());
			host.AddService(typeof(System.ComponentModel.Design.IEventBindingService), CreateEventBindingService());
			host.AddService(typeof(System.ComponentModel.Design.ISelectionService),    new SelectionService(host));
			
			host.AddService(typeof(AmbientProperties),                                                ambientProperties);
			host.AddService(typeof(System.ComponentModel.Design.Serialization.INameCreationService),  new NameCreationService(host));
			host.AddService(typeof(System.ComponentModel.Design.IDesignerEventService), new DesignerEventService());
			host.AddService(typeof(System.ComponentModel.Design.IResourceService), new DesignerResourceService(host, this.resources));
			this.resources = null;
			host.AddService(typeof(ITypeResolutionService), ToolboxProvider.TypeResolutionService);
			host.AddService(typeof(System.ComponentModel.Design.IReferenceService), new ReferenceService(host));
			
			host.AddService(typeof(IHelpService), new HelpService());
			host.AddService(typeof(IDesignerSerializationManager), new CodeDomDesignerSerializetionManager(host));
			host.AddService(typeof(System.Windows.Forms.Design.IMenuEditorService), new MenuEditorService(host));

			host.AddService(typeof(System.ComponentModel.Design.Serialization.IDesignerSerializationService), new DesignerSerializationService(host));
//			host.AddService(typeof(PropertyGrid), PropertyPad.Grid);
			InitializeExtendersForProject(host);
			host.Activate();
			
			host.TransactionClosed += new DesignerTransactionCloseEventHandler(TransactionFinished);
			
			if (designPanel == null) {
				designPanel = new DesignPanel(host);
			} else {
				designPanel.Host = host;
			}
			
			host.AddService(typeof(System.ComponentModel.Design.IMenuCommandService),  new ICSharpCode.SharpDevelop.FormDesigner.Services.MenuCommandService(host, designPanel));
			
			designPanel.Location = new Point(0, 0);
			designPanel.Dock     = DockStyle.Fill;
			
			if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ActiveViewContent == this) {
				ICSharpCode.SharpDevelop.Gui.Pads.PropertyPad.SetDesignerHost(host);
			}
			undoHandler.Attach(host);
			ISelectionService selectionService = (ISelectionService)host.GetService(typeof(ISelectionService));
			selectionService.SelectionChanged += new EventHandler(SelectionServiceSelectionChanged);
		}
		
		public virtual void Initialize()
		{
			if (host != null) {
				if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ActiveViewContent == this) {
					ICSharpCode.SharpDevelop.Gui.Pads.PropertyPad.SetDesignableObject(null);
				}
				
				if (designPanel != null) {
					designPanel.Reset();
				}
				
				undoHandler.Reset();
				undoHandler.Detach();
// for host re-use:
//				((DesignComponentContainer)((DefaultDesignerHost)host).Container).Clear();
				host.Dispose();
				CreateDesignerHost();
			} else {
				CreateDesignerHost();
			}
		}
		
		public virtual IEventBindingService CreateEventBindingService()
		{
			return new ICSharpCode.SharpDevelop.FormDesigner.Services.EventBindingService(host);
		}

		void SelectionServiceSelectionChanged(object sender, EventArgs e)
		{
			((DefaultWorkbench)WorkbenchSingleton.Workbench).UpdateToolbars();
		}
		
		// IDisplayBinding interface
		public void InitializeFrom(string fileName, string xmlContent)
		{
			Initialize();
			
			XmlFormReader xmlReader = new XmlFormReader(host);
			xmlReader.SetUpDesignerHost(xmlContent);
			
			FileName = TitleName = fileName;
			designPanel.SetRootDesigner();
		}
		
		protected virtual void DeselectAllComponents()
		{
			ISelectionService selectionService = (ISelectionService)host.GetService(typeof(ISelectionService));
			selectionService.SetSelectedComponents(new object[] {});
		}
		
		protected virtual void SelectRootComponent()
		{
			ISelectionService selectionService = (ISelectionService)host.GetService(typeof(ISelectionService));
			selectionService.SetSelectedComponents(new object[] {host.RootComponent});
		}
	
		public virtual void Undo()
		{
			undoHandler.Undo();
		}
		
		public virtual void Redo()
		{
			undoHandler.Redo();
		}
		
		public void Cut(object sender, EventArgs e)
		{
			IMenuCommandService menuCommandService = (IMenuCommandService)host.GetService(typeof(IMenuCommandService));
			menuCommandService.GlobalInvoke(StandardCommands.Cut);
		}
		
		public void Copy(object sender, EventArgs e)
		{
			IMenuCommandService menuCommandService = (IMenuCommandService)host.GetService(typeof(IMenuCommandService));
			menuCommandService.GlobalInvoke(StandardCommands.Copy);
		}
		
		public void Paste(object sender, EventArgs e)
		{
			IMenuCommandService menuCommandService = (IMenuCommandService)host.GetService(typeof(IMenuCommandService));
			menuCommandService.GlobalInvoke(StandardCommands.Paste);
		}
		
		public void Delete(object sender, EventArgs e)
		{
			IMenuCommandService menuCommandService = (IMenuCommandService)host.GetService(typeof(IMenuCommandService));
			menuCommandService.GlobalInvoke(StandardCommands.Delete);
		}
		
		public void SelectAll(object sender, EventArgs e)
		{
			IMenuCommandService menuCommandService = (IMenuCommandService)host.GetService(typeof(IMenuCommandService));
			menuCommandService.GlobalInvoke(StandardCommands.SelectAll);
		}
		
		protected void UpdateSelectableObjects()
		{
			if (host != null) {
				PropertyPad.SetSelectableObjects(host.Container.Components);
				ISelectionService selectionService = (ISelectionService)host.GetService(typeof(ISelectionService));
				if (selectionService != null) {
					ICSharpCode.SharpDevelop.Gui.Pads.PropertyPad.SetDesignableObject(selectionService.PrimarySelection);
				}
			}
		}
		
		void TransactionFinished(object sender, DesignerTransactionCloseEventArgs e)
		{
			IsDirty = true;
		}
		
		void InitializeExtendersForProject(IDesignerHost host)
		{
			IExtenderProviderService elsi = (IExtenderProviderService)host.GetService(typeof(IExtenderProviderService));
			elsi.AddExtenderProvider(new NameExtender());
		}
		
		#region ICSharpCode.SharpDevelop.Gui.IHelpProvider interface implementation
		public void ShowHelp()
		{
			HelpService helpService = (HelpService)host.GetService(typeof(IHelpService));
			helpService.ShowGeneralHelp();
		}
		#endregion
		
		public virtual bool IsTabOrderMode {
			get { 
				return designPanel == null ? false : designPanel.IsTabOrderMode;
			}
		}
		
		public virtual void SetPrevTabIndex(Point p)
		{
			designPanel.SetPrevTabIndex(p); 
		}
		
		public virtual void SetNextTabIndex(Point p)
		{
			designPanel.SetNextTabIndex(p); 
		}
		
		public virtual void ShowTabOrder()
		{
			if (!IsTabOrderMode) {
				designPanel.ShowTabOrder();
				IMenuCommandService menuCommandService = (IMenuCommandService)host.GetService(typeof(IMenuCommandService));
				menuCommandService.GlobalInvoke(StandardCommands.TabOrder);
			}
		}
		public virtual void HideTabOrder()
		{
			if (IsTabOrderMode) {
				designPanel.HideTabOrder();
				IMenuCommandService menuCommandService = (IMenuCommandService)host.GetService(typeof(IMenuCommandService));
				menuCommandService.GlobalInvoke(StandardCommands.TabOrder);
			}
		}
		
		protected virtual string ExtractBaseClass(IClass c)
		{
			IParserService parserService = (IParserService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IParserService));
			foreach (string baseType in c.BaseTypes) {
				IClass type = parserService.SearchType(baseType, c, c.Region != null ? c.Region.BeginLine : 0, c.Region != null ? c.Region.BeginColumn : 0); 
				if (type != null) {
//					if (type.ClassType == ClassType.Class) {
//						return type.FullyQualifiedName;
//					}
					if (type.FullyQualifiedName == "System.Windows.Forms.Form" ||
					    type.FullyQualifiedName == "System.Windows.Forms.UserControl") {
						return type.FullyQualifiedName;
					}
					string extractBaseClass = ExtractBaseClass(type);
					if (extractBaseClass.Length > 0) {
						return extractBaseClass;
					}
				}
			}
			return String.Empty;
		}
		
		protected virtual bool IsBaseClassDesignable(IClass c)
		{
			return AbstractFormDesignerSecondaryDisplayBinding.BaseClassIsFormOrControl(c);
		}
		
		/// <summary>
		/// This is used for letting the View Code command work.
		/// </summary>
		public virtual void ShowSourceCode()
		{
		}
		public virtual void ShowSourceCode(int lineNumber)
		{
		}
		public virtual void ShowSourceCode(IComponent component, EventDescriptor e, string methodName)
		{
		}
		public virtual ICollection GetCompatibleMethods(EventDescriptor e)
		{
			return new string[]{};
		}
		public virtual ICollection GetCompatibleMethods(EventInfo e)
		{
			return new string[]{};
		}
		
		protected virtual void OnEnableCutChanged(EventArgs e)
		{
			if (EnableCutChanged != null) {
				EnableCutChanged(this, e);
			}
		}
		
		protected virtual void OnEnableCopyChanged(EventArgs e)
		{
			if (EnableCopyChanged != null) {
				EnableCopyChanged(this, e);
			}
		}
		
		protected virtual void OnEnablePasteChanged(EventArgs e)
		{
			if (EnablePasteChanged != null) {
				EnablePasteChanged(this, e);
			}
		}
		
		protected virtual void OnEnableDeleteChanged(EventArgs e)
		{
			if (EnableDeleteChanged != null) {
				EnableDeleteChanged(this, e);
			}
		}
		
		protected virtual void OnEnableSelectAllChanged(EventArgs e)
		{
			if (EnableSelectAllChanged != null) {
				EnableSelectAllChanged(this, e);
			}
		}
		
		public event EventHandler EnableCutChanged;
		public event EventHandler EnableCopyChanged;
		public event EventHandler EnablePasteChanged;
		public event EventHandler EnableDeleteChanged;
		public event EventHandler EnableSelectAllChanged;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -