Skip to content

Commit

Permalink
Fully complete book, chapter, and verse for USFM/USJ/USX
Browse files Browse the repository at this point in the history
  • Loading branch information
lyonsil committed Jun 25, 2024
1 parent da9d954 commit 62fa22a
Show file tree
Hide file tree
Showing 20 changed files with 624 additions and 298 deletions.
2 changes: 1 addition & 1 deletion c-sharp-tests/DummyPapiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public override void SendRequest(
// handle, and no translation is needed.
var ourSettingName = (string)details[1];
var pbSettingName =
ProjectSettings.GetPlatformBibleSettingNameFromParatextSettingName(
ProjectSettingsNames.GetPlatformBibleSettingNameFromParatextSettingName(
ourSettingName
);
Expand Down
10 changes: 5 additions & 5 deletions c-sharp-tests/Services/ProjectSettingsServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public void IsValid_ValidLanguage_ReturnsTrue()
var newValueJson = JsonConvert.SerializeObject("Spanish");
var currentValueJson = JsonConvert.SerializeObject("German");
papiClient.AddSettingValueToTreatAsValid(
ProjectSettings.PB_LANGUAGE,
ProjectSettingsNames.PB_LANGUAGE,
newValueJson,
currentValueJson
);
var result = ProjectSettingsService.IsValid(
papiClient,
newValueJson,
currentValueJson,
ProjectSettings.PT_LANGUAGE,
ProjectSettingsNames.PT_LANGUAGE,
""
);

Expand All @@ -39,7 +39,7 @@ public void IsValid_InvalidSetting_ReturnsFalse()
papiClient,
newValueJson,
currentValueJson,
ProjectSettings.PT_LANGUAGE,
ProjectSettingsNames.PT_LANGUAGE,
""
);

Expand All @@ -50,9 +50,9 @@ public void IsValid_InvalidSetting_ReturnsFalse()
public void GetDefault_KnownProperty_ReturnsDefaultValue()
{
DummyPapiClient papiClient = new DummyPapiClient();
var result = ProjectSettingsService.GetDefault(papiClient, ProjectSettings.PT_LANGUAGE);
var result = ProjectSettingsService.GetDefault(papiClient, ProjectSettingsNames.PT_LANGUAGE);

Assert.That(result, Is.EqualTo($"default value for {ProjectSettings.PB_LANGUAGE}"));
Assert.That(result, Is.EqualTo($"default value for {ProjectSettingsNames.PB_LANGUAGE}"));
}

[Test]
Expand Down
4 changes: 4 additions & 0 deletions c-sharp/ParanextDataProvider.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=getTime/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ldml/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=papi/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=parameterless/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Paranext/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=paratext/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Paratext_0027s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PDPF/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=setTime/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SLDR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=subdir/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SUBDIRECTORY/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unregister/@EntryIndexedValue">True</s:Boolean>
Expand Down
78 changes: 48 additions & 30 deletions c-sharp/Projects/LocalParatextProjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class LocalParatextProjects
{
#region Constructors, consts, and fields

// Inside of each project's "home" directory, these are the subdirectories and files
// Inside each project's "home" directory, these are the subdirectories and files
protected const string PROJECT_SETTINGS_FILE = "Settings.xml";

/// <summary>
Expand All @@ -21,10 +21,18 @@ internal class LocalParatextProjects
public const string EXTENSION_DATA_SUBDIRECTORY = "shared/platform.bible/extensions";

private bool _isInitialized = false;
private readonly object _initializationLock = new();

private List<string> _requiredProjectRootFiles = ["usfm.sty", "Attribution.md"];
private readonly List<string> _requiredProjectRootFiles = ["usfm.sty", "Attribution.md"];

private static readonly List<string> _paratextProjectInterfaces = [ProjectInterfaces.Base, ProjectInterfaces.USFM_BookChapterVerse, ProjectInterfaces.USX_Chapter];
private static readonly List<string> s_paratextProjectInterfaces = [
ProjectInterfaces.BASE,
ProjectInterfaces.USFM_BOOK,
ProjectInterfaces.USFM_CHAPTER,
ProjectInterfaces.USFM_VERSE,
ProjectInterfaces.USX_BOOK,
ProjectInterfaces.USX_CHAPTER,
ProjectInterfaces.USX_VERSE];

public LocalParatextProjects()
{
Expand All @@ -42,46 +50,56 @@ public LocalParatextProjects()

#region Public properties and methods


public virtual void Initialize(bool shouldIncludePT9ProjectsOnWindows)
{
if (_isInitialized)
return;

// Make sure the necessary directory and files exist for the project root folder
SetUpProjectRootFolder();
lock (_initializationLock)
{
if (_isInitialized)
return;

// Make sure the necessary directory and files exist for the project root folder
SetUpProjectRootFolder();

// Set up the ScrTextCollection and read the projects in that folder
ParatextGlobals.Initialize(ProjectRootFolder);
// Set up the ScrTextCollection and read the projects in that folder
ParatextGlobals.Initialize(ProjectRootFolder);

Console.WriteLine($"Projects loaded from {ProjectRootFolder}: {GetScrTexts().Select(scrText => scrText.Name)}");
Console.WriteLine(
$"Projects loaded from {ProjectRootFolder}: {string.Join(",", GetScrTexts().Select(scrText => scrText.Name))}");

// Read the projects in any locations other than project root folder
IEnumerable<ProjectDetails> otherProjectDetails = LoadOtherProjectDetails(shouldIncludePT9ProjectsOnWindows);
// Read the projects in any locations other than project root folder
IEnumerable<ProjectDetails> otherProjectDetails =
LoadOtherProjectDetails(shouldIncludePT9ProjectsOnWindows);

if (otherProjectDetails.Any())
Console.WriteLine($"Projects found in other locations: {otherProjectDetails.Select(projectDetails => projectDetails.Name)}");
if (otherProjectDetails.Any())
Console.WriteLine(
$"Projects found in other locations: {string.Join(",", otherProjectDetails.Select(projectDetails => projectDetails.Name))}");

foreach (ProjectDetails projectDetails in otherProjectDetails)
{
try
foreach (ProjectDetails projectDetails in otherProjectDetails)
{
AddProjectToScrTextCollection(projectDetails);
Console.WriteLine($"Loaded project details: {projectDetails}");
try
{
AddProjectToScrTextCollection(projectDetails);
Console.WriteLine($"Loaded project details: {projectDetails}");
}
catch (Exception ex)
{
Console.WriteLine($"Failed to load project for {projectDetails}: {ex}");
}
}
catch (Exception ex)

// If there are no projects available anywhere, throw in the sample WEB one
if (!GetScrTexts().Any())
{
Console.WriteLine($"Failed to load project for {projectDetails}: {ex}");
}
}
Console.WriteLine("No projects found. Setting up sample WEB project");
SetUpSampleProject();

// If there are no projects available anywhere, throw in the sample WEB one
if (!GetScrTexts().Any())
{
Console.WriteLine("No projects found. Setting up sample WEB project");
SetUpSampleProject();
ScrTextCollection.RefreshScrTexts();
}

ScrTextCollection.RefreshScrTexts();
_isInitialized = true;
}
}

Expand All @@ -102,7 +120,7 @@ public static ScrText GetParatextProject(string projectId)

public static List<string> GetParatextProjectInterfaces()
{
return new List<string>(_paratextProjectInterfaces);
return [..s_paratextProjectInterfaces];
}

#endregion
Expand Down Expand Up @@ -152,7 +170,7 @@ private static void AddProjectToScrTextCollection(ProjectDetails projectDetails)
/// <returns>Enumeration of (ProjectMetadata, project directory) tuples for all projects</returns>
private IEnumerable<ProjectDetails> LoadOtherProjectDetails(bool shouldIncludePT9ProjectsOnWindows)
{
// Get project info for projects outside of the normal project root folder
// Get project info for projects outside the normal project root folder
List<string> nonPT9ProjectRootFolders = [];
if (OperatingSystem.IsWindows() && shouldIncludePT9ProjectsOnWindows && Directory.Exists(Paratext9ProjectsFolder)) nonPT9ProjectRootFolders.Add(Paratext9ProjectsFolder);

Expand Down
Loading

0 comments on commit 62fa22a

Please sign in to comment.