Skip to content

Commit

Permalink
Auto-save, part 1
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fadden committed Aug 2, 2024
1 parent ef13101 commit 3d4250c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions SourceGen/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public class AppSettings {

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";

Expand Down
3 changes: 3 additions & 0 deletions SourceGen/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ private void LoadAppSettings() {
// 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);
Expand Down Expand Up @@ -1073,6 +1075,7 @@ public void NewProject() {
bool ok = PrepareNewProject(Path.GetFullPath(dlg.DataFileName), dlg.SystemDef);
if (ok) {
FinishPrep();
SaveProjectAs();
}
}

Expand Down
3 changes: 3 additions & 0 deletions SourceGen/Res/Strings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ limitations under the License.
<system:String x:Key="str_AsmMismatchDataFmt">Assembled output does not match: offset +{0:x6} has value ${1:x2}, expected ${2:x2}.</system:String>
<system:String x:Key="str_AsmMismatchLengthFmt">Assembled output does not match: length is {0}, expected {1}.</system:String>
<system:String x:Key="str_AsmOutputNotFound">Expected output file wasn't created</system:String>
<system:String x:Key="str_AutoSave1Min">60 seconds</system:String>
<system:String x:Key="str_AutoSave5Min">5 minutes</system:String>
<system:String x:Key="str_AutoSaveOff">disabled</system:String>
<system:String x:Key="str_ClipformatAllColumns">All Columns</system:String>
<system:String x:Key="str_ClipformatAssemblerSource">Assembler Source</system:String>
<system:String x:Key="str_ClipformatDisassembly">Disassembly</system:String>
Expand Down
6 changes: 6 additions & 0 deletions SourceGen/Res/Strings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public static class Strings {
(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 =
Expand Down
6 changes: 6 additions & 0 deletions SourceGen/WpfGui/EditAppSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ limitations under the License.
IsChecked="{Binding ShowCycleCountsScreen}"/>
<CheckBox Content="Use &quot;dark&quot; color scheme" Margin="0,4"
IsChecked="{Binding DarkColorScheme}"/>
<DockPanel LastChildFill="True">
<TextBlock Margin="0,3,0,0">Auto-save interval:</TextBlock>
<ComboBox Name="autoSaveComboBox" IsReadOnly="True" Margin="8,0,0,0"
ItemsSource="{Binding AutoSaveItems}" DisplayMemberPath="Title"
SelectionChanged="AutoSaveComboBox_SelectionChanged"/>
</DockPanel>
</StackPanel>
</GroupBox>

Expand Down
39 changes: 38 additions & 1 deletion SourceGen/WpfGui/EditAppSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public ClipboardFormatItem(string name, MainController.ClipLineFormat value) {
}
}
// 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,
Expand All @@ -254,6 +254,26 @@ public ClipboardFormatItem[] ClipboardFormatItems {
get { return sClipboardFormatItems; }
}

/// <summary>
/// Entries for the auto-save combo box.
/// </summary>
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.
Expand Down Expand Up @@ -289,6 +309,17 @@ private void Loaded_CodeView() {
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);
}

Expand Down Expand Up @@ -419,6 +450,12 @@ private void ClipboardFormatComboBox_SelectionChanged(object sender,
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 {
Expand Down

0 comments on commit 3d4250c

Please sign in to comment.