Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimizer/3.3/OptimizerMainForm.cs @ 3741

Last change on this file since 3741 was 3741, checked in by swagner, 14 years ago

Implemented reviewers' comments (#893)

  • added "Do you want to close Optimizer" dialog
File size: 5.2 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.ComponentModel;
24using System.Linq;
25using System.Reflection;
26using System.Windows.Forms;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Core.Views;
30using HeuristicLab.MainForm;
31using HeuristicLab.MainForm.WindowsForms;
32
33namespace HeuristicLab.Optimizer {
34  internal partial class OptimizerMainForm : DockingMainForm {
35    private string title;
36    private int appStartingCursors;
37    private int waitingCursors;
38
39    private Clipboard<IItem> clipboard;
40    public Clipboard<IItem> Clipboard {
41      get { return clipboard; }
42    }
43
44    public OptimizerMainForm()
45      : base() {
46      InitializeComponent();
47      appStartingCursors = 0;
48      waitingCursors = 0;
49    }
50    public OptimizerMainForm(Type userInterfaceItemType)
51      : base(userInterfaceItemType) {
52      InitializeComponent();
53      appStartingCursors = 0;
54      waitingCursors = 0;
55    }
56    public OptimizerMainForm(Type userInterfaceItemType, bool showContentInViewHost)
57      : this(userInterfaceItemType) {
58      this.ShowContentInViewHost = showContentInViewHost;
59    }
60
61    protected override void OnInitialized(EventArgs e) {
62      base.OnInitialized(e);
63      AssemblyFileVersionAttribute version = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).
64                                             Cast<AssemblyFileVersionAttribute>().FirstOrDefault();
65      title = "HeuristicLab Optimizer";
66      if (version != null) title += " " + version.Version;
67      Title = title;
68
69      ContentManager.Initialize(new PersistenceContentManager());
70
71      clipboard = new Clipboard<IItem>();
72      clipboard.Dock = DockStyle.Left;
73      if (Properties.Settings.Default.ShowClipboard) {
74        clipboard.Show();
75      }
76      if (Properties.Settings.Default.ShowOperatorsSidebar) {
77        OperatorsSidebar operatorsSidebar = new OperatorsSidebar();
78        operatorsSidebar.Dock = DockStyle.Left;
79        operatorsSidebar.Show();
80      }
81      if (Properties.Settings.Default.ShowStartPage) {
82        StartPage startPage = new StartPage();
83        startPage.Show();
84      }
85    }
86
87    protected override void OnClosing(CancelEventArgs e) {
88      base.OnClosing(e);
89      if (MainFormManager.MainForm.Views.OfType<IContentView>().FirstOrDefault() != null) {
90        if (MessageBox.Show(this, "Some views are still opened. If their content has not been saved, it will be lost after closing. Do you really want to close HeuristicLab Optimizer?", "Close Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No)
91          e.Cancel = true;
92      }
93    }
94
95    protected override void OnActiveViewChanged() {
96      base.OnActiveViewChanged();
97      UpdateTitle();
98    }
99
100    public void UpdateTitle() {
101      if (InvokeRequired)
102        Invoke(new Action(UpdateTitle));
103      else {
104        IContentView activeView = ActiveView as IContentView;
105        if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IStorableContent)) {
106          IStorableContent content = (IStorableContent)activeView.Content;
107          Title = title + " [" + (string.IsNullOrEmpty(content.Filename) ? "Unsaved" : content.Filename) + "]";
108        } else {
109          Title = title;
110        }
111      }
112    }
113
114    #region Cursor Handling
115    public void SetAppStartingCursor() {
116      if (InvokeRequired)
117        Invoke(new Action(SetAppStartingCursor));
118      else {
119        appStartingCursors++;
120        SetCursor();
121      }
122    }
123    public void ResetAppStartingCursor() {
124      if (InvokeRequired)
125        Invoke(new Action(ResetAppStartingCursor));
126      else {
127        appStartingCursors--;
128        SetCursor();
129      }
130    }
131    public void SetWaitCursor() {
132      if (InvokeRequired)
133        Invoke(new Action(SetWaitCursor));
134      else {
135        waitingCursors++;
136        SetCursor();
137      }
138    }
139    public void ResetWaitCursor() {
140      if (InvokeRequired)
141        Invoke(new Action(ResetWaitCursor));
142      else {
143        waitingCursors--;
144        SetCursor();
145      }
146    }
147    private void SetCursor() {
148      if (waitingCursors > 0) Cursor = Cursors.WaitCursor;
149      else if (appStartingCursors > 0) Cursor = Cursors.AppStarting;
150      else Cursor = Cursors.Default;
151    }
152    #endregion
153  }
154}
Note: See TracBrowser for help on using the repository browser.