//=------------------------------------------------------------------= // OnRemove //=------------------------------------------------------------------= /// <summary> /// The user has selected the "Remove" verb in the designer. /// Remove the active TaskFrame. /// </summary> /// private void OnRemove(object sender, EventArgs e) { DesignerTransaction dt = null; MemberDescriptor md; IDesignerHost idh; TaskPane tp; // // Make sure we have a task pane with some valid frames !!! // tp = (TaskPane)this.Component; if (tp == null || this.m_lastFrameSelected == null || !tp.TaskFrames.Contains(this.m_lastFrameSelected)) { return; } md = TypeDescriptor.GetProperties(this.Component)["Controls"]; // // Get last selection taskframe. // // // get the designer host // idh = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (idh != null) { try { try { dt = idh.CreateTransaction(TaskPaneMain.GetResourceManager().GetString("TaskPaneMiscTransR")); RaiseComponentChanging(md); } catch (CheckoutException ex) { // // If this was cancelled, then that's cool. // if (ex == CheckoutException.Canceled) { return; } throw ex; } idh.DestroyComponent(this.m_lastFrameSelected); RaiseComponentChanged(md, null, null); tp.Refresh(); } finally { if (dt != null) { dt.Commit(); } } } }
//=------------------------------------------------------------------= // OnAdd //=------------------------------------------------------------------= /// <summary> /// The user has selected the 'Add' verb in the designer. Go and /// add a new TaskFrame to the TaskPane. This is surprisingly /// complicated ... /// </summary> /// private void OnAdd(object sender, EventArgs e) { DesignerTransaction dt = null; PropertyDescriptor pd; MemberDescriptor md; IDesignerHost idh; TaskFrame tf; TaskPane tp; tp = (TaskPane)this.Component; md = TypeDescriptor.GetProperties(this.Component)["Controls"]; idh = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (idh != null) { try { try { dt = idh.CreateTransaction(TaskPaneMain.GetResourceManager().GetString("TaskPaneMiscTransA")); RaiseComponentChanging(md); } catch (CheckoutException ex) { // // if it was cancelled, then we have no problem. // if (ex == CheckoutException.Canceled) { return; } // // otherwise, rethrow the exception. // throw ex; } // // create the new component, name it, and then add it. // tf = (TaskFrame)idh.CreateComponent(typeof(TaskFrame)); pd = TypeDescriptor.GetProperties(tf)["Name"]; if (pd != null && pd.PropertyType == typeof(string)) { tf.Text = (string)pd.GetValue(tf); } tp.Controls.Add(tf); // // Finally, fire some more events... // RaiseComponentChanged(md, null, null); } finally { if (dt != null) { dt.Commit(); } } } }