Skip to content

Commit 47f9d0c

Browse files
committed
Added Viewer display defaults in VS settings
1 parent 64e00e2 commit 47f9d0c

6 files changed

Lines changed: 45 additions & 18 deletions

File tree

StructLayout/Shared/Editor/EditorProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private string GetParserOutputDirectory()
9292
private void ApplyUserSettingsToWindow(LayoutWindow window, GeneralSettingsPageGrid settings)
9393
{
9494
if (window == null || settings == null) return;
95-
window.SetGridNumberBase(settings.OptionViewerGridBase);
95+
window.RefreshDefaults();
9696
}
9797

9898
public void OnUserSettingsChanged()

StructLayout/Shared/Editor/EditorUtils.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ static public void Initialize(StructLayoutPackage package)
2525
{
2626
Package = package;
2727
ServiceProvider = package;
28+
29+
GetGeneralSettings(); //Force a settings load and propagation
2830
}
2931

3032
static public GeneralSettingsPageGrid GetGeneralSettings()

StructLayout/Shared/LayoutWindow/LayoutViewer.xaml.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,22 @@ protected override Visual GetVisualChild(int index)
146146

147147
public partial class LayoutViewer : UserControl
148148
{
149-
private enum DisplayAlignmentType
149+
public enum DisplayAlignmentType
150150
{
151-
Struct,
151+
Struct = 0,
152152
Cacheline,
153153
Custom
154154
}
155155

156156
public enum DisplayMode
157157
{
158-
Stack,
158+
Stack = 0,
159159
Flat
160160
}
161161

162162
public enum GridBase
163163
{
164-
Decimal,
164+
Decimal = 0,
165165
Hexadecimal,
166166
}
167167

@@ -179,6 +179,10 @@ public enum GridBase
179179
const double MarginBottom = 25;
180180
const double paddingSize = 5;
181181

182+
public static DisplayAlignmentType DefaultDisplayAlignment { set; get; } = DisplayAlignmentType.Struct;
183+
public static DisplayMode DefaultDisplayMode { set; get; } = DisplayMode.Stack;
184+
public static GridBase DefaultGridNumberBase { set; get; } = GridBase.Hexadecimal;
185+
182186
private Typeface Font = new Typeface("Verdana");
183187
private Pen gridPen = new Pen(new SolidColorBrush(Color.FromArgb(100, 0, 0, 0)), 1);
184188

@@ -208,19 +212,23 @@ public enum GridBase
208212

209213
public LayoutViewer()
210214
{
215+
ThreadHelper.ThrowIfNotOnUIThread();
216+
211217
InitializeComponent();
212218
this.DataContext = this;
213219

214220
overlayBrush.Opacity = 0.3;
215221
SetDisplayGridColumns(8);
216222

223+
GridNumberBase = DefaultGridNumberBase;
224+
217225
tooltipTimer.Tick += ShowTooltip;
218226

219227
displayAlignementComboBox.ItemsSource = Enum.GetValues(typeof(DisplayAlignmentType)).Cast<DisplayAlignmentType>();
220-
displayAlignementComboBox.SelectedIndex = 0;
228+
displayAlignementComboBox.SelectedIndex = (int)DefaultDisplayAlignment;
221229

222230
displayModeComboBox.ItemsSource = Enum.GetValues(typeof(DisplayMode)).Cast<DisplayMode>();
223-
displayModeComboBox.SelectedIndex = 0;
231+
displayModeComboBox.SelectedIndex = (int)DefaultDisplayMode;
224232

225233
scrollViewer.Loaded += ScrollViewer_OnLoaded;
226234
scrollViewer.On2DMouseScroll += ScrollViewer_On2DMouseScroll;
@@ -248,11 +256,11 @@ public void SetLayout(LayoutNode root)
248256
}
249257
}
250258

251-
public void SetGridNumberBase(GridBase newBase)
259+
public void RefreshDefaults()
252260
{
253-
if (newBase != GridNumberBase)
261+
if (DefaultGridNumberBase != GridNumberBase)
254262
{
255-
GridNumberBase = newBase;
263+
GridNumberBase = DefaultGridNumberBase;
256264

257265
RenderGrid();
258266
RefreshShapes();

StructLayout/Shared/LayoutWindow/LayoutWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public void SetResult(ParseResult result)
4545
(this.Content as LayoutWindowControl).SetResult(result);
4646
}
4747

48-
public void SetGridNumberBase(LayoutViewer.GridBase gridBase)
48+
public void RefreshDefaults()
4949
{
50-
(this.Content as LayoutWindowControl).SetGridNumberBase(gridBase);
50+
(this.Content as LayoutWindowControl).RefreshDefaults();
5151
}
5252
}
5353
}

StructLayout/Shared/LayoutWindow/LayoutWindowControl.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public void SetResult(ParseResult result)
4545
viewer.SetLayout(result.Layout);
4646
}
4747

48-
public void SetGridNumberBase(LayoutViewer.GridBase gridBase)
48+
public void RefreshDefaults()
4949
{
50-
viewer.SetGridNumberBase(gridBase);
50+
viewer.RefreshDefaults();
5151
}
5252

5353
public void OpenSettings(object a, object e)

StructLayout/Shared/StructLayoutSettings.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ namespace StructLayout
55
{
66
public class GeneralSettingsPageGrid : DialogPage
77
{
8-
private LayoutViewer.GridBase gridNumberBase = LayoutViewer.GridBase.Hexadecimal;
9-
108
[Category("Parser")]
119
[DisplayName("Print Command Line")]
1210
[Description("Print the command line argument passed to the parser in the Tool output pane")]
@@ -16,9 +14,28 @@ public class GeneralSettingsPageGrid : DialogPage
1614
[DisplayName("Grid Number Base")]
1715
[Description("Base for the numbers in the viewer grid rows and columns")]
1816
public LayoutViewer.GridBase OptionViewerGridBase {
19-
get { return gridNumberBase; }
20-
set { gridNumberBase = value; ThreadHelper.ThrowIfNotOnUIThread(); EditorProcessor.Instance.OnUserSettingsChanged(); }
17+
get { return LayoutViewer.DefaultGridNumberBase; }
18+
set { LayoutViewer.DefaultGridNumberBase = value; ThreadHelper.ThrowIfNotOnUIThread(); EditorProcessor.Instance.OnUserSettingsChanged(); }
19+
}
20+
21+
[Category("Viewer")]
22+
[DisplayName("Default Display Alignment")]
23+
[Description("Default value for the viewer display alignment")]
24+
public LayoutViewer.DisplayAlignmentType OptionDefaultDisplayAlignment
25+
{
26+
get { return LayoutViewer.DefaultDisplayAlignment; }
27+
set { LayoutViewer.DefaultDisplayAlignment = value; }
2128
}
29+
30+
[Category("Viewer")]
31+
[DisplayName("Default Display Mode")]
32+
[Description("Default value for the viewer display mode")]
33+
public LayoutViewer.DisplayMode OptionDefaultDisplayMode
34+
{
35+
get { return LayoutViewer.DefaultDisplayMode; }
36+
set { LayoutViewer.DefaultDisplayMode = value; }
37+
}
38+
2239
}
2340
}
2441

0 commit comments

Comments
 (0)