From 3d4250cbc4d1f655a0385a3adbb63eb159f6618f Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Fri, 2 Aug 2024 13:47:39 -0700 Subject: [PATCH] Auto-save, part 1 Added configuration option to app settings. It's in the "code view" tab, which isn't quite right, but none of the others fit better. Also, force a Save As when a new project is first created. --- SourceGen/AppSettings.cs | 2 ++ SourceGen/MainController.cs | 3 ++ SourceGen/Res/Strings.xaml | 3 ++ SourceGen/Res/Strings.xaml.cs | 6 ++++ SourceGen/WpfGui/EditAppSettings.xaml | 6 ++++ SourceGen/WpfGui/EditAppSettings.xaml.cs | 39 +++++++++++++++++++++++- 6 files changed, 58 insertions(+), 1 deletion(-) diff --git a/SourceGen/AppSettings.cs b/SourceGen/AppSettings.cs index 340bbb5..ffa79cf 100644 --- a/SourceGen/AppSettings.cs +++ b/SourceGen/AppSettings.cs @@ -75,7 +75,9 @@ namespace SourceGen { public const string CLIP_LINE_FORMAT = "clip-line-format"; + // Project open/save settings. public const string PRVW_RECENT_PROJECT_LIST = "prvw-recent-project-list"; + public const string PROJ_AUTO_SAVE_INTERVAL = "proj-auto-save-interval"; public const string SKIN_DARK_COLOR_SCHEME = "skin-dark-color-scheme"; diff --git a/SourceGen/MainController.cs b/SourceGen/MainController.cs index a2513d1..2b02938 100644 --- a/SourceGen/MainController.cs +++ b/SourceGen/MainController.cs @@ -325,6 +325,8 @@ namespace SourceGen { // values here when that isn't the case. The point at which the setting is // actually used is expected to do something reasonable by default. + settings.SetInt(AppSettings.PROJ_AUTO_SAVE_INTERVAL, 60); // enabled by default + settings.SetBool(AppSettings.SYMWIN_SHOW_USER, true); settings.SetBool(AppSettings.SYMWIN_SHOW_NON_UNIQUE, false); settings.SetBool(AppSettings.SYMWIN_SHOW_PROJECT, true); @@ -1073,6 +1075,7 @@ namespace SourceGen { bool ok = PrepareNewProject(Path.GetFullPath(dlg.DataFileName), dlg.SystemDef); if (ok) { FinishPrep(); + SaveProjectAs(); } } diff --git a/SourceGen/Res/Strings.xaml b/SourceGen/Res/Strings.xaml index bdec3c5..e324b5f 100644 --- a/SourceGen/Res/Strings.xaml +++ b/SourceGen/Res/Strings.xaml @@ -32,6 +32,9 @@ limitations under the License. Assembled output does not match: offset +{0:x6} has value ${1:x2}, expected ${2:x2}. Assembled output does not match: length is {0}, expected {1}. Expected output file wasn't created + 60 seconds + 5 minutes + disabled All Columns Assembler Source Disassembly diff --git a/SourceGen/Res/Strings.xaml.cs b/SourceGen/Res/Strings.xaml.cs index 83495d1..818fc2b 100644 --- a/SourceGen/Res/Strings.xaml.cs +++ b/SourceGen/Res/Strings.xaml.cs @@ -45,6 +45,12 @@ namespace SourceGen.Res { (string)Application.Current.FindResource("str_AsmMismatchLengthFmt"); public static string ASM_OUTPUT_NOT_FOUND = (string)Application.Current.FindResource("str_AsmOutputNotFound"); + public static string AUTO_SAVE_OFF = + (string)Application.Current.FindResource("str_AutoSaveOff"); + public static string AUTO_SAVE_1_MIN = + (string)Application.Current.FindResource("str_AutoSave1Min"); + public static string AUTO_SAVE_5_MIN = + (string)Application.Current.FindResource("str_AutoSave5Min"); public static string CONFIRMATION_NEEDED = (string)Application.Current.FindResource("str_ConfirmationNeeded"); public static string DATA_BANK_AUTO_FMT = diff --git a/SourceGen/WpfGui/EditAppSettings.xaml b/SourceGen/WpfGui/EditAppSettings.xaml index acaf899..28b39b4 100644 --- a/SourceGen/WpfGui/EditAppSettings.xaml +++ b/SourceGen/WpfGui/EditAppSettings.xaml @@ -135,6 +135,12 @@ limitations under the License. IsChecked="{Binding ShowCycleCountsScreen}"/> + + Auto-save interval: + + diff --git a/SourceGen/WpfGui/EditAppSettings.xaml.cs b/SourceGen/WpfGui/EditAppSettings.xaml.cs index 9d70f4f..690c57f 100644 --- a/SourceGen/WpfGui/EditAppSettings.xaml.cs +++ b/SourceGen/WpfGui/EditAppSettings.xaml.cs @@ -241,7 +241,7 @@ namespace SourceGen.WpfGui { } } // NOTE: in the current implementation, the array index must match the enum value - private static ClipboardFormatItem[] sClipboardFormatItems = { + private static readonly ClipboardFormatItem[] sClipboardFormatItems = { new ClipboardFormatItem(Res.Strings.CLIPFORMAT_ASSEMBLER_SOURCE, MainController.ClipLineFormat.AssemblerSource), new ClipboardFormatItem(Res.Strings.CLIPFORMAT_DISASSEMBLY, @@ -254,6 +254,26 @@ namespace SourceGen.WpfGui { get { return sClipboardFormatItems; } } + /// + /// Entries for the auto-save combo box. + /// + public class AutoSaveItem { + public string Title { get; private set; } + public int Interval { get; private set; } + + public AutoSaveItem(string title, int interval) { + Title = title; + Interval = interval; + } + } + private static readonly AutoSaveItem[] sAutoSaveItems = { + new AutoSaveItem(Res.Strings.AUTO_SAVE_OFF, 0), + new AutoSaveItem(Res.Strings.AUTO_SAVE_1_MIN, 60), + new AutoSaveItem(Res.Strings.AUTO_SAVE_5_MIN, 300), + }; + public AutoSaveItem[] AutoSaveItems { get { return sAutoSaveItems; } } + + private void Loaded_CodeView() { // Column widths. We called CaptureColumnWidths() during init, so this // should always be a valid serialized string. @@ -289,6 +309,17 @@ namespace SourceGen.WpfGui { clipboardFormatComboBox.SelectedIndex = clipIndex; } + // Look for a matching auto-save interval. + int autoSaveInterval = mSettings.GetInt(AppSettings.PROJ_AUTO_SAVE_INTERVAL, 0); + int autoSaveIndex = 1; // show a non-disabled value if we don't find a match + for (int i = 0; i < sAutoSaveItems.Length; i++) { + if (sAutoSaveItems[i].Interval == autoSaveInterval) { + autoSaveIndex = i; + break; + } + } + autoSaveComboBox.SelectedIndex = autoSaveIndex; + EnableDebugMenu = mSettings.GetBool(AppSettings.DEBUG_MENU_ENABLED, false); } @@ -419,6 +450,12 @@ namespace SourceGen.WpfGui { IsDirty = true; } + private void AutoSaveComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { + AutoSaveItem item = (AutoSaveItem)autoSaveComboBox.SelectedItem; + mSettings.SetInt(AppSettings.PROJ_AUTO_SAVE_INTERVAL, item.Interval); + IsDirty = true; + } + public bool ShowCycleCountsScreen { get { return mSettings.GetBool(AppSettings.FMT_SHOW_CYCLE_COUNTS, false); } set {