Changeset 10042 for branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms
- Timestamp:
- 10/15/13 16:11:27 (11 years ago)
- Location:
- branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewContextMenuStrip.cs
r9456 r10042 30 30 public ViewContextMenuStrip() { 31 31 InitializeComponent(); 32 this.menuItems = new Dictionary<Type, ToolStripMenuItem>();33 this.ignoredViewTypes = new List<Type>();32 menuItems = new Dictionary<Type, ToolStripMenuItem>(); 33 ignoredViewTypes = new List<Type>(); 34 34 } 35 35 36 36 public ViewContextMenuStrip(IContainer container) 37 37 : base(container) { 38 InitializeComponent(); 39 this.menuItems = new Dictionary<Type, ToolStripMenuItem>(); 40 this.ignoredViewTypes = new List<Type>(); 38 InitializeComponent(); 39 menuItems = new Dictionary<Type, ToolStripMenuItem>(); 40 ignoredViewTypes = new List<Type>(); 41 ShowBreadcrumbsToolStripMenuItem = new ToolStripMenuItem("Show Breadcrumbs"); 42 ShowBreadcrumbsToolStripMenuItem.Click += ShowBreadcrumbsToolStripMenuItem_Click; 43 ShowBreadcrumbsToolStripMenuItem.CheckedChanged += ShowBreadcrumbsToolStripMenuItem_CheckedChanged; 41 44 } 42 45 43 46 private object item; 44 47 public object Item { 45 get { return this.item; }48 get { return item; } 46 49 set { 47 if ( this.item != value) {48 this.item = value;49 this.RefreshMenuItems();50 if (item != value) { 51 item = value; 52 RefreshMenuItems(); 50 53 } 51 54 } … … 54 57 private List<Type> ignoredViewTypes; 55 58 public IEnumerable<Type> IgnoredViewTypes { 56 get { return this.ignoredViewTypes; }57 set { this.ignoredViewTypes = new List<Type>(value); RefreshMenuItems(); }59 get { return ignoredViewTypes; } 60 set { ignoredViewTypes = new List<Type>(value); RefreshMenuItems(); } 58 61 } 59 62 60 63 private Dictionary<Type, ToolStripMenuItem> menuItems; 61 64 public IEnumerable<KeyValuePair<Type, ToolStripMenuItem>> MenuItems { 62 get { return this.menuItems; }65 get { return menuItems; } 63 66 } 67 68 public ToolStripMenuItem ShowBreadcrumbsToolStripMenuItem { get; private set; } 64 69 65 70 private void RefreshMenuItems() { … … 68 73 foreach (ToolStripMenuItem m in menuItems.Values) 69 74 m.Dispose(); 70 this.Items.Clear();71 this.menuItems.Clear();75 Items.Clear(); 76 menuItems.Clear(); 72 77 73 if ( this.item != null) {78 if (item != null) { 74 79 ToolStripMenuItem menuItem; 75 80 IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType(), true); … … 79 84 menuItem.Text = ViewAttribute.GetViewName(t); 80 85 81 this.menuItems.Add(t, menuItem);82 this.Items.Add(menuItem);86 menuItems.Add(t, menuItem); 87 Items.Add(menuItem); 83 88 } 89 if (Items.Count > 0) 90 Items.Add(new ToolStripSeparator()); 91 Items.Add(ShowBreadcrumbsToolStripMenuItem); 84 92 } 85 93 } 86 94 } 95 96 public event EventHandler ShowBreadcrumbsChanged; 97 private void OnShowBreadcrumbsChanged() { 98 var handler = ShowBreadcrumbsChanged; 99 if (handler != null) handler(this, EventArgs.Empty); 100 } 101 102 private void ShowBreadcrumbsToolStripMenuItem_CheckedChanged(object sender, EventArgs e) { 103 OnShowBreadcrumbsChanged(); 104 } 105 106 private void ShowBreadcrumbsToolStripMenuItem_Click(object sender, EventArgs e) { 107 ShowBreadcrumbsToolStripMenuItem.Checked = !ShowBreadcrumbsToolStripMenuItem.Checked; 108 } 87 109 } 88 110 } -
branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.Designer.cs
r9920 r10042 52 52 this.configurationLabel = new System.Windows.Forms.Label(); 53 53 this.helpLabel = new System.Windows.Forms.Label(); 54 this.breadcrumbControl = new HeuristicLab.MainForm.WindowsForms.BreadcrumbControl(); 54 55 this.SuspendLayout(); 55 56 // … … 86 87 this.viewContextMenuStrip.Name = "viewContextMenuStrip"; 87 88 this.viewContextMenuStrip.Size = new System.Drawing.Size(61, 4); 89 this.viewContextMenuStrip.ShowBreadcrumbsChanged += new System.EventHandler(this.viewContextMenuStrip_ShowBreadcrumbsChanged); 88 90 this.viewContextMenuStrip.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.viewContextMenuStrip_ItemClicked); 89 91 // … … 114 116 this.helpLabel.DoubleClick += new System.EventHandler(this.helpLabel_DoubleClick); 115 117 // 118 // breadcrumbControl 119 // 120 this.breadcrumbControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 121 | System.Windows.Forms.AnchorStyles.Right))); 122 this.breadcrumbControl.Location = new System.Drawing.Point(0, 0); 123 this.breadcrumbControl.Name = "breadcrumbControl"; 124 this.breadcrumbControl.Size = new System.Drawing.Size(202, 15); 125 this.breadcrumbControl.TabIndex = 4; 126 this.breadcrumbControl.ViewHost = null; 127 // 116 128 // ViewHost 117 129 // 118 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);119 130 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 131 this.Controls.Add(this.breadcrumbControl); 120 132 this.Controls.Add(this.helpLabel); 121 133 this.Controls.Add(this.viewsLabel); … … 124 136 this.Name = "ViewHost"; 125 137 this.Size = new System.Drawing.Size(227, 184); 138 this.VisibleChanged += new System.EventHandler(this.ViewHost_VisibleChanged); 126 139 this.ResumeLayout(false); 127 140 … … 135 148 private System.Windows.Forms.Label configurationLabel; 136 149 private System.Windows.Forms.Label helpLabel; 150 private BreadcrumbControl breadcrumbControl; 137 151 138 152 } -
branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.cs
r9921 r10042 33 33 InitializeComponent(); 34 34 startDragAndDrop = false; 35 viewContextMenuStrip.IgnoredViewTypes = new List<Type> (){ typeof(ViewHost) };35 viewContextMenuStrip.IgnoredViewTypes = new List<Type> { typeof(ViewHost) }; 36 36 37 37 viewType = null; … … 41 41 viewsLabel.Visible = false; 42 42 viewsLabelVisible = true; 43 44 breadcrumbControl.ViewHost = this; 43 45 } 44 46 … … 51 53 viewsLabel.Visible = value; 52 54 View view = activeView as View; 53 if (view != null) view.Dock = viewsLabelVisible ? DockStyle.None : DockStyle.Fill;55 if (view != null) AdjustActiveViewSize(); 54 56 } 55 57 } … … 87 89 #endregion 88 90 89 this.Caption = activeView.Caption;91 Caption = activeView.Caption; 90 92 viewType = activeView.GetType(); 91 93 RegisterActiveViewEvents(); … … 93 95 if (view != null) { 94 96 view.Visible = true; 95 if (ViewsLabelVisible) { 96 view.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; 97 view.Size = new Size(Width - this.viewsLabel.Width - this.viewsLabel.Margin.Left - this.viewsLabel.Margin.Right, this.Height); 98 } else view.Dock = DockStyle.Fill; 97 AdjustActiveViewSize(); 99 98 if (!Controls.Contains((view))) Controls.Add(view); 100 99 view.OnShown(new ViewShownEventArgs(view, false)); … … 125 124 } 126 125 } 126 127 public bool ShowBreadcrumbs { 128 get { return viewContextMenuStrip.ShowBreadcrumbsToolStripMenuItem.Checked; } 129 set { viewContextMenuStrip.ShowBreadcrumbsToolStripMenuItem.Checked = value; } 130 } 131 132 private bool isOutmostViewHost; 133 public IEnumerable<IContent> Breadcrumbs { get { return breadcrumbControl.Breadcrumbs; } } 127 134 128 135 protected override void SetEnabledStateOfControls() { … … 151 158 UpdateLabels(); 152 159 UpdateActiveMenuItem(); 160 UpdateBreadcrumbControl(); 153 161 } 154 162 … … 201 209 OnChanged(); 202 210 } 211 private void ViewHost_VisibleChanged(object sender, EventArgs e) { 212 PerformOuterViewHostDetection(); 213 } 214 private void viewContextMenuStrip_ShowBreadcrumbsChanged(object sender, EventArgs e) { 215 UpdateBreadcrumbControl(); 216 AdjustActiveViewSize(); 217 } 203 218 204 219 protected override void OnSizeChanged(EventArgs e) { … … 263 278 } 264 279 280 private void UpdateBreadcrumbControl() { 281 breadcrumbControl.Visible = ShowBreadcrumbs; 282 if (ShowBreadcrumbs) 283 UpdateBreadcrumbTrail(breadcrumbControl.Breadcrumbs, BuildBreadcrumbTrail()); 284 } 285 265 286 private bool ViewCanShowContent(Type viewType, object content) { 266 287 if (content == null) // every view can display null … … 274 295 IContentView view = MainFormManager.MainForm.ShowContent(this.Content, this.ViewType); 275 296 if (view != null) { 276 view.ReadOnly = this.ReadOnly;277 view.Locked = this.Locked;297 view.ReadOnly = ReadOnly; 298 view.Locked = Locked; 278 299 } 279 300 } … … 285 306 private bool startDragAndDrop; 286 307 private void viewsLabel_MouseDown(object sender, MouseEventArgs e) { 287 if (e.Button == System.Windows.Forms.MouseButtons.Right) {308 if (e.Button == MouseButtons.Right) { 288 309 Screen screen = Screen.FromControl(viewsLabel); 289 int rightBorder = viewsLabel.PointToScreen(viewsLabel.Location).X + viewContextMenuStrip.Width; //310 int rightBorder = viewsLabel.PointToScreen(viewsLabel.Location).X + viewContextMenuStrip.Width; 290 311 rightBorder = rightBorder - screen.Bounds.X; //pixel position on active screen 291 312 … … 319 340 } 320 341 #endregion 342 343 #region Helpers 344 private void AdjustActiveViewSize() { 345 var view = activeView as View; 346 if (view == null) return; 347 int width = viewsLabelVisible ? Width - viewsLabel.Width - viewsLabel.Margin.Left - viewsLabel.Margin.Right : Width; 348 int height = ShowBreadcrumbs ? Height - viewsLabel.Height - viewsLabel.Margin.Top - viewsLabel.Margin.Bottom : Height; 349 view.Location = new Point(0, Height - height); 350 view.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; 351 view.Size = new Size(width, height); 352 } 353 354 private IEnumerable<IContent> BuildBreadcrumbTrail() { 355 var ll = new LinkedList<IContent>(); 356 for (var control = (Control)this; control != null; control = control.Parent) { 357 var viewHost = control as ViewHost; 358 if (viewHost != null && viewHost.Content != null) 359 ll.AddFirst(viewHost.Content); 360 } 361 return ll; 362 } 363 364 public void UpdateBreadcrumbTrail(IEnumerable<IContent> oldCrumbs, IEnumerable<IContent> newCrumbs) { 365 if (!newCrumbs.Any()) return; 366 var ll = new LinkedList<IContent>(); 367 foreach (var c in oldCrumbs) { 368 if (c != newCrumbs.First()) 369 ll.AddLast(c); 370 else break; 371 } 372 foreach (var c in newCrumbs) 373 ll.AddLast(c); 374 breadcrumbControl.Breadcrumbs = ll; 375 } 376 377 private void PerformOuterViewHostDetection() { 378 var outmostViewHost = this; 379 for (var parent = Parent; parent != null; parent = parent.Parent) { 380 var vh = parent as ViewHost; 381 if (vh != null) outmostViewHost = vh; 382 } 383 isOutmostViewHost = outmostViewHost == this; 384 viewContextMenuStrip.ShowBreadcrumbsToolStripMenuItem.Checked = isOutmostViewHost; 385 } 386 #endregion 321 387 } 322 388 } -
branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/HeuristicLab.MainForm.WindowsForms-3.3.csproj
r9915 r10042 120 120 <ItemGroup> 121 121 <Compile Include="ActionUserInterfaceItem.cs" /> 122 <Compile Include="Controls\BreadcrumbControl.cs"> 123 <SubType>UserControl</SubType> 124 </Compile> 125 <Compile Include="Controls\BreadcrumbControl.Designer.cs"> 126 <DependentUpon>BreadcrumbControl.cs</DependentUpon> 127 </Compile> 122 128 <Compile Include="Controls\DragOverTabControl.cs"> 123 129 <SubType>Component</SubType>
Note: See TracChangeset
for help on using the changeset viewer.