Skip to content

Commit

Permalink
Fix initial position and size
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreye committed Jan 5, 2019
1 parent c21e4a2 commit 8f61fab
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions ILSpy.Core/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public SessionSettings SessionSettings {

public IList<RoutedCommandBinding> CommandBindings { get; } = new List<RoutedCommandBinding>();

static MainWindow()
{
IsVisibleProperty.Changed.Subscribe(OnShow);
}

public MainWindow()
{
instance = this;
Expand Down Expand Up @@ -290,10 +295,9 @@ private void ApplyTheme()

void SetWindowBounds(Rect bounds)
{
this.Position = bounds.Position;
this.Width = bounds.Width;
this.Height = bounds.Height;
}
ClientSize = bounds.Size;
Position = bounds.Position;
}

#region Toolbar extensibility

Expand Down Expand Up @@ -378,27 +382,35 @@ void InitMainMenu()
}
mainMenu.Items = mainMenuItems;
}
#endregion

#region Message Hook
public override void Show()
#endregion

#region Message Hook

static void OnShow(AvaloniaPropertyChangedEventArgs args)
{
base.Show();

// Validate and Set Window Bounds
var boundsRect = sessionSettings.WindowBounds;
bool boundsOK = false;
foreach (var screen in this.Screens.All) {
var intersection = boundsRect.Intersect(screen.WorkingArea);
if (intersection.Width > 10 && intersection.Height > 10)
boundsOK = true;
if (args.Sender == instance && (bool)args.NewValue)
{
// Validate and Set Window Bounds
if (instance.sessionSettings.WindowState == WindowState.Normal)
{
var boundsRect = instance.sessionSettings.WindowBounds;
bool boundsOK = false;
foreach (var screen in instance.Screens.All)
{
var intersection = boundsRect.Intersect(screen.WorkingArea);
if (intersection.Width > 10 && intersection.Height > 10)
boundsOK = true;
}
if (boundsOK)
instance.SetWindowBounds(instance.sessionSettings.WindowBounds);
else
instance.SetWindowBounds(SessionSettings.DefaultWindowBounds);
}
else
{
instance.WindowState = instance.sessionSettings.WindowState;
}
}
if (boundsOK)
SetWindowBounds(sessionSettings.WindowBounds);
else
SetWindowBounds(SessionSettings.DefaultWindowBounds);

this.WindowState = sessionSettings.WindowState;
}
#endregion

Expand Down Expand Up @@ -1181,7 +1193,7 @@ protected override bool HandleClosing()
sessionSettings.ActiveAssemblyList = assemblyList.ListName;
sessionSettings.ActiveTreeViewPath = GetPathForNode(treeView.SelectedItem as SharpTreeNode);
sessionSettings.ActiveAutoLoadedAssembly = GetAutoLoadedAssemblyNode(treeView.SelectedItem as SharpTreeNode);
sessionSettings.WindowBounds = this.Bounds;
sessionSettings.WindowBounds = new Rect(Position, ClientSize);
sessionSettings.SplitterPosition = leftColumn.Width.Value / (leftColumn.Width.Value + rightColumn.Width.Value);
if (topPane.IsVisible == true)
sessionSettings.TopPaneSplitterPosition = topPaneRow.Height.Value / (topPaneRow.Height.Value + textViewRow.Height.Value);
Expand Down

0 comments on commit 8f61fab

Please sign in to comment.