private void OnPointSelected(object sender, MouseButtonEventArgs e) { if (PointsList.SelectedIndex == -1) { return; } e.Handled = true; int pointID = DatabaseHandler.GetPointsList()[PointsList.SelectedIndex].id; string pointName = DatabaseHandler.GetPointsList()[PointsList.SelectedIndex].name; Frame frame = new Frame(); PointView view = new PointView(pointID); view.updater += UpdatePoint; frame.Content = view; if (isUsingTabs) { CreatePointTab(pointID, pointName, view, frame); } else { CreatePointWindow(pointID, pointName, view, frame); } PointsList.SelectedIndex = -1; //TODO Tell main window to select add and select tab }
public void AddTab(TabItem newTab, PointView pointView) { Tabs.Items.Add(newTab); Tabs.SelectedIndex = Tabs.Items.Count - 1; typesPage.updatePointTypesHandler += pointView.UpdatePointTypes; page.updaterOfPoints += pointView.UpdateCategories; }
void CreatePointTab(int pointID, string pointName, PointView view, Frame frame) { if (clickedPoints.ContainsKey(pointID)) { int index = orderedTabs.FindIndex(a => a == clickedPoints[pointID]); if (index == -1) { return; } mainWindow.OpenTab(index); PointsList.SelectedIndex = -1; return; } //TODO Checks if can add more tabs if (mainWindow.CheckCanOpenTab()) { return; } TabItem newTabItem = new TabItem { Name = "Point" + pointID.ToString() }; newTabItem.Content = frame; newTabItem.Header = CreateTabHeader(pointName, pointID, view); clickedPoints.Add(pointID, newTabItem); orderedTabs.Add(newTabItem); mainWindow.AddTab(newTabItem, view); }
public void OnTabClosing(int index, TabItem removeTab, PointView pointView) { if (Tabs.SelectedIndex == index + Util.startingTabsCount) { Tabs.SelectedIndex = 0; } //TODO: CHECK IF SAVED Tabs.Items.Remove(removeTab); typesPage.updatePointTypesHandler += pointView.UpdatePointTypes; page.updaterOfPoints -= pointView.UpdateCategories; }
public bool OnTabClosing(int index, PointView view) { if (view.CloseTab()) { //TODO: CHECK IF SAVED if (isUsingTabs) { if (!clickedPoints.ContainsKey(index)) { return(true); } mainWindow.OnTabClosing(orderedTabs.FindIndex(a => a == clickedPoints[index]), clickedPoints[index], view); orderedTabs.Remove(clickedPoints[index]); clickedPoints.Remove(index); view.Dispose(); } return(false); } return(true); }
void CreatePointWindow(int pointID, string pointName, PointView view, Frame frame) { Window window = new Window(); window.Owner = Window.GetWindow(this); window.Title = pointName; window.WindowStartupLocation = WindowStartupLocation.CenterOwner; window.Height = Util.BigHeight; window.Width = Util.BigWidth; frame.Margin = Util.borderThickness; window.Content = frame; window.Owner = Window.GetWindow(this); window.Closing += (sender, e) => { e.Cancel = OnTabClosing(pointID, view); }; window.ShowInTaskbar = false; window.ShowDialog(); }
StackPanel CreateTabHeader(string name, int id, PointView view) { StackPanel panel = new StackPanel(); panel.Height = Util.panelHeight; panel.Orientation = Orientation.Horizontal; TextBlock label = new TextBlock(); label.DataContext = view.tabLabel; label.SetBinding(TextBlock.TextProperty, "tabName"); label.Height = Util.panelHeight; label.Padding = Util.rightThickness; label.MouseDown += (object sender, MouseButtonEventArgs e) => { if (e.ChangedButton == MouseButton.Middle) { OnTabClosing(id, view); } }; Button closeButton = new Button(); closeButton.Content = Util.x; closeButton.Height = Util.buttonSize; closeButton.Width = Util.buttonSize; closeButton.Background = Brushes.Transparent; closeButton.FontSize = Util.fontSize; closeButton.Click += (object sender, RoutedEventArgs e) => { OnTabClosing(id, view); }; panel.Children.Add(label); panel.Children.Add(closeButton); return(panel); }