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

📄 quickclassbrowserpanel.cs

📁 全功能c#编译器
💻 CS
📖 第 1 页 / 共 2 页
字号:
					for (int i = 0; i < classComboBox.Items.Count; ++i) {
						if (((ComboBoxItem)classComboBox.Items[i]).IsInside(textAreaControl.ActiveTextAreaControl.Caret.Line)) {
							bool innerClassContainsCaret = false;
							for (int j = i + 1; j < classComboBox.Items.Count; ++j) {
								if (((ComboBoxItem)classComboBox.Items[j]).IsInside(textAreaControl.ActiveTextAreaControl.Caret.Line)) {
									innerClassContainsCaret = true;
									break;
								}
							}
							if (!innerClassContainsCaret) {
								if (classComboBox.SelectedIndex != i) {
									classComboBox.SelectedIndex = i;
									FillMembersComboBox();
								}
								if (!classComboBoxSelectedMember) {
									classComboBox.Refresh();
								}
								classComboBoxSelectedMember = true;
								return;
							}
						}
					}
				}
				if (classComboBoxSelectedMember) {
					classComboBox.Refresh();
					classComboBoxSelectedMember = false;
				}
			} finally {
				autoselect = true;
			}
//				classComboBox.SelectedIndex = -1;
		}
		
		bool NeedtoUpdate(ArrayList items, ComboBox comboBox)
		{
			if (items.Count != comboBox.Items.Count) {
				return true;
			}
			for (int i = 0; i < items.Count; ++i) {
				ComboBoxItem oldItem = (ComboBoxItem)comboBox.Items[i];
				ComboBoxItem newItem = (ComboBoxItem)items[i];
				if (oldItem.GetType() != newItem.GetType()) {
					return true;
				}
				if (newItem.CompareItemTo(oldItem) != 0) {
					return true;
				}
			}
			return false;
		}
		
		void FillMembersComboBox()
		{
			IClass c = GetCurrentSelectedClass();
			if (c != null) {
				ArrayList items = new ArrayList();
				ClassBrowserIconsService classBrowserIconService = (ClassBrowserIconsService)ServiceManager.Services.GetService(typeof(ClassBrowserIconsService));
				int lastIndex = 0;
				IComparer comparer = new Comparer(System.Globalization.CultureInfo.InvariantCulture);
				foreach (IMethod m in c.Methods) {
					items.Add(new ComboBoxItem(m, m.Name, classBrowserIconService.GetIcon(m)));
				}
				items.Sort(lastIndex, c.Methods.Count, comparer);
				lastIndex = items.Count;
				
				foreach (IProperty p in c.Properties) {
					items.Add(new ComboBoxItem(p, p.Name, classBrowserIconService.GetIcon(p)));
				}
				items.Sort(lastIndex, c.Properties.Count, comparer);
				lastIndex = items.Count;
				
				foreach (IIndexer indexer in c.Indexer) {
					items.Add(new ComboBoxItem(indexer, indexer.Name, classBrowserIconService.GetIcon(indexer)));
				}
				items.Sort(lastIndex, c.Indexer.Count, comparer);
				lastIndex = items.Count;
				
				foreach (IField f in c.Fields) {
					items.Add(new ComboBoxItem(f, f.Name, classBrowserIconService.GetIcon(f)));
				}
				items.Sort(lastIndex, c.Fields.Count, comparer);
				lastIndex = items.Count;
				
				foreach (IEvent evt in c.Events) {
					items.Add(new ComboBoxItem(evt, evt.Name, classBrowserIconService.GetIcon(evt)));
				}
				items.Sort(lastIndex, c.Events.Count, comparer);
				lastIndex = items.Count;
				
				if (NeedtoUpdate(items, membersComboBox)) {
					membersComboBox.BeginUpdate();
					membersComboBox.Items.Clear();
					membersComboBox.Items.AddRange(items.ToArray());
					membersComboBox.EndUpdate();
					UpdateMembersComboBox();
				}
			} else {
				if (membersComboBox.Items.Count > 0) {
					membersComboBox.Items.Clear();
				}
			}
		}
		
		void AddClasses(ArrayList items, ICollection classes)
		{
			ClassBrowserIconsService classBrowserIconService = (ClassBrowserIconsService)ServiceManager.Services.GetService(typeof(ClassBrowserIconsService));
			foreach (IClass c in classes) {
				items.Add(new ComboBoxItem(c, c.FullyQualifiedName, classBrowserIconService.GetIcon(c)));
				AddClasses(items, c.InnerClasses);
			}
		}
		
		void FillClassComboBox(bool isUpdateRequired)
		{
			ArrayList items = new ArrayList();
			AddClasses(items, currentCompilationUnit.Classes);
			if (NeedtoUpdate(items, classComboBox)) {
				if (isUpdateRequired) {
					classComboBox.BeginUpdate();
				}
				classComboBox.Items.Clear();
				classComboBox.Items.AddRange(items.ToArray());
				if (isUpdateRequired) {
					classComboBox.EndUpdate();
				}
				UpdateClassComboBox();
			} 
		}
		
		
		// THIS METHOD IS MAINTAINED BY THE FORM DESIGNER
		// DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST
		void InitializeComponent() {
			this.membersComboBox = new System.Windows.Forms.ComboBox();
			this.classComboBox = new System.Windows.Forms.ComboBox();
			this.SuspendLayout();
			// 
			// membersComboBox
			// 
			this.membersComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.membersComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
			this.membersComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.membersComboBox.Location = new System.Drawing.Point(200, 4);
			this.membersComboBox.Name = "membersComboBox";
			this.membersComboBox.Size = new System.Drawing.Size(161, 21);
			this.membersComboBox.TabIndex = 1;
			this.membersComboBox.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectedIndexChanged);
			this.membersComboBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.MeasureComboBoxItem);
			this.membersComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBoxDrawItem);
			
			//
			// classComboBox
			// 
			this.classComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
			this.classComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.classComboBox.Location = new System.Drawing.Point(4, 4);
			this.classComboBox.Name = "classComboBox";
			this.classComboBox.Size = new System.Drawing.Size(189, 21);
			this.classComboBox.TabIndex = 0;
			this.classComboBox.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectedIndexChanged);
			this.classComboBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.MeasureComboBoxItem);
			this.classComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBoxDrawItem);
			this.classComboBox.Sorted = true;
			
			//
			// QuickClassBrowserPanel
			// 
			this.Controls.Add(this.membersComboBox);
			this.Controls.Add(this.classComboBox);
			this.Name = "QuickClassBrowserPanel";
			this.Size = new System.Drawing.Size(368, 28);
			this.Resize += new System.EventHandler(this.QuickClassBrowserPanelResize);
			this.ResumeLayout(false);
		}
		
		public IClass GetCurrentSelectedClass()
		{
			if (classComboBox.SelectedIndex >= 0) {
				return (IClass)((ComboBoxItem)classComboBox.Items[classComboBox.SelectedIndex]).Item;
			}
			return null;
		}
		
		void ComboBoxSelectedIndexChanged(object sender, System.EventArgs e)
		{
			ComboBox comboBox = (ComboBox)sender;
			if (comboBox.SelectedIndex < 0) {
				membersComboBox.Items.Clear();
			} else if (autoselect) {
				textAreaControl.ActiveTextAreaControl.Caret.Position = new Point(((ComboBoxItem)comboBox.Items[comboBox.SelectedIndex]).Column,
				                                                                 ((ComboBoxItem)comboBox.Items[comboBox.SelectedIndex]).Line);
				textAreaControl.ActiveTextAreaControl.TextArea.Focus();
			}
		}
		
		// font - has to be static - don't create on each draw
		static Font font = font = new Font("Arial", 8.25f);
		static StringFormat drawStringFormat = new StringFormat(StringFormatFlags.NoWrap);
