Changeset 13458


Ignore:
Timestamp:
12/14/15 15:21:47 (5 years ago)
Author:
pfleck
Message:

#1235 Added a context menu to the DockForm to close (this, all, all but this) and clone the item of the current tab.

Location:
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/DockForm.Designer.cs

    r12012 r13458  
    3434    /// </summary>
    3535    private void InitializeComponent() {
     36      this.components = new System.ComponentModel.Container();
    3637      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DockForm));
    3738      this.viewPanel = new System.Windows.Forms.Panel();
     39      this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
     40      this.closeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     41      this.closeAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     42      this.closeAllButThisToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     43      this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
     44      this.cloneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     45      this.contextMenuStrip.SuspendLayout();
    3846      this.SuspendLayout();
    3947      //
    4048      // viewPanel
    4149      //
    42       this.viewPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    43                   | System.Windows.Forms.AnchorStyles.Left)
    44                   | System.Windows.Forms.AnchorStyles.Right)));
     50      this.viewPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     51            | System.Windows.Forms.AnchorStyles.Left)
     52            | System.Windows.Forms.AnchorStyles.Right)));
    4553      this.viewPanel.Location = new System.Drawing.Point(12, 12);
    4654      this.viewPanel.Name = "viewPanel";
     
    4856      this.viewPanel.TabIndex = 0;
    4957      //
     58      // contextMenuStrip
     59      //
     60      this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
     61            this.closeToolStripMenuItem,
     62            this.closeAllToolStripMenuItem,
     63            this.closeAllButThisToolStripMenuItem,
     64            this.toolStripSeparator1,
     65            this.cloneToolStripMenuItem});
     66      this.contextMenuStrip.Name = "contextMenuStrip";
     67      this.contextMenuStrip.Size = new System.Drawing.Size(167, 120);
     68      //
     69      // closeToolStripMenuItem
     70      //
     71      this.closeToolStripMenuItem.Name = "closeToolStripMenuItem";
     72      this.closeToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
     73      this.closeToolStripMenuItem.Text = "Close";
     74      this.closeToolStripMenuItem.Click += new System.EventHandler(this.closeToolStripMenuItem_Click);
     75      //
     76      // closeAllToolStripMenuItem
     77      //
     78      this.closeAllToolStripMenuItem.Name = "closeAllToolStripMenuItem";
     79      this.closeAllToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
     80      this.closeAllToolStripMenuItem.Text = "Close All";
     81      this.closeAllToolStripMenuItem.Click += new System.EventHandler(this.closeAllToolStripMenuItem_Click);
     82      //
     83      // closeAllButThisToolStripMenuItem
     84      //
     85      this.closeAllButThisToolStripMenuItem.Name = "closeAllButThisToolStripMenuItem";
     86      this.closeAllButThisToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
     87      this.closeAllButThisToolStripMenuItem.Text = "Close All But This";
     88      this.closeAllButThisToolStripMenuItem.Click += new System.EventHandler(this.closeAllButThisToolStripMenuItem_Click);
     89      //
     90      // toolStripSeparator1
     91      //
     92      this.toolStripSeparator1.Name = "toolStripSeparator1";
     93      this.toolStripSeparator1.Size = new System.Drawing.Size(163, 6);
     94      //
     95      // cloneToolStripMenuItem
     96      //
     97      this.cloneToolStripMenuItem.Name = "cloneToolStripMenuItem";
     98      this.cloneToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
     99      this.cloneToolStripMenuItem.Text = "Create Copy";
     100      this.cloneToolStripMenuItem.Click += new System.EventHandler(this.cloneToolStripMenuItem_Click);
     101      //
    50102      // DockForm
    51103      //
    52       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    53104      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    54105      this.ClientSize = new System.Drawing.Size(632, 446);
     
    59110      this.ShowInTaskbar = false;
    60111      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
     112      this.TabPageContextMenuStrip = this.contextMenuStrip;
     113      this.contextMenuStrip.ResumeLayout(false);
    61114      this.ResumeLayout(false);
     115
    62116    }
    63117
     
    65119
    66120    private System.Windows.Forms.Panel viewPanel;
     121    private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
     122    private System.Windows.Forms.ToolStripMenuItem closeToolStripMenuItem;
     123    private System.Windows.Forms.ToolStripMenuItem closeAllToolStripMenuItem;
     124    private System.Windows.Forms.ToolStripMenuItem closeAllButThisToolStripMenuItem;
     125    private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
     126    private System.Windows.Forms.ToolStripMenuItem cloneToolStripMenuItem;
    67127  }
    68128}
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/DockForm.cs

    r12012 r13458  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2325using System.Windows.Forms;
     26using HeuristicLab.Common;
    2427using WeifenLuo.WinFormsUI.Docking;
    2528
     
    111114    }
    112115    #endregion
     116
     117    #region Context Menu Events
     118    private void closeToolStripMenuItem_Click(object sender, EventArgs e) {
     119      Close();
     120    }
     121    private void closeAllToolStripMenuItem_Click(object sender, EventArgs e) {
     122      foreach (var dockForm in CurrentDockForms.ToList()) {
     123        dockForm.Close();
     124      }
     125    }
     126    private void closeAllButThisToolStripMenuItem_Click(object sender, EventArgs e) {
     127      foreach (var dockForm in CurrentDockForms.Except(this.ToEnumerable()).ToList()) {
     128        dockForm.Close();
     129      }
     130    }
     131    private IEnumerable<DockForm> CurrentDockForms {
     132      get {
     133        return DockPanel.ActivePane.IsActiveDocumentPane
     134            ? DockPanel.Documents.OfType<DockForm>()
     135            : DockPanel.ActivePane.Contents.OfType<DockForm>();
     136        // ActivePane.Contents contains all dockforms if ActivePane is the main DocumentPane
     137      }
     138    }
     139
     140    private void cloneToolStripMenuItem_Click(object sender, EventArgs e) {
     141      var contentView = View as IContentView;
     142      if (contentView == null) return;
     143
     144      var cloneable = contentView.Content as IDeepCloneable;
     145      if (cloneable == null) return;
     146
     147      var clone = (IContent)cloneable.Clone();
     148      MainFormManager.MainForm.ShowContent(clone);
     149    }
     150    #endregion
    113151  }
    114152}
Note: See TracChangeset for help on using the changeset viewer.