Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/08/16 15:26:41 (8 years ago)
Author:
mkommend
Message:

#1235: Merged r13458,r13614,r13627,r13628 into stable.

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/DockForm.cs

    r12009 r13883  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2325using System.Windows.Forms;
     26using HeuristicLab.Common;
    2427using WeifenLuo.WinFormsUI.Docking;
    2528
     
    2932  /// </summary>
    3033  internal partial class DockForm : DockContent {
    31     public DockForm(IView view) {
     34    public DockForm(IView view, bool allowContextMenu) {
    3235      InitializeComponent();
    3336      this.view = view;
     37      this.allowContextMenu = allowContextMenu;
     38
    3439      if (view != null) {
    3540        if (view is UserControl) {
     
    8792      get { return this.view; }
    8893    }
     94    private readonly bool allowContextMenu;
    8995
    9096    private void UpdateText() {
     
    111117    }
    112118    #endregion
     119
     120    #region Context Menu Events
     121    private void contextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
     122      if (!allowContextMenu) {
     123        e.Cancel = true;
     124        return;
     125      }
     126
     127      var contentView = View as IContentView;
     128      var content = contentView != null ? contentView.Content : null;
     129
     130      cloneToolStripMenuItem.Enabled = contentView != null && !contentView.Locked && content is IDeepCloneable;
     131    }
     132
     133    private void closeToolStripMenuItem_Click(object sender, EventArgs e) {
     134      Close();
     135    }
     136    private void closeAllToolStripMenuItem_Click(object sender, EventArgs e) {
     137      foreach (var dockForm in CurrentDockForms) {
     138        dockForm.Close();
     139      }
     140    }
     141    private void closeAllButThisToolStripMenuItem_Click(object sender, EventArgs e) {
     142      foreach (var dockForm in CurrentDockForms.Except(this.ToEnumerable())) {
     143        dockForm.Close();
     144      }
     145    }
     146    private IEnumerable<DockForm> CurrentDockForms {
     147      get {
     148        var dockForms = Pane.Contents.OfType<DockForm>().Where(c => c.Pane == Pane); // Pane.Contents contains DockForms that are not placed on that pane
     149        return dockForms.ToList(); // .ToList() necessary because closing a DockForm removes it from the Content collection
     150      }
     151    }
     152
     153    private void cloneToolStripMenuItem_Click(object sender, EventArgs e) {
     154      var contentView = View as IContentView;
     155      if (contentView == null) return;
     156
     157      var cloneable = contentView.Content as IDeepCloneable;
     158      if (cloneable == null) return;
     159
     160      var clone = (IContent)cloneable.Clone();
     161
     162      var viewHost = contentView as ViewHost;
     163      var newView = viewHost != null ? viewHost.ViewType : contentView.GetType();
     164      MainFormManager.MainForm.ShowContent(clone, newView);
     165    }
     166    #endregion
    113167  }
    114168}
Note: See TracChangeset for help on using the changeset viewer.