[2655] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12009] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2655] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.ComponentModel;
|
---|
| 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.MainForm;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Core.Views {
|
---|
[2917] | 28 | [View("NamedItem View")]
|
---|
[2790] | 29 | [Content(typeof(NamedItem), false)]
|
---|
[2727] | 30 | [Content(typeof(INamedItem), false)]
|
---|
[2664] | 31 | public partial class NamedItemView : ItemView {
|
---|
[5832] | 32 | private const string infoLabelToolTipSuffix = "Double-click to open description editor.";
|
---|
| 33 |
|
---|
[2727] | 34 | public new INamedItem Content {
|
---|
| 35 | get { return (INamedItem)base.Content; }
|
---|
[2713] | 36 | set { base.Content = value; }
|
---|
[2655] | 37 | }
|
---|
| 38 |
|
---|
[2664] | 39 | public NamedItemView() {
|
---|
[2655] | 40 | InitializeComponent();
|
---|
[2676] | 41 | errorProvider.SetIconAlignment(nameTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
| 42 | errorProvider.SetIconPadding(nameTextBox, 2);
|
---|
[2655] | 43 | }
|
---|
| 44 |
|
---|
[2713] | 45 | protected override void DeregisterContentEvents() {
|
---|
| 46 | Content.NameChanged -= new EventHandler(Content_NameChanged);
|
---|
| 47 | Content.DescriptionChanged -= new EventHandler(Content_DescriptionChanged);
|
---|
| 48 | base.DeregisterContentEvents();
|
---|
[2655] | 49 | }
|
---|
[2713] | 50 | protected override void RegisterContentEvents() {
|
---|
| 51 | base.RegisterContentEvents();
|
---|
| 52 | Content.NameChanged += new EventHandler(Content_NameChanged);
|
---|
| 53 | Content.DescriptionChanged += new EventHandler(Content_DescriptionChanged);
|
---|
[2655] | 54 | }
|
---|
| 55 |
|
---|
[2713] | 56 | protected override void OnContentChanged() {
|
---|
| 57 | base.OnContentChanged();
|
---|
| 58 | if (Content == null) {
|
---|
[3454] | 59 | nameTextBox.Text = string.Empty;
|
---|
[5832] | 60 | toolTip.SetToolTip(infoLabel, string.Empty);
|
---|
[3764] | 61 | if (ViewAttribute.HasViewAttribute(this.GetType()))
|
---|
| 62 | this.Caption = ViewAttribute.GetViewName(this.GetType());
|
---|
| 63 | else
|
---|
| 64 | this.Caption = "NamedItem View";
|
---|
[2655] | 65 | } else {
|
---|
[2713] | 66 | nameTextBox.Text = Content.Name;
|
---|
[5833] | 67 | toolTip.SetToolTip(infoLabel, string.IsNullOrEmpty(Content.Description) ? infoLabelToolTipSuffix : Content.Description + Environment.NewLine + Environment.NewLine + infoLabelToolTipSuffix);
|
---|
[3764] | 68 | Caption = Content.Name;
|
---|
[2655] | 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[3904] | 72 | protected override void SetEnabledStateOfControls() {
|
---|
| 73 | base.SetEnabledStateOfControls();
|
---|
[3350] | 74 | if (Content == null) {
|
---|
| 75 | nameTextBox.Enabled = false;
|
---|
[5832] | 76 | infoLabel.Enabled = false;
|
---|
[3350] | 77 | } else {
|
---|
| 78 | nameTextBox.Enabled = true;
|
---|
[5832] | 79 | nameTextBox.ReadOnly = ReadOnly || !Content.CanChangeName;
|
---|
| 80 | infoLabel.Enabled = true;
|
---|
[3350] | 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[2713] | 84 | protected virtual void Content_NameChanged(object sender, EventArgs e) {
|
---|
[2655] | 85 | if (InvokeRequired)
|
---|
[2713] | 86 | Invoke(new EventHandler(Content_NameChanged), sender, e);
|
---|
[3764] | 87 | else {
|
---|
[2713] | 88 | nameTextBox.Text = Content.Name;
|
---|
[3764] | 89 | Caption = Content.Name;
|
---|
| 90 | }
|
---|
[2655] | 91 | }
|
---|
[2713] | 92 | protected virtual void Content_DescriptionChanged(object sender, EventArgs e) {
|
---|
[2655] | 93 | if (InvokeRequired)
|
---|
[2713] | 94 | Invoke(new EventHandler(Content_DescriptionChanged), sender, e);
|
---|
[2917] | 95 | else {
|
---|
[5833] | 96 | toolTip.SetToolTip(infoLabel, string.IsNullOrEmpty(Content.Description) ? infoLabelToolTipSuffix : Content.Description + Environment.NewLine + Environment.NewLine + infoLabelToolTipSuffix);
|
---|
[2917] | 97 | }
|
---|
[2655] | 98 | }
|
---|
| 99 |
|
---|
| 100 | protected virtual void nameTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
[2916] | 101 | if ((Content != null) && (Content.CanChangeName)) {
|
---|
[3764] | 102 | if (string.IsNullOrEmpty(nameTextBox.Text)) {
|
---|
| 103 | e.Cancel = true;
|
---|
| 104 | errorProvider.SetError(nameTextBox, "Name cannot be empty");
|
---|
| 105 | nameTextBox.SelectAll();
|
---|
| 106 | return;
|
---|
| 107 | }
|
---|
[2713] | 108 | Content.Name = nameTextBox.Text;
|
---|
[2655] | 109 | // check if variable name was set successfully
|
---|
[2713] | 110 | if (!Content.Name.Equals(nameTextBox.Text)) {
|
---|
[2676] | 111 | e.Cancel = true;
|
---|
| 112 | errorProvider.SetError(nameTextBox, "Invalid Name");
|
---|
[2655] | 113 | nameTextBox.SelectAll();
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
[2676] | 117 | protected virtual void nameTextBox_Validated(object sender, EventArgs e) {
|
---|
| 118 | errorProvider.SetError(nameTextBox, string.Empty);
|
---|
| 119 | }
|
---|
| 120 | protected virtual void nameTextBox_KeyDown(object sender, KeyEventArgs e) {
|
---|
| 121 | if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
|
---|
| 122 | nameLabel.Focus(); // set focus on label to validate data
|
---|
| 123 | if (e.KeyCode == Keys.Escape) {
|
---|
[2713] | 124 | nameTextBox.Text = Content.Name;
|
---|
[2676] | 125 | nameLabel.Focus(); // set focus on label to validate data
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
[5832] | 128 | protected virtual void infoLabel_DoubleClick(object sender, EventArgs e) {
|
---|
| 129 | using (TextDialog dialog = new TextDialog("Description of " + Content.Name, Content.Description, ReadOnly || !Content.CanChangeDescription)) {
|
---|
[2917] | 130 | if (dialog.ShowDialog(this) == DialogResult.OK)
|
---|
| 131 | Content.Description = dialog.Content;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
[2655] | 134 | }
|
---|
| 135 | }
|
---|