1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-11-26 06:49:19 +00:00

Clean up clipboard format combo box

The order of items in XAML was tied to enum values, which isn't
great.  Since the value gets stored in the settings file, we want
the values to come from the code-behind.  So now we provide an
ItemsSource for the combo box from the code-behind instead of
defining the items in XAML.
This commit is contained in:
Andy McFadden 2019-06-28 15:39:35 -07:00
parent 7e0faf2800
commit 8907197d58
4 changed files with 38 additions and 8 deletions

View File

@ -26,6 +26,8 @@ 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_ClipformatAssemblerSource">Assembler Source</system:String>
<system:String x:Key="str_ClipformatDisassembly">Disassembly</system:String>
<system:String x:Key="str_DefaultValue">Default</system:String>
<system:String x:Key="str_ErrBadFd">Bad format descriptor at +{0:x6}.</system:String>
<system:String x:Key="str_ErrBadFdFormat">Bad format descriptor type</system:String>

View File

@ -39,6 +39,10 @@ namespace SourceGenWPF.Res {
(string)Application.Current.FindResource("str_AsmOutputNotFound");
public static string DEFAULT_VALUE =
(string)Application.Current.FindResource("str_DefaultValue");
public static string CLIPFORMAT_ASSEMBLER_SOURCE =
(string)Application.Current.FindResource("str_ClipformatAssemblerSource");
public static string CLIPFORMAT_DISASSEMBLY =
(string)Application.Current.FindResource("str_ClipformatDisassembly");
public static string ERR_BAD_FD =
(string)Application.Current.FindResource("str_ErrBadFd");
public static string ERR_BAD_FD_FORMAT =

View File

@ -112,10 +112,8 @@ limitations under the License.
<StackPanel>
<TextBlock Margin="0,4,0,0">Format for lines copied to clipboard:</TextBlock>
<ComboBox Name="clipboardFormatComboBox" IsReadOnly="True" Margin="0,8,0,0"
SelectionChanged="ClipboardFormatComboBox_SelectionChanged">
<ComboBoxItem>Assembler Source</ComboBoxItem>
<ComboBoxItem>Disassembly</ComboBoxItem>
</ComboBox>
ItemsSource="{Binding ClipboardFormatItems}" DisplayMemberPath="Name"
SelectionChanged="ClipboardFormatComboBox_SelectionChanged"/>
</StackPanel>
</GroupBox>

View File

@ -245,6 +245,30 @@ namespace SourceGenWPF.WpfGui {
#region Code View
/// <summary>
/// Entries for the clipboard format item combo box.
/// </summary>
public class ClipboardFormatItem {
public string Name { get; private set; }
public MainController.ClipLineFormat Value { get; private set; }
public ClipboardFormatItem(string name, MainController.ClipLineFormat value) {
Name = name;
Value = value;
}
}
// NOTE: in the current implementation, the array index must match the enum value
private static ClipboardFormatItem[] sClipboardFormatItems = {
new ClipboardFormatItem(Res.Strings.CLIPFORMAT_ASSEMBLER_SOURCE,
MainController.ClipLineFormat.AssemblerSource),
new ClipboardFormatItem(Res.Strings.CLIPFORMAT_DISASSEMBLY,
MainController.ClipLineFormat.Disassembly)
};
// ItemsSource for combo box
public ClipboardFormatItem[] ClipboardFormatItems {
get { return sClipboardFormatItems; }
}
private void Loaded_CodeView() {
// Column widths. We called CaptureColumnWidths() during init, so this
// should always be a valid serialized string.
@ -271,10 +295,12 @@ namespace SourceGenWPF.WpfGui {
UpperOperandS = mSettings.GetBool(AppSettings.FMT_UPPER_OPERAND_S, false);
UpperOperandXY = mSettings.GetBool(AppSettings.FMT_UPPER_OPERAND_XY, false);
Debug.Assert(clipboardFormatComboBox.Items.Count == sClipboardFormatItems.Length);
int clipIndex = mSettings.GetEnum(AppSettings.CLIP_LINE_FORMAT,
typeof(MainController.ClipLineFormat), 0);
if (clipIndex >= 0 && clipIndex < clipboardFormatComboBox.Items.Count) {
// NOTE: this couples the ClipLineFormat enum to the XAML.
if (clipIndex >= 0 && clipIndex < sClipboardFormatItems.Length) {
// require Value == clipIndex because we're lazy and don't want to search
Debug.Assert((int)sClipboardFormatItems[clipIndex].Value == clipIndex);
clipboardFormatComboBox.SelectedIndex = clipIndex;
}
@ -416,9 +442,9 @@ namespace SourceGenWPF.WpfGui {
private void ClipboardFormatComboBox_SelectionChanged(object sender,
SelectionChangedEventArgs e) {
// NOTE: again, this ties the combo box index to the enum value
ClipboardFormatItem item = (ClipboardFormatItem)clipboardFormatComboBox.SelectedItem;
mSettings.SetEnum(AppSettings.CLIP_LINE_FORMAT, typeof(MainController.ClipLineFormat),
clipboardFormatComboBox.SelectedIndex);
(int)item.Value);
IsDirty = true;
}