/// <summary> /// Constructs an instance of DisplayController with a handle to the two displays. /// </summary> /// <param name="editDisplay">Handle to the edit display hosted by the MainWindow</param> /// <param name="runDisplay">Handle to the run display hosted by the MainWindow</param> public DisplayController(IDisplay editDisplay, IDisplay runDisplay) { // Init tab control var designTabControl = new NewTabControl(); designTabControl.Font = new Font("Segoe UI", 10.75F); designTabControl.SelectedTabColor = Color.DodgerBlue; designTabControl.TabBoundaryColor = SystemColors.ControlDarkDark; designTabControl.SelectedTabTextColor = Color.White; designTabControl.TabSwapped += (sender, e) => { MainWindowController.SwapDesignNodes(e.SourceTabPageIndex, e.DestinationTabPageIndex); }; var browserTabControl = new NewTabControl(); browserTabControl.Font = new Font("Segoe UI", 10.75F); browserTabControl.SelectedTabColor = Color.DodgerBlue; browserTabControl.TabBoundaryColor = SystemColors.ControlDarkDark; browserTabControl.SelectedTabTextColor = Color.White; // Create html builder HtmlBuilder = new HtmlBuilder(); // Init edit display EditDisplay = editDisplay; EditDisplay.AttachTabControl(designTabControl); EditDisplay.DisplayTabChanged += (tabName) => { // Select the tab associated with the tab MainWindowController.SelectFile(tabName); if (tabName != null) { MainWindowController.LoadDisplay(DisplayType.EDIT); } }; EditDisplay.DisplayTabClosing += (tabName) => { // Close file associated with the tab MainWindowController.CloseFile(tabName, true); }; // Init run display RunDisplay = runDisplay; RunDisplay.AttachTabControl(browserTabControl); RunDisplay.DisplayTabChanged += (tabName) => { if (tabName != null) { if (DesignController.ActiveDesign.FileName != InstantiationClicks.Text) { // Select top level MainWindowController.SelectFile(InstantiationClicks.Text); } // Select the tab associated with the tab MainWindowController.SelectFile(tabName); } }; RunDisplay.DisplayTabClosing += (tabName) => { CurrentDisplay.CloseTab(tabName); }; RunDisplay.DisplayTabClosed += (tabName, tabCount) => { // If the tab is an instantiation parser if (tabName.Contains(".")) { if (DesignController.ActiveDesign.FileName != InstantiationClicks.Text) { // Select top level MainWindowController.SelectFile(InstantiationClicks.Text); } // Close parser associated with the tab MainWindowController.CloseInstantiation(tabName); var treeNodes = Collect(InstantiationClicks.Nodes).ToList(); foreach (TreeNode treeNode in treeNodes) { if (treeNode.Text == tabName) { var childNodes = Collect(treeNode.Nodes).ToList(); foreach (var childNode in childNodes) { CurrentDisplay.CloseTab(childNode.Name); } treeNode.Parent.Nodes.Remove(treeNode); break; } } } else { // Select the tab associated with the tab MainWindowController.SelectFile(tabName); MainWindowController.SuspendRunDisplay(); if (CurrentDisplay is DisplayRun) { MainWindowController.LoadDisplay(DisplayType.EDIT); } } }; CurrentDisplay = editDisplay; }