[6827] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16565] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6827] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.ComponentModel;
|
---|
| 24 | using System.Linq;
|
---|
[7013] | 25 | using System.Reflection;
|
---|
[6827] | 26 | using System.Windows.Forms;
|
---|
| 27 | using HeuristicLab.Common;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
| 29 | using HeuristicLab.Core.Views;
|
---|
| 30 | using HeuristicLab.MainForm;
|
---|
| 31 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Optimizer {
|
---|
| 34 | internal partial class OptimizerMultipleDocumentMainForm : MultipleDocumentMainForm {
|
---|
[7013] | 35 | private string title;
|
---|
[6827] | 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 |
|
---|
[7013] | 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 |
|
---|
[6827] | 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);
|
---|
[10498] | 86 | if (MainFormManager.MainForm.Views.OfType<IContentView>().Any(v => v.Content is IStorableContent)) {
|
---|
[6827] | 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 | }
|
---|
[7013] | 103 |
|
---|
| 104 | public override void UpdateTitle() {
|
---|
| 105 | if (InvokeRequired)
|
---|
| 106 | Invoke(new Action(UpdateTitle));
|
---|
| 107 | else {
|
---|
| 108 | IContentView activeView = ActiveView as IContentView;
|
---|
[10498] | 109 | if ((activeView != null) && (activeView.Content is IStorableContent)) {
|
---|
[7013] | 110 | IStorableContent content = (IStorableContent)activeView.Content;
|
---|
| 111 | Title = title + " [" + (string.IsNullOrEmpty(content.Filename) ? "Unsaved" : content.Filename) + "]";
|
---|
| 112 | } else {
|
---|
| 113 | Title = title;
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
[11470] | 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 | }
|
---|
[6827] | 130 | }
|
---|
| 131 | }
|
---|