Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/29/13 13:47:35 (11 years ago)
Author:
jkarder
Message:

#2116:

  • refactored breadcrumb navigation
  • added possibility to navigate to the first invisible breadcrumb via the ellipsis
Location:
branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/BreadcrumbControl.cs

    r10042 r10093  
    6666            Tag = bc
    6767          };
    68           label.Click += label_Click;
     68          ((LinkLabel)label).LinkClicked += label_LinkClicked;
    6969        }
    7070        labels.Add(label);
     
    9393      if (!labels.Any()) return;
    9494      var curLoc = new Point(3, 0);
    95       var ellipsis = new Label {
     95      var ellipsis = new LinkLabel {
    9696        Location = curLoc,
    9797        AutoSize = true,
     
    113113      if (i == labels.Count - 1) return;
    114114      i += 1 + i % 2;
     115      ellipsis.Tag = breadcrumbs.ElementAt(i / 2);
     116      ellipsis.LinkClicked += label_LinkClicked;
    115117      while (i < labels.Count) {
    116118        var l = labels[i++];
     
    121123    }
    122124
    123     private void label_Click(object sender, EventArgs e) {
     125    private void label_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
    124126      var label = (LinkLabel)sender;
    125127      var content = (IContent)label.Tag;
    126       int crumbCount = breadcrumbs.Count;
    127       while (breadcrumbs.Any()) {
    128         var item = breadcrumbs.Last.Value;
    129         if (item == content) break;
     128      while (breadcrumbs.Any() && breadcrumbs.Last.Value != content)
    130129        breadcrumbs.RemoveLast();
    131       }
    132       var targetViewHost = ViewHost;
    133       if (crumbCount - breadcrumbs.Count > 0) {
    134         for (var parent = Parent; parent != null; parent = parent.Parent) {
    135           var vh = parent as ViewHost;
    136           if (vh != null) targetViewHost = vh;
    137         }
    138       }
    139       bool showBreadcrumbs = targetViewHost.ShowBreadcrumbs;
    140       targetViewHost.Content = null;
     130      var mainForm = MainFormManager.GetMainForm<MainForm>();
     131      var outermostViewHost = mainForm.GetOutermostViewOfType<ViewHost>(ViewHost);
     132      bool showBreadcrumbs = outermostViewHost.ShowBreadcrumbs;
     133      outermostViewHost.Content = null;
    141134      var viewType = MainFormManager.GetDefaultViewType(content.GetType());
    142       targetViewHost.ViewType = viewType;
    143       targetViewHost.Content = content;
    144       targetViewHost.UpdateBreadcrumbTrail(targetViewHost.Breadcrumbs, breadcrumbs);
    145       targetViewHost.ShowBreadcrumbs = showBreadcrumbs;
     135      outermostViewHost.ViewType = viewType;
     136      outermostViewHost.Content = content;
     137      outermostViewHost.UpdateBreadcrumbTrail(outermostViewHost.Breadcrumbs, breadcrumbs);
     138      outermostViewHost.ShowBreadcrumbs = showBreadcrumbs;
    146139    }
    147140
  • branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.cs

    r10089 r10093  
    379379    private void PerformOutermostViewHostDetection() {
    380380      var mainForm = MainFormManager.GetMainForm<MainForm>();
     381      if (mainForm == null) return;
    381382      var outermostViewHost = mainForm.GetOutermostViewOfType<ViewHost>(this);
    382383      isOutermostViewHost = outermostViewHost == this;
  • branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs

    r10089 r10093  
    224224
    225225    public T GetOutermostViewOfType<T>(Control childControl) where T : class, IView {
     226      if (childControl == null) throw new ArgumentNullException("childControl", "ChildControl cannot be null.");
     227
    226228      T outermostView = null;
    227229      for (var control = childControl; control != null; control = control.Parent) {
     
    273275    }
    274276
    275     public void ShowContentInSpecificViewHost(IContent content, ViewHost viewHost) {
    276       if (viewHost == null) return;
    277       viewHost.Content = null;
    278       var viewType = MainFormManager.GetDefaultViewType(content.GetType());
    279       viewHost.ViewType = viewType;
    280       viewHost.Content = content;
     277    public ViewHost ShowContentInOutermostViewHost(IContent content, Control childControl, bool requireHotlinking = false) {
     278      if (content == null) throw new ArgumentNullException("content", "Content cannot be null.");
     279      if (childControl == null) throw new ArgumentNullException("childControl", "ChildControl cannot be null.");
     280
     281      var outermostViewHost = GetOutermostViewOfType<ViewHost>(childControl);
     282      if (outermostViewHost == null)
     283        throw new ArgumentException("No outermost ViewHost could be found for the specified child control.", "childControl");
     284
     285      if (!requireHotlinking || outermostViewHost.HotlinkingEnabled) {
     286        var oldCrumbs = outermostViewHost.Breadcrumbs;
     287        var newCrumbs = new LinkedList<IContent>();
     288        for (var control = childControl; control != null; control = control.Parent) {
     289          var vh = control as ViewHost;
     290          if (vh != null && vh.Content != null)
     291            newCrumbs.AddFirst(vh.Content);
     292        }
     293        bool showBreadcrumbs = outermostViewHost.ShowBreadcrumbs;
     294        outermostViewHost.Content = null;
     295        var viewType = MainFormManager.GetDefaultViewType(content.GetType());
     296        outermostViewHost.ViewType = viewType;
     297        outermostViewHost.Content = content;
     298        outermostViewHost.UpdateBreadcrumbTrail(oldCrumbs, newCrumbs.Concat(new[] { content }));
     299        outermostViewHost.ShowBreadcrumbs = showBreadcrumbs;
     300      }
     301      return outermostViewHost;
    281302    }
    282303
Note: See TracChangeset for help on using the changeset viewer.