Changeset 14597 for trunk/sources
- Timestamp:
- 01/23/17 12:15:12 (8 years ago)
- Location:
- trunk/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Data.Views/3.3/EnumValueView.Designer.cs
r14185 r14597 47 47 this.valueLabel = new System.Windows.Forms.Label(); 48 48 this.valueComboBox = new System.Windows.Forms.ComboBox(); 49 this.flagsListView = new System.Windows.Forms.ListView(); 50 this.columnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 49 51 this.SuspendLayout(); 50 52 // … … 54 56 this.valueLabel.Location = new System.Drawing.Point(3, 3); 55 57 this.valueLabel.Name = "valueLabel"; 56 this.valueLabel.Size = new System.Drawing.Size( 56, 13);58 this.valueLabel.Size = new System.Drawing.Size(37, 13); 57 59 this.valueLabel.TabIndex = 0; 58 60 this.valueLabel.Text = "&Value:"; … … 60 62 // valueComboBox 61 63 // 62 this.valueComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 64 this.valueComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 63 65 | System.Windows.Forms.AnchorStyles.Right))); 64 66 this.valueComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; … … 71 73 this.valueComboBox.SelectedIndexChanged += new System.EventHandler(this.valueComboBox_SelectedIndexChanged); 72 74 // 75 // flagsListView 76 // 77 this.flagsListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 78 | System.Windows.Forms.AnchorStyles.Left) 79 | System.Windows.Forms.AnchorStyles.Right))); 80 this.flagsListView.CheckBoxes = true; 81 this.flagsListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 82 this.columnHeader}); 83 this.flagsListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; 84 this.flagsListView.Location = new System.Drawing.Point(65, 0); 85 this.flagsListView.Name = "flagsListView"; 86 this.flagsListView.Size = new System.Drawing.Size(212, 21); 87 this.flagsListView.TabIndex = 2; 88 this.flagsListView.UseCompatibleStateImageBehavior = false; 89 this.flagsListView.View = System.Windows.Forms.View.Details; 90 this.flagsListView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.flagsListView_ItemChecked); 91 // 92 // columnHeader 93 // 94 this.columnHeader.Width = 100; 95 // 73 96 // EnumValueView 74 97 // 75 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);76 98 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 99 this.Controls.Add(this.flagsListView); 77 100 this.Controls.Add(this.valueComboBox); 78 101 this.Controls.Add(this.valueLabel); … … 81 104 this.ResumeLayout(false); 82 105 this.PerformLayout(); 106 83 107 } 84 108 … … 87 111 private System.Windows.Forms.Label valueLabel; 88 112 private System.Windows.Forms.ComboBox valueComboBox; 113 private System.Windows.Forms.ListView flagsListView; 114 private System.Windows.Forms.ColumnHeader columnHeader; 89 115 } 90 116 } -
trunk/sources/HeuristicLab.Data.Views/3.3/EnumValueView.cs
r14185 r14597 21 21 22 22 using System; 23 using System.Windows.Forms; 23 24 using HeuristicLab.Core.Views; 24 25 using HeuristicLab.MainForm; … … 44 45 public EnumValueView() { 45 46 InitializeComponent(); 47 this.Name = typeof(T).Name + "EnumView"; 48 46 49 valueComboBox.DataSource = Enum.GetValues(typeof(T)); 47 this.Name = typeof(T).Name + "EnumView"; 50 foreach (T flag in Enum.GetValues(typeof(T))) 51 flagsListView.Items.Add(new ListViewItem(flag.ToString()) { Tag = flag }); 52 columnHeader.Width = -1; 53 54 bool isFlags = Attribute.IsDefined(typeof(T), typeof(FlagsAttribute)); 55 if (isFlags) valueLabel.Text = "Flags:"; 56 valueComboBox.Visible = !isFlags; 57 flagsListView.Visible = isFlags; 48 58 } 49 59 public EnumValueView(EnumValue<T> content) … … 64 74 protected override void OnContentChanged() { 65 75 base.OnContentChanged(); 66 if (Content == null) 67 valueComboBox.Enabled = false; 68 else 76 if (Content == null) { 77 valueComboBox.SelectedIndex = -1; 78 foreach (ListViewItem item in flagsListView.Items) 79 item.Checked = false; 80 } else { 69 81 valueComboBox.SelectedItem = Content.Value; 82 foreach (ListViewItem item in flagsListView.Items) { 83 var flag = (Enum)item.Tag; 84 item.Checked = ((Enum)(object)Content.Value).HasFlag(flag); 85 } 86 } 70 87 } 71 88 72 89 protected override void SetEnabledStateOfControls() { 73 90 base.SetEnabledStateOfControls(); 74 if (Content == null) valueComboBox.Enabled = false; 75 else valueComboBox.Enabled = !ReadOnly; 91 if (Content == null) { 92 valueComboBox.Enabled = false; 93 flagsListView.Enabled = false; 94 } else { 95 valueComboBox.Enabled = !ReadOnly; 96 flagsListView.Enabled = !ReadOnly; 97 } 76 98 } 77 99 … … 79 101 if (InvokeRequired) 80 102 Invoke(new EventHandler(Content_ValueChanged), sender, e); 81 else 103 else { 82 104 valueComboBox.SelectedItem = Content.Value; 105 foreach (ListViewItem item in flagsListView.Items) { 106 var flag = (Enum)item.Tag; 107 item.Checked = ((Enum)(object)Content.Value).HasFlag(flag); 108 } 109 } 83 110 } 84 111 … … 87 114 Content.Value = (T)valueComboBox.SelectedItem; 88 115 } 116 117 private void flagsListView_ItemChecked(object sender, ItemCheckedEventArgs e) { 118 var flag = (T)e.Item.Tag; 119 if ((Content != null) && !Content.ReadOnly) 120 Content.Value = ((Enum)(object)Content.Value).SetFlag(flag, e.Item.Checked); 121 } 89 122 } 90 123 } -
trunk/sources/HeuristicLab.Data/3.3/EnumValue.cs
r14185 r14597 52 52 private EnumValue(EnumValue<T> original, Cloner cloner) 53 53 : base(original, cloner) { 54 this.value = original.value;55 this.readOnly = original.readOnly;56 54 } 57 55 … … 64 62 } 65 63 } 64 65 public static class EnumHelper { 66 public static T SetFlag<T>(this Enum value, T flag, bool set) { 67 var baseType = Enum.GetUnderlyingType(value.GetType()); 68 dynamic valueAsBase = Convert.ChangeType(value, baseType); 69 dynamic flagAsBase = Convert.ChangeType(flag, baseType); 70 if (set) 71 valueAsBase |= flagAsBase; 72 else 73 valueAsBase &= ~flagAsBase; 74 return (T)valueAsBase; 75 } 76 } 66 77 } -
trunk/sources/HeuristicLab.Data/3.3/HeuristicLab.Data-3.3.csproj
r13695 r14597 108 108 </PropertyGroup> 109 109 <ItemGroup> 110 <Reference Include="Microsoft.CSharp" /> 110 111 <Reference Include="System" /> 111 112 <Reference Include="System.Core">
Note: See TracChangeset
for help on using the changeset viewer.