Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimizer/3.3/OptimizerMultipleDocumentMainForm.cs @ 6827

Last change on this file since 6827 was 6827, checked in by ascheibe, 13 years ago

#1652

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