From ea6125ea82c1cde2b8dde9589320057500433bb5 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Thu, 20 Jun 2019 15:10:35 -0700 Subject: [PATCH] Save and restore grid column widths Now preserving column widths for the three DataGrids and the main ListView. In theory the various grids would conveniently auto-size to the content, but in practice that doesn't work well with virtualization. There is, of course, no simple "the width has changed" event provided by the control. On the plus side, you can attach a property-change event handler to pretty much anything, so once you know the trick it's possible to make everything work. Yay WPF. --- CommonUtil/TextUtil.cs | 7 +- CommonWPF/WindowPlacement.cs | 11 +- SourceGenWPF/MainController.cs | 21 +--- SourceGenWPF/ProjWin/MainWindow.xaml | 49 +++++---- SourceGenWPF/ProjWin/MainWindow.xaml.cs | 132 +++++++++++++++++++++--- 5 files changed, 159 insertions(+), 61 deletions(-) diff --git a/CommonUtil/TextUtil.cs b/CommonUtil/TextUtil.cs index 3473343..b595661 100644 --- a/CommonUtil/TextUtil.cs +++ b/CommonUtil/TextUtil.cs @@ -215,10 +215,11 @@ namespace CommonUtil { } /// - /// Deserializes an integer array from a string. + /// Deserializes an integer array from a string. Throws an exception if the format + /// is incorrect. /// - /// - /// + /// Serialized data. + /// Integer array with contents. public static int[] DeserializeIntArray(string cereal) { string[] splitted = cereal.Split(','); if (splitted.Length == 0) { diff --git a/CommonWPF/WindowPlacement.cs b/CommonWPF/WindowPlacement.cs index 25ccc88..298fc65 100644 --- a/CommonWPF/WindowPlacement.cs +++ b/CommonWPF/WindowPlacement.cs @@ -1,15 +1,16 @@ /* - * This comes from "David Rickard's Tech Blog", posted by RandomEngy on March 8 2010: + * This comes from a blog entry, posted by RandomEngy on March 8 2010: * https://blogs.msdn.microsoft.com/davidrickard/2010/03/08/saving-window-size-and-location-in-wpf-and-winforms/ + * (see https://stackoverflow.com/a/2406604/294248 for discussion) * * Saving and restoring a window's size and position can be tricky when there are multiple * displays involved. This uses the Win32 system functions to do the job properly and * consistently. (In theory.) * * The code works for WinForms (save on FormClosing, restore on Load, using the native handle - * from the Handle property) and WPF (use the Window extension methods in Closing and - * SourceInitialized). Besides convenience, it has the added benefit of being able to - * capture the non-maximized values for a maximized window. + * from the Handle property) and WPF (use the Window extension methods provided below, in + * Closing and SourceInitialized). Besides convenience, it has the added benefit of being able + * to capture the non-maximized values for a maximized window. */ using System; @@ -116,9 +117,11 @@ namespace CommonWPF { // Extension methods for WPF. // + // Call from Closing event. Returns XML string with placement info. public static string GetPlacement(this Window window) { return GetPlacement(new WindowInteropHelper(window).Handle); } + // Call from SourceInitialized event, passing in string from GetPlacement(). public static void SetPlacement(this Window window, string placementXml) { SetPlacement(new WindowInteropHelper(window).Handle, placementXml); } diff --git a/SourceGenWPF/MainController.cs b/SourceGenWPF/MainController.cs index 1eda803..30c4d14 100644 --- a/SourceGenWPF/MainController.cs +++ b/SourceGenWPF/MainController.cs @@ -289,12 +289,7 @@ namespace SourceGenWPF { AppSettings.Global.SetInt(AppSettings.MAIN_SYMBOLS_HEIGHT, (int)mMainWin.SymbolsPanelHeight); -#if false - SerializeCodeListColumnWidths(); - SerializeReferencesColumnWidths(); - SerializeNotesColumnWidths(); - SerializeSymbolColumnWidths(); -#endif + mMainWin.CaptureColumnWidths(); string runtimeDataDir = RuntimeDataAccess.GetDirectory(); if (runtimeDataDir == null) { @@ -350,19 +345,7 @@ namespace SourceGenWPF { mMainWin.SymbolsPanelHeight = settings.GetInt(AppSettings.MAIN_SYMBOLS_HEIGHT, 400); -#if false - // Configure column widths. - string widthStr = settings.GetString(AppSettings.CDLV_COL_WIDTHS, null); - if (!string.IsNullOrEmpty(widthStr)) { - CodeListColumnWidths widths = CodeListColumnWidths.Deserialize(widthStr); - if (widths != null) { - SetCodeListHeaderWidths(widths); - } - } - DeserializeReferencesColumnWidths(); - DeserializeNotesColumnWidths(); - DeserializeSymbolColumnWidths(); -#endif + mMainWin.RestoreColumnWidths(); } /// diff --git a/SourceGenWPF/ProjWin/MainWindow.xaml b/SourceGenWPF/ProjWin/MainWindow.xaml index dee8772..de7404e 100644 --- a/SourceGenWPF/ProjWin/MainWindow.xaml +++ b/SourceGenWPF/ProjWin/MainWindow.xaml @@ -23,7 +23,7 @@ limitations under the License. mc:Ignorable="d" Title="6502bench SourceGen" Icon="/SourceGenWPF;component/Res/SourceGenIcon.ico" - Width="1000" Height="600" MinWidth="800" MinHeight="500" + Width="1000" Height="700" MinWidth="800" MinHeight="500" SourceInitialized="Window_SourceInitialized" Loaded="Window_Loaded" LocationChanged="Window_LocationChanged" @@ -241,11 +241,11 @@ limitations under the License. DockPanel, so that LastChildFill will expand this to fill all available space. --> - + - + @@ -272,9 +272,9 @@ limitations under the License. SelectionMode="Single" MouseDoubleClick="ReferencesList_MouseDoubleClick"> - - - + + + @@ -292,8 +292,8 @@ limitations under the License. SelectionMode="Single" MouseDoubleClick="NotesList_MouseDoubleClick"> - - + +