Skip to content

Commit 0b29b57

Browse files
committed
Add Use Last Used Folder (for startup purposes) #191
1 parent f8c6e3f commit 0b29b57

12 files changed

Lines changed: 436 additions & 194 deletions

FrmMainApp.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ private void AppClosingPersistData()
535535
// Write lat/long + visual settings for future reference to db
536536
Log.Debug(message: "Write lat/long + visual settings for future reference to db");
537537
List<AppSettingContainer> settingsToWrite = [];
538-
List<KeyValuePair<string, string>> persistDataSettingsList =
538+
List<KeyValuePair<string, string>> persistDataSettingsListGeneric =
539539
[
540540
new KeyValuePair<string, string>(key: "lastLat", value: nud_lat.Text),
541541
new KeyValuePair<string, string>(key: "lastLng", value: nud_lng.Text),
@@ -544,18 +544,41 @@ private void AppClosingPersistData()
544544
new KeyValuePair<string, string>(key: "splitContainerLeftTopSplitterDistance",
545545
value: splitContainerLeftTop.SplitterDistance.ToString(provider: CultureInfo.InvariantCulture))
546546
];
547-
settingsToWrite.AddRange(collection: persistDataSettingsList.Select(selector: persistDataSetting =>
547+
548+
List<KeyValuePair<string, string>> persistDataSettingsListApplication = [];
549+
550+
if (HelperVariables.UserSettingUseLastUsedFolderAsStartup && !Program.CollectionModeEnabled)
551+
{
552+
persistDataSettingsListApplication.Add
553+
(
554+
new KeyValuePair<string, string>(key: "tbx_LastUsed_Folder", value: tbx_FolderName.Text)
555+
);
556+
}
557+
558+
settingsToWrite.AddRange(collection: persistDataSettingsListGeneric.Select(selector: persistDataSetting =>
548559
new AppSettingContainer
549560
{
550561
TableName = "settings",
551562
SettingTabPage = "generic",
552563
SettingId = persistDataSetting.Key,
553564
SettingValue = persistDataSetting.Value
554565
}));
566+
567+
if (persistDataSettingsListApplication.Count > 0)
568+
{
569+
settingsToWrite.AddRange(collection: persistDataSettingsListApplication.Select(selector: persistDataSetting =>
570+
new AppSettingContainer
571+
{
572+
TableName = "settings",
573+
SettingTabPage = "tpg_Application",
574+
SettingId = persistDataSetting.Key,
575+
SettingValue = persistDataSetting.Value
576+
}));
577+
}
555578
HelperDataApplicationSettings.DataWriteSQLiteSettings(settingsToWrite: settingsToWrite);
556579

557580
// Log stuff
558-
foreach (KeyValuePair<string, string> keyValuePair in persistDataSettingsList)
581+
foreach (KeyValuePair<string, string> keyValuePair in persistDataSettingsListGeneric)
559582
{
560583
Log.Debug(
561584
message:

FrmSettings.Designer.cs

Lines changed: 52 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FrmSettings.cs

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public partial class FrmSettings : Form
4848
"rbt_MapColourModeDarkPale"
4949
];
5050

51+
private readonly List<string> _rbtStartupFolderOptions =
52+
[
53+
"rbt_SetStartup_Folder",
54+
"rbt_UseLastUsedFolder"
55+
];
56+
5157
/// <summary>
5258
/// This Form provides an interface for the user to edit various app and file-specific settings.
5359
/// </summary>
@@ -64,6 +70,14 @@ public FrmSettings()
6470
_nowLoadingSettingsData = false;
6571
}
6672

73+
/// <summary>
74+
/// Initializes and assigns labels and values to controls within the form, including populating language selection
75+
/// ComboBoxes and restoring saved user preferences.
76+
/// </summary>
77+
/// <remarks>This method retrieves all relevant controls from the various tab pages,
78+
/// populates language selection ComboBoxes with both native and English names, and selects the previously saved
79+
/// language if available. It also assigns text values to other controls as needed. This method should be called
80+
/// during form initialization to ensure controls are properly configured for user interaction.</remarks>
6781
private void AssignControlLabelsAndValues()
6882
{
6983
HelperNonStatic helperNonstatic = new();
@@ -209,10 +223,15 @@ private static string GetParentNameToUse(Control cItem)
209223
}
210224

211225
/// <summary>
212-
/// Handles loading the basic values into Settings when the user opens the Form
226+
/// Handles the Load event of the settings form, initializing controls and loading user preferences from application
227+
/// settings.
213228
/// </summary>
214-
/// <param name="sender">Unused</param>
215-
/// <param name="e">Unused</param>
229+
/// <remarks>This method populates form controls with values from persisted settings, sets up file
230+
/// extension lists, and configures UI elements based on user preferences. It is called automatically when the form
231+
/// is loaded. Changes made during this event ensure that the form reflects the current application state and user
232+
/// configuration.</remarks>
233+
/// <param name="sender">The source of the event, typically the settings form instance.</param>
234+
/// <param name="e">An EventArgs object containing event data.</param>
216235
private void FrmSettings_Load(object sender,
217236
EventArgs e)
218237
{
@@ -353,6 +372,13 @@ private void FrmSettings_Load(object sender,
353372
"Normal"; // technically we could just ignore this
354373
}
355374

375+
// ensure that there _is_ a setting for UserSettingUseLastUsedFolderAsStartup
376+
// this could be a situation when the user updates to the app version newly containing this feature
377+
if (!rbt_SetStartup_Folder.Checked && !rbt_UseLastUsedFolder.Checked)
378+
{
379+
rbt_SetStartup_Folder.Checked = true;
380+
}
381+
356382
_nowLoadingSettingsData = false;
357383

358384
LoadCustomRulesDGV();
@@ -560,7 +586,6 @@ private void LoadCustomCityLogicDGV()
560586
/// checkbox changes.
561587
/// </summary>
562588
/// <returns>KVP list of country codes and countries</returns>
563-
564589
private static Dictionary<string, string> refreshClh_CountryCodeOptions(bool ckb_IncludePredeterminedCountries)
565590
{
566591
Dictionary<string, string> clh_CountryCodeOptions = [];
@@ -780,6 +805,11 @@ private void btn_Generic_OK_Click(object sender,
780805
newValue: "");
781806
}
782807
}
808+
809+
else if (_rbtStartupFolderOptions.Contains(item: rbt.Name))
810+
{
811+
HelperVariables.UserSettingUseLastUsedFolderAsStartup = rbt_UseLastUsedFolder.Checked;
812+
}
783813
}
784814
}
785815
}
@@ -813,6 +843,11 @@ private void btn_Generic_OK_Click(object sender,
813843
private void Pbx_Browse_Startup_Folder_Click(object sender,
814844
EventArgs e)
815845
{
846+
fbd_StartupFolder.Description = ReturnControlText(
847+
fakeControlType: FakeControlTypes.RadioButton,
848+
controlName: "rbt_SetStartup_Folder"
849+
);
850+
816851
if (fbd_StartupFolder.ShowDialog() == DialogResult.OK)
817852
{
818853
tbx_Startup_Folder.Text = fbd_StartupFolder.SelectedPath;
@@ -954,6 +989,9 @@ private void Any_rbt_CheckedChanged(object sender,
954989
cbx_TryUseGeoNamesLanguage.Enabled = !rbt.Checked;
955990
}
956991

992+
break;
993+
case "gbx_Startup_Folder":
994+
pbx_Browse_Startup_Folder.Enabled = rbt_SetStartup_Folder.Checked;
957995
break;
958996
case "gbx_MapColourMode":
959997
// also set the other values to False
@@ -1270,7 +1308,7 @@ private void btn_ExportSettings_Click(object sender,
12701308

12711309
Dictionary<string, string> buttonsDictionary = GetButtonsDictionary();
12721310

1273-
1311+
12741312
List<string> ItemsToExport = DialogWithOrWithoutCheckBox.DisplayAndReturnList(
12751313
labelText: ReturnControlText(
12761314
controlName: "mbx_FrmSettings_QuestionWhatToExport",
@@ -1339,7 +1377,7 @@ private void btn_ImportSettings_Click(object sender,
13391377

13401378
Dictionary<string, string> buttonsDictionary = GetButtonsDictionary();
13411379

1342-
1380+
13431381
List<string> ItemsToImport = DialogWithOrWithoutCheckBox.DisplayAndReturnList(
13441382
labelText: ReturnControlText(
13451383
controlName: "mbx_FrmSettings_QuestionWhatToImport",
@@ -1519,4 +1557,5 @@ private static Dictionary<string, string> GetCheckboxDictionary()
15191557
}
15201558

15211559
#endregion
1560+
15221561
}

0 commit comments

Comments
 (0)