コード例 #1
0
ファイル: AutoSettingPanel.cs プロジェクト: mind0n/hive
		void pb_OnTextChanged(PathBrowser sender)
		{
			if (sender.Tag != null && sender.Tag is SettingTag)
			{
				SettingTag tag = (SettingTag)sender.Tag;
				tag.SetValue(sender.SelectedPath);
			}
		}
コード例 #2
0
ファイル: AutoSettingPanel.cs プロジェクト: mind0n/hive
		public SettingTag AddCmdItem(string name, CommandNode target, string field, int editorType = 0, bool isReadonly = false)
		{
			if (target == null)
			{
				return null;
			}
			UICommandNode ucmd = null;
			if (target is UICommandNode)
			{
				ucmd = (UICommandNode)target;
			}
			PathBrowser pb = new PathBrowser();
			ComboBox rd = new ComboBox();
			TextBox editor = new TextBox();
			CheckBox ck = new CheckBox();
			Label lb = new Label { Text = name, AutoSize = true };
			if (!string.IsNullOrEmpty(target.Editor) && editors.ContainsKey(target.Editor))
			{
				editorType = editors[target.Editor];
			}
			editor.AllowDrop = true;
            editor.MouseDoubleClick += new MouseEventHandler(editor_MouseDoubleClick);
			ck.Enabled = !isReadonly;
			editor.Enabled = !isReadonly;
			rd.Enabled = !isReadonly;
			lb.MouseDown += new MouseEventHandler(lb_MouseDown);
			SettingTag rlt = null;
			FieldInfo f = target.GetType().GetField(field);
			if (f != null)
			{
				rlt = new SettingTag { FieldInfo = f, Target = target };
				lb.Tag = rlt;
				object value = f.GetValue(target);
				rlt.EditorType = editorType;
				rlt.LabelControl = lb;
				if (editorType == 1)
				{
					rlt.EditControl = ck;
					ck.Tag = rlt;
					ck.Checked = value != null ? bool.Parse(value.ToString()) : false;
					ck.CheckedChanged += new EventHandler(ck_CheckedChanged);
					UpdatePos(lb, ck);
					NotifyUINode(ucmd, ck, lb);
				}
				else if (editorType == 2)
				{
					ArrayCommand arr = target as ArrayCommand;
					if (arr != null)
					{
						//rd.DataSource = null;
						rd.Items.Clear();	 
						rlt.EditControl = rd;
						rd.Tag = rlt;
						//rd.DataSource = arr.GetList();
						rd.Items.AddRange(arr.GetList());
						rd.SelectedIndex = arr.SelectedIndex;
						rd.SelectedIndexChanged += new EventHandler(rd_SelectedIndexChanged);						
						UpdatePos(lb, rd);
						NotifyUINode(ucmd, rd, lb);
					}
				}
				else if (editorType == 3)
				{
					rlt.EditControl = pb;
					pb.Tag = rlt;
					if (value != null)
					{
						pb.StartupPath = value.ToString();
					}
					pb.OnTextChanged+=new Action<PathBrowser>(pb_OnTextChanged);
					UpdatePos(lb, pb);
					NotifyUINode(ucmd, pb, lb);
				}
				else
				{
					if (lb.Text.IndexOf("pwd", StringComparison.OrdinalIgnoreCase) >= 0 || lb.Text.IndexOf("password", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						editor.PasswordChar = '*';
					}
					editor.DragEnter += new DragEventHandler(editor_DragEnter);
					editor.DragDrop += new DragEventHandler(editor_DragDrop);
					if (editorType == 4)
					{
						editor.WordWrap = false;
						editor.ScrollBars = ScrollBars.Both;
						editor.Multiline = true;
						editor.Height = 100;
					}
					rlt.EditControl = editor;
					rlt.Id = lb.Text;
					rlt.EditorType = 0;
					editor.Tag = rlt;
					editor.Text = value != null ? value.ToString() : string.Empty;
					editor.TextChanged += new EventHandler(editor_TextChanged);
					UpdatePos(lb, editor);
					NotifyUINode(ucmd, editor, lb);
				}
			}
			return rlt;
		}