Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5270


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

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

Location:
trunk/sources
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/Clipboard.cs

    r5237 r5270  
    260260      if (listView.SelectedItems.Count == 1) {
    261261        T item = (T)listView.SelectedItems[0].Tag;
    262         IContentView view;
    263         view = MainFormManager.MainForm.Views.OfType<IContentView>().Where(x => (x.Content != null) && (x.Content == item)).FirstOrDefault();
    264         if (view != null) {
    265           view.Show();
    266         } else {
    267           view = MainFormManager.MainForm.ShowContent(item);
    268           if (view != null) {
    269             view.ReadOnly = this.ReadOnly;
    270           }
    271         }
     262        IContentView view = MainFormManager.MainForm.ShowContent(item, true);
    272263      }
    273264    }
  • 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;
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ViewHost.cs

    r5012 r5270  
    108108      get { return viewType; }
    109109      set {
    110         if (viewType != value) {
     110        if (viewType != value && value.GetType() != typeof(ViewHost)) {
    111111          if (value != null && Content != null && !ViewCanShowContent(value, Content))
    112112            throw new ArgumentException(string.Format("View \"{0}\" cannot display content \"{1}\".",
  • trunk/sources/HeuristicLab.MainForm/3.3/Interfaces/IMainForm.cs

    r4068 r5270  
    3939
    4040    IContentView ShowContent(IContent content);
     41    IContentView ShowContent<T>(T content, bool reuseExistingView, IEqualityComparer<T> comparer = null) where T : class,IContent;
    4142    IContentView ShowContent(IContent content, Type viewType);
    4243
Note: See TracChangeset for help on using the changeset viewer.