private void RebuildTabs() { tabBar.Nodes.Clear(); foreach (var doc in Project.Current.Documents) { var tab = new ThemedTab { Closable = true }; tab.Tasks.Add(Tooltip.Instance.ShowOnMouseOverTask(tab, () => doc.FullPath.Replace('/', '\\'))); tab.AddChangeWatcher(() => Document.Current, _ => { if (doc == Document.Current) { tabBar.ActivateTab(tab); } }); tab.Gestures.Add(new ClickGesture(1, () => { DocumentTabContextMenu.Create(doc); })); tab.AddChangeWatcher(() => doc.DisplayName, _ => tab.Text = doc.DisplayName); tab.Clicked += doc.MakeCurrent; tab.Closing += () => Project.Current.CloseDocument(doc); tabBar.AddNode(tab); } tabBar.AddNode(new Widget { LayoutCell = new LayoutCell { StretchX = 0 } }); }
public void ActivateTab(int index) { var tab = TabBar.Nodes[index] as Tab; TabBar.ActivateTab(tab); ContentContainer.Nodes.Clear(); ContentContainer.Nodes.Add(Contents[index]); Contents[index].ExpandToContainerWithAnchors(); activeTabIndex = index; }
public void ActivateTab(int index) { var tab = TabBar.Nodes[index] as Tab; for (int i = 0; i < TabBar.Nodes.Count; i++) { Frame.Nodes[i].AsWidget.Visible = i == index; } TabBar.ActivateTab(tab); }
private void RebuildTabs(TabBar tabBar) { tabBar.Nodes.Clear(); foreach (var doc in Project.Current.Documents) { var tab = new ThemedTab { Closable = true }; var currentDocumentChanged = new Property <bool>(() => Document.Current == doc).DistinctUntilChanged().Where(i => i); tab.Tasks.Add(currentDocumentChanged.Consume(_ => tabBar.ActivateTab(tab))); tab.AddChangeWatcher(() => doc.Path, _ => RefreshTabText(doc, tab)); tab.AddChangeWatcher(() => doc.IsModified, _ => RefreshTabText(doc, tab)); tab.Clicked += doc.MakeCurrent; tab.Closing += () => Project.Current.CloseDocument(doc); tab.Updated += (dt) => { if (tab.Input.WasKeyReleased(Key.Mouse1)) { var menu = new Menu { GenericCommands.CloseDocument, GenericCommands.Save, FilesystemCommands.NavigateTo, FilesystemCommands.OpenInSystemFileManager, }; var path = Path.Combine(Project.Current.AssetsDirectory, doc.Path); FilesystemCommands.NavigateTo.UserData = path; FilesystemCommands.OpenInSystemFileManager.UserData = path; menu.Popup(); } }; tabBar.AddNode(tab); } tabBar.AddNode(new Widget { LayoutCell = new LayoutCell { StretchX = 0 } }); }
private void RebuildTabs(TabBar tabBar) { tabBar.Nodes.Clear(); foreach (var doc in Project.Current.Documents) { var tab = new ThemedTab { Closable = true }; var currentDocumentChanged = new Property <bool>(() => Document.Current == doc).DistinctUntilChanged().Where(i => i); tab.Tasks.Add(currentDocumentChanged.Consume(_ => tabBar.ActivateTab(tab))); tab.AddChangeWatcher(() => doc.Path, _ => RefreshTabText(doc, tab)); tab.AddChangeWatcher(() => doc.IsModified, _ => RefreshTabText(doc, tab)); tab.Clicked += doc.MakeCurrent; tab.Closing += () => Project.Current.CloseDocument(doc); tab.Updated += (dt) => { if (tab.Input.WasKeyReleased(Key.Mouse1)) { DocumentTabContextMenu.Create(doc); } }; DragGesture dragGesture = new DragGesture(); tab.Gestures.Add(dragGesture); dragGesture.Changed += () => { int index = -1; foreach (Tab tabEl in tabBar.Nodes.OfType <Tab>()) { index++; if (tabEl == tab) { continue; } Vector2 localMousePosition = tabEl.LocalMousePosition(); if (!(localMousePosition.X >= 0 && localMousePosition.Y >= 0 && localMousePosition.X < tabEl.Width && localMousePosition.Y < tabEl.Height)) { continue; } Project.Current.ReorderDocument(doc, index); int previousIndex = tabBar.Nodes.IndexOf(tab); int toIndex = tabBar.Nodes.IndexOf(tabEl); if (previousIndex < 0 || toIndex < 0) { RebuildTabs(tabBar); break; } tabBar.Nodes.Remove(tab); tabBar.Nodes.Insert(toIndex, tab); break; } }; tabBar.AddNode(tab); } tabBar.AddNode(new Widget { LayoutCell = new LayoutCell { StretchX = 0 } }); }