Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/27/14 09:35:43 (10 years ago)
Author:
jkarder
Message:

#2116: reverted to r10041

Location:
branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3
Files:
2 deleted
6 edited

Legend:

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

    r10042 r11591  
    3030    public ViewContextMenuStrip() {
    3131      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>();
    3434    }
    3535
    3636    public ViewContextMenuStrip(IContainer container)
    3737      : 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>();
    4441    }
    4542
    4643    private object item;
    4744    public object Item {
    48       get { return item; }
     45      get { return this.item; }
    4946      set {
    50         if (item != value) {
    51           item = value;
    52           RefreshMenuItems();
     47        if (this.item != value) {
     48          this.item = value;
     49          this.RefreshMenuItems();
    5350        }
    5451      }
     
    5754    private List<Type> ignoredViewTypes;
    5855    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(); }
    6158    }
    6259
    6360    private Dictionary<Type, ToolStripMenuItem> menuItems;
    6461    public IEnumerable<KeyValuePair<Type, ToolStripMenuItem>> MenuItems {
    65       get { return menuItems; }
     62      get { return this.menuItems; }
    6663    }
    67 
    68     public ToolStripMenuItem ShowBreadcrumbsToolStripMenuItem { get; private set; }
    6964
    7065    private void RefreshMenuItems() {
     
    7368        foreach (ToolStripMenuItem m in menuItems.Values)
    7469          m.Dispose();
    75         Items.Clear();
    76         menuItems.Clear();
     70        this.Items.Clear();
     71        this.menuItems.Clear();
    7772
    78         if (item != null) {
     73        if (this.item != null) {
    7974          ToolStripMenuItem menuItem;
    8075          IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType(), true);
     
    8479            menuItem.Text = ViewAttribute.GetViewName(t);
    8580
    86             menuItems.Add(t, menuItem);
    87             Items.Add(menuItem);
     81            this.menuItems.Add(t, menuItem);
     82            this.Items.Add(menuItem);
    8883          }
    89           if (Items.Count > 0)
    90             Items.Add(new ToolStripSeparator());
    91           Items.Add(ShowBreadcrumbsToolStripMenuItem);
    9284        }
    9385      }
    9486    }
    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     }
    10987  }
    11088}
  • branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.Designer.cs

    r10042 r11591  
    5252      this.configurationLabel = new System.Windows.Forms.Label();
    5353      this.helpLabel = new System.Windows.Forms.Label();
    54       this.breadcrumbControl = new HeuristicLab.MainForm.WindowsForms.BreadcrumbControl();
    5554      this.SuspendLayout();
    5655      //
     
    8786      this.viewContextMenuStrip.Name = "viewContextMenuStrip";
    8887      this.viewContextMenuStrip.Size = new System.Drawing.Size(61, 4);
    89       this.viewContextMenuStrip.ShowBreadcrumbsChanged += new System.EventHandler(this.viewContextMenuStrip_ShowBreadcrumbsChanged);
    9088      this.viewContextMenuStrip.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.viewContextMenuStrip_ItemClicked);
    9189      //
     
    116114      this.helpLabel.DoubleClick += new System.EventHandler(this.helpLabel_DoubleClick);
    117115      //
    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       //
    128116      // ViewHost
    129117      //
     118      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    130119      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    131       this.Controls.Add(this.breadcrumbControl);
    132120      this.Controls.Add(this.helpLabel);
    133121      this.Controls.Add(this.viewsLabel);
     
    136124      this.Name = "ViewHost";
    137125      this.Size = new System.Drawing.Size(227, 184);
    138       this.VisibleChanged += new System.EventHandler(this.ViewHost_VisibleChanged);
    139126      this.ResumeLayout(false);
    140127
     
    148135    private System.Windows.Forms.Label configurationLabel;
    149136    private System.Windows.Forms.Label helpLabel;
    150     private BreadcrumbControl breadcrumbControl;
    151137
    152138  }
  • branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.cs

    r10106 r11591  
    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;
    4543    }
    4644
     
    5351          viewsLabel.Visible = value;
    5452          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    }
    6157
    6258    private IContentView cachedView;
     
    9187            #endregion
    9288
    93             Caption = activeView.Caption;
     89            this.Caption = activeView.Caption;
    9490            viewType = activeView.GetType();
    9591            RegisterActiveViewEvents();
     
    9793            if (view != null) {
    9894              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;
    10099              if (!Controls.Contains((view))) Controls.Add(view);
    101100              view.OnShown(new ViewShownEventArgs(view, false));
     
    126125      }
    127126    }
    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; } }
    135127
    136128    protected override void SetEnabledStateOfControls() {
     
    159151      UpdateLabels();
    160152      UpdateActiveMenuItem();
    161       UpdateBreadcrumbControl();
    162153    }
    163154
     
    210201      OnChanged();
    211202    }
    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     }
    219203
    220204    protected override void OnSizeChanged(EventArgs e) {
     
    279263    }
    280264
    281     private void UpdateBreadcrumbControl() {
    282       breadcrumbControl.Visible = ShowBreadcrumbs && Content != null;
    283       if (ShowBreadcrumbs)
    284         UpdateBreadcrumbTrail(breadcrumbControl.Breadcrumbs, BuildBreadcrumbTrail());
    285     }
    286 
    287265    private bool ViewCanShowContent(Type viewType, object content) {
    288266      if (content == null) // every view can display null
     
    296274      IContentView view = MainFormManager.MainForm.ShowContent(this.Content, this.ViewType);
    297275      if (view != null) {
    298         view.ReadOnly = ReadOnly;
    299         view.Locked = Locked;
     276        view.ReadOnly = this.ReadOnly;
     277        view.Locked = this.Locked;
    300278      }
    301279    }
     
    307285    private bool startDragAndDrop;
    308286    private void viewsLabel_MouseDown(object sender, MouseEventArgs e) {
    309       if (e.Button == MouseButtons.Right) {
     287      if (e.Button == System.Windows.Forms.MouseButtons.Right) {
    310288        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; //
    312290        rightBorder = rightBorder - screen.Bounds.X; //pixel position on active screen
    313291
     
    341319    }
    342320    #endregion
    343 
    344     #region Helpers
    345     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     #endregion
    385321  }
    386322}
  • branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/HeuristicLab.MainForm.WindowsForms-3.3.csproj

    r10042 r11591  
    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>
    128122    <Compile Include="Controls\DragOverTabControl.cs">
    129123      <SubType>Component</SubType>
  • branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs

    r10103 r11591  
    223223    }
    224224
    225     public T GetOutermostControlOfType<T>(Control childControl) where T : Control {
    226       if (childControl == null) throw new ArgumentNullException("childControl", "ChildControl cannot be null.");
    227 
    228       T outermostControl = null;
    229       for (var control = childControl; control != null; control = control.Parent) {
    230         var c = control as T;
    231         if (c != null) outermostControl = c;
    232       }
    233       return outermostControl;
    234     }
    235 
    236225    public IContentView ShowContent(IContent content) {
    237226      if (content == null) throw new ArgumentNullException("Content cannot be null.");
     
    241230    }
    242231
    243     public IContentView ShowContent<T>(T content, bool reuseExistingView, IEqualityComparer<T> comparer = null) where T : class, IContent {
     232    public IContentView ShowContent<T>(T content, bool reuseExistingView, IEqualityComparer<T> comparer = null) where T : class,IContent {
    244233      if (content == null) throw new ArgumentNullException("Content cannot be null.");
    245234      if (!reuseExistingView) return ShowContent(content);
     
    273262        return view;
    274263      }
    275     }
    276 
    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 = GetOutermostControlOfType<ViewHost>(childControl);
    282       if (outermostViewHost == null) return null;
    283 
    284       if (!requireHotlinking || outermostViewHost.HotlinkingEnabled) {
    285         var oldCrumbs = outermostViewHost.Breadcrumbs;
    286         var newCrumbs = new LinkedList<IContent>();
    287         for (var control = childControl; control != null; control = control.Parent) {
    288           var vh = control as ViewHost;
    289           if (vh != null && vh.Content != null)
    290             newCrumbs.AddFirst(vh.Content);
    291         }
    292         bool showBreadcrumbs = outermostViewHost.ShowBreadcrumbs;
    293         outermostViewHost.Content = null;
    294         var viewType = MainFormManager.GetDefaultViewType(content.GetType());
    295         outermostViewHost.ViewType = viewType;
    296         outermostViewHost.Content = content;
    297         outermostViewHost.UpdateBreadcrumbTrail(oldCrumbs, newCrumbs.Concat(new[] { content }));
    298         outermostViewHost.ShowBreadcrumbs = showBreadcrumbs;
    299       }
    300       return outermostViewHost;
    301264    }
    302265
     
    587550      try {
    588551        ((IActionUserInterfaceItem)item.Tag).Execute();
    589       } catch (Exception ex) {
     552      }
     553      catch (Exception ex) {
    590554        ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, ex);
    591555      }
  • branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Views/View.cs

    r10106 r11591  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    2524using System.Reflection;
     
    262261        ((Control)this).ResumeRepaint(refresh);
    263262    }
    264 
    265     public IEnumerable<T> GetParentViewsOfType<T>() where T : View {
    266       for (var view = Parent; view != null; view = view.Parent)
    267         if (view is View) yield return view as T;
    268     }
    269263  }
    270264}
Note: See TracChangeset for help on using the changeset viewer.