Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimizer/3.3/OptimizerSingleDocumentMainForm.cs @ 8012

Last change on this file since 8012 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 4.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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 OptimizerSingleDocumentMainForm : SingleDocumentMainForm {
35    private string title;
36
37    private Clipboard<IItem> clipboard;
38    public Clipboard<IItem> Clipboard {
39      get { return clipboard; }
40    }
41
42    public OptimizerSingleDocumentMainForm()
43      : base() {
44      InitializeComponent();
45    }
46    public OptimizerSingleDocumentMainForm(Type userInterfaceItemType)
47      : base(userInterfaceItemType) {
48      InitializeComponent();
49    }
50    public OptimizerSingleDocumentMainForm(Type userInterfaceItemType, bool showContentInViewHost)
51      : this(userInterfaceItemType) {
52      this.ShowContentInViewHost = showContentInViewHost;
53    }
54
55    protected override void OnInitialized(EventArgs e) {
56      base.OnInitialized(e);
57
58      AssemblyFileVersionAttribute version = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).
59                                         Cast<AssemblyFileVersionAttribute>().FirstOrDefault();
60      title = "HeuristicLab Optimizer";
61      if (version != null) title += " " + version.Version;
62      Title = title;
63
64      ContentManager.Initialize(new PersistenceContentManager());
65
66      clipboard = new Clipboard<IItem>();
67      clipboard.Dock = DockStyle.Left;
68      clipboard.Collapsed = Properties.Settings.Default.CollapseClipboard;
69      if (Properties.Settings.Default.ShowClipboard) {
70        clipboard.Show();
71      }
72      if (Properties.Settings.Default.ShowOperatorsSidebar) {
73        OperatorsSidebar operatorsSidebar = new OperatorsSidebar();
74        operatorsSidebar.Dock = DockStyle.Left;
75        operatorsSidebar.Show();
76        operatorsSidebar.Collapsed = Properties.Settings.Default.CollapseOperatorsSidebar;
77      }
78      if (Properties.Settings.Default.ShowStartPage) {
79        StartPage startPage = new StartPage();
80        startPage.Show();
81      }
82
83      WindowState = Properties.Settings.Default.ShowMaximized ? FormWindowState.Maximized : FormWindowState.Normal;
84    }
85
86    protected override void OnClosing(CancelEventArgs e) {
87      base.OnClosing(e);
88      if (MainFormManager.MainForm.Views.OfType<IContentView>().FirstOrDefault() != null) {
89        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)
90          e.Cancel = true;
91      }
92    }
93    protected override void OnClosed(EventArgs e) {
94      base.OnClosed(e);
95      Properties.Settings.Default.ShowMaximized = WindowState == FormWindowState.Maximized;
96      Properties.Settings.Default.CollapseClipboard = clipboard.Collapsed;
97      OperatorsSidebar operatorsSidebar = MainFormManager.MainForm.Views.OfType<OperatorsSidebar>().FirstOrDefault();
98      if (operatorsSidebar != null) Properties.Settings.Default.CollapseOperatorsSidebar = operatorsSidebar.Collapsed;
99      Properties.Settings.Default.Save();
100    }
101
102    protected override void OnActiveViewChanged() {
103      base.OnActiveViewChanged();
104      UpdateTitle();
105    }
106
107    public override void UpdateTitle() {
108      if (InvokeRequired)
109        Invoke(new Action(UpdateTitle));
110      else {
111        IContentView activeView = ActiveView as IContentView;
112        if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IStorableContent)) {
113          IStorableContent content = (IStorableContent)activeView.Content;
114          Title = title + " [" + (string.IsNullOrEmpty(content.Filename) ? "Unsaved" : content.Filename) + "]";
115        } else {
116          Title = title;
117        }
118      }
119    }
120  }
121}
Note: See TracBrowser for help on using the repository browser.