Free cookie consent management tool by TermsFeed Policy Generator

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

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

Updated year of copyrights (#1406)

File size: 6.0 KB
RevLine 
[2790]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2790]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;
[3741]23using System.ComponentModel;
[2931]24using System.Linq;
[2547]25using System.Reflection;
26using System.Windows.Forms;
[3376]27using HeuristicLab.Common;
[3298]28using HeuristicLab.Core;
[2790]29using HeuristicLab.Core.Views;
[2547]30using HeuristicLab.MainForm;
31using HeuristicLab.MainForm.WindowsForms;
32
33namespace HeuristicLab.Optimizer {
34  internal partial class OptimizerMainForm : DockingMainForm {
[3483]35    private string title;
36    private int appStartingCursors;
37    private int waitingCursors;
38
[3298]39    private Clipboard<IItem> clipboard;
40    public Clipboard<IItem> Clipboard {
[3292]41      get { return clipboard; }
42    }
43
[2547]44    public OptimizerMainForm()
45      : base() {
46      InitializeComponent();
[3483]47      appStartingCursors = 0;
48      waitingCursors = 0;
[2547]49    }
50    public OptimizerMainForm(Type userInterfaceItemType)
51      : base(userInterfaceItemType) {
52      InitializeComponent();
[3483]53      appStartingCursors = 0;
54      waitingCursors = 0;
[2547]55    }
[3557]56    public OptimizerMainForm(Type userInterfaceItemType, bool showContentInViewHost)
[3394]57      : this(userInterfaceItemType) {
[3557]58      this.ShowContentInViewHost = showContentInViewHost;
[3394]59    }
[2547]60
[2791]61    protected override void OnInitialized(EventArgs e) {
62      base.OnInitialized(e);
[2931]63      AssemblyFileVersionAttribute version = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).
64                                             Cast<AssemblyFileVersionAttribute>().FirstOrDefault();
[3483]65      title = "HeuristicLab Optimizer";
66      if (version != null) title += " " + version.Version;
67      Title = title;
[3292]68
[3483]69      ContentManager.Initialize(new PersistenceContentManager());
70
[3298]71      clipboard = new Clipboard<IItem>();
[3292]72      clipboard.Dock = DockStyle.Left;
[3768]73      clipboard.Collapsed = Properties.Settings.Default.CollapseClipboard;
[3292]74      if (Properties.Settings.Default.ShowClipboard) {
75        clipboard.Show();
76      }
[3290]77      if (Properties.Settings.Default.ShowOperatorsSidebar) {
78        OperatorsSidebar operatorsSidebar = new OperatorsSidebar();
79        operatorsSidebar.Dock = DockStyle.Left;
80        operatorsSidebar.Show();
[3768]81        operatorsSidebar.Collapsed = Properties.Settings.Default.CollapseOperatorsSidebar;
[3290]82      }
[3163]83      if (Properties.Settings.Default.ShowStartPage) {
84        StartPage startPage = new StartPage();
85        startPage.Show();
86      }
[3794]87
88      WindowState = Properties.Settings.Default.ShowMaximized ? FormWindowState.Maximized : FormWindowState.Normal;
[2547]89    }
[3483]90
[3741]91    protected override void OnClosing(CancelEventArgs e) {
92      base.OnClosing(e);
93      if (MainFormManager.MainForm.Views.OfType<IContentView>().FirstOrDefault() != null) {
94        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)
95          e.Cancel = true;
96      }
97    }
[3768]98    protected override void OnClosed(EventArgs e) {
99      base.OnClosed(e);
100      Properties.Settings.Default.ShowMaximized = WindowState == FormWindowState.Maximized;
101      Properties.Settings.Default.CollapseClipboard = clipboard.Collapsed;
102      OperatorsSidebar operatorsSidebar = MainFormManager.MainForm.Views.OfType<OperatorsSidebar>().FirstOrDefault();
103      if (operatorsSidebar != null) Properties.Settings.Default.CollapseOperatorsSidebar = operatorsSidebar.Collapsed;
104      Properties.Settings.Default.Save();
105    }
[3741]106
[3483]107    protected override void OnActiveViewChanged() {
108      base.OnActiveViewChanged();
109      UpdateTitle();
110    }
111
112    public void UpdateTitle() {
113      if (InvokeRequired)
114        Invoke(new Action(UpdateTitle));
115      else {
116        IContentView activeView = ActiveView as IContentView;
117        if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IStorableContent)) {
118          IStorableContent content = (IStorableContent)activeView.Content;
119          Title = title + " [" + (string.IsNullOrEmpty(content.Filename) ? "Unsaved" : content.Filename) + "]";
120        } else {
121          Title = title;
122        }
123      }
124    }
125
126    #region Cursor Handling
127    public void SetAppStartingCursor() {
128      if (InvokeRequired)
129        Invoke(new Action(SetAppStartingCursor));
130      else {
131        appStartingCursors++;
132        SetCursor();
133      }
134    }
135    public void ResetAppStartingCursor() {
136      if (InvokeRequired)
137        Invoke(new Action(ResetAppStartingCursor));
138      else {
139        appStartingCursors--;
140        SetCursor();
141      }
142    }
143    public void SetWaitCursor() {
144      if (InvokeRequired)
145        Invoke(new Action(SetWaitCursor));
146      else {
147        waitingCursors++;
148        SetCursor();
149      }
150    }
151    public void ResetWaitCursor() {
152      if (InvokeRequired)
153        Invoke(new Action(ResetWaitCursor));
154      else {
155        waitingCursors--;
156        SetCursor();
157      }
158    }
159    private void SetCursor() {
160      if (waitingCursors > 0) Cursor = Cursors.WaitCursor;
161      else if (appStartingCursors > 0) Cursor = Cursors.AppStarting;
162      else Cursor = Cursors.Default;
163    }
164    #endregion
[2547]165  }
166}
Note: See TracBrowser for help on using the repository browser.