From 3c8c80afe367021de94ce806bf74b5db7bd16914 Mon Sep 17 00:00:00 2001
From: Eric Oulashin <eric.oulashin@gmail.com>
Date: Sun, 12 Jun 2022 13:55:38 -0700
Subject: [PATCH] DD File Area Chooser: The "false command-line parameter works
 again, allowing the user to choose the file directory within their file
 library.

---
 xtrn/DDAreaChoosers/DDFileAreaChooser.js | 33 ++++++++++++++++++++++++
 xtrn/DDAreaChoosers/DDMsgAreaChooser.js  |  4 +--
 xtrn/DDAreaChoosers/readme.txt           |  4 +--
 xtrn/DDAreaChoosers/revision_history.txt |  3 +++
 4 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/xtrn/DDAreaChoosers/DDFileAreaChooser.js b/xtrn/DDAreaChoosers/DDFileAreaChooser.js
index dfc730803f..0b555ec592 100644
--- a/xtrn/DDAreaChoosers/DDFileAreaChooser.js
+++ b/xtrn/DDAreaChoosers/DDFileAreaChooser.js
@@ -23,8 +23,15 @@
  * 2022-05-17 Eric Oulashin   Version 1.24
  *                            Fixes for searching and search error reporting (probably
  *                            due to mistaken copy & paste in an earlier commit)
+ * 2022-06-12 Eric Oulashin   Version 1.26
+ *                            Running this scipt with the "false command-line parameter
+ *                            works again, allowing the user to choose the file directory
+ *                            within their file library.
  */
 
+// TODO: Failing silently when 1st argument is true
+// TODO: In the area list, the 10,000ths digit (for # items) is in a different color)
+
 /* Command-line arguments:
    1 (argv[0]): Boolean - Whether or not to choose a file library first (default).  If
                 false, the user will only be able to choose a different directory within
@@ -189,6 +196,7 @@ function DDFileAreaChooser()
 	this.SelectFileArea_Traditional = DDFileAreaChooser_SelectFileArea_Traditional;
 	this.SelectDirWithinFileLib_Traditional = DDFileAreaChooser_SelectDirWithinFileLib_Traditional;
 	this.SelectSubdirWithinDir_Traditional = DDFileAreaChooser_SelectSubdirWithinDir_Traditional;
+	this.GetActualLibIdx = DDFileAreaChooser_GetActualLibIdx;
 	this.ListFileLibs_Traditional = DDFileAreaChooser_ListFileLibs_Traditional;
 	this.ListDirsInFileLib_Traditional = DDFileAreaChooser_ListDirsInFileLib_Traditional;
 	this.ListSubdirsInFileDir_Traditional = DDFileAreaChooser_ListSubdirsInFileDir_Traditional;
@@ -351,6 +359,9 @@ function DDFileAreaChooser_SelectFileArea_Traditional(pLevel, pLibIdx, pDirIdx)
 		return;
 	}
 
+	if (pLevel > 1 && typeof(pLibIdx) !== "number")
+		pLibIdx = this.GetActualLibIdx();
+
 	var curLibIdx = 0;
 	var curDirIdx = 0;
 	if (typeof(bbs.curdir_code) == "string")
@@ -700,6 +711,26 @@ function DDFileAreaChooser_SelectSubdirWithinDir_Traditional(pLibIdx, pDirIdx)
 	return retObj;
 }
 
+// For the DDFileAreaChooser class: Maps bbs.curlib to the collapsed library array library index
+function DDFileAreaChooser_GetActualLibIdx()
+{
+	var libIdx = bbs.curlib;
+	if (this.useDirCollapsing)
+	{
+		var syncLibName = file_area.lib_list[bbs.curlib].name;
+		var syncLibDesc = file_area.lib_list[bbs.curlib].description;
+		for (var i = 0; i < this.lib_list.length; ++i)
+		{
+			if (this.lib_list[i].name == syncLibName && this.lib_list[i].description == syncLibDesc)
+			{
+				libIdx = i;
+				break;
+			}
+		}
+	}
+	return libIdx;
+}
+
 // For the DDFileAreaChooser class: Traditional user interface for listing
 // the file libraries
 //
@@ -970,6 +1001,8 @@ function DDFileAreaChooser_WriteDirListHdr1Line(pLibIdx, pDirIdx, pNumPages, pPa
 //           directory name collapsing
 function DDFileAreaChooser_SelectFileArea_Lightbar(pLevel, pLibIdx, pDirIdx)
 {
+	if (pLevel > 1 && typeof(pLibIdx) !== "number")
+		pLibIdx = this.GetActualLibIdx();
 	// If there are file libraries, then don't let the user
 	// choose one.
 	if (file_area.lib_list.length == 0)
diff --git a/xtrn/DDAreaChoosers/DDMsgAreaChooser.js b/xtrn/DDAreaChoosers/DDMsgAreaChooser.js
index 2574f5c12e..a2d848f318 100644
--- a/xtrn/DDAreaChoosers/DDMsgAreaChooser.js
+++ b/xtrn/DDAreaChoosers/DDMsgAreaChooser.js
@@ -78,8 +78,8 @@ if (system.version_num < 31400)
 }
 
 // Version & date variables
-var DD_MSG_AREA_CHOOSER_VERSION = "1.25";
-var DD_MSG_AREA_CHOOSER_VER_DATE = "2022-06-06";
+var DD_MSG_AREA_CHOOSER_VERSION = "1.26";
+var DD_MSG_AREA_CHOOSER_VER_DATE = "2022-06-11";
 
 // Keyboard input key codes
 var CTRL_H = "\x08";
diff --git a/xtrn/DDAreaChoosers/readme.txt b/xtrn/DDAreaChoosers/readme.txt
index ea8833aef4..89594daf5a 100644
--- a/xtrn/DDAreaChoosers/readme.txt
+++ b/xtrn/DDAreaChoosers/readme.txt
@@ -1,6 +1,6 @@
                      Digital Distortion Area Choosers
-                           Version 1.26/1.24
-                        Release date: 2022-06-11
+                              Version 1.26
+                        Release date: 2022-06-12
 
                                   by
 
diff --git a/xtrn/DDAreaChoosers/revision_history.txt b/xtrn/DDAreaChoosers/revision_history.txt
index f0024a7b57..348a85fdfd 100644
--- a/xtrn/DDAreaChoosers/revision_history.txt
+++ b/xtrn/DDAreaChoosers/revision_history.txt
@@ -5,6 +5,9 @@ Revision History (change log)
 =============================
 Version  Date         Description
 -------  ----         -----------
+1.26     2022-06-12   File area chooser fix: Running the scipt with the "false"
+                      command-line parameter works again, allowing the user to
+                      choose the file directory within their file library.
 1.26     2022-06-11   Message area chooser only: Updated to try to prevent the
                       error "this.subBoardListPrintfInfo[pGrpIdx] is undefined"
 1.25     2022-06-06   Message area chooser only: Fix for miscolored digit(s) in
-- 
GitLab