[3437] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3437] | 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;
|
---|
[13458] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
[3437] | 25 | using System.Windows.Forms;
|
---|
[13458] | 26 | using HeuristicLab.Common;
|
---|
[3437] | 27 | using WeifenLuo.WinFormsUI.Docking;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.MainForm.WindowsForms {
|
---|
| 30 | /// <summary>
|
---|
| 31 | /// Displays the used view.
|
---|
| 32 | /// </summary>
|
---|
| 33 | internal partial class DockForm : DockContent {
|
---|
| 34 | public DockForm(IView view) {
|
---|
| 35 | InitializeComponent();
|
---|
| 36 | this.view = view;
|
---|
| 37 | if (view != null) {
|
---|
| 38 | if (view is UserControl) {
|
---|
| 39 | switch (((UserControl)view).Dock) {
|
---|
| 40 | case DockStyle.Left:
|
---|
| 41 | this.ShowHint = DockState.DockLeft;
|
---|
| 42 | break;
|
---|
| 43 | case DockStyle.Right:
|
---|
| 44 | this.ShowHint = DockState.DockRight;
|
---|
| 45 | break;
|
---|
| 46 | case DockStyle.Top:
|
---|
| 47 | this.ShowHint = DockState.DockTop;
|
---|
| 48 | break;
|
---|
| 49 | case DockStyle.Bottom:
|
---|
| 50 | this.ShowHint = DockState.DockBottom;
|
---|
| 51 | break;
|
---|
| 52 | }
|
---|
[3644] | 53 | Sidebar sidebar = view as Sidebar;
|
---|
| 54 | if (sidebar != null) {
|
---|
| 55 | if (sidebar.Collapsed)
|
---|
| 56 | this.ShowHint = DockState.DockLeftAutoHide;
|
---|
| 57 | else
|
---|
| 58 | this.ShowHint = DockState.DockLeft;
|
---|
[3571] | 59 | this.DockAreas = DockAreas.DockLeft | DockAreas.DockRight;
|
---|
[3644] | 60 | }
|
---|
[3571] | 61 |
|
---|
[3437] | 62 | Type viewType = view.GetType();
|
---|
| 63 | Control control = (Control)view;
|
---|
| 64 | control.Dock = DockStyle.Fill;
|
---|
| 65 | this.view.CaptionChanged += new EventHandler(View_CaptionChanged);
|
---|
| 66 | UpdateText();
|
---|
| 67 | viewPanel.Controls.Add(control);
|
---|
| 68 | }
|
---|
| 69 | } else {
|
---|
| 70 | Label errorLabel = new Label();
|
---|
| 71 | errorLabel.Name = "errorLabel";
|
---|
| 72 | errorLabel.Text = "No view available";
|
---|
| 73 | errorLabel.AutoSize = false;
|
---|
| 74 | errorLabel.Dock = DockStyle.Fill;
|
---|
| 75 | viewPanel.Controls.Add(errorLabel);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
[5237] | 78 |
|
---|
| 79 | protected override void Dispose(bool disposing) {
|
---|
| 80 | if (View != null)
|
---|
| 81 | View.CaptionChanged -= new System.EventHandler(View_CaptionChanged);
|
---|
| 82 | if (disposing && (components != null)) {
|
---|
| 83 | components.Dispose();
|
---|
| 84 | }
|
---|
| 85 | base.Dispose(disposing);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[3437] | 88 | private IView view;
|
---|
| 89 | public IView View {
|
---|
| 90 | get { return this.view; }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | private void UpdateText() {
|
---|
| 94 | if (InvokeRequired)
|
---|
| 95 | Invoke(new MethodInvoker(UpdateText));
|
---|
| 96 | else
|
---|
| 97 | this.Text = this.View.Caption;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[3644] | 100 | protected override void OnDockStateChanged(EventArgs e) {
|
---|
| 101 | base.OnDockStateChanged(e);
|
---|
| 102 | Sidebar sidebar = view as Sidebar;
|
---|
| 103 | if (sidebar != null) {
|
---|
| 104 | if (this.DockState == DockState.DockLeftAutoHide || this.DockState == DockState.DockRightAutoHide)
|
---|
| 105 | sidebar.Collapsed = true;
|
---|
| 106 | else
|
---|
| 107 | sidebar.Collapsed = false;
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[3437] | 111 | #region View Events
|
---|
| 112 | private void View_CaptionChanged(object sender, EventArgs e) {
|
---|
| 113 | UpdateText();
|
---|
| 114 | }
|
---|
| 115 | #endregion
|
---|
[13458] | 116 |
|
---|
| 117 | #region Context Menu Events
|
---|
[13614] | 118 | private void contextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
| 119 | var contentView = View as IContentView;
|
---|
| 120 | var content = contentView != null ? contentView.Content : null;
|
---|
| 121 |
|
---|
| 122 | cloneToolStripMenuItem.Enabled = contentView != null && !contentView.Locked && content is IDeepCloneable;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[13458] | 125 | private void closeToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 126 | Close();
|
---|
| 127 | }
|
---|
| 128 | private void closeAllToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
[13614] | 129 | foreach (var dockForm in CurrentDockForms) {
|
---|
[13458] | 130 | dockForm.Close();
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 | private void closeAllButThisToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
[13614] | 134 | foreach (var dockForm in CurrentDockForms.Except(this.ToEnumerable())) {
|
---|
[13458] | 135 | dockForm.Close();
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 | private IEnumerable<DockForm> CurrentDockForms {
|
---|
| 139 | get {
|
---|
[13614] | 140 | var dockForms = Pane.Contents.OfType<DockForm>().Where(c => c.Pane == Pane); // Pane.Contents contains DockForms that are not placed on that pane
|
---|
| 141 | return dockForms.ToList(); // .ToList() necessary because closing a DockForm removes it from the Content collection
|
---|
[13458] | 142 | }
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | private void cloneToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 146 | var contentView = View as IContentView;
|
---|
| 147 | if (contentView == null) return;
|
---|
| 148 |
|
---|
| 149 | var cloneable = contentView.Content as IDeepCloneable;
|
---|
| 150 | if (cloneable == null) return;
|
---|
| 151 |
|
---|
| 152 | var clone = (IContent)cloneable.Clone();
|
---|
[13614] | 153 |
|
---|
| 154 | var viewHost = contentView as ViewHost;
|
---|
| 155 | var newView = viewHost != null ? viewHost.ViewType : contentView.GetType();
|
---|
| 156 | MainFormManager.MainForm.ShowContent(clone, newView);
|
---|
[13458] | 157 | }
|
---|
| 158 | #endregion
|
---|
[3437] | 159 | }
|
---|
| 160 | }
|
---|