source: branches/HeuristicLab.Data Path DataTypes/HeuristicLab.Data.Views/3.3/Path Views/FileValueView.cs @ 9697

Last change on this file since 9697 was 9697, checked in by mkommend, 8 years ago

#2081: Updated branches from trunk and implemented all review comments.

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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.Data.Views {
27  [View("FileValueView")]
28  [Content(typeof(FileValue), true)]
29  public partial class FileValueView : StringConvertibleValueView {
30    public new FileValue Content {
31      get { return (FileValue)base.Content; }
32      set { base.Content = value; }
33    }
34
35    public override bool ReadOnly {
36      get {
37        if ((Content != null) && Content.ReadOnly) return true;
38        return base.ReadOnly;
39      }
40      set { base.ReadOnly = value; }
41    }
42
43    public FileValueView() {
44      InitializeComponent();
45    }
46
47    protected override void RegisterContentEvents() {
48      base.RegisterContentEvents();
49      Content.FileOpenDialogFilterChanged += new EventHandler(Content_FileOpenDialogFilterChanged);
50    }
51    protected override void DeregisterContentEvents() {
52      Content.FileOpenDialogFilterChanged -= new EventHandler(Content_FileOpenDialogFilterChanged);
53      base.DeregisterContentEvents();
54    }
55    protected override void SetEnabledStateOfControls() {
56      base.SetEnabledStateOfControls();
57      valueTextBox.Enabled = !Locked && !ReadOnly && Content != null;
58      valueTextBox.ReadOnly = Locked || ReadOnly || Content == null;
59      openButton.Enabled = !Locked && !ReadOnly && Content != null;
60    }
61
62    protected override void OnContentChanged() {
63      base.OnContentChanged();
64      if (Content == null) {
65        valueTextBox.Text = string.Empty;
66        return;
67      }
68
69      valueTextBox.Text = Content.Value;
70      openButton.Enabled = !Content.ReadOnly;
71      openFileDialog.Filter = Content.FileDialogFilter;
72    }
73
74    protected virtual void Content_FileOpenDialogFilterChanged(object sender, EventArgs e) {
75      openFileDialog.Filter = Content.FileDialogFilter;
76    }
77
78    protected virtual void openButton_Click(object sender, EventArgs e) {
79      if (openFileDialog.ShowDialog(this) != DialogResult.OK) return;
80      Content.Value = openFileDialog.FileName;
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.