Skip to content

Commit 8799bf7

Browse files
committed
Use ShowModalErrorDialogBox.
1 parent 01bfb78 commit 8799bf7

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

src/Stratis.VS.StratisEVM/UI/BlockchainExplorer/BlockchainExplorerToolWindowControl.xaml.cs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
using Stratis.VS.StratisEVM.UI.ViewModel;
1818
using Stratis.DevEx.Ethereum;
1919
using static Stratis.DevEx.Result;
20+
using System.IO;
21+
using Stratis.DevEx;
2022

2123
namespace Stratis.VS.StratisEVM.UI
2224
{
@@ -28,7 +30,7 @@ public partial class BlockchainExplorerToolWindowControl : UserControl
2830
/// <summary>
2931
/// Initializes a new instance of the <see cref="BlockchainExplorerToolWindowControl"/> class.
3032
/// </summary>
31-
public BlockchainExplorerToolWindowControl()
33+
public BlockchainExplorerToolWindowControl() : base()
3234
{
3335
var _ = new Wpf.Ui.Controls.Card(); // Bug workaround, see https://github.com/microsoft/XamlBehaviorsWpf/issues/86
3436
InitializeComponent();
@@ -149,14 +151,20 @@ private async void NewNetworkCmd_Executed(object sender, ExecutedRoutedEventArgs
149151
endpoints.AddChild(BlockchainInfoKind.Endpoint, rpcurl.Text);
150152
if (!tree.RootItem.Save("BlockchainExplorerTree", out var ex))
151153
{
152-
#if !IS_VSIX
153-
System.Windows.MessageBox.Show("Error saving tree data: " + ex?.Message);
154+
#if IS_VSIX
155+
VSUtil.ShowModalErrorDialogBox("Error saving tree data: " + ex?.Message);
156+
#else
157+
System.Windows.MessageBox.Show("Error saving tree data: " + ex?.Message);
154158
#endif
155159
}
156160
}
157161
catch (Exception ex)
158162
{
159-
System.Windows.MessageBox.Show(ex.Message);
163+
#if IS_VSIX
164+
VSUtil.ShowModalErrorDialogBox(ex?.Message);
165+
#else
166+
System.Windows.MessageBox.Show(ex?.Message);
167+
#endif
160168
}
161169
}
162170

@@ -230,7 +238,11 @@ private async void NewEndpointCmd_Executed(object sender, ExecutedRoutedEventArg
230238
}
231239
catch (Exception ex)
232240
{
233-
System.Windows.MessageBox.Show(ex.Message);
241+
#if IS_VSIX
242+
VSUtil.ShowModalErrorDialogBox(ex?.Message);
243+
#else
244+
System.Windows.MessageBox.Show(ex?.Message);
245+
#endif
234246
}
235247
}
236248

@@ -355,30 +367,19 @@ private async void NewFolderCmd_Executed(object sender, ExecutedRoutedEventArgs
355367
var f = item.AddChild(BlockchainInfoKind.UserFolder, foldername.Text);
356368
if (!item.Save("BlockchainExplorerTree", out var ex))
357369
{
358-
#if !IS_VSIX
359-
System.Windows.MessageBox.Show("Error saving tree data: " + ex?.Message);
370+
#if IS_VSIX
371+
VSUtil.ShowModalErrorDialogBox("Error saving tree data: " + ex?.Message);
360372
#else
361-
var dialog = new Microsoft.VisualStudio.PlatformUI.DialogWindow()
362-
{
363-
Title = "Error",
364-
Content = "Error saving Blockchain Explorer tree state: " + ex?.Message,
365-
};
366-
dialog.ShowModal();
373+
System.Windows.MessageBox.Show("Error saving tree data: " + ex?.Message);
367374
#endif
368375
}
369376
}
370377
catch (Exception ex)
371378
{
372-
#if !IS_VSIX
373-
System.Windows.MessageBox.Show(ex.Message);
379+
#if IS_VSIX
380+
VSUtil.ShowModalErrorDialogBox(ex?.Message);
374381
#else
375-
376-
var dialog = new Microsoft.VisualStudio.PlatformUI.DialogWindow()
377-
{
378-
Title = "Error",
379-
Content = "Error saving Blockchain Explorer tree state: " + ex?.Message,
380-
};
381-
dialog.ShowModal();
382+
System.Windows.MessageBox.Show(ex?.Message);
382383
#endif
383384
}
384385
}
@@ -391,8 +392,10 @@ private void DeleteFolderCmd_Executed(object sender, ExecutedRoutedEventArgs e)
391392
item.Parent.DeleteChild(item);
392393
if (!tree.RootItem.Save("BlockchainExplorerTree", out var ex))
393394
{
394-
#if !IS_VSIX
395-
System.Windows.MessageBox.Show("Error saving tree data: " + ex?.Message);
395+
#if IS_VSIX
396+
VSUtil.ShowModalErrorDialogBox("Error saving tree data: " + ex?.Message);
397+
#else
398+
System.Windows.MessageBox.Show("Error saving tree data: " + ex?.Message);
396399
#endif
397400
}
398401
}
@@ -405,15 +408,16 @@ private void DeleteNetworkCmd_Executed(object sender, ExecutedRoutedEventArgs e)
405408
item.Parent.DeleteChild(item);
406409
if (!tree.RootItem.Save("BlockchainExplorerTree", out var ex))
407410
{
408-
#if !IS_VSIX
409-
System.Windows.MessageBox.Show("Error saving tree data: " + ex?.Message);
411+
#if IS_VSIX
412+
VSUtil.ShowModalErrorDialogBox("Error saving tree data: " + ex?.Message);
413+
#else
414+
System.Windows.MessageBox.Show("Error saving tree data: " + ex?.Message);
410415
#endif
411416
}
412417
}
413418

414419
private void DeleteNetworkCmd_CanExecute(object sender, CanExecuteRoutedEventArgs e)
415420
{
416-
417421
var item = GetSelectedItem(sender);
418422
if (item.Name == "Stratis Mainnet")
419423
{
@@ -422,8 +426,7 @@ private void DeleteNetworkCmd_CanExecute(object sender, CanExecuteRoutedEventArg
422426
else
423427
{
424428
e.CanExecute = true;
425-
}
426-
429+
}
427430
}
428431
}
429432
}

src/Stratis.VS.StratisEVM/VSUtil.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ public static void SaveUserSettings(IServiceProvider serviceProvider, string pro
235235
settingsStore.SetString("StratisEVM", propertyName, value);
236236
}
237237

238+
public static void ShowModalErrorDialogBox(string text, string title = null)
239+
{
240+
ThreadHelper.ThrowIfNotOnUIThread();
241+
VsShellUtilities.ShowMessageBox(StratisEVMPackage.Instance, text, title ?? "StratisEVM error",
242+
OLEMSGICON.OLEMSGICON_CRITICAL,
243+
OLEMSGBUTTON.OLEMSGBUTTON_OK,
244+
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
245+
}
246+
238247
public static bool VSServicesInitialized = false;
239248
}
240249
}

0 commit comments

Comments
 (0)