Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/10 02:08:29 (14 years ago)
Author:
mkommend
Message:

enhanced caching of views in ViewHost and adapted MainFormManager to use IContentView (ticket #972)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewHost.cs

    r3388 r3389  
    2727
    2828namespace HeuristicLab.MainForm.WindowsForms {
    29   public sealed partial class ViewHost : View {
    30     private Dictionary<Type, IView> cachedViews;
     29  [Content(typeof(object))]
     30  public sealed partial class ViewHost : ContentView {
     31    private Dictionary<Type, IContentView> cachedViews;
    3132    public ViewHost() {
    3233      InitializeComponent();
    33       cachedViews = new Dictionary<Type, IView>();
     34      cachedViews = new Dictionary<Type, IContentView>();
    3435      viewType = null;
    3536      Content = null;
     37      viewContextMenuStrip.IgnoredViewTypes = new List<Type>() { typeof(ViewHost) };
    3638    }
    37     public ViewHost(bool readOnly)
     39    public ViewHost(object content)
    3840      : this() {
    39       this.ReadOnly = readOnly;
     41      this.Content = content;
    4042    }
    4143
     
    5456    }
    5557
    56     private object content;
    57     public object Content {
    58       get { return this.content; }
     58    public new object Content {
     59      get { return base.Content; }
    5960      set {
    60         if (value != this.content) {
    61           if (value == null || this.content == null || value.GetType() != this.content.GetType())
    62             cachedViews.Clear();
    63           viewContextMenuStrip.Item = value;
    64           this.viewsLabel.Enabled = value != null;
    65           this.content = value;
    66           this.OnContentChanged();
    67         }
    68 
     61        if (value == null || this.Content == null || value.GetType() != this.Content.GetType())
     62          cachedViews.Clear();
     63        viewContextMenuStrip.Item = value;
     64        this.viewsLabel.Enabled = value != null;
     65        base.Content = value;
    6966      }
    7067    }
     
    8279    protected override void OnReadOnlyChanged() {
    8380      base.OnReadOnlyChanged();
    84       foreach (IView view in cachedViews.Values)
     81      foreach (IContentView view in cachedViews.Values)
    8582        view.ReadOnly = this.ReadOnly;
    8683    }
    8784
    88     private void OnContentChanged() {
     85    protected override void OnContentChanged() {
    8986      messageLabel.Visible = false;
    9087      viewsLabel.Visible = false;
     
    10097
    10198        if (!ViewCanShowContent(viewType, Content)) {
    102           viewType = MainFormManager.GetDefaultViewType(Content.GetType());
     99          ViewType = MainFormManager.GetDefaultViewType(Content.GetType());
    103100          if ((viewType == null) && (viewContextMenuStrip.Items.Count > 0))  // create first available view if default view is not available
    104             viewType = (Type)viewContextMenuStrip.Items[0].Tag;
     101            ViewType = (Type)viewContextMenuStrip.Items[0].Tag;
    105102        }
    106         UpdateView();
     103        foreach (IContentView view in cachedViews.Values)
     104          view.Content = this.Content;
     105      } else {
     106        if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();
     107        viewPanel.Controls.Clear();
     108        cachedViews.Clear();
    107109      }
    108110    }
     
    120122
    121123      UpdateActiveMenuItem();
    122       IView view;
     124      IContentView view;
    123125      if (cachedViews.ContainsKey(ViewType))
    124126        view = cachedViews[ViewType];
    125127      else {
    126128        view = MainFormManager.CreateView(viewType, Content, ReadOnly);
    127         cachedViews.Add(viewType, ((IView)view));
     129        cachedViews.Add(viewType, view);
    128130      }
    129131
Note: See TracChangeset for help on using the changeset viewer.