Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2548 for trunk/sources


Ignore:
Timestamp:
12/10/09 10:11:28 (15 years ago)
Author:
mkommend
Message:

added ViewShown, ViewHidden and ViewClosed events in MainForm (ticket #771)

Location:
trunk/sources
Files:
2 added
7 edited

Legend:

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

    r2458 r2548  
    4242    }
    4343
    44     public override bool ShowView(IView view) {
    45       if (InvokeRequired) return (bool)Invoke((Func<IView, bool>)ShowView, view);
     44    protected override void Show(IView view, bool firstTimeShown) {
     45      if (InvokeRequired) Invoke((Action<IView, bool>)Show, view, firstTimeShown);
    4646      else {
    47         bool ret = base.ShowView(view);
    48         if (ret)
     47        base.Show(view, firstTimeShown);
     48        if (firstTimeShown)
    4949          ((DockForm)GetForm(view)).Show(dockPanel);
    5050        else
    5151          ((DockForm)GetForm(view)).Activate();
    52         return ret;
    5352      }
    5453    }
    55     public override void HideView(IView view) {
     54
     55    protected override void Hide(IView view) {
    5656      if (InvokeRequired) Invoke((Action<IView>)HideView, view);
    5757      else {
    5858        Form form = base.GetForm(view);
    59         if (form != null)
     59        if (form != null) {
    6060          ((DockForm)form).Hide();
     61        }
    6162      }
    6263    }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MainFormBase.cs

    r2544 r2548  
    130130    }
    131131
     132    public event EventHandler<ViewEventArgs> ViewClosed;
     133    protected virtual void OnViewClosed(IView view) {
     134      if (InvokeRequired) Invoke((Action<IView>)OnViewClosed, view);
     135      else if (this.ViewClosed != null) {
     136        this.ViewClosed(this, new ViewEventArgs(view));
     137      }
     138    }
     139
     140    public event EventHandler<ViewShownEventArgs> ViewShown;
     141    protected virtual void OnViewShown(IView view, bool firstTimeShown) {
     142      if (InvokeRequired) Invoke((Action<IView, bool>)OnViewShown, view, firstTimeShown);
     143      else if (this.ViewShown != null) {
     144        this.ViewShown(this, new ViewShownEventArgs(view, firstTimeShown));
     145      }
     146    }
     147
     148    public event EventHandler<ViewEventArgs> ViewHidden;
     149    protected virtual void OnViewHidden(IView view) {
     150      if (InvokeRequired) Invoke((Action<IView>)OnViewHidden, view);
     151      else if (this.ViewHidden != null) {
     152        this.ViewHidden(this, new ViewEventArgs(view));
     153      }
     154    }
     155
    132156    public event EventHandler Changed;
    133157    public void FireMainFormChanged() {
     
    145169    }
    146170
    147     public virtual bool ShowView(IView view) {
    148       if (InvokeRequired) return (bool)Invoke((Func<IView, bool>)ShowView, view);
     171    public void ShowView(IView view) {
     172      if (InvokeRequired) Invoke((Action<IView>)ShowView, view);
    149173      else {
    150174        if (!views.Keys.Contains(view)) {
     
    159183          foreach (IUserInterfaceItem item in UserInterfaceItems)
    160184            view.Changed += new EventHandler(item.ViewChanged);
    161           return true;
    162         } else
    163           return false;
    164       }
    165     }
    166 
    167     public virtual void HideView(IView view) {
     185          this.Show(view, true);
     186          this.OnViewShown(view, true);
     187        } else {
     188          this.Show(view, false);
     189          this.OnViewShown(view, false);
     190        }
     191      }
     192    }
     193
     194    protected virtual void Show(IView view, bool firstTimeShown) {     
     195    }
     196
     197    public void HideView(IView view) {
    168198      if (InvokeRequired) Invoke((Action<IView>)HideView, view);
    169199      else {
    170         if (views.ContainsKey(view))
    171           views[view].Hide();
    172       }
     200        if (this.views.ContainsKey(view)) {
     201          this.Hide(view);
     202          this.OnViewHidden(view);
     203        }
     204      }
     205    }
     206
     207    protected virtual void Hide(IView view) {
    173208    }
    174209
     
    176211      if (InvokeRequired) Invoke((Action<IView>)CloseView, view);
    177212      else {
    178         if (views.ContainsKey(view))
    179           views[view].Close();
     213        if (this.views.ContainsKey(view)) {
     214          this.views[view].Close();
     215          this.OnViewClosed(view);
     216        }
    180217      }
    181218    }
     
    184221      if (InvokeRequired) Invoke((Action<IView>)CloseView, view);
    185222      else {
    186         if (views.ContainsKey(view)) {
     223        if (this.views.ContainsKey(view)) {
    187224          ((ViewBase)view).closeReason = closeReason;
    188           views[view].Close();
     225          this.CloseView(view);
    189226        }
    190227      }
     
    198235    public virtual void CloseAllViews(CloseReason closeReason) {
    199236      foreach (IView view in views.Keys.ToArray())
    200         CloseView(view,closeReason);
     237        CloseView(view, closeReason);
    201238    }
    202239    #endregion
     
    217254
    218255      views.Remove(view);
     256      this.OnViewClosed(view);
    219257      if (ActiveView == view)
    220258        ActiveView = null;
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MultipleDocumentMainForm.cs

    r2458 r2548  
    4848    }
    4949
    50     public override bool ShowView(IView view) {
    51       if (InvokeRequired) return (bool)Invoke((Func<IView, bool>)ShowView, view);
     50    protected override void Show(IView view, bool firstTimeShown) {
     51      if (InvokeRequired) Invoke((Action<IView, bool>)Show, view, firstTimeShown);
    5252      else {
    53         bool ret = base.ShowView(view);
    54         if (ret)
    55           GetForm(view).Show();
     53        base.Show(view, firstTimeShown);
     54        if (firstTimeShown)
     55          GetForm(view).Show(this);
    5656        else {
    5757          GetForm(view).Visible = true;
    5858          GetForm(view).Activate();
    5959        }
    60         return ret;
     60      }
     61    }
     62
     63    protected override void Hide(IView view) {
     64      if (InvokeRequired) Invoke((Action<IView>)Hide, view);
     65      else {
     66        base.Hide(view);
     67        this.GetForm(view).Hide();
    6168      }
    6269    }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/SingleDocumentMainForm.cs

    r2458 r2548  
    4242    }
    4343
    44     public override bool ShowView(IView view) {
    45       if (InvokeRequired) return (bool)Invoke((Func<IView, bool>)ShowView, view);
     44    protected override void Show(IView view, bool firstTimeShown) {
     45      if (InvokeRequired) Invoke((Action<IView, bool>)Show, view, firstTimeShown);
    4646      else {
    47         bool ret = base.ShowView(view);
    48         if (ret)
     47        base.Show(view, firstTimeShown);
     48        if (firstTimeShown)
    4949          GetForm(view).Show(this);
    5050        else {
     
    5252          GetForm(view).Activate();
    5353        }
    54         return ret;
     54      }
     55    }
     56
     57    protected override void Hide(IView view) {
     58      if (InvokeRequired) Invoke((Action<IView>)Hide, view);
     59      else {
     60        base.Hide(view);
     61        this.GetForm(view).Hide();
    5562      }
    5663    }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewBase.cs

    r2543 r2548  
    4242      get { return myCaption; }
    4343      set {
    44         if (value != myCaption) {
    45           myCaption = value;
    46           OnCaptionChanged();
     44        if (InvokeRequired) {
     45          Action<string> action = delegate(string s) { this.Caption = s; };
     46          Invoke(action, value);
     47        } else {
     48          if (value != myCaption) {
     49            myCaption = value;
     50            OnCaptionChanged();
     51          }
    4752        }
    4853      }
     
    5762    public event EventHandler Changed;
    5863    protected virtual void OnChanged() {
    59       if (Changed != null)
     64      if (InvokeRequired)
     65        Invoke((MethodInvoker)OnChanged);
     66      else if (Changed != null)
    6067        Changed(this, new EventArgs());
    6168    }
    6269
    63     public virtual void OnClosing(object sender, CancelEventArgs e) {     
     70    public virtual void OnClosing(object sender, CancelEventArgs e) {
    6471    }
    6572
     
    6774    internal void OnClosingHelper(object sender, FormClosingEventArgs e) {
    6875      if (this.closeReason != CloseReason.None)
    69         this.OnClosing(sender, new FormClosingEventArgs(this.closeReason,e.Cancel));
     76        this.OnClosing(sender, new FormClosingEventArgs(this.closeReason, e.Cancel));
    7077      else
    7178        this.OnClosing(sender, e);
    72      
     79
    7380      this.closeReason = CloseReason.None;
    7481    }
    7582
    76     public virtual void OnClosing(object sender, FormClosingEventArgs e) {     
     83    public virtual void OnClosing(object sender, FormClosingEventArgs e) {
    7784    }
    7885
  • trunk/sources/HeuristicLab.MainForm/3.2/HeuristicLab.MainForm-3.2.csproj

    r2514 r2548  
    8181  </ItemGroup>
    8282  <ItemGroup>
     83    <Compile Include="ViewShownEventArgs.cs" />
     84    <Compile Include="ViewEventArgs.cs" />
    8385    <Compile Include="ToolBarSeparatorItemBase.cs" />
    8486    <Compile Include="Interfaces\IToolBarSeparatorItem.cs" />
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IMainForm.cs

    r2458 r2548  
    3131
    3232    IView ActiveView { get; }
     33    IEnumerable<IView> Views { get; }
     34
    3335    event EventHandler ActiveViewChanged;
    3436    event EventHandler Changed;
    35     IEnumerable<IView> Views { get; }
     37   
     38    event EventHandler<ViewEventArgs> ViewClosed;
     39    event EventHandler<ViewShownEventArgs> ViewShown;
     40    event EventHandler<ViewEventArgs> ViewHidden;
    3641
    3742    Type UserInterfaceItemType { get; }
    38     bool ShowView(IView view);  //return value indicates if a new form for the view is created
     43    void ShowView(IView view);
    3944    void HideView(IView view);
    4045    void CloseView(IView view);
Note: See TracChangeset for help on using the changeset viewer.