//		static int drawingCount = 0;
		
		void ComboBoxDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
		{
//			Console.WriteLine("Draw " + (drawingCount++));
			ComboBox comboBox = (ComboBox)sender;
			e.DrawBackground();
			if (e.Index >= 0) {
				ComboBoxItem item = (ComboBoxItem)comboBox.Items[e.Index];
				ClassBrowserIconsService classBrowserIconService = (ClassBrowserIconsService)ServiceManager.Services.GetService(typeof(ClassBrowserIconsService));
				e.Graphics.DrawImageUnscaled(classBrowserIconService.ImageList.Images[item.IconIndex],
				                             new Point(e.Bounds.X, e.Bounds.Y + (e.Bounds.Height - classBrowserIconService.ImageList.ImageSize.Height) / 2));
				Rectangle drawingRect = new Rectangle(e.Bounds.X + classBrowserIconService.ImageList.ImageSize.Width,
				                                      e.Bounds.Y,
				                                      e.Bounds.Width - classBrowserIconService.ImageList.ImageSize.Width,
				                                      e.Bounds.Height);
				
				Brush drawItemBrush = SystemBrushes.WindowText;
				if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
					drawItemBrush = SystemBrushes.HighlightText;
				}
				if (e.State == DrawItemState.ComboBoxEdit && !item.IsInside(textAreaControl.ActiveTextAreaControl.Caret.Line)) {
					drawItemBrush = SystemBrushes.ControlDark;
				}
				e.Graphics.DrawString(item.ToString(),
				                      font,
				                      drawItemBrush,
				                      drawingRect,
				                      drawStringFormat);
			}
			e.DrawFocusRectangle();
		}
		
		void QuickClassBrowserPanelResize(object sender, System.EventArgs e)
		{
			Size comboBoxSize = new Size(Width / 2 - 4 * 3, 21);
			classComboBox.Size = comboBoxSize;
			membersComboBox.Location = new Point(classComboBox.Bounds.Right + 8, classComboBox.Bounds.Top);
			membersComboBox.Size = comboBoxSize;
		}
		
		void MeasureComboBoxItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
		{
			ComboBox comboBox = (ComboBox)sender;
			if (e.Index >= 0) {
				ComboBoxItem item = (ComboBoxItem)comboBox.Items[e.Index];
				SizeF size = e.Graphics.MeasureString(item.ToString(), font);
				e.ItemWidth  = (int)size.Width;
				ClassBrowserIconsService classBrowserIconService = (ClassBrowserIconsService)ServiceManager.Services.GetService(typeof(ClassBrowserIconsService));
				e.ItemHeight = (int)Math.Max(size.Height, classBrowserIconService.ImageList.ImageSize.Height);
			}
		}
	}
}

⌨️ 快捷键说明

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