Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15117


Ignore:
Timestamp:
07/03/17 23:04:37 (7 years ago)
Author:
mkommend
Message:

#2724: Merged r14597, r15009, r15010 into stable.

Location:
stable
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Data.Views

  • stable/HeuristicLab.Data.Views/3.3

  • stable/HeuristicLab.Data.Views/3.3/EnumValueView.Designer.cs

    r14186 r15117  
    4747      this.valueLabel = new System.Windows.Forms.Label();
    4848      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()));
    4951      this.SuspendLayout();
    5052      //
     
    5456      this.valueLabel.Location = new System.Drawing.Point(3, 3);
    5557      this.valueLabel.Name = "valueLabel";
    56       this.valueLabel.Size = new System.Drawing.Size(56, 13);
     58      this.valueLabel.Size = new System.Drawing.Size(37, 13);
    5759      this.valueLabel.TabIndex = 0;
    5860      this.valueLabel.Text = "&Value:";
     
    6062      // valueComboBox
    6163      //
    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) 
    6365            | System.Windows.Forms.AnchorStyles.Right)));
    6466      this.valueComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     
    7173      this.valueComboBox.SelectedIndexChanged += new System.EventHandler(this.valueComboBox_SelectedIndexChanged);
    7274      //
     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      //
    7396      // EnumValueView
    7497      //
    75       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    7698      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     99      this.Controls.Add(this.flagsListView);
    77100      this.Controls.Add(this.valueComboBox);
    78101      this.Controls.Add(this.valueLabel);
     
    81104      this.ResumeLayout(false);
    82105      this.PerformLayout();
     106
    83107    }
    84108
     
    87111    private System.Windows.Forms.Label valueLabel;
    88112    private System.Windows.Forms.ComboBox valueComboBox;
     113    private System.Windows.Forms.ListView flagsListView;
     114    private System.Windows.Forms.ColumnHeader columnHeader;
    89115  }
    90116}
  • stable/HeuristicLab.Data.Views/3.3/EnumValueView.cs

    r14186 r15117  
    2121
    2222using System;
     23using System.Windows.Forms;
    2324using HeuristicLab.Core.Views;
    2425using HeuristicLab.MainForm;
     
    4243    }
    4344
     45    static EnumValueView() {
     46      if (!typeof(T).IsEnum)
     47        throw new InvalidOperationException("Generic type " + typeof(T).Name + " is not an enum.");
     48    }
     49
    4450    public EnumValueView() {
    4551      InitializeComponent();
     52      this.Caption = typeof(T).Name + " View";
     53
    4654      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;
    4863    }
    4964    public EnumValueView(EnumValue<T> content)
     
    6479    protected override void OnContentChanged() {
    6580      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 {
    6986        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      }
    7092    }
    7193
    7294    protected override void SetEnabledStateOfControls() {
    7395      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      }
    76103    }
    77104
     
    79106      if (InvokeRequired)
    80107        Invoke(new EventHandler(Content_ValueChanged), sender, e);
    81       else
     108      else {
    82109        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      }
    83115    }
    84116
     
    87119        Content.Value = (T)valueComboBox.SelectedItem;
    88120    }
     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    }
    89141  }
    90142}
  • stable/HeuristicLab.Data.Views/3.3/HeuristicLab.Data.Views-3.3.csproj

    r13637 r15117  
    105105  </PropertyGroup>
    106106  <ItemGroup>
     107    <Reference Include="Microsoft.CSharp" />
    107108    <Reference Include="System" />
    108109    <Reference Include="System.Core">
  • stable/HeuristicLab.Data/3.3

  • stable/HeuristicLab.Data/3.3/EnumValue.cs

    r14186 r15117  
    5252    private EnumValue(EnumValue<T> original, Cloner cloner)
    5353      : base(original, cloner) {
    54       this.value = original.value;
    55       this.readOnly = original.readOnly;
    5654    }
    5755
Note: See TracChangeset for help on using the changeset viewer.