private object OpenOrFocusPluginWindow(Type tp) { if (!_retainedControls.ContainsKey(tp)) { IXbimXplorerPluginWindow instance; if (_retainedControls.ContainsKey(tp)) { instance = _retainedControls[tp].PluginInterface; } else { try { instance = (IXbimXplorerPluginWindow)Activator.CreateInstance(tp); } catch (Exception ex) { var msg = $"Error creating instance of type '{tp}'"; Logger.LogError(0, ex, "Error creating instance of type '{type}'", tp); return(null); } } var menuWindow = ShowPluginWindow(instance, true); if (menuWindow == null) { return(null); } // if returned the window must be retained. var i = new SinglePluginItem() { PluginInterface = instance, UiObject = menuWindow }; _retainedControls.Add(tp, i); return(instance); } var v = _retainedControls[tp]; var anchorable = v.UiObject as LayoutAnchorable; if (anchorable == null) { return(null); } if (anchorable.IsHidden) { anchorable.Show(); } if (!anchorable.IsVisible) { GetRightPane().Children.Add(anchorable); } anchorable.IsActive = true; return(anchorable.Content); }
private bool OpenOrFocusPluginWindow(Type tp) { if (!_retainedControls.ContainsKey(tp)) { IXbimXplorerPluginWindow instance; if (_retainedControls.ContainsKey(tp)) { instance = _retainedControls[tp].pluginInterface; } else { try { instance = (IXbimXplorerPluginWindow)Activator.CreateInstance(tp); } catch (Exception ex) { var msg = string.Format("Error creating instance of type '{0}'", tp); Log.Error(msg, ex); return(false); } } var menuWindow = ShowPluginWindow(instance, true); if (menuWindow == null) { return(true); } // if returned the window must be retained. var i = new SinglePluginItem() { pluginInterface = instance, UiObject = menuWindow }; _retainedControls.Add(tp, i); return(true); } var v = _retainedControls[tp]; if (v.UiObject is LayoutAnchorable) { var anch = v.UiObject as LayoutAnchorable; if (anch.IsHidden) { anch.Show(); } anch.IsActive = true; return(true); } else if (v.UiObject is Window) { // ShowPluginWindow(v, true); } return(false); }
private void EvaluateXbimUiType(Type type) { if (!typeof(IXbimXplorerPluginWindow).IsAssignableFrom(type)) { return; } EvaluateXbimUiMenu(type); var act = type.GetUiActivation(); if (act != PluginWindowActivation.OnLoad) { return; } var instance = Activator.CreateInstance(type); var asPWin = instance as IXbimXplorerPluginWindow; if (asPWin == null) { return; } if (_pluginWindows.Contains(asPWin)) { return; } //(instance as UserControl).Loaded += PluginWindowLoaded; //(instance as UserControl).Unloaded += PluginWindowUnloaded; //(instance as UserControl).IsVisibleChanged += PluginWindowVisibleChanged; var menuWindow = ShowPluginWindow(asPWin, true); // if returned the window must be retained. var item = new SinglePluginItem() { PluginInterface = asPWin, UiObject = menuWindow }; _retainedControls.Add(type, item); if ((_retainedControls[type].UiObject as LayoutAnchorable) != null) { (_retainedControls[type].UiObject as LayoutAnchorable).IsActive = true; //(_retainedControls[type].UiObject as LayoutAnchorable).Hiding += PluginWindowHiding; } }
private void OpenOrFocusPluginWindow(Type tp) { bool pluginWindowIsInitialized = false; SinglePluginItem v = null; _retainedControls.TryGetValue(tp, out v); if (v != null) { var anchorableTest = v.UiObject as LayoutContent; // The plugin is already loaded in the memory. We need to figure out whether it is already loaded in the UI. There are a few things to check before it is certain that the plugin is still there // 1. From the Plugin itself whether it is Loaded and Visible var plgInW = anchorableTest.Content as Window; if (plgInW != null) { if (plgInW.IsLoaded && plgInW.IsVisible) { return; // It is already Loaded and Visible } } var plgInUC = anchorableTest.Content as UserControl; if (plgInUC != null) { if (plgInUC.IsLoaded && plgInUC.IsVisible) { return; // It is already Loaded and Visible, or it is AutoHidden } if (anchorableTest.Parent is LayoutDocumentPane || anchorableTest.Parent is LayoutAnchorablePane) { // If it is docked under the LayoutDocumentPane or another LayoutAnchorablePane, it should be active there even though it might be Unloaded (e.g. when the Tab is not in focus) return; } // Item might be not in focus as a tab item to any of the possible panel. Search whether it is there if (plgInUC.Parent is Xceed.Wpf.AvalonDock.DockingManager) { Xceed.Wpf.AvalonDock.DockingManager dockMgr = plgInUC.Parent as Xceed.Wpf.AvalonDock.DockingManager; if (dockMgr.Layout.Children.Count() > 0) { foreach (LayoutElement layoutElem in dockMgr.Layout.Children) { // Layout Panel may be recursive if (layoutElem is LayoutPanel) { if (LocateControlInLayoutPanel(layoutElem as LayoutPanel, plgInUC)) { return; } } if (layoutElem is LayoutAnchorSide) { foreach (LayoutAnchorGroup lyG in (layoutElem as LayoutAnchorSide).Children) { foreach (LayoutAnchorable lyGA in lyG.Children) { if (lyGA.Content == plgInUC) { return; // The item is already in a LayoutAnchorGroup, probably is AutoHidden } } } } } } } } // If the status is not any of the above, show the plugin again ShowPluginWindow(v.PluginInterface, true); } else { IXbimXplorerPluginWindow instance; if (_retainedControls.ContainsKey(tp)) { instance = _retainedControls[tp].PluginInterface; } else { try { instance = (IXbimXplorerPluginWindow)Activator.CreateInstance(tp); } catch (Exception ex) { var msg = $"Error creating instance of type '{tp}'"; Log.Error(msg, ex); return; } } var menuWindow = ShowPluginWindow(instance, true); if (menuWindow == null) { return; } // if returned the window must be retained. var item = new SinglePluginItem() { PluginInterface = instance, UiObject = menuWindow }; if (!_retainedControls.ContainsKey(tp)) { _retainedControls.Add(tp, item); } if ((_retainedControls[tp].UiObject as LayoutAnchorable) != null) { (_retainedControls[tp].UiObject as LayoutAnchorable).IsActive = true; } return; } }