11using System ;
2+ using System . Collections . Generic ;
23using System . IO ;
34using System . Windows ;
45using System . Windows . Forms ;
6+ using DICUI . Data ;
7+ using DICUI . Utilities ;
58using DICUI . Web ;
69using Button = System . Windows . Controls . Button ;
710using TextBox = System . Windows . Controls . TextBox ;
@@ -20,11 +23,26 @@ public partial class OptionsWindow : Window
2023 /// </summary>
2124 public UIOptions UIOptions { get ; set ; }
2225
26+ /// <summary>
27+ /// List of available internal programs
28+ /// </summary>
29+ public List < InternalProgramComboBoxItem > InternalPrograms { get ; private set ; }
30+
2331 #endregion
2432
2533 public OptionsWindow ( )
2634 {
2735 InitializeComponent ( ) ;
36+
37+ PopulateInternalPrograms ( ) ;
38+ }
39+
40+ #region Helpers
41+
42+ private FolderBrowserDialog CreateFolderBrowserDialog ( )
43+ {
44+ FolderBrowserDialog dialog = new FolderBrowserDialog ( ) ;
45+ return dialog ;
2846 }
2947
3048 private OpenFileDialog CreateOpenFileDialog ( )
@@ -39,17 +57,52 @@ private OpenFileDialog CreateOpenFileDialog()
3957 return dialog ;
4058 }
4159
42- private FolderBrowserDialog CreateFolderBrowserDialog ( )
60+ /// <summary>
61+ /// Get a complete list of internal programs and fill the combo box
62+ /// </summary>
63+ private void PopulateInternalPrograms ( )
4364 {
44- FolderBrowserDialog dialog = new FolderBrowserDialog ( ) ;
45- return dialog ;
65+ // We only support certain programs for dumping
66+ var internalPrograms = new List < InternalProgram > { InternalProgram . DiscImageCreator , InternalProgram . Aaru , InternalProgram . DD } ;
67+ ViewModels . LoggerViewModel . VerboseLogLn ( "Populating internal programs, {0} internal programs found." , internalPrograms . Count ) ;
68+
69+ InternalPrograms = new List < InternalProgramComboBoxItem > ( ) ;
70+ foreach ( var internalProgram in internalPrograms )
71+ {
72+ InternalPrograms . Add ( new InternalProgramComboBoxItem ( internalProgram ) ) ;
73+ }
74+
75+ InternalProgramComboBox . ItemsSource = InternalPrograms ;
76+ InternalProgramComboBox . SelectedIndex = 0 ;
77+ }
78+
79+ /// <summary>
80+ /// Refresh any options-related elements
81+ /// </summary>
82+ public void Refresh ( )
83+ {
84+ // Handle non-bindable fields
85+ InternalProgramComboBox . SelectedIndex = InternalPrograms . FindIndex ( r => r == Converters . ToInternalProgram ( UIOptions . Options . InternalProgram ) ) ;
86+ RedumpPasswordBox . Password = UIOptions . Options . Password ;
4687 }
4788
89+ /// <summary>
90+ /// Find a TextBox by setting name
91+ /// </summary>
92+ /// <param name="name">Setting name to find</param>
93+ /// <returns>TextBox for that setting</returns>
4894 private TextBox TextBoxForPathSetting ( string name )
4995 {
5096 return FindName ( name + "TextBox" ) as TextBox ;
5197 }
5298
99+ #endregion
100+
101+ #region Event Handlers
102+
103+ /// <summary>
104+ /// Handler for generic Click event
105+ /// </summary>
53106 private void BrowseForPathClick ( object sender , EventArgs e )
54107 {
55108 Button button = sender as Button ;
@@ -97,17 +150,13 @@ private void BrowseForPathClick(object sender, EventArgs e)
97150 }
98151 }
99152
100- public void Refresh ( )
101- {
102- // Handle non-bindable fields
103- RedumpPasswordBox . Password = UIOptions . Options . Password ;
104- }
105-
106- #region Event Handlers
107-
153+ /// <summary>
154+ /// Handler for AcceptButton Click event
155+ /// </summary>
108156 private void OnAcceptClick ( object sender , EventArgs e )
109157 {
110158 // Handle non-bindable fields
159+ UIOptions . Options . InternalProgram = ( InternalProgramComboBox . SelectedItem as InternalProgramComboBoxItem ) ? . Name ?? InternalProgram . DiscImageCreator . ToString ( ) ;
111160 UIOptions . Options . Password = RedumpPasswordBox . Password ;
112161
113162 UIOptions . Save ( ) ;
@@ -116,6 +165,9 @@ private void OnAcceptClick(object sender, EventArgs e)
116165 ( Owner as MainWindow ) . OnOptionsUpdated ( ) ;
117166 }
118167
168+ /// <summary>
169+ /// Handler for CancelButton Click event
170+ /// </summary>
119171 private void OnCancelClick ( object sender , EventArgs e )
120172 {
121173 // just hide the window and don't care
0 commit comments