Skip to content

Commit

Permalink
[gh-4] Improvements to the breakpoint settings dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmind committed Jan 10, 2015
1 parent babbc6e commit a148339
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 51 deletions.
1 change: 1 addition & 0 deletions ExceptionBreaker.OptionsUITester/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Windows;
using ExceptionBreaker.Core.Observable;
using ExceptionBreaker.Options;
using ExceptionBreaker.Options.Support;

Expand Down
10 changes: 0 additions & 10 deletions ExceptionBreaker/Breakpoints/BreakpointExceptionSettings.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
using ExceptionBreaker.Core;

namespace ExceptionBreaker.Breakpoints {
public class BreakpointSetupExceptionsController {
public class BreakpointExceptionsController {
private readonly BreakpointFinder _breakpointFinder;
private readonly BreakpointExtraDataStore _extraDataStore;
private readonly IDiagnosticLogger _logger;
private readonly MenuCommand _command;

public BreakpointSetupExceptionsController(CommandInitializer commandInitializer,
BreakpointFinder breakpointFinder,
BreakpointExtraDataStore extraDataStore,
IDiagnosticLogger logger)
public BreakpointExceptionsController(CommandInitializer commandInitializer,
BreakpointFinder breakpointFinder,
BreakpointExtraDataStore extraDataStore,
IDiagnosticLogger logger)
{
_breakpointFinder = breakpointFinder;
_extraDataStore = extraDataStore;
Expand Down Expand Up @@ -57,7 +57,8 @@ private void command_Callback(object sender, EventArgs e) {
private void RequestAndUpdateExceptionSettings(Breakpoint2 breakpoint) {
var extraData = _extraDataStore.GetData(breakpoint);
var dialog = new BreakpointExceptionsDialog {
ViewModel = new BreakpointExceptionSettings {
ViewModel = new BreakpointExceptionsViewModel {
ShouldChange = { Value = extraData.ExceptionBreakChange != ExceptionBreakChange.NoChange },
Change = extraData.ExceptionBreakChange,
ContinueExecution = !breakpoint.BreakWhenHit
}
Expand All @@ -68,9 +69,23 @@ private void RequestAndUpdateExceptionSettings(Breakpoint2 breakpoint) {
return;
}

_logger.WriteLine("Updating breakpoint settings: continue execution = {0}, change = {1}.", dialog.ViewModel.ContinueExecution, dialog.ViewModel.Change);
extraData.ExceptionBreakChange = dialog.ViewModel.Change;
breakpoint.BreakWhenHit = !dialog.ViewModel.ContinueExecution;
var change = dialog.ViewModel.ShouldChange.Value ? dialog.ViewModel.Change : ExceptionBreakChange.NoChange;
_logger.WriteLine("Updating breakpoint settings: continue execution = {0}, change = {1}.", dialog.ViewModel.ContinueExecution, change);
extraData.ExceptionBreakChange = change;

SetBreakWhenHit(breakpoint, !dialog.ViewModel.ContinueExecution);
}

private static void SetBreakWhenHit(Breakpoint2 breakpoint, bool value) {
var messageStubbed = false;
if (!breakpoint.BreakWhenHit && string.IsNullOrEmpty(breakpoint.Message)) {
// http://stackoverflow.com/questions/27753513/visual-studio-sdk-breakpoint2-breakwhenhit-true-throws-exception-0x8971101a/27870066#27870066
breakpoint.Message = "stub";
messageStubbed = true;
}
breakpoint.BreakWhenHit = value;
if (messageStubbed)
breakpoint.Message = "";
}
}
}
48 changes: 29 additions & 19 deletions ExceptionBreaker/Breakpoints/BreakpointExceptionsDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,43 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.10.0"
xmlns:breakpoints="clr-namespace:ExceptionBreaker.Breakpoints"
xmlns:breakpoints="clr-namespace:ExceptionBreaker.Breakpoints"
WindowStartupLocation="CenterOwner"
Title="When Breakpoint Is Hit"
SizeToContent="WidthAndHeight"
ResizeMode="NoResize">
SizeToContent="Height"
ResizeMode="NoResize"
ShowInTaskbar="False"
Width="504">

<vsui:DialogWindow.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Width" Value="101" />
<Setter Property="Height" Value="24" />
</Style>
</vsui:DialogWindow.Resources>

<StackPanel Margin="10">
<TextBlock Margin="0 0 0 5">Change exception settings:</TextBlock>
<StackPanel Margin="15 0 0 0" Orientation="Horizontal">
<TextBlock Margin="0 0 5 0" VerticalAlignment="Center">CLR exceptions:</TextBlock>
<ComboBox SelectedValuePath="Tag" SelectedValue="{Binding Path=(breakpoints:BreakpointExceptionSettings.Change)}" Width="120" SelectionChanged="comboChange_OnSelectionChanged">
<ComboBoxItem Tag="{x:Static breakpoints:ExceptionBreakChange.NoChange}">No change</ComboBoxItem>
<ComboBoxItem Tag="{x:Static breakpoints:ExceptionBreakChange.SetBreakOnAll}">Set Break on All</ComboBoxItem>
<ComboBoxItem Tag="{x:Static breakpoints:ExceptionBreakChange.SetBreakOnNone}">Set Break on None</ComboBoxItem>
<StackPanel>
<CheckBox IsChecked="{Binding Path=(breakpoints:BreakpointExceptionsViewModel.ShouldChange).Value}"
VerticalAlignment="Center">Change exception settings:</CheckBox>
<ComboBox IsEnabled="{Binding Path=(breakpoints:BreakpointExceptionsViewModel.ShouldChange).Value}"
SelectedValuePath="Tag"
SelectedValue="{Binding Path=(breakpoints:BreakpointExceptionsViewModel.Change)}"
SelectionChanged="comboChange_OnSelectionChanged"
Margin="22 5 0 0"
VerticalAlignment="Center">
<ComboBoxItem Tag="{x:Static breakpoints:ExceptionBreakChange.SetBreakOnAll}">Break on CLR exceptions</ComboBoxItem>
<ComboBoxItem Tag="{x:Static breakpoints:ExceptionBreakChange.SetBreakOnNone}">Don't break on CLR exceptions</ComboBoxItem>
</ComboBox>
</StackPanel>
<CheckBox IsChecked="{Binding Path=(breakpoints:BreakpointExceptionSettings.ContinueExecution)}" Margin="0 5 0 0">Continue execution</CheckBox>

<StackPanel Margin="0 5 0 0" HorizontalAlignment="Right" Orientation="Horizontal">
<Button x:Name="buttonOk"
Width="75" Height="21"
Margin="5 2 2 2"
Click="buttonOk_Click"

<CheckBox IsChecked="{Binding Path=(breakpoints:BreakpointExceptionsViewModel.ContinueExecution)}"
Margin="0 10 0 0">Continue execution</CheckBox>
<StackPanel Margin="0 10 0 0" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Click="buttonOk_Click"
IsDefault="True">OK</Button>

<Button Width="75" Height="21"
Margin="2 2 5 2"
<Button Margin="10 0 0 0"
IsCancel="True">Cancel</Button>
</StackPanel>
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public BreakpointExceptionsDialog() {
InitializeComponent();
}

public BreakpointExceptionSettings ViewModel {
get { return (BreakpointExceptionSettings)DataContext; }
public BreakpointExceptionsViewModel ViewModel {
get { return (BreakpointExceptionsViewModel)DataContext; }
set { DataContext = value; }
}

Expand Down
16 changes: 16 additions & 0 deletions ExceptionBreaker/Breakpoints/BreakpointExceptionsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ExceptionBreaker.Core.Observable;

namespace ExceptionBreaker.Breakpoints {
public class BreakpointExceptionsViewModel {
public BreakpointExceptionsViewModel() {
ShouldChange = new ObservableValue<bool>();
}

public ObservableValue<bool> ShouldChange { get; private set; }
public ExceptionBreakChange Change { get; set; }
public bool ContinueExecution { get; set; }
}
}
2 changes: 1 addition & 1 deletion ExceptionBreaker/Core/ExtensionLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private IVsOutputWindowPane GetOutputPane() {
var guid = _outputPaneGuid;
var pane = (IVsOutputWindowPane)null;
var hr = outputWindow.GetPane(ref guid, out pane);
if (hr != VSConstants.E_FAIL)
if (hr != VSConstants.E_FAIL && hr != VSConstants.E_INVALIDARG)
VSInteropHelper.Validate(hr);

if (pane == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;

namespace ExceptionBreaker.Options.Support {
namespace ExceptionBreaker.Core.Observable {
public interface IObservableResult<T> : INotifyPropertyChanged {
event EventHandler ValueChanged;
T Value { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace ExceptionBreaker.Options.Support {
namespace ExceptionBreaker.Core.Observable {
public static class ObservableCollectionExtensions {
public static IObservableResult<TResult> GetObservable<TCollection, TResult>(this TCollection collection, Func<TCollection, TResult> get, Action<TCollection, NotifyCollectionChangedEventArgs, Action> subscribeExtra = null)
where TCollection : INotifyCollectionChanged
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.ComponentModel;

namespace ExceptionBreaker.Options.Support {
namespace ExceptionBreaker.Core.Observable {
public class ObservableValue<T> : IObservableResult<T> {
public event PropertyChangedEventHandler PropertyChanged = delegate { };
public event EventHandler ValueChanged = delegate { };
Expand Down
10 changes: 5 additions & 5 deletions ExceptionBreaker/ExceptionBreaker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<DependentUpon>BreakpointExceptionsDialog.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Breakpoints\BreakpointExceptionSettings.cs">
<Compile Include="Breakpoints\BreakpointExceptionsViewModel.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Breakpoints\BreakpointFinder.cs">
Expand All @@ -169,7 +169,7 @@
<Compile Include="Breakpoints\BreakpointExtraData.cs" />
<Compile Include="Breakpoints\Glyphs\BreakpointGlyphFactoryProvider.cs" />
<Compile Include="Breakpoints\BreakpointKeyProvider.cs" />
<Compile Include="Breakpoints\BreakpointSetupExceptionsController.cs">
<Compile Include="Breakpoints\BreakpointExceptionsController.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Breakpoints\Glyphs\BreakpointGlyphFactory.cs" />
Expand Down Expand Up @@ -228,9 +228,9 @@
<Compile Include="Options\Support\CollectionSyncExtensions.cs" />
<Compile Include="Options\ImprovedComponentModel\CustomPropertyDescriptor.cs" />
<Compile Include="Options\Support\ProperListPropertyDescriptor.cs" />
<Compile Include="Options\Support\ObservableCollectionExtensions.cs" />
<Compile Include="Options\Support\IObservableResult.cs" />
<Compile Include="Options\Support\ObservableValue.cs">
<Compile Include="Core\Observable\ObservableCollectionExtensions.cs" />
<Compile Include="Core\Observable\IObservableResult.cs" />
<Compile Include="Core\Observable\ObservableValue.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Options\OptionsPageData.cs">
Expand Down
4 changes: 2 additions & 2 deletions ExceptionBreaker/ExceptionBreakerPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public sealed class ExceptionBreakerPackage : Package {
private DTE _dte;
// ReSharper disable NotAccessedField.Local
private ToggleBreakOnAllController _toolbarController;
private BreakpointSetupExceptionsController _breakpointController;
private BreakpointExceptionsController _breakpointController;
private BreakpointEventProcessor _breakpointEventProcessor;
// ReSharper restore NotAccessedField.Local

Expand Down Expand Up @@ -110,7 +110,7 @@ private void SetupBreakpoints() {
_solutionDataPersisters.Add(extraDataStore);

_breakpointEventProcessor = new BreakpointEventProcessor(debugger, extraDataStore, ExceptionBreakManager, Logger);
_breakpointController = new BreakpointSetupExceptionsController(
_breakpointController = new BreakpointExceptionsController(
new CommandInitializer(CommandIDs.BreakpointToggleExceptions, menuCommandService),
finder, extraDataStore, Logger
);
Expand Down
1 change: 1 addition & 0 deletions ExceptionBreaker/Options/ExceptionViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ExceptionBreaker.Core.Observable;
using ExceptionBreaker.Options.Support;

namespace ExceptionBreaker.Options {
Expand Down
1 change: 1 addition & 0 deletions ExceptionBreaker/Options/OptionsPageData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Windows;
using AshMind.Extensions;
using ExceptionBreaker.Core;
using ExceptionBreaker.Core.Observable;
using ExceptionBreaker.Options.ImprovedComponentModel;
using ExceptionBreaker.Options.Support;
using Microsoft.Forums.WpfDialogPageIntegration;
Expand Down
1 change: 1 addition & 0 deletions ExceptionBreaker/Options/OptionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using ExceptionBreaker.Core.Observable;
using ExceptionBreaker.Options.Support;

namespace ExceptionBreaker.Options {
Expand Down
1 change: 1 addition & 0 deletions ExceptionBreaker/Options/PatternCollectionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.ComponentModel;
using System.Linq;
using AshMind.Extensions;
using ExceptionBreaker.Core.Observable;
using ExceptionBreaker.Options.Support;

namespace ExceptionBreaker.Options {
Expand Down
1 change: 1 addition & 0 deletions ExceptionBreaker/Options/PatternViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.RegularExpressions;
using System.Windows.Data;
using ExceptionBreaker.Core.Observable;
using ExceptionBreaker.Options.Support;

namespace ExceptionBreaker.Options {
Expand Down

0 comments on commit a148339

Please sign in to comment.