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