Changeset 15117
- Timestamp:
- 07/03/17 23:04:37 (7 years ago)
- Location:
- stable
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 14597,15009-15010
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Data.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Data.Views merged: 14597,15009-15010
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Data.Views/3.3
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Data.Views/3.3 merged: 14597,15009-15010
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Data.Views/3.3/EnumValueView.Designer.cs
r14186 r15117 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 } -
stable/HeuristicLab.Data.Views/3.3/EnumValueView.cs
r14186 r15117 21 21 22 22 using System; 23 using System.Windows.Forms; 23 24 using HeuristicLab.Core.Views; 24 25 using HeuristicLab.MainForm; … … 42 43 } 43 44 45 static EnumValueView() { 46 if (!typeof(T).IsEnum) 47 throw new InvalidOperationException("Generic type " + typeof(T).Name + " is not an enum."); 48 } 49 44 50 public EnumValueView() { 45 51 InitializeComponent(); 52 this.Caption = typeof(T).Name + " View"; 53 46 54 valueComboBox.DataSource = Enum.GetValues(typeof(T)); 47 this.Name = typeof(T).Name + "EnumView"; 55 foreach (T flag in Enum.GetValues(typeof(T))) 56 flagsListView.Items.Add(new ListViewItem(flag.ToString()) { Tag = flag }); 57 columnHeader.Width = -1; 58 59 bool isFlags = Attribute.IsDefined(typeof(T), typeof(FlagsAttribute)); 60 if (isFlags) valueLabel.Text = "Flags:"; 61 valueComboBox.Visible = !isFlags; 62 flagsListView.Visible = isFlags; 48 63 } 49 64 public EnumValueView(EnumValue<T> content) … … 64 79 protected override void OnContentChanged() { 65 80 base.OnContentChanged(); 66 if (Content == null) 67 valueComboBox.Enabled = false; 68 else 81 if (Content == null) { 82 valueComboBox.SelectedIndex = -1; 83 foreach (ListViewItem item in flagsListView.Items) 84 item.Checked = false; 85 } else { 69 86 valueComboBox.SelectedItem = Content.Value; 87 foreach (ListViewItem item in flagsListView.Items) { 88 var flag = (Enum)item.Tag; 89 item.Checked = ((Enum)(object)Content.Value).HasFlag(flag); 90 } 91 } 70 92 } 71 93 72 94 protected override void SetEnabledStateOfControls() { 73 95 base.SetEnabledStateOfControls(); 74 if (Content == null) valueComboBox.Enabled = false; 75 else valueComboBox.Enabled = !ReadOnly; 96 if (Content == null) { 97 valueComboBox.Enabled = false; 98 flagsListView.Enabled = false; 99 } else { 100 valueComboBox.Enabled = !ReadOnly; 101 flagsListView.Enabled = !ReadOnly; 102 } 76 103 } 77 104 … … 79 106 if (InvokeRequired) 80 107 Invoke(new EventHandler(Content_ValueChanged), sender, e); 81 else 108 else { 82 109 valueComboBox.SelectedItem = Content.Value; 110 foreach (ListViewItem item in flagsListView.Items) { 111 var flag = (Enum)item.Tag; 112 item.Checked = ((Enum)(object)Content.Value).HasFlag(flag); 113 } 114 } 83 115 } 84 116 … … 87 119 Content.Value = (T)valueComboBox.SelectedItem; 88 120 } 121 122 private void flagsListView_ItemChecked(object sender, ItemCheckedEventArgs e) { 123 var flag = (T)e.Item.Tag; 124 if ((Content != null) && !Content.ReadOnly) 125 Content.Value = ((Enum)(object)Content.Value).SetFlag(flag, e.Item.Checked); 126 } 127 } 128 129 internal static class EnumHelper { 130 //https://stackoverflow.com/a/21581418 131 public static T SetFlag<T>(this Enum value, T flag, bool set) { 132 var baseType = Enum.GetUnderlyingType(value.GetType()); 133 dynamic valueAsBase = Convert.ChangeType(value, baseType); 134 dynamic flagAsBase = Convert.ChangeType(flag, baseType); 135 if (set) 136 valueAsBase |= flagAsBase; 137 else 138 valueAsBase &= ~flagAsBase; 139 return (T)valueAsBase; 140 } 89 141 } 90 142 } -
stable/HeuristicLab.Data.Views/3.3/HeuristicLab.Data.Views-3.3.csproj
r13637 r15117 105 105 </PropertyGroup> 106 106 <ItemGroup> 107 <Reference Include="Microsoft.CSharp" /> 107 108 <Reference Include="System" /> 108 109 <Reference Include="System.Core"> -
stable/HeuristicLab.Data/3.3
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Data/3.3 merged: 14597,15009
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Data/3.3/EnumValue.cs
r14186 r15117 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
Note: See TracChangeset
for help on using the changeset viewer.