Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/15/13 16:11:27 (11 years ago)
Author:
jkarder
Message:

#2116: added prototype of a breadcrumb navigation

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  
    3030    public ViewContextMenuStrip() {
    3131      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>();
    3434    }
    3535
    3636    public ViewContextMenuStrip(IContainer container)
    3737      : 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;
    4144    }
    4245
    4346    private object item;
    4447    public object Item {
    45       get { return this.item; }
     48      get { return item; }
    4649      set {
    47         if (this.item != value) {
    48           this.item = value;
    49           this.RefreshMenuItems();
     50        if (item != value) {
     51          item = value;
     52          RefreshMenuItems();
    5053        }
    5154      }
     
    5457    private List<Type> ignoredViewTypes;
    5558    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(); }
    5861    }
    5962
    6063    private Dictionary<Type, ToolStripMenuItem> menuItems;
    6164    public IEnumerable<KeyValuePair<Type, ToolStripMenuItem>> MenuItems {
    62       get { return this.menuItems; }
     65      get { return menuItems; }
    6366    }
     67
     68    public ToolStripMenuItem ShowBreadcrumbsToolStripMenuItem { get; private set; }
    6469
    6570    private void RefreshMenuItems() {
     
    6873        foreach (ToolStripMenuItem m in menuItems.Values)
    6974          m.Dispose();
    70         this.Items.Clear();
    71         this.menuItems.Clear();
     75        Items.Clear();
     76        menuItems.Clear();
    7277
    73         if (this.item != null) {
     78        if (item != null) {
    7479          ToolStripMenuItem menuItem;
    7580          IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType(), true);
     
    7984            menuItem.Text = ViewAttribute.GetViewName(t);
    8085
    81             this.menuItems.Add(t, menuItem);
    82             this.Items.Add(menuItem);
     86            menuItems.Add(t, menuItem);
     87            Items.Add(menuItem);
    8388          }
     89          if (Items.Count > 0)
     90            Items.Add(new ToolStripSeparator());
     91          Items.Add(ShowBreadcrumbsToolStripMenuItem);
    8492        }
    8593      }
    8694    }
     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    }
    87109  }
    88110}
  • branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.Designer.cs

    r9920 r10042  
    5252      this.configurationLabel = new System.Windows.Forms.Label();
    5353      this.helpLabel = new System.Windows.Forms.Label();
     54      this.breadcrumbControl = new HeuristicLab.MainForm.WindowsForms.BreadcrumbControl();
    5455      this.SuspendLayout();
    5556      //
     
    8687      this.viewContextMenuStrip.Name = "viewContextMenuStrip";
    8788      this.viewContextMenuStrip.Size = new System.Drawing.Size(61, 4);
     89      this.viewContextMenuStrip.ShowBreadcrumbsChanged += new System.EventHandler(this.viewContextMenuStrip_ShowBreadcrumbsChanged);
    8890      this.viewContextMenuStrip.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.viewContextMenuStrip_ItemClicked);
    8991      //
     
    114116      this.helpLabel.DoubleClick += new System.EventHandler(this.helpLabel_DoubleClick);
    115117      //
     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      //
    116128      // ViewHost
    117129      //
    118       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    119130      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     131      this.Controls.Add(this.breadcrumbControl);
    120132      this.Controls.Add(this.helpLabel);
    121133      this.Controls.Add(this.viewsLabel);
     
    124136      this.Name = "ViewHost";
    125137      this.Size = new System.Drawing.Size(227, 184);
     138      this.VisibleChanged += new System.EventHandler(this.ViewHost_VisibleChanged);
    126139      this.ResumeLayout(false);
    127140
     
    135148    private System.Windows.Forms.Label configurationLabel;
    136149    private System.Windows.Forms.Label helpLabel;
     150    private BreadcrumbControl breadcrumbControl;
    137151
    138152  }
  • branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.cs

    r9921 r10042  
    3333      InitializeComponent();
    3434      startDragAndDrop = false;
    35       viewContextMenuStrip.IgnoredViewTypes = new List<Type>() { typeof(ViewHost) };
     35      viewContextMenuStrip.IgnoredViewTypes = new List<Type> { typeof(ViewHost) };
    3636
    3737      viewType = null;
     
    4141      viewsLabel.Visible = false;
    4242      viewsLabelVisible = true;
     43
     44      breadcrumbControl.ViewHost = this;
    4345    }
    4446
     
    5153          viewsLabel.Visible = value;
    5254          View view = activeView as View;
    53           if (view != null) view.Dock = viewsLabelVisible ? DockStyle.None : DockStyle.Fill;
     55          if (view != null) AdjustActiveViewSize();
    5456        }
    5557      }
     
    8789            #endregion
    8890
    89             this.Caption = activeView.Caption;
     91            Caption = activeView.Caption;
    9092            viewType = activeView.GetType();
    9193            RegisterActiveViewEvents();
     
    9395            if (view != null) {
    9496              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();
    9998              if (!Controls.Contains((view))) Controls.Add(view);
    10099              view.OnShown(new ViewShownEventArgs(view, false));
     
    125124      }
    126125    }
     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; } }
    127134
    128135    protected override void SetEnabledStateOfControls() {
     
    151158      UpdateLabels();
    152159      UpdateActiveMenuItem();
     160      UpdateBreadcrumbControl();
    153161    }
    154162
     
    201209      OnChanged();
    202210    }
     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    }
    203218
    204219    protected override void OnSizeChanged(EventArgs e) {
     
    263278    }
    264279
     280    private void UpdateBreadcrumbControl() {
     281      breadcrumbControl.Visible = ShowBreadcrumbs;
     282      if (ShowBreadcrumbs)
     283        UpdateBreadcrumbTrail(breadcrumbControl.Breadcrumbs, BuildBreadcrumbTrail());
     284    }
     285
    265286    private bool ViewCanShowContent(Type viewType, object content) {
    266287      if (content == null) // every view can display null
     
    274295      IContentView view = MainFormManager.MainForm.ShowContent(this.Content, this.ViewType);
    275296      if (view != null) {
    276         view.ReadOnly = this.ReadOnly;
    277         view.Locked = this.Locked;
     297        view.ReadOnly = ReadOnly;
     298        view.Locked = Locked;
    278299      }
    279300    }
     
    285306    private bool startDragAndDrop;
    286307    private void viewsLabel_MouseDown(object sender, MouseEventArgs e) {
    287       if (e.Button == System.Windows.Forms.MouseButtons.Right) {
     308      if (e.Button == MouseButtons.Right) {
    288309        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;
    290311        rightBorder = rightBorder - screen.Bounds.X; //pixel position on active screen
    291312
     
    319340    }
    320341    #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
    321387  }
    322388}
  • branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/HeuristicLab.MainForm.WindowsForms-3.3.csproj

    r9915 r10042  
    120120  <ItemGroup>
    121121    <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>
    122128    <Compile Include="Controls\DragOverTabControl.cs">
    123129      <SubType>Component</SubType>
Note: See TracChangeset for help on using the changeset viewer.