Skip to content
This repository was archived by the owner on May 19, 2021. It is now read-only.

Commit d6df006

Browse files
committed
fix null selected rows after search
1 parent 4b0fee7 commit d6df006

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

UnityLauncher/Form1.cs

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -598,19 +598,12 @@ private void ShowForm()
598598

599599
void LaunchSelectedProject(bool openProject = true)
600600
{
601-
if (gridRecent.CurrentCell == null)
602-
{
603-
if (gridRecent.SelectedRows.Count != 0)
604-
{
605-
DataGridViewRow row = gridRecent.SelectedRows[0];
606-
gridRecent.CurrentCell = row.Cells[0];
607-
}
608-
}
609-
var selected = gridRecent.CurrentCell.RowIndex;
601+
FixSelectedRow();
602+
var selected = gridRecent?.CurrentCell?.RowIndex;
610603

611-
if (selected > -1)
604+
if (selected.HasValue && selected > -1)
612605
{
613-
var projectPath = gridRecent.Rows[selected].Cells["_path"].Value.ToString();
606+
var projectPath = gridRecent.Rows[(int)selected].Cells["_path"].Value.ToString();
614607
var version = Tools.GetProjectVersion(projectPath);
615608
LaunchProject(projectPath, version, openProject);
616609
SetStatus("Ready");
@@ -621,11 +614,12 @@ void LaunchSelectedProject(bool openProject = true)
621614

622615
void LaunchSelectedUnity()
623616
{
624-
var selected = gridUnityList.CurrentCell.RowIndex;
625-
if (selected > -1)
617+
FixSelectedRow();
618+
var selected = gridRecent?.CurrentCell?.RowIndex;
619+
if (selected.HasValue && selected > -1)
626620
{
627621
SetStatus("Launching Unity..");
628-
var version = gridUnityList.Rows[selected].Cells["_unityVersion"].Value.ToString();
622+
var version = gridUnityList.Rows[(int)selected].Cells["_unityVersion"].Value.ToString();
629623
try
630624
{
631625
Process myProcess = new Process();
@@ -686,10 +680,11 @@ private void btnRemovePackFolder_Click(object sender, EventArgs e)
686680

687681
private void btnOpenReleasePage_Click(object sender, EventArgs e)
688682
{
689-
var selected = gridUnityList.CurrentCell.RowIndex;
690-
if (selected > -1)
683+
FixSelectedRow();
684+
var selected = gridRecent?.CurrentCell?.RowIndex;
685+
if (selected.HasValue && selected > -1)
691686
{
692-
var version = gridUnityList.Rows[selected].Cells["_unityVersion"].Value.ToString();
687+
var version = gridUnityList.Rows[(int)selected].Cells["_unityVersion"].Value.ToString();
693688
if (Tools.OpenReleaseNotes(version) == true)
694689
{
695690
SetStatus("Opening release notes for version " + version);
@@ -708,10 +703,11 @@ private void btnLaunchUnity_Click(object sender, EventArgs e)
708703

709704
private void btnExploreUnity_Click(object sender, EventArgs e)
710705
{
711-
var selected = gridUnityList.CurrentCell.RowIndex;
712-
if (selected > -1)
706+
FixSelectedRow();
707+
var selected = gridRecent?.CurrentCell?.RowIndex;
708+
if (selected.HasValue && selected > -1)
713709
{
714-
var unityPath = Path.GetDirectoryName(gridUnityList.Rows[selected].Cells["_unityPath"].Value.ToString());
710+
var unityPath = Path.GetDirectoryName(gridUnityList.Rows[(int)selected].Cells["_unityPath"].Value.ToString());
715711
if (Tools.LaunchExplorer(unityPath) == false)
716712
{
717713
SetStatus("Error> Directory not found: " + unityPath);
@@ -873,10 +869,11 @@ private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
873869

874870
private void btn_openFolder_Click(object sender, EventArgs e)
875871
{
876-
var selected = gridRecent.CurrentCell.RowIndex;
877-
if (selected > -1)
872+
FixSelectedRow();
873+
var selected = gridRecent?.CurrentCell?.RowIndex;
874+
if (selected.HasValue && selected > -1)
878875
{
879-
string folder = gridRecent.Rows[selected].Cells["_path"].Value.ToString();
876+
string folder = gridRecent.Rows[(int)selected].Cells["_path"].Value.ToString();
880877
if (Tools.LaunchExplorer(folder) == false)
881878
{
882879
SetStatus("Error> Directory not found: " + folder);
@@ -959,8 +956,9 @@ private void btnOpenLogFolder_Click(object sender, EventArgs e)
959956

960957
private void btnOpenUpdateWebsite_Click(object sender, EventArgs e)
961958
{
959+
FixSelectedRow();
962960
var selected = gridUnityUpdates?.CurrentCell?.RowIndex;
963-
if (selected != null && selected > -1)
961+
if (selected.HasValue && selected > -1)
964962
{
965963
var version = gridUnityUpdates.Rows[(int)selected].Cells["_UnityUpdateVersion"].Value.ToString();
966964
Tools.OpenReleaseNotes(version);
@@ -1079,12 +1077,13 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
10791077
// displays version selector to upgrade project
10801078
void UpgradeProject()
10811079
{
1082-
var selected = gridRecent.CurrentCell.RowIndex;
1083-
if (selected > -1)
1080+
FixSelectedRow();
1081+
var selected = gridRecent?.CurrentCell?.RowIndex;
1082+
if (selected.HasValue && selected > -1)
10841083
{
10851084
SetStatus("Upgrading project ...");
10861085

1087-
var projectPath = gridRecent.Rows[selected].Cells["_path"].Value.ToString();
1086+
var projectPath = gridRecent.Rows[(int)selected].Cells["_path"].Value.ToString();
10881087
var currentVersion = Tools.GetProjectVersion(projectPath);
10891088

10901089
if (string.IsNullOrEmpty(currentVersion) == true)
@@ -1183,10 +1182,11 @@ private void UnityVersionsListDownloaded(object sender, DownloadStringCompletedE
11831182
string GetSelectedRowData(string key)
11841183
{
11851184
string path = null;
1185+
FixSelectedRow();
11861186
var selected = gridRecent?.CurrentCell?.RowIndex;
11871187
if (selected.HasValue && selected > -1)
11881188
{
1189-
path = gridRecent.Rows[selected.Value].Cells[key].Value?.ToString();
1189+
path = gridRecent.Rows[(int)selected].Cells[key].Value?.ToString();
11901190
}
11911191
return path;
11921192
}
@@ -1318,5 +1318,17 @@ private void SaveSettingsOnExit()
13181318
Properties.Settings.Default.Save();
13191319
}
13201320

1321+
void FixSelectedRow()
1322+
{
1323+
if (gridRecent.CurrentCell == null)
1324+
{
1325+
if (gridRecent.SelectedRows.Count != 0)
1326+
{
1327+
DataGridViewRow row = gridRecent.SelectedRows[0];
1328+
gridRecent.CurrentCell = row.Cells[0];
1329+
}
1330+
}
1331+
}
1332+
13211333
} // class Form
13221334
} // namespace

UnityLauncher/PreviousVersion.txt

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)