Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Optimizer/3.3/OptimizerMultipleDocumentMainForm.cs @ 15800

Last change on this file since 15800 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 5.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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
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
84    protected override void OnClosing(CancelEventArgs e) {
85      base.OnClosing(e);
86      if (MainFormManager.MainForm.Views.OfType<IContentView>().Any(v => v.Content is IStorableContent)) {
87        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)
88          e.Cancel = true;
89      }
90    }
91    protected override void OnClosed(EventArgs e) {
92      base.OnClosed(e);
93      Properties.Settings.Default.CollapseClipboard = clipboard.Collapsed;
94      OperatorsSidebar operatorsSidebar = MainFormManager.MainForm.Views.OfType<OperatorsSidebar>().FirstOrDefault();
95      if (operatorsSidebar != null) Properties.Settings.Default.CollapseOperatorsSidebar = operatorsSidebar.Collapsed;
96      Properties.Settings.Default.Save();
97    }
98
99    protected override void OnActiveViewChanged() {
100      base.OnActiveViewChanged();
101      UpdateTitle();
102    }
103
104    public override void UpdateTitle() {
105      if (InvokeRequired)
106        Invoke(new Action(UpdateTitle));
107      else {
108        IContentView activeView = ActiveView as IContentView;
109        if ((activeView != null) && (activeView.Content is IStorableContent)) {
110          IStorableContent content = (IStorableContent)activeView.Content;
111          Title = title + " [" + (string.IsNullOrEmpty(content.Filename) ? "Unsaved" : content.Filename) + "]";
112        } else {
113          Title = title;
114        }
115      }
116    }
117
118    private void optimizerMainForm_DragEnter(object sender, DragEventArgs e) {
119      // perform type checking to ensure that the data being dragged is of an acceptable type
120      e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;
121
122    }
123
124    private void optimizerMainForm_DragDrop(object sender, DragEventArgs e) {
125      if (e.Data.GetDataPresent(DataFormats.FileDrop)) {
126        string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
127        FileManager.OpenFiles(files);
128      }
129    }
130  }
131}
Note: See TracBrowser for help on using the repository browser.