Skip to content

Commit

Permalink
Form now resize on startup. Change some messageBox behavior on Aircra…
Browse files Browse the repository at this point in the history
…ftMenu.
  • Loading branch information
JetStream96 committed Jun 6, 2016
1 parent 6bac3a7 commit 5642f18
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 49 deletions.
43 changes: 24 additions & 19 deletions src/QSP/UI/ToLdgModule/AircraftMenu/AcConfigValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,8 @@ public AcConfigValidator(AcMenuElements elem)
}

/// <exception cref="InvalidUserInputException"></exception>
public AircraftConfigItem Validate()
public AircraftConfigItem Read()
{
string acType = elem.AcType.Text.Trim();

if (acType == "")
{
throw new InvalidUserInputException(
"Aircraft type cannot be empty.");
}

string reg = elem.Registration.Text.Trim().ToUpper();

if (reg == "")
{
throw new InvalidUserInputException(
"Registration cannot be empty.");
}

var wtUnit = elem.ZfwUnit.SelectedIndex == 0 ?
WeightUnit.KG :
WeightUnit.LB;
Expand Down Expand Up @@ -66,14 +50,35 @@ public AircraftConfigItem Validate()
maxToWt *= wtUnitFactor;
maxLdgWt *= wtUnitFactor;

return new AircraftConfigItem(acType,
reg,
return new AircraftConfigItem(
elem.AcType.Text.Trim(),
elem.Registration.Text.Trim().ToUpper(),
elem.ToProfile.Text,
elem.LdgProfile.Text,
zfw,
maxToWt,
maxLdgWt,
wtUnit);
}

/// <exception cref="InvalidUserInputException"></exception>
public AircraftConfigItem Validate()
{
var item = Read();

if (item.AC == "")
{
throw new InvalidUserInputException(
"Aircraft type cannot be empty.");
}

if (item.Registration == "")
{
throw new InvalidUserInputException(
"Registration cannot be empty.");
}

return item;
}
}
}
10 changes: 5 additions & 5 deletions src/QSP/UI/ToLdgModule/AircraftMenu/AcMenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using QSP.AircraftProfiles.Configs;
using QSP.AviationTools;
using QSP.Common;
using QSP.Utilities.Units;
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using static QSP.MathTools.Doubles;
using static QSP.UI.Utilities.MsgBoxHelper;
using QSP.Utilities.Units;

namespace QSP.UI.ToLdgModule.AircraftMenu
{
Expand Down Expand Up @@ -391,9 +391,9 @@ public void DeleteConfig(object sender, EventArgs e)

var result =
MessageBox.Show(
"Permanently delete " + reg + " (" + ac + ") ?",
$"Permanently delete {reg} ({ac}) ?",
"",
MessageBoxButtons.YesNo,
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button2);

Expand Down Expand Up @@ -426,7 +426,7 @@ private bool changesMade()

try
{
config = new AcConfigValidator(elem).Validate();
config = new AcConfigValidator(elem).Read();
}
catch
{
Expand Down Expand Up @@ -457,7 +457,7 @@ public void CancelBtnClicked(object sender, EventArgs e)
MessageBox.Show(
"Discard the changes to config?",
"",
MessageBoxButtons.YesNo,
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button2);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 41 additions & 19 deletions src/QSP/UI/ToLdgModule/Forms/QspLiteForm.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using QSP.AircraftProfiles;
using QSP.RouteFinding.Airports;
using QSP.UI.Controllers.ButtonGroup;
using QSP.UI.ToLdgModule.AboutPage;
using QSP.UI.ToLdgModule.AircraftMenu;
using QSP.UI.ToLdgModule.AirportMap;
using QSP.UI.ToLdgModule.LandingPerf;
using QSP.UI.ToLdgModule.Options;
using QSP.UI.ToLdgModule.TOPerf;
using QSP.UI.ToLdgModule.AboutPage;
using QSP.Utilities;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
Expand All @@ -26,9 +27,26 @@ public partial class QspLiteForm : Form
public OptionsControl OptionsMenu { get; private set; }
public AboutPageControl AboutMenu { get; private set; }

public IEnumerable<UserControl> Pages
{
get
{
return new UserControl[]
{
AcMenu,
ToMenu,
LdgMenu,
AirportMenu,
OptionsMenu,
AboutMenu
};
}
}

private BtnGroupController btnControl;
private ControlSwitcher viewControl;
private AirportManager _airports;
private Point controlDefaultLocation = new Point(12, 60);

public QspLiteForm()
{
Expand All @@ -38,6 +56,7 @@ public QspLiteForm()

public void Initialize(ProfileManager manager)
{
resizeForm();
checkRegistry();
subscribeEvents();
OptionsMenu.Initialize();
Expand Down Expand Up @@ -66,7 +85,7 @@ public void Initialize(ProfileManager manager)
private void addToolTip()
{
var tp = new ToolTip();

tp.AutoPopDelay = 5000;
tp.InitialDelay = 1000;
tp.ReshowDelay = 500;
Expand Down Expand Up @@ -170,28 +189,31 @@ private void enableBtnColorControls()
private void addControls()
{
AcMenu = new AircraftMenuControl();
AcMenu.Location = new Point(12, 60);
Controls.Add(AcMenu);

ToMenu = new TOPerfControl();
ToMenu.Location = new Point(12, 60);
Controls.Add(ToMenu);

LdgMenu = new LandingPerfControl();
LdgMenu.Location = new Point(12, 60);
Controls.Add(LdgMenu);

AirportMenu = new AirportMapControl();
AirportMenu.Location = new Point(12, 60);
Controls.Add(AirportMenu);

OptionsMenu = new OptionsControl();
OptionsMenu.Location = new Point(12, 60);
Controls.Add(OptionsMenu);

AboutMenu = new AboutPageControl();
AboutMenu.Location = new Point(12, 60);
Controls.Add(AboutMenu);

foreach (var i in Pages)
{
i.Location = controlDefaultLocation;
Controls.Add(i);
}
}

private void resizeForm()
{
int maxWidth = Pages.Max(c => c.Width);
int maxHeight = Pages.Max(c => c.Height);

int right = Pages.Where(c => c.Width == maxWidth)
.First().Right;

int bottom = Pages.Where(c => c.Height == maxHeight)
.First().Bottom;

ClientSize = new Size(right + 15, bottom + 15);
}

private static void checkRegistry()
Expand Down
1 change: 1 addition & 0 deletions src/QSP/UI/ToLdgModule/Options/OptionsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ private Panel infoPanel(DataSource.Type type)
var panel = new Panel();
panel.Size = new Size(450, 100);
panel.BackColor = Color.FromArgb(216, 244, 215);
panel.BorderStyle = BorderStyle.FixedSingle;
var pt = infoLbl.Location;
panel.Location = new Point(pt.X - 150, pt.Y + 100);

Expand Down

0 comments on commit 5642f18

Please sign in to comment.