Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/29/10 15:10:17 (14 years ago)
Author:
mkommend
Message:

changed logic of showing new views (ticket #972)

Location:
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3
Files:
7 edited

Legend:

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

    r3483 r3557  
    3737      get { return content; }
    3838      set {
    39         if ((value != null) && (!MainFormManager.ViewCanViewObject(this, value)))
     39        if ((value != null) && (!MainFormManager.ViewCanViewContent(this, value)))
    4040          throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name));
    4141        if (InvokeRequired) {
     
    5757      InitializeComponent();
    5858      this.locked = false;
    59     }
    60     public ContentView(IContent content)
    61       : this() {
    62       this.content = content;
    6359    }
    6460
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/DockingMainForm.cs

    r3437 r3557  
    4040      InitializeComponent();
    4141    }
    42     public DockingMainForm(Type userInterfaceItemType, bool showViewsInViewHost)
     42    public DockingMainForm(Type userInterfaceItemType, bool showContentInViewHost)
    4343      : this(userInterfaceItemType) {
    44       this.ShowViewsInViewHost = showViewsInViewHost;
     44      this.ShowContentInViewHost = showContentInViewHost;
    4545    }
    4646
     
    6767
    6868    protected override Form CreateForm(IView view) {
    69       DockForm form;
    70       IContentView contentView = view as IContentView;
    71       if (ShowViewsInViewHost && contentView != null && contentView.GetType() != typeof(ViewHost)) {
    72         ViewHost viewHost = new ViewHost(contentView);
    73         form = new DockForm(viewHost);
    74         this.AddViewFormCombination(viewHost, form);
    75       } else {
    76         form = new DockForm(view);
    77         this.AddViewFormCombination(view, form);
    78       }
    79       return form;
     69      return new DockForm(view);
    8070    }
    8171
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForm.cs

    r3488 r3557  
    3232using System.Collections;
    3333using WeifenLuo.WinFormsUI.Docking;
     34using HeuristicLab.Common;
    3435
    3536namespace HeuristicLab.MainForm.WindowsForms {
     
    4344      this.userInterfaceItems = new List<IUserInterfaceItem>();
    4445      this.initialized = false;
    45       this.showViewsInViewHost = false;
     46      this.showContentInViewHost = false;
    4647    }
    4748
     
    5253
    5354    #region properties
    54     private bool showViewsInViewHost;
    55     public bool ShowViewsInViewHost {
    56       get { return this.showViewsInViewHost; }
    57       set { this.showViewsInViewHost = value; }
     55    private bool showContentInViewHost;
     56    public bool ShowContentInViewHost {
     57      get { return this.showContentInViewHost; }
     58      set { this.showContentInViewHost = value; }
    5859    }
    5960
     
    8889    public IEnumerable<IView> Views {
    8990      get { return views.Keys; }
    90     }
    91     protected void AddViewFormCombination(IView view, Form form) {
    92       this.views.Add(view, form);
    93       view.Changed += new EventHandler(View_Changed);
    9491    }
    9592
     
    216213
    217214    internal Form GetForm(IView view) {
    218       IView internalView = GetView(view);
    219       if (internalView != null && views.ContainsKey(internalView))
    220         return views[internalView];
     215      if (views.ContainsKey(view))
     216        return views[view];
    221217      return null;
    222218    }
     
    224220      return views.Where(x => x.Value == form).Single().Key;
    225221    }
    226     private IView GetView(IView view) {
    227       if (view == null || views.ContainsKey(view))
    228         return view;
    229       IContentView contentView = view as IContentView;
    230       if (contentView != null) {
    231         IView viewHost =
    232           (from ViewHost v in views.Keys.OfType<ViewHost>()
    233            where v.Views.Contains(contentView)
    234            select v).SingleOrDefault();
    235         return viewHost;
    236       }
    237       return contentView;
     222
     223    public IContentView ShowContent(IContent content) {
     224      IContentView view;
     225      if (this.ShowContentInViewHost)
     226        view = new ViewHost();
     227      else
     228        view = MainFormManager.CreateDefaultView(content.GetType());
     229
     230      if (view != null) {
     231        view.Show();
     232        view.Content = content;
     233      }
     234      return view;
    238235    }
    239236
     
    243240        Form form = GetForm(view);
    244241        bool firstTimeShown = form == null;
    245         if (form == null) {
     242        if (firstTimeShown) {
    246243          form = CreateForm(view);
    247244          form.Activated += new EventHandler(FormActivated);
    248245          form.FormClosed += new FormClosedEventHandler(ChildFormClosed);
    249         }
    250         IView internalView = GetView(form);
    251         this.ShowView(internalView, firstTimeShown);
    252         this.OnViewShown(internalView, firstTimeShown);
     246          view.Changed += new EventHandler(View_Changed);
     247          views[view] = form;
     248        }
     249        this.ShowView(view, firstTimeShown);
     250        this.OnViewShown(view, firstTimeShown);
    253251      }
    254252    }
     
    267265      if (InvokeRequired) Invoke((Action<IView>)HideView, view);
    268266      else {
    269         IView internalView = this.GetView(view);
    270         if (internalView != null && this.views.ContainsKey(internalView)) {
    271           this.Hide(internalView);
    272           if (this.activeView == internalView)
    273             this.ActiveView = null;
    274           this.OnViewHidden(internalView);
    275         }
     267        this.Hide(view);
     268        if (this.activeView == view)
     269          this.ActiveView = null;
     270        this.OnViewHidden(view);
    276271      }
    277272    }
     
    296291    internal void CloseView(IView view) {
    297292      if (InvokeRequired) Invoke((Action<IView>)CloseView, view);
    298       else {
    299         IView internalView = GetView(view);
    300         if (internalView != null && this.views.ContainsKey(internalView)) {
    301           this.views[internalView].Close();
    302           this.OnViewClosed(internalView);
    303         }
     293      else if (views.ContainsKey(view)) {
     294        this.views[view].Close();
     295        this.OnViewClosed(view);
    304296      }
    305297    }
     
    307299    internal void CloseView(IView view, CloseReason closeReason) {
    308300      if (InvokeRequired) Invoke((Action<IView>)CloseView, view);
    309       else {
    310         IView internalView = GetView(view);
    311         if (internalView != null && this.views.ContainsKey(internalView)) {
    312           ((View)internalView).CloseReason = closeReason;
    313           this.CloseView(internalView);
    314         }
     301      else if (views.ContainsKey(view)) {
     302        ((View)view).CloseReason = closeReason;
     303        this.CloseView(view);
    315304      }
    316305    }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MultipleDocumentMainForm.cs

    r3437 r3557  
    3939      InitializeComponent();
    4040    }
    41     public MultipleDocumentMainForm(Type userInterfaceItemType, bool showViewsInViewHost)
     41    public MultipleDocumentMainForm(Type userInterfaceItemType, bool showContentInViewHost)
    4242      : this(userInterfaceItemType) {
    43       this.ShowViewsInViewHost = showViewsInViewHost;
     43      this.ShowContentInViewHost = showContentInViewHost;
    4444    }
    4545
     
    7676
    7777    protected override Form CreateForm(IView view) {
    78       Form form;
    79       IContentView contentView = view as IContentView;
    80       if (ShowViewsInViewHost && contentView != null && contentView.GetType() != typeof(ViewHost)) {
    81         ViewHost viewHost = new ViewHost(contentView);
    82         form = new DocumentForm(viewHost);
    83         this.AddViewFormCombination(viewHost, form);
    84       } else {
    85         form = new DocumentForm(view);
    86         this.AddViewFormCombination(view, form);
    87       }
    88 
     78      Form form = new DocumentForm(view);
    8979      form.MdiParent = this;
    9080      return form;
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/SingleDocumentMainForm.cs

    r3437 r3557  
    4040      InitializeComponent();
    4141    }
    42     public SingleDocumentMainForm(Type userInterfaceItemType, bool showViewsInViewHost)
     42    public SingleDocumentMainForm(Type userInterfaceItemType, bool showContentInViewHost)
    4343      : this(userInterfaceItemType) {
    44       this.ShowViewsInViewHost = showViewsInViewHost;
     44      this.ShowContentInViewHost = showContentInViewHost;
    4545    }
    4646
     
    7070
    7171    protected override Form CreateForm(IView view) {
    72       Form form;
    73       IContentView contentView = view as IContentView;
    74       if (ShowViewsInViewHost && contentView != null && contentView.GetType() != typeof(ViewHost)) {
    75         ViewHost viewHost = new ViewHost(contentView);
    76         form = new DocumentForm(viewHost);
    77         this.AddViewFormCombination(viewHost, form);
    78       } else {
    79         form = new DocumentForm(view);
    80         this.AddViewFormCombination(view, form);
    81       }
    82 
     72      Form form = new DocumentForm(view);
    8373      form.ShowInTaskbar = true;
    8474      return form;
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/View.cs

    r3437 r3557  
    3535      this.closeReason = CloseReason.None;
    3636      this.readOnly = false;
    37     }
    38 
    39     public View(bool readOnly)
    40       : this() {
    41       this.readOnly = readOnly;
    4237    }
    4338
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ViewHost.cs

    r3552 r3557  
    2828
    2929namespace HeuristicLab.MainForm.WindowsForms {
    30   [Content(typeof(object))]
     30  [Content(typeof(IContent))]
    3131  public sealed partial class ViewHost : AsynchronousContentView {
    3232    public ViewHost() {
     
    3939      Content = null;
    4040      OnContentChanged();
    41     }
    42     public ViewHost(IContent content)
    43       : this() {
    44       this.Content = content;
    45     }
    46 
    47     public ViewHost(IContentView contentView)
    48       : this() {
    49       this.viewType = contentView.GetType();
    50       this.Content = contentView.Content;
    51       this.cachedViews.Add(contentView.GetType(), contentView);
    52       this.activeView = contentView;
    53       this.RegisterActiveViewEvents();
    54       this.OnViewTypeChanged();
    55       this.ActiveViewChanged();
    5641    }
    5742
     
    117102    }
    118103
    119 
    120 
    121104    protected override void OnContentChanged() {
    122105      messageLabel.Visible = false;
     
    133116        }
    134117
    135 
    136118        if (!ViewCanShowContent(viewType, Content)) {
    137119          ViewType = MainFormManager.GetDefaultViewType(Content.GetType());
     
    148130      }
    149131    }
    150 
    151132
    152133    private void OnViewTypeChanged() {
     
    176157    }
    177158
    178 
    179 
    180159    private void RegisterActiveViewEvents() {
    181160      activeView.Changed += new EventHandler(activeView_Changed);
     
    256235
    257236    private void viewsLabel_DoubleClick(object sender, EventArgs e) {
    258       IContentView view = MainFormManager.CreateView(viewType, Content);
     237      IContentView view = MainFormManager.MainForm.ShowContent(this.Content);
    259238      view.ReadOnly = this.ReadOnly;
    260239      view.Locked = this.Locked;
    261       view.Show();
    262240    }
    263241    private void viewContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) {
Note: See TracChangeset for help on using the changeset viewer.