Changeset 2838


Ignore:
Timestamp:
02/19/10 11:46:57 (11 years ago)
Author:
mkommend
Message:

changed ViewHost to use ViewContextMenuStrip (ticket #95)

Location:
trunk/sources/HeuristicLab.Core.Views/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/ViewHost.Designer.cs

    r2800 r2838  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.components = new System.ComponentModel.Container();
     47      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ViewHost));
    4848      this.viewPanel = new System.Windows.Forms.Panel();
    4949      this.messageLabel = new System.Windows.Forms.Label();
    5050      this.viewsLabel = new System.Windows.Forms.Label();
    51       this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
    52       this.toolTip = new System.Windows.Forms.ToolTip(this.components);
     51      this.viewContextMenuStrip = new HeuristicLab.MainForm.WindowsForms.ViewContextMenuStrip();
    5352      this.SuspendLayout();
    5453      //
     
    7675      //
    7776      this.viewsLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    78       this.viewsLabel.ContextMenuStrip = this.contextMenuStrip;
    79       this.viewsLabel.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Windows;
     77      this.viewsLabel.ContextMenuStrip = this.viewContextMenuStrip;
     78      this.viewsLabel.Image = ((System.Drawing.Image)(resources.GetObject("viewsLabel.Image")));
    8079      this.viewsLabel.Location = new System.Drawing.Point(211, 0);
    8180      this.viewsLabel.Name = "viewsLabel";
    8281      this.viewsLabel.Size = new System.Drawing.Size(16, 16);
    8382      this.viewsLabel.TabIndex = 0;
    84       this.toolTip.SetToolTip(this.viewsLabel, "Double-click to open a new window of the current view.\r\nRight-click to change cur" +
    85               "rent view.");
    8683      this.viewsLabel.DoubleClick += new System.EventHandler(this.viewsLabel_DoubleClick);
    8784      //
    88       // contextMenuStrip
     85      // viewContextMenuStrip
    8986      //
    90       this.contextMenuStrip.Name = "contextMenuStrip";
    91       this.contextMenuStrip.ShowCheckMargin = true;
    92       this.contextMenuStrip.ShowImageMargin = false;
    93       this.contextMenuStrip.Size = new System.Drawing.Size(61, 4);
    94       this.contextMenuStrip.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.contextMenuStrip_ItemClicked);
     87      this.viewContextMenuStrip.Item = null;
     88      this.viewContextMenuStrip.Name = "viewContextMenuStrip";
     89      this.viewContextMenuStrip.Size = new System.Drawing.Size(61, 4);
     90      this.viewContextMenuStrip.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.viewContextMenuStrip_ItemClicked);
    9591      //
    9692      // ViewHost
     
    112108    private System.Windows.Forms.Label viewsLabel;
    113109    private System.Windows.Forms.Label messageLabel;
    114     private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
    115     private System.Windows.Forms.ToolTip toolTip;
     110    private HeuristicLab.MainForm.WindowsForms.ViewContextMenuStrip viewContextMenuStrip;
    116111
    117112  }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ViewHost.cs

    r2818 r2838  
    2929namespace HeuristicLab.Core.Views {
    3030  public sealed partial class ViewHost : UserControl {
    31     private Dictionary<Type, ToolStripMenuItem> typeMenuItemTable;
    32 
    33     public IEnumerable<Type> AvailableViewTypes {
    34       get { return typeMenuItemTable.Keys; }
    35     }
    36 
    3731    private Type viewType;
    3832    public Type ViewType {
     
    5448        if (value != content) {
    5549          content = value;
     50          viewContextMenuStrip.Item = content;
    5651          Initialize();
    5752        }
     
    6055
    6156    public ViewHost() {
    62       typeMenuItemTable = new Dictionary<Type, ToolStripMenuItem>();
     57      InitializeComponent();
    6358      viewType = null;
    6459      content = null;
    65       InitializeComponent();
    6660      Initialize();
    6761    }
     
    7064      viewsLabel.Enabled = false;
    7165      viewsLabel.Visible = false;
    72       typeMenuItemTable.Clear();
    73       contextMenuStrip.Items.Clear();
    74       contextMenuStrip.Enabled = false;
     66      viewContextMenuStrip.Enabled = false;
    7567      messageLabel.Visible = false;
     68
    7669      if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();
    7770      viewPanel.Controls.Clear();
     
    8073
    8174      if (Content != null) {
    82         var viewTypes = from t in MainFormManager.GetViewTypes(Content.GetType())
    83                         orderby t.Name ascending
    84                         select t;
    85         foreach (Type v in viewTypes) {
    86           ToolStripMenuItem item = new ToolStripMenuItem(v.GetPrettyName());
    87           item.Name = v.FullName;
    88           item.ToolTipText = v.GetPrettyName(true);
    89           item.Tag = v;
    90           contextMenuStrip.Items.Add(item);
    91           typeMenuItemTable.Add(v, item);
    92         }
    93         if (contextMenuStrip.Items.Count == 0) {
     75        if (viewContextMenuStrip.Items.Count == 0) {
    9476          messageLabel.Visible = true;
    9577        } else {
    9678          viewsLabel.Enabled = true;
    9779          viewsLabel.Visible = true;
    98           contextMenuStrip.Enabled = true;
     80          viewContextMenuStrip.Enabled = true;
    9981          messageLabel.Visible = false;
    10082        }
     
    10284        if (!ViewCanShowContent(viewType, Content)) {
    10385          viewType = MainFormManager.GetDefaultViewType(Content.GetType());
    104           if ((viewType == null) && (contextMenuStrip.Items.Count > 0))  // create first available view if default view is not available
    105             viewType = (Type)contextMenuStrip.Items[0].Tag;
     86          if ((viewType == null) && (viewContextMenuStrip.Items.Count > 0))  // create first available view if default view is not available
     87            viewType = (Type)viewContextMenuStrip.Items[0].Tag;
    10688        }
    10789        UpdateView();
     
    121103                                                  Content.GetType().GetPrettyName()));
    122104
    123       foreach (ToolStripMenuItem item in typeMenuItemTable.Values) {
    124         item.Checked = false;
    125         item.Enabled = true;
    126       }
    127       typeMenuItemTable[viewType].Checked = true;
    128       typeMenuItemTable[viewType].Enabled = false;
    129 
     105      UpdateActiveMenuItem();
    130106      Control view = (Control)MainFormManager.CreateView(viewType, Content);
    131107      viewPanel.Controls.Add(view);
     
    136112    }
    137113
     114    private void UpdateActiveMenuItem() {
     115      foreach (KeyValuePair<Type, ToolStripMenuItem> item in viewContextMenuStrip.MenuItems) {
     116        if (item.Key == viewType) {
     117          item.Value.Checked = true;
     118          item.Value.Enabled = false;
     119        } else {
     120          item.Value.Checked = false;
     121          item.Value.Enabled = true;
     122        }
     123      }
     124    }
     125
    138126    private bool ViewCanShowContent(Type viewType, object content) {
    139127      if (content == null) // every view can display null
     
    141129      if (viewType == null)
    142130        return false;
    143       return ContentAttribute.CanViewType(viewType, Content.GetType()) && typeMenuItemTable.ContainsKey(viewType);
     131      return ContentAttribute.CanViewType(viewType, Content.GetType()) && viewContextMenuStrip.MenuItems.Any(item => item.Key == viewType);
    144132    }
    145133
    146134    private void viewsLabel_DoubleClick(object sender, EventArgs e) {
    147       MainFormManager.CreateView(viewPanel.Tag.GetType(), Content).Show();
     135      MainFormManager.CreateView(viewType, Content).Show();
    148136    }
    149     private void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) {
     137
     138    private void viewContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) {
    150139      Type viewType = (Type)e.ClickedItem.Tag;
    151140      ViewType = viewType;
Note: See TracChangeset for help on using the changeset viewer.