Skip to content

Commit 2e62af4

Browse files
committed
Refactoring Execute with Confirmation
Ensure frmSettings form load changing UI layout
1 parent 16ec669 commit 2e62af4

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

src/SQLScriptsExplorer.Addin/Controls/FileExplorerTreeView.xaml.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,22 @@ private void mnuExecuteFile_Click(object sender, RoutedEventArgs e)
180180
try
181181
{
182182
ISettingsRepository settingsRepository = new SettingsRepository();
183+
184+
DocumentManager.OpenTemplate(treeNode.FileName, treeNode.FileFullPath);
185+
var messageBoxResult = MessageBoxResult.Yes;
186+
187+
if (settingsRepository.ConfirmScriptExecution)
188+
{
189+
messageBoxResult = MessageBox.Show($"Are sure you want to execute the script '{treeNode.FileName}'?", "Confirmation",
190+
MessageBoxButton.YesNo,
191+
MessageBoxImage.None,
192+
MessageBoxResult.No);
193+
}
183194

184-
DocumentManager.ExecuteTemplate(treeNode.FileName, treeNode.FileFullPath, settingsRepository.ConfirmScriptExecution);
195+
if (messageBoxResult == MessageBoxResult.Yes)
196+
{
197+
DocumentManager.ExecuteTemplate(treeNode.FileName, treeNode.FileFullPath, settingsRepository.ConfirmScriptExecution);
198+
}
185199
}
186200
catch (Exception ex)
187201
{

src/SQLScriptsExplorer.Addin/Infrastructure/DocumentManager.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Collections.Generic;
88
using System.IO;
99
using System.Linq;
10-
using System.Windows.Forms;
1110

1211
namespace SQLScriptsExplorer.Addin.Infrastructure
1312
{
@@ -75,24 +74,12 @@ public static void ExecuteTemplate(string fileName, string fileFullPath, bool co
7574
{
7675
ThreadHelper.ThrowIfNotOnUIThread();
7776

78-
OpenTemplate(fileName, fileFullPath);
79-
8077
DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;
8178

8279
// Ensure the document we are executing is the document we have opened by checking its name
8380
if (dte.ActiveDocument != null && dte.ActiveDocument.ProjectItem.Name.Equals(fileName))
8481
{
85-
DialogResult dialogResult = DialogResult.Yes;
86-
87-
if (confirmScriptExecution)
88-
{
89-
dialogResult = MessageBox.Show($"Are sure you want to execute the script {fileName}?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button2);
90-
}
91-
92-
if (dialogResult == DialogResult.Yes)
93-
{
94-
dte.ExecuteCommand(CMD_QUERY_EXECUTE);
95-
}
82+
dte.ExecuteCommand(CMD_QUERY_EXECUTE);
9683
}
9784
}
9885
catch (Exception ex)

src/SQLScriptsExplorer.Addin/frmSettings.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public frmSettings()
3333
chkShowExecuteFileButton.Checked = settingsRepository.ShowExecuteFileButton;
3434
chkConfirmScriptExecution.Checked = settingsRepository.ConfirmScriptExecution;
3535

36+
chkShowExecuteFileButton_CheckedChanged(null, System.EventArgs.Empty);
37+
3638
// General
3739
cboParserVersion.SelectedItem = settingsRepository.SQLParserVersion;
3840
txtAllowedFileTypes.Text = settingsRepository.AllowedFileTypes;
@@ -63,6 +65,11 @@ private void btnSave_Click(object sender, System.EventArgs e)
6365
Close();
6466
}
6567

68+
private void chkShowExecuteFileButton_CheckedChanged(object sender, System.EventArgs e)
69+
{
70+
chkConfirmScriptExecution.Enabled = chkShowExecuteFileButton.Checked;
71+
}
72+
6673
private void btnCancel_Click(object sender, System.EventArgs e)
6774
{
6875
DialogResult = DialogResult.Cancel;
@@ -174,10 +181,5 @@ private void gdvFolderMapping_CellFormatting(object sender, DataGridViewCellForm
174181
}
175182

176183
#endregion
177-
178-
private void chkShowExecuteFileButton_CheckedChanged(object sender, System.EventArgs e)
179-
{
180-
chkConfirmScriptExecution.Enabled = chkShowExecuteFileButton.Checked;
181-
}
182184
}
183185
}

0 commit comments

Comments
 (0)