Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/VariableValueView.cs @ 11569

Last change on this file since 11569 was 11171, checked in by ascheibe, 10 years ago

#2115 merged r11170 (copyright update) into trunk

File size: 5.3 KB
RevLine 
[2989]1#region License Information
2/* HeuristicLab
[11171]3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2989]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Windows.Forms;
24using HeuristicLab.MainForm;
25
26namespace HeuristicLab.Core.Views {
27  [View("Variable Value View")]
28  [Content(typeof(Variable), false)]
29  [Content(typeof(IVariable), false)]
30  public partial class VariableValueView : ItemView {
[7235]31    private const string infoLabelToolTipSuffix = "Double-click to open description editor.";
32
[2989]33    public new IVariable Content {
34      get { return (IVariable)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public VariableValueView() {
39      InitializeComponent();
40    }
41
42    protected override void DeregisterContentEvents() {
[7235]43      Content.NameChanged -= new EventHandler(Content_NameChanged);
44      Content.DescriptionChanged -= new EventHandler(Content_DescriptionChanged);
[2989]45      Content.ValueChanged -= new EventHandler(Content_ValueChanged);
46      base.DeregisterContentEvents();
47    }
48    protected override void RegisterContentEvents() {
49      base.RegisterContentEvents();
[7235]50      Content.NameChanged += new EventHandler(Content_NameChanged);
51      Content.DescriptionChanged += new EventHandler(Content_DescriptionChanged);
[2989]52      Content.ValueChanged += new EventHandler(Content_ValueChanged);
53    }
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
57      if (Content == null) {
58        viewHost.Content = null;
[7235]59        toolTip.SetToolTip(infoLabel, string.Empty);
60        if (ViewAttribute.HasViewAttribute(this.GetType()))
61          this.Caption = ViewAttribute.GetViewName(this.GetType());
62        else
63          this.Caption = "VariableValue View";
[2989]64      } else {
65        viewHost.ViewType = null;
66        viewHost.Content = Content.Value;
[7235]67        toolTip.SetToolTip(infoLabel, string.IsNullOrEmpty(Content.Description) ? infoLabelToolTipSuffix : Content.Description + Environment.NewLine + Environment.NewLine + infoLabelToolTipSuffix);
68        Caption = Content.Name;
[2989]69      }
70    }
71
[7235]72    protected override void SetEnabledStateOfControls() {
73      base.SetEnabledStateOfControls();
74      viewHost.Enabled = Content != null;
75      viewHost.ReadOnly = this.ReadOnly;
76      infoLabel.Enabled = Content != null;
77    }
78
79    protected virtual void Content_NameChanged(object sender, EventArgs e) {
80      if (InvokeRequired)
81        Invoke(new EventHandler(Content_NameChanged), sender, e);
82      else
83        Caption = Content.Name;
84    }
85    protected virtual void Content_DescriptionChanged(object sender, EventArgs e) {
86      if (InvokeRequired)
87        Invoke(new EventHandler(Content_DescriptionChanged), sender, e);
88      else
89        toolTip.SetToolTip(infoLabel, string.IsNullOrEmpty(Content.Description) ? infoLabelToolTipSuffix : Content.Description + Environment.NewLine + Environment.NewLine + infoLabelToolTipSuffix);
90    }
[2989]91    protected virtual void Content_ValueChanged(object sender, EventArgs e) {
92      if (InvokeRequired)
93        Invoke(new EventHandler(Content_ValueChanged), sender, e);
94      else {
95        viewHost.ViewType = null;
96        viewHost.Content = Content.Value;
97      }
98    }
99
[4445]100    protected virtual void VariableValueView_DragEnterOver(object sender, DragEventArgs e) {
[2989]101      e.Effect = DragDropEffects.None;
[5837]102      if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IItem)) {
[3694]103        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
[2989]104        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
[5744]105        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
106        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
107        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
[2989]108      }
109    }
[4445]110    protected virtual void VariableValueView_DragDrop(object sender, DragEventArgs e) {
[2989]111      if (e.Effect != DragDropEffects.None) {
[5837]112        IItem item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IItem;
[5744]113        if (e.Effect.HasFlag(DragDropEffects.Copy)) item = (IItem)item.Clone();
[2989]114        Content.Value = item;
115      }
116    }
[7235]117    protected virtual void infoLabel_DoubleClick(object sender, EventArgs e) {
118      using (TextDialog dialog = new TextDialog("Description of " + Content.Name, Content.Description, ReadOnly || !Content.CanChangeDescription)) {
119        if (dialog.ShowDialog(this) == DialogResult.OK)
120          Content.Description = dialog.Content;
121      }
122    }
[2989]123  }
124}
Note: See TracBrowser for help on using the repository browser.