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

📄 quickclassbrowserpanel.cs

📁 SharpDevelop2.0.0 c#开发免费工具
💻 CS
📖 第 1 页 / 共 2 页
字号:
				if (currentCompilationUnit != null) {
					//// Alex: when changing between files in different compilation units whole process must be restarted
					//// happens usually when files are opened from different project(s)
					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;
		}
		
		IClass lastClassInMembersComboBox;
		
		void FillMembersComboBox()
		{
			IClass c = GetCurrentSelectedClass();
			if (c != null && lastClassInMembersComboBox != c) {
				lastClassInMembersComboBox = c;
				ArrayList items = new ArrayList();
				bool partialMode = false;
				IClass currentPart = c;
				if (c.IsPartial) {
					CompoundClass cc = c.GetCompoundClass() as CompoundClass;
					if (cc != null && cc.Parts.Count > 0) {
						partialMode = true;
						c = cc;
					}
				}
				
				lock (c) {
					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), partialMode ? currentPart.Methods.Contains(m) : true));
					}
					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), partialMode ? currentPart.Properties.Contains(p) : true));
					}
					items.Sort(lastIndex, c.Properties.Count, comparer);
					lastIndex = items.Count;
					
					foreach (IField f in c.Fields) {
						items.Add(new ComboBoxItem(f, f.Name, ClassBrowserIconService.GetIcon(f), partialMode ? currentPart.Fields.Contains(f) : true));
					}
					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), partialMode ? currentPart.Events.Contains(evt) : true));
					}
					items.Sort(lastIndex, c.Events.Count, comparer);
					lastIndex = items.Count;
				}
				
				membersComboBox.BeginUpdate();
				membersComboBox.Items.Clear();
				membersComboBox.Items.AddRange(items.ToArray());
				membersComboBox.EndUpdate();
				UpdateMembersComboBox();
			}
		}
		
		void AddClasses(ArrayList items, ICollection classes)
		{
			foreach (IClass c in classes) {
				items.Add(new ComboBoxItem(c, c.FullyQualifiedName, ClassBrowserIconService.GetIcon(c), true));
				AddClasses(items, c.InnerClasses);
			}
		}
		
		void FillClassComboBox(bool isUpdateRequired)
		{
			ArrayList items = new ArrayList();
			AddClasses(items, currentCompilationUnit.Classes);
			if (isUpdateRequired) {
				classComboBox.BeginUpdate();
			}
			classComboBox.Items.Clear();
			membersComboBox.Items.Clear();
			classComboBox.Items.AddRange(items.ToArray());
			if (items.Count == 1) {
				try {
					autoselect = false;
					classComboBox.SelectedIndex = 0;
					FillMembersComboBox();
				} finally {
					autoselect = true;
				}
			}
			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 (autoselect) {
				ComboBoxItem item = (ComboBoxItem)comboBox.Items[comboBox.SelectedIndex];
				if (item.IsInCurrentPart) {
					textAreaControl.ActiveTextAreaControl.Caret.Position = new Point(item.Column, item.Line);
					textAreaControl.ActiveTextAreaControl.TextArea.Focus();
				} else {
					IMember m = item.Item as IMember;
					if (m != null) {
						string fileName = m.DeclaringType.CompilationUnit.FileName;
						FileService.JumpToFilePosition(fileName, item.Line, item.Column);
					}
				}
			}
		}
		
		// 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);
		
		void ComboBoxDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
		{
			ComboBox comboBox = (ComboBox)sender;
			e.DrawBackground();
			
			if (e.Index >= 0) {
				ComboBoxItem item = (ComboBoxItem)comboBox.Items[e.Index];
				
				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 (!item.IsInCurrentPart) {
					drawItemBrush = SystemBrushes.ControlDark;
				} else 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;
				
				e.ItemHeight = (int)Math.Max(size.Height, ClassBrowserIconService.ImageList.ImageSize.Height);
			}
		}
	}
}

⌨️ 快捷键说明

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