private void CurrentDataSet_SchemaObjectReplaced(object sender, SchemaObjectReplacedEventArgs e) { foreach (TreeViewItem item in treeViewDB.Items) { ReplaceSchemaObjectRecursive(item, e.New, e.Old); } for (int i = tabControlMain.Items.Count - 1; 0 <= i; i--) { TabItem item = tabControlMain.Items[i] as TabItem; if (item == null) { continue; } ISchemaObjectWpfControl obj = (item.Content as ISchemaObjectWpfControl); if (obj != null && obj.Target == e.Old) { if (e.New == null) { tabControlMain.Items.RemoveAt(i); } else { obj.Target = e.New; } } } }
public static TabItem RequireTabItem(SchemaObject target, Style tabItemStyle, TabControl tabControl, Db2SourceContext dataSet) { ISchemaObjectWpfControl ctrl = target.Control as ISchemaObjectWpfControl; if (ctrl != null) { ctrl.Target = dataSet.Refresh(target); return(ctrl.Parent as TabItem); } lock (TabItemLock) { if (ctrl != null) { return(ctrl.Parent as TabItem); } ctrl = NewControl(target, tabControl); if (ctrl == null) { return(null); } TabItem item = NewTabItem(tabControl, target.FullName, ctrl as UIElement, tabItemStyle); item.Tag = target; return(item); } }
private void TabItemCloseButton_Click(object sender, RoutedEventArgs e) { TabItem item = (sender as Control).TemplatedParent as TabItem; if (item == null) { return; } TabControl tab = item.Parent as TabControl; if (tab == null) { return; } ISchemaObjectWpfControl ctrl = item.Content as ISchemaObjectWpfControl; bool cancel = false; ctrl?.OnTabClosing(sender, ref cancel); if (cancel) { return; } tab.Items.Remove(item); ctrl?.OnTabClosed(sender); }
private void window_Closing(object sender, CancelEventArgs e) { foreach (TabItem c in tabControlMain.Items) { ISchemaObjectWpfControl obj = c.Content as ISchemaObjectWpfControl; if (obj == null) { continue; } bool f = e.Cancel; obj.OnTabClosing(sender, ref f); e.Cancel = f; if (e.Cancel) { return; } } }
public static ISchemaObjectWpfControl NewControl(SchemaObject target, TabControl parent) { Type t; if (!_schemaObjectToControl.TryGetValue(target.GetType(), out t)) { return(null); } ISchemaObjectWpfControl ret = t.GetConstructor(new Type[0]).Invoke(null) as ISchemaObjectWpfControl; if (ret == null) { return(null); } ret.Target = target; target.Control = ret; return(ret); }
//#pragma warning restore 1998 public void OpenViewer(SchemaObject target) { ISchemaObjectWpfControl curCtl = (tabControlMain.SelectedItem as TabItem)?.Content as ISchemaObjectWpfControl; TabItem item = MovableTabItem.RequireTabItem(target, FindResource("TabItemStyleClosable") as Style, tabControlMain, CurrentDataSet); if (item == null) { return; } if (item.Parent == null) { tabControlMain.Items.Add(item); } tabControlMain.SelectedItem = item; ISchemaObjectWpfControl newCtl = item.Content as ISchemaObjectWpfControl; if (newCtl != null && curCtl != null) { newCtl.SelectedTabKey = curCtl.SelectedTabKey; } }