Changeset 2426 for branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/MainFormBase.cs
- Timestamp:
- 10/13/09 10:58:31 (15 years ago)
- Location:
- branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms
- Files:
-
- 2 added
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/MainFormBase.cs
r2420 r2426 31 31 using HeuristicLab.PluginInfrastructure; 32 32 33 namespace HeuristicLab.MainForm {33 namespace HeuristicLab.MainForm.WindowsForms { 34 34 public partial class MainFormBase : Form, IMainForm { 35 35 protected MainFormBase() 36 36 : base() { 37 37 InitializeComponent(); 38 views = new List<IView>();39 t oolStripItems = new List<IToolStripItem>();40 this.StatusStripText = "";38 this.views = new List<IView>(); 39 this.userInterfaceItems = new List<IUserInterfaceItem>(); 40 MainFormManager.RegisterMainForm(this); 41 41 } 42 42 … … 58 58 } else 59 59 this.Text = value; 60 }61 }62 63 public string StatusStripText {64 get { return this.toolStripStatusLabel.Text; }65 set {66 if (InvokeRequired) {67 Action<string> action = delegate(string s) { this.StatusStripText = s; };68 Invoke(action, value);69 } else70 this.toolStripStatusLabel.Text = value;71 }72 }73 74 public bool StatusStripProgressBarVisible {75 get { return this.toolStripProgressBar.Visible; }76 set {77 if (InvokeRequired) {78 Action<bool> action = delegate(bool b) { this.StatusStripProgressBarVisible = b; };79 Invoke(action, value);80 } else81 this.toolStripProgressBar.Visible = value;82 60 } 83 61 } … … 121 99 } 122 100 123 private List<I ToolStripItem> toolStripItems;124 protected IEnumerable<I ToolStripItem> ToolStripItems {125 get { return this. toolStripItems; }101 private List<IUserInterfaceItem> userInterfaceItems; 102 protected IEnumerable<IUserInterfaceItem> UserInterfaceItems { 103 get { return this.userInterfaceItems; } 126 104 } 127 105 … … 134 112 } 135 113 136 public event EventHandler MainFormChanged;114 public event EventHandler Changed; 137 115 public void FireMainFormChanged() { 138 116 OnMainFormChanged(); … … 141 119 if (InvokeRequired) 142 120 Invoke((MethodInvoker)FireMainFormChanged); 143 else if ( MainFormChanged != null)144 MainFormChanged(this, new EventArgs());121 else if (Changed != null) 122 Changed(this, new EventArgs()); 145 123 } 146 124 147 125 public virtual void ShowView(IView view) { 148 126 if (!views.Contains(view)) { 149 view.MainForm = this;150 127 views.Add(view); 151 ActiveView = view;152 }128 } 129 this.ActiveView = view; 153 130 } 154 131 … … 173 150 174 151 object[] items = ds.GetInstances(userInterfaceItemType); 175 IEnumerable< IToolStripMenuItem> toolStripMenuItems =152 IEnumerable<MenuItemBase> toolStripMenuItems = 176 153 from mi in items 177 where mi is IToolStripMenuItem178 orderby (( IToolStripMenuItem)mi).Position179 select ( IToolStripMenuItem)mi;180 foreach ( IToolStripMenuItemmenuItem in toolStripMenuItems)154 where mi is MenuItemBase 155 orderby ((MenuItemBase)mi).Position 156 select (MenuItemBase)mi; 157 foreach (MenuItemBase menuItem in toolStripMenuItems) 181 158 AddToolStripMenuItem(menuItem); 182 159 183 160 items = ds.GetInstances(userInterfaceItemType); 184 IEnumerable< IToolStripButtonItem> toolStripButtonItems =161 IEnumerable<ToolBarItemBase> toolStripButtonItems = 185 162 from bi in items 186 where bi is IToolStripButtonItem187 orderby (( IToolStripButtonItem)bi).Position188 select ( IToolStripButtonItem)bi;189 foreach ( IToolStripButtonItemtoolStripButtonItem in toolStripButtonItems)163 where bi is ToolBarItemBase 164 orderby ((ToolBarItemBase)bi).Position 165 select (ToolBarItemBase)bi; 166 foreach (ToolBarItemBase toolStripButtonItem in toolStripButtonItems) 190 167 AddToolStripButtonItem(toolStripButtonItem); 191 168 } 192 169 193 private void AddToolStripMenuItem( IToolStripMenuItemmenuItem) {170 private void AddToolStripMenuItem(MenuItemBase menuItem) { 194 171 ToolStripMenuItem item = new ToolStripMenuItem(); 195 172 SetToolStripItemProperties(item, menuItem); 173 menuItem.ToolStripItem = item; 196 174 item.ShortcutKeys = menuItem.ShortCutKeys; 197 198 ToolStripDropDownItem parent = FindParent(menuItem, menuStrip.Items); 199 if (parent == null) 200 menuStrip.Items.Add(item); 201 else 202 parent.DropDownItems.Add(item); 203 } 204 205 private void AddToolStripButtonItem(IToolStripButtonItem buttonItem) { 175 item.DisplayStyle = menuItem.ToolStripItemDisplayStyle; 176 this.InsertItem(menuItem.Structure, typeof(ToolStripMenuItem), item, menuStrip.Items); 177 } 178 179 private void AddToolStripButtonItem(ToolBarItemBase buttonItem) { 206 180 ToolStripItem item; 207 181 if (buttonItem.IsDropDownButton) … … 211 185 212 186 SetToolStripItemProperties(item, buttonItem); 213 ToolStripDropDownItem parent = FindParent(buttonItem, toolStrip.Items); 214 if (parent == null) 215 toolStrip.Items.Add(item); 216 else 217 parent.DropDownItems.Add(item); 218 } 219 220 private ToolStripDropDownItem FindParent(IToolStripItem item, ToolStripItemCollection parentItems) { 221 if (String.IsNullOrEmpty(item.Structure)) 222 return null; 223 187 item.DisplayStyle = buttonItem.ToolStripItemDisplayStyle; 188 buttonItem.ToolStripItem = item; 189 this.InsertItem(buttonItem.Structure, typeof(ToolStripDropDownButton), item, toolStrip.Items); 190 } 191 192 private void InsertItem(IEnumerable<string> structure, Type t,ToolStripItem item, ToolStripItemCollection parentItems) { 224 193 ToolStripDropDownItem parent = null; 225 foreach (string structure in item.Structure.Split(item.StructureSeparator)) { 226 if (parentItems.ContainsKey(structure)) 227 parent = (ToolStripDropDownItem)parentItems[structure]; 228 else 229 throw new ArgumentException("Structure string for item " + item.Name + 230 " is invalid. Could not find " + structure + " in toolstrip!"); 194 foreach (string s in structure) { 195 if (parentItems.ContainsKey(s)) 196 parent = (ToolStripDropDownItem)parentItems[s]; 197 else { 198 parent = (ToolStripDropDownItem)Activator.CreateInstance(t, s,null,null,s); ; 199 parentItems.Add(parent); 200 } 231 201 parentItems = parent.DropDownItems; 232 202 } 233 return parent;234 } 235 236 private void SetToolStripItemProperties(ToolStripItem toolStripItem, I ToolStripItem iToolStripItem) {237 toolStripItem. Text = iToolStripItem.Name;238 toolStripItem. Name = iToolStripItem.Name;239 toolStripItem.T ag = iToolStripItem;240 toolStripItem. Image = iToolStripItem.Image;241 toolStripItem. DisplayStyle = iToolStripItem.DisplayStyle;242 this.ActiveViewChanged += new EventHandler( iToolStripItem.ActiveViewChanged);243 this. MainFormChanged += new EventHandler(iToolStripItem.MainFormChanged);203 parentItems.Add(item); 204 } 205 206 private void SetToolStripItemProperties(ToolStripItem toolStripItem, IUserInterfaceItem userInterfaceItem) { 207 toolStripItem.Name = userInterfaceItem.Name; 208 toolStripItem.Text = userInterfaceItem.Name; 209 toolStripItem.ToolTipText = userInterfaceItem.ToolTipText; 210 toolStripItem.Tag = userInterfaceItem; 211 toolStripItem.Image = userInterfaceItem.Image; 212 this.ActiveViewChanged += new EventHandler(userInterfaceItem.ActiveViewChanged); 213 this.Changed += new EventHandler(userInterfaceItem.MainFormChanged); 244 214 toolStripItem.Click += new EventHandler(ToolStripItemClicked); 245 this.toolStripItems.Add(iToolStripItem); 246 iToolStripItem.ToolStripItem = toolStripItem; 215 this.userInterfaceItems.Add(userInterfaceItem); 247 216 } 248 217 249 218 private void ToolStripItemClicked(object sender, EventArgs e) { 250 219 System.Windows.Forms.ToolStripItem item = (System.Windows.Forms.ToolStripItem)sender; 251 ((I Action)item.Tag).Execute(this);220 ((IUserInterfaceItem)item.Tag).Execute(); 252 221 } 253 222 #endregion
Note: See TracChangeset
for help on using the changeset viewer.