Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ContentView.cs @ 3229

Last change on this file since 3229 was 2961, checked in by swagner, 15 years ago

Refactored enabling and disabling of save buttons and menu items to prevent saving of running algorithms (#685)

File size: 2.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30
31namespace HeuristicLab.MainForm.WindowsForms {
32  public partial class ContentView : View, IContentView {
33    private object content;
34    public object Content {
35      get { return content; }
36      protected set {
37        if ((value != null) && (!MainFormManager.ViewCanViewObject(this, value)))
38          throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name));
39        if (InvokeRequired) {
40          Invoke(new Action<object>(delegate(object o) { this.Content = o; }), value);
41        } else {
42          if (this.content != value) {
43            if (this.content != null) this.DeregisterContentEvents();
44            this.content = value;
45            if (this.content != null) this.RegisterContentEvents();
46            this.OnContentChanged();
47          }
48        }
49      }
50    }
51    private bool saveEnabled;
52    public bool SaveEnabled {
53      get { return saveEnabled; }
54      protected set {
55        if (value != saveEnabled) {
56          saveEnabled = value;
57          OnChanged();
58        }
59      }
60    }
61
62    public ContentView()
63      : base() {
64      InitializeComponent();
65      saveEnabled = true;
66    }
67    public ContentView(object content)
68      : this() {
69      this.content = content;
70    }
71
72    /// <summary>
73    /// Adds eventhandlers to the current instance.
74    /// </summary>
75    protected virtual void RegisterContentEvents() {
76    }
77
78    /// <summary>
79    /// Removes the eventhandlers from the current instance.
80    /// </summary>
81    protected virtual void DeregisterContentEvents() {
82    }
83
84    /// <summary>
85    /// Is called when the content property changes.
86    /// </summary>
87    protected virtual void OnContentChanged() {
88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.