Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/11/11 12:00:36 (13 years ago)
Author:
mkommend
Message:

Implemented ShowContent method in MainForm which reuses existing views and adapted the ClipBoard (ticket #1372).

File:
1 edited

Legend:

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

    r5237 r5270  
    2121
    2222using System;
    23 using System.Collections;
    2423using System.Collections.Generic;
    2524using System.Linq;
     
    220219
    221220    public IContentView ShowContent(IContent content) {
    222       if (content == null)
    223         throw new ArgumentNullException("Content cannot be null.");
     221      if (content == null) throw new ArgumentNullException("Content cannot be null.");
    224222      Type viewType = MainFormManager.GetDefaultViewType(content.GetType());
    225       if (viewType != null)
    226         return ShowContent(content, viewType);
     223      if (viewType != null) return ShowContent(content, viewType);
    227224      return null;
     225    }
     226
     227    public IContentView ShowContent<T>(T content, bool reuseExistingView, IEqualityComparer<T> comparer = null) where T : class,IContent {
     228      if (content == null) throw new ArgumentNullException("Content cannot be null.");
     229      if (!reuseExistingView) return ShowContent(content);
     230
     231      IContentView view = null;
     232      if (comparer == null) view = Views.OfType<IContentView>().Where(v => (v.Content as T) == content).FirstOrDefault();
     233      else view = Views.OfType<IContentView>().Where(v => comparer.Equals((v.Content as T), content)).FirstOrDefault();
     234
     235      if (view == null) view = ShowContent(content);
     236      else view.Show();
     237
     238      return view;
    228239    }
    229240
     
    231242      if (InvokeRequired) return (IContentView)Invoke((Func<IContent, Type, IContentView>)ShowContent, content, viewType);
    232243      else {
    233         if (content == null)
    234           throw new ArgumentNullException("Content cannot be null.");
    235         if (viewType == null)
    236           throw new ArgumentNullException("ViewType cannot be null.");
    237 
    238         IContentView view;
    239         if (this.ShowContentInViewHost) {
     244        if (content == null) throw new ArgumentNullException("Content cannot be null.");
     245        if (viewType == null) throw new ArgumentNullException("ViewType cannot be null.");
     246
     247        IContentView view = null;
     248        if (ShowContentInViewHost) {
    240249          ViewHost viewHost = new ViewHost();
    241250          viewHost.ViewType = viewType;
    242251          view = viewHost;
    243         } else
    244           view = MainFormManager.CreateView(viewType);
     252
     253        } else view = MainFormManager.CreateView(viewType);
    245254
    246255        view.Content = content;
Note: See TracChangeset for help on using the changeset viewer.