/// <summary> /// Open a new tab given a scene file to load. If the specified scene is /// already open in a tab, the existing /// tab is selected in the UI (if requested) and no tab is added. /// </summary> /// <param name="file">Source file</param> /// <param name="async">Specifies whether the data is loaded asynchr.</param> /// <param name="setActive">Specifies whether the newly added tab will /// be selected when the loading process is complete.</param> public void AddTab(string file, bool async = true, bool setActive = true) { AddRecentItem(file); // check whether the scene is already loaded for (int j = 0; j < tabControl1.TabPages.Count; ++j) { var tab = UiState.TabForId(tabControl1.TabPages[j]); Debug.Assert(tab != null); if (tab.File == file) { // if so, activate its tab and return if (setActive) { SelectTab(tabControl1.TabPages[j]); } return; } } var key = GenerateTabKey(); tabControl1.TabPages.Add(key, GenerateTabCaption(file) + LoadingTitlePostfix); var ui = tabControl1.TabPages[key]; ui.ToolTipText = file; tabControl1.ShowToolTips = true; PopulateUITab(ui); var t = new Tab(ui, file); UiState.AddTab(t); if (TabChanged != null) { TabChanged(t, true); } if (async) { var th = new Thread(() => OpenFile(t, setActive)); th.Start(); } else { OpenFile(t, setActive); } if (_emptyTab != null) { CloseTab(_emptyTab); } }
/// <summary> /// Add an "empty" tab if it doesn't exist yet /// </summary> private void AddEmptyTab() { // create default tab tabControl1.TabPages.Add("empty"); _emptyTab = tabControl1.TabPages[tabControl1.TabPages.Count - 1]; PopulateUITab(_emptyTab); ActivateUiTab(_emptyTab); // happens when being called from ctor if (_ui != null) { _ui.AddTab(new Tab(_emptyTab, null)); } }