Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2254


Ignore:
Timestamp:
08/07/09 11:27:34 (15 years ago)
Author:
mkommend
Message:

added ability for toolstripitems to listen for specific events (ticket #716)

Location:
trunk/sources
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/SaveToolStripButtonItem.cs

    r2249 r2254  
    2121      new SaveAction().Execute(mainform);
    2222    }
     23
     24    public override bool ListenActiveViewChanged {
     25      get { return true; }
     26    }
     27
     28    public override void ActiveViewChanged(object sender, EventArgs e) {
     29      IMainForm mainform = (IMainForm)sender;
     30      if (mainform.ActiveView == null)
     31        this.ToolStripItem.Enabled = false;
     32      else
     33        this.ToolStripItem.Enabled = !(mainform.ActiveView is FormView);
     34    }
     35
     36    public override bool ListenViewStateChanged {
     37      get { return true; }
     38    }
     39
     40    public override void ViewStateChanged(object sender, EventArgs e) {
     41      this.ToolStripItem.Enabled = !this.ToolStripItem.Enabled;
     42    }
    2343  }
    2444}
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/EditorView.Designer.cs

    r2250 r2254  
    2525    private void InitializeComponent() {
    2626      this.label1 = new System.Windows.Forms.Label();
     27      this.ChangeStateButton = new System.Windows.Forms.Button();
    2728      this.SuspendLayout();
    2829      //
     
    3738      this.label1.Text = "EditorForm";
    3839      //
     40      // ChangeStateButton
     41      //
     42      this.ChangeStateButton.Location = new System.Drawing.Point(34, 100);
     43      this.ChangeStateButton.Name = "ChangeStateButton";
     44      this.ChangeStateButton.Size = new System.Drawing.Size(75, 23);
     45      this.ChangeStateButton.TabIndex = 1;
     46      this.ChangeStateButton.Text = "ChangeState";
     47      this.ChangeStateButton.UseVisualStyleBackColor = true;
     48      this.ChangeStateButton.Click += new System.EventHandler(this.ChangeStateButton_Click);
     49      //
    3950      // EditorView
    4051      //
    4152      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    4253      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     54      this.Controls.Add(this.ChangeStateButton);
    4355      this.Controls.Add(this.label1);
    4456      this.ForeColor = System.Drawing.SystemColors.ControlText;
     
    5264
    5365    private System.Windows.Forms.Label label1;
     66    private System.Windows.Forms.Button ChangeStateButton;
    5467  }
    5568}
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/EditorView.cs

    r2250 r2254  
    1717      : base(mainform) {
    1818    }
     19
     20    private void ChangeStateButton_Click(object sender, EventArgs e) {
     21      this.OnStateChanged();
     22    }
    1923  }
    2024}
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/ExitToolStripMenuItem.cs

    r2250 r2254  
    2323
    2424    public override void Execute(IMainForm mainform) {
    25       mainform.Close();
     25      mainform.CloseForm();
    2626    }
    2727  }
  • trunk/sources/HeuristicLab.MainForm/3.2/DockingMainForm.cs

    r2253 r2254  
    4444    private DockPanel dockPanel;
    4545
    46     public override void ShowView(IView view) {
    47      
     46    public override void ShowView(IView view) {     
    4847      if (InvokeRequired) Invoke((Action<IView>)ShowView, view);
    4948      else {
     
    5251        content.Activated += new EventHandler(DockFormActivated);
    5352        content.FormClosing += new FormClosingEventHandler(DockFormClosing);
     53        foreach (IToolStripItem item in viewStateChangeToolStripItems)
     54          view.StateChanged += new EventHandler(item.ViewStateChanged);
    5455        content.Show(dockPanel);
    5556      }
     
    6061      openViews.Remove(dockForm.View);
    6162      if (openViews.Count == 0)
    62         activeView = null;
     63        ActiveView = null;
    6364      dockForm.Activated -= new EventHandler(DockFormActivated);
    6465      dockForm.FormClosing -= new FormClosingEventHandler(DockFormClosing);
     66      foreach (IToolStripItem item in viewStateChangeToolStripItems)
     67        dockForm.View.StateChanged -= new EventHandler(item.ViewStateChanged);
    6568    }
    6669
    6770    private void DockFormActivated(object sender, EventArgs e) {
    68       base.activeView = ((DockForm)sender).View;
     71      base.ActiveView = ((DockForm)sender).View;
    6972      base.StatusStripText = ((DockForm)sender).View.Caption;
    7073    }
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IMainForm.cs

    r2250 r2254  
    3333
    3434    IView ActiveView { get; }
     35    event EventHandler ActiveViewChanged;
    3536    IEnumerable<IView> OpenViews { get; }
    3637
    3738    Type UserInterfaceItemType { get; }
    3839    void ShowView(IView view);
    39 
    40     void Close();
     40    void CloseForm();
    4141  }
    4242}
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IToolStripItem.cs

    r2249 r2254  
    3737
    3838    ToolStripItem ToolStripItem { get; set; }
     39
     40    bool ListenActiveViewChanged { get; }
     41    bool ListenViewStateChanged { get; }
     42    void ActiveViewChanged(object sender, EventArgs e);
     43    void ViewStateChanged(object sender, EventArgs e);
    3944  }
    4045}
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IView.cs

    r2233 r2254  
    2828    string Caption { get; set; }
    2929    event EventHandler CaptionChanged;
     30    event EventHandler StateChanged;
    3031    IMainForm MainForm { get; set; }
    3132  }
  • trunk/sources/HeuristicLab.MainForm/3.2/MainFormBase.cs

    r2250 r2254  
    3737      InitializeComponent();
    3838      openViews = new List<IView>();
     39      viewStateChangeToolStripItems = new List<IToolStripItem>();
    3940      this.userInterfaceItemType = userInterfaceItemType;
    4041      CreateGUI();
     42      OnActiveViewChanged();
    4143    }
    4244
     
    5759    }
    5860
    59     protected IView activeView;
     61    private IView activeView;
    6062    public IView ActiveView {
    6163      get { return this.activeView; }
     64      protected set {
     65        if (this.activeView != value) {
     66          this.activeView = value;
     67          OnActiveViewChanged();
     68        }
     69      }
     70    }
     71
     72    protected List<IToolStripItem> viewStateChangeToolStripItems;
     73
     74    public event EventHandler ActiveViewChanged;
     75    protected virtual void OnActiveViewChanged() {
     76      if(ActiveViewChanged != null)
     77        ActiveViewChanged(this,new EventArgs());
    6278    }
    6379
     
    6884
    6985    public virtual void ShowView(IView view) {
    70       view.MainForm = this;
    71       activeView = view;
     86      view.MainForm = this;     
    7287      openViews.Add(view);
     88      ActiveView = view;
    7389    }
    7490
    75     public void Close() {
    76       ((Form)this).Close();
     91    public void CloseForm() {
     92      this.Close();
    7793    }
    7894    #endregion
     
    94110      foreach (IToolStripButtonItem toolStripButtonItem in toolStripItems) {
    95111        AddToolStripButtonItem(toolStripButtonItem);
    96       }     
     112      }
    97113    }
    98114
     
    117133
    118134      SetToolStripItemProperties(item, buttonItem);
    119       ToolStripDropDownItem parent = FindParent(buttonItem,toolStrip.Items);
     135      ToolStripDropDownItem parent = FindParent(buttonItem, toolStrip.Items);
    120136      if (parent == null)
    121137        toolStrip.Items.Add(item);
     
    142158      toolStripItem.Image = iToolStripItem.Image;
    143159      toolStripItem.DisplayStyle = iToolStripItem.DisplayStyle;
     160      if (iToolStripItem.ListenActiveViewChanged)
     161        this.ActiveViewChanged += new EventHandler(iToolStripItem.ActiveViewChanged);
     162      if (iToolStripItem.ListenViewStateChanged)
     163        this.viewStateChangeToolStripItems.Add(iToolStripItem);
    144164      toolStripItem.Click += new EventHandler(ToolStripItemClicked);
    145165      iToolStripItem.ToolStripItem = toolStripItem;
  • trunk/sources/HeuristicLab.MainForm/3.2/MultipleDocumentMainForm.Designer.cs

    r2253 r2254  
    3434      this.Name = "MultipleDocumentMainForm";
    3535      this.ResumeLayout(false);
    36 
    3736    }
    3837
  • trunk/sources/HeuristicLab.MainForm/3.2/MultipleDocumentMainForm.cs

    r2253 r2254  
    2929
    3030    private void MultipleDocumentFormActivated(object sender, EventArgs e) {
    31       base.activeView = ((MultipleDocumentForm)sender).View;
     31      base.ActiveView = ((MultipleDocumentForm)sender).View;
    3232      base.StatusStripText = ((MultipleDocumentForm)sender).View.Caption;
    3333    }
     
    3737      openViews.Remove(form.View);
    3838      if (openViews.Count == 0)
    39         activeView = null;
     39        ActiveView = null;
    4040      form.Activated -= new EventHandler(MultipleDocumentFormActivated);
    4141      form.FormClosing -= new FormClosingEventHandler(MultipleDocumentFormClosing);
  • trunk/sources/HeuristicLab.MainForm/3.2/ToolStripItemBase.cs

    r2249 r2254  
    5555      get { return ToolStripMenuItemBase.structureSeparator; }
    5656    }
     57
     58    public virtual bool ListenActiveViewChanged {
     59      get { return false; }
     60    }
     61    public virtual bool ListenViewStateChanged {
     62      get { return false; }
     63    }
     64
     65    public virtual void ActiveViewChanged(object sender, EventArgs e) {
     66    }
     67
     68    public virtual void ViewStateChanged(object sender, EventArgs e) {
     69    }
    5770    #endregion
    5871  }
  • trunk/sources/HeuristicLab.MainForm/3.2/ViewBase.cs

    r2250 r2254  
    5757    }
    5858
     59    public event EventHandler StateChanged;
     60    protected virtual void OnStateChanged() {
     61      if (StateChanged != null)
     62        StateChanged(this, new EventArgs());
     63    }
     64
    5965    private IMainForm mainForm;
    6066    public IMainForm MainForm {
     
    6268      set { this.mainForm = value; }
    6369    }
    64 
    6570  }
    6671}
Note: See TracChangeset for help on using the changeset viewer.