Skip to content

Commit 4f95bbf

Browse files
committed
#1 Prevent PL/SQL Developer from closing when tests are running
1 parent ac4f7c4 commit 4f95bbf

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

PlsqlDeveloperUtPlsqlPlugin/PlsqlDeveloperUtPlsqlPlugin/PlsqlDeveloperUtPlsqlPlugin.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Reflection;
77
using System.IO;
88
using utPLSQL;
9+
using System.Collections.Generic;
910

1011
namespace PlsqlDeveloperUtPlsqlPlugin
1112
{
@@ -44,6 +45,8 @@ public class PlsqlDeveloperUtPlsqlPlugin
4445

4546
private static RealTimeTestRunner testRunner;
4647

48+
private static readonly List<RealTimeTestResultWindow> windows = new List<RealTimeTestResultWindow>();
49+
4750
private PlsqlDeveloperUtPlsqlPlugin()
4851
{
4952
testRunner = new RealTimeTestRunner();
@@ -88,6 +91,27 @@ public static void OnActivate()
8891

8992
}
9093

94+
[DllExport("CanClose", CallingConvention = CallingConvention.Cdecl)]
95+
public static bool CanClose()
96+
{
97+
foreach (RealTimeTestResultWindow window in windows)
98+
{
99+
if (window.Running)
100+
{
101+
var confirmResult = MessageBox.Show("utPLSQL Tests are still running.\r\n\r\nDo you really want to close PL/SQL Developer?", "Running utPLSQL Tests", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
102+
if (confirmResult == DialogResult.Yes)
103+
{
104+
return true;
105+
}
106+
else
107+
{
108+
return false;
109+
}
110+
}
111+
}
112+
return true;
113+
}
114+
91115
[DllExport("RegisterCallback", CallingConvention = CallingConvention.Cdecl)]
92116
public static void RegisterCallback(int index, IntPtr function)
93117
{
@@ -141,6 +165,7 @@ public static void OnMenuClick(int index)
141165
if (PlsqlDeveloperUtPlsqlPlugin.connected())
142166
{
143167
var testResultWindow = new RealTimeTestResultWindow(testRunner);
168+
windows.Add(testResultWindow);
144169
testResultWindow.RunTests("_ALL", username, null, null);
145170
}
146171
}
@@ -155,6 +180,7 @@ public static void OnMenuClick(int index)
155180
PlsqlDeveloperUtPlsqlPlugin.getPopupObject(out type, out owner, out name, out subType);
156181

157182
var testResultWindow = new RealTimeTestResultWindow(testRunner);
183+
windows.Add(testResultWindow);
158184
testResultWindow.RunTests(Marshal.PtrToStringAnsi(type), Marshal.PtrToStringAnsi(owner), Marshal.PtrToStringAnsi(name), Marshal.PtrToStringAnsi(subType));
159185
}
160186
}

PlsqlDeveloperUtPlsqlPlugin/PlsqlDeveloperUtPlsqlPlugin/RealTimeTestResultWindow.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ namespace PlsqlDeveloperUtPlsqlPlugin
1010
{
1111
public partial class RealTimeTestResultWindow : Form
1212
{
13+
internal bool Running { get; set; }
14+
1315
private const int IconSize = 24;
1416

1517
private readonly RealTimeTestRunner testRunner;
1618
private BindingList<TestResult> testResults = new BindingList<TestResult>();
1719
private int totalNumberOfTests;
18-
private bool running;
1920

2021
public RealTimeTestResultWindow(RealTimeTestRunner testRunner)
2122
{
@@ -36,7 +37,7 @@ public RealTimeTestResultWindow(RealTimeTestRunner testRunner)
3637

3738
internal void RunTests(string type, string owner, string name, string subType)
3839
{
39-
running = true;
40+
Running = true;
4041

4142
ResetComponents();
4243

@@ -100,7 +101,7 @@ internal void RunTests(string type, string owner, string name, string subType)
100101

101102
gridResults.Rows[0].Selected = true;
102103

103-
running = false;
104+
Running = false;
104105
}
105106
});
106107
});
@@ -281,9 +282,9 @@ private void TestResultWindow_FormClosing(object sender, FormClosingEventArgs e)
281282
{
282283
if (e.CloseReason == CloseReason.UserClosing)
283284
{
284-
if (running)
285+
if (Running)
285286
{
286-
var confirmResult = MessageBox.Show("Tests are still running.\r\nDo you really want to close the Dialog?", "Running Tests", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
287+
var confirmResult = MessageBox.Show("utPLSQL Tests are still running.\r\n\r\nDo you really want to close?", "Running utPLSQL Tests", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
287288
if (confirmResult == DialogResult.No)
288289
{
289290
e.Cancel = true;

0 commit comments

Comments
 (0)