Changeset 11591 for branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.cs
- Timestamp:
- 11/27/14 09:35:43 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.