From 5971101b60d4af9b77446ad948eee51e91593279 Mon Sep 17 00:00:00 2001 From: ags Date: Fri, 23 Feb 2024 22:39:02 +0000 Subject: [PATCH] Insert, for Loco --- dcs-dtc/New/UI/Base/Systems/WaypointsPage.cs | 31 +++++++++++++++++++ .../Systems/WaypointsPageControl.Designer.cs | 19 ++++++++++++ .../UI/Base/Systems/WaypointsPageControl.cs | 5 +++ 3 files changed, 55 insertions(+) diff --git a/dcs-dtc/New/UI/Base/Systems/WaypointsPage.cs b/dcs-dtc/New/UI/Base/Systems/WaypointsPage.cs index 416b57d..88aea20 100644 --- a/dcs-dtc/New/UI/Base/Systems/WaypointsPage.cs +++ b/dcs-dtc/New/UI/Base/Systems/WaypointsPage.cs @@ -22,6 +22,11 @@ public WaypointsPage(AircraftPage parent, WaypointSystem waypoints, IWaypoint this.RefreshList(); } + protected override void InsertButtonClick(object sender, EventArgs e) + { + this.InsertAtSelection(); + } + protected override void AddButtonClick(object sender, EventArgs e) { this.ShowEditDialog(); @@ -104,6 +109,32 @@ protected override void ShiftDown(int[] rows) this.SavePreset(); } + private void InsertAtSelection() + { + int? selectedRow = null; + foreach (DataGridViewRow row in this.dgWaypoints.SelectedRows) + { + selectedRow = row.Index; + break; + } + + if (selectedRow.HasValue) + { + var newWp = new T(); + var atSelection = this.waypoints.Waypoints[selectedRow.Value].Sequence; + foreach (var w in this.waypoints.Waypoints) + { + if(w.Sequence >= atSelection) + { + w.Sequence++; + } + } + newWp.Sequence = atSelection; + this.waypoints.Waypoints.Insert(selectedRow.Value, newWp); + } + this.RefreshList(); + } + private void DeleteSelection() { if (!DTCMessageBox.ShowQuestion("Are you sure you want to delete the selected(s) waypoint(s)?")) diff --git a/dcs-dtc/New/UI/Base/Systems/WaypointsPageControl.Designer.cs b/dcs-dtc/New/UI/Base/Systems/WaypointsPageControl.Designer.cs index ad182cb..62d1a0b 100644 --- a/dcs-dtc/New/UI/Base/Systems/WaypointsPageControl.Designer.cs +++ b/dcs-dtc/New/UI/Base/Systems/WaypointsPageControl.Designer.cs @@ -35,6 +35,7 @@ private void InitializeComponent() clearButton = new DTCButton(); btnImport = new DTCDropDownButton(); btnDelete = new DTCButton(); + btnInsert = new DTCButton(); btnAdd = new DTCButton(); dgWaypoints = new DTCGrid(); contextMenu = new ContextMenuStrip(components); @@ -54,6 +55,7 @@ private void InitializeComponent() panel1.Controls.Add(clearButton); panel1.Controls.Add(btnImport); panel1.Controls.Add(btnDelete); + panel1.Controls.Add(btnInsert); panel1.Controls.Add(btnAdd); panel1.Dock = DockStyle.Top; panel1.Location = new Point(0, 0); @@ -108,6 +110,22 @@ private void InitializeComponent() btnDelete.UseVisualStyleBackColor = false; btnDelete.Click += DeleteButtonClick; // + // btnInsert + // + btnInsert.BackColor = Color.DarkKhaki; + btnInsert.Enabled = false; + btnInsert.FlatAppearance.BorderSize = 0; + btnInsert.FlatStyle = FlatStyle.Flat; + btnInsert.Font = new Font("Microsoft Sans Serif", 10F, FontStyle.Regular, GraphicsUnit.Point); + btnInsert.Location = new Point(260, 5); + btnInsert.Name = "btnInsert"; + btnInsert.Size = new Size(80, 25); + btnInsert.TabIndex = 3; + btnInsert.Text = "Insert"; + btnInsert.UseVisualStyleBackColor = false; + btnInsert.Enabled = true; + btnInsert.Click += InsertButtonClick; + // // btnAdd // btnAdd.BackColor = Color.DarkKhaki; @@ -199,6 +217,7 @@ private void InitializeComponent() #endregion private Panel panel1; private DTCButton btnDelete; + private DTCButton btnInsert; private DTCButton btnAdd; protected DTCGrid dgWaypoints; protected Panel pnlContents; diff --git a/dcs-dtc/New/UI/Base/Systems/WaypointsPageControl.cs b/dcs-dtc/New/UI/Base/Systems/WaypointsPageControl.cs index 9194edb..e6fb093 100644 --- a/dcs-dtc/New/UI/Base/Systems/WaypointsPageControl.cs +++ b/dcs-dtc/New/UI/Base/Systems/WaypointsPageControl.cs @@ -185,6 +185,11 @@ protected void SelectRows(int[] rows) this.dgWaypoints.Select(rows); } + protected virtual void InsertButtonClick(object sender, EventArgs e) + { + throw new NotImplementedException(); + } + protected virtual void AddButtonClick(object sender, EventArgs e) { throw new NotImplementedException();