Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions Src/xWorks/Archiving/ArchivingExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015 SIL International
// Copyright (c) 2015-2026 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand All @@ -11,25 +11,19 @@ namespace SIL.FieldWorks.XWorks.Archiving
public static class ArchivingExtensions
{
/// <summary>
/// Combines the functionality fo StringBuilder.AppendFormat and StringBuilder.AppendLine.
/// Also allows for the delimiter to be specified. If the delimiter is null, Environment.NewLine
/// will be used.
/// Appends a formatted line to the StringBuilder, preceded by a delimiter if the StringBuilder already has content.
/// Allows specifying a custom delimiter; defaults to Environment.NewLine.
/// </summary>
/// <param name="sb"></param>
/// <param name="format"></param>
/// <param name="args"></param>
/// <param name="delimiter"></param>
public static void AppendLineFormat(this StringBuilder sb, string format, object[] args, string delimiter)
public static StringBuilder AppendLineFormat(this StringBuilder sb, string format, object[] args, string delimiter = null)
{
if (delimiter == null) delimiter = Environment.NewLine;
if (sb.Length != 0) sb.Append(delimiter);
sb.AppendFormat(format, args);
return sb.AppendFormat(format, args);
}

/// <summary>
/// Finds the ISO3 code for the given writing system.
/// </summary>
/// <param name="ws"></param>
/// <returns>The ISO3 code, or <value>mis</value> if the code is not found.</returns>
public static string GetIso3Code(this CoreWritingSystemDefinition ws)
{
Expand Down
50 changes: 21 additions & 29 deletions Src/xWorks/DictionaryConfigurationImportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Xml.XPath;
Expand Down Expand Up @@ -113,17 +114,8 @@ internal void DoImport()

ImportCustomFields(_importLiftLocation);

// REVIEW (Hasso) 2026.01: should this be calculated closer to where it is used?
// If the configuration to import has the same label as an existing configuration in the project folder
// then overwrite the existing configuration.
var existingConfigurationInTheWay = _configurations.FirstOrDefault(config => config.Label == NewConfigToImport.Label &&
Path.GetDirectoryName(config.FilePath) == _projectConfigDir);
NewConfigToImport.Publications.ForEach(publication => AddPublicationTypeIfNotPresent(publication, _cache));

NewConfigToImport.Publications.ForEach(
publication =>
{
AddPublicationTypeIfNotPresent(publication, _cache);
});
try
{
ImportStyles(_importStylesLocation);
Expand All @@ -147,6 +139,10 @@ internal void DoImport()
_view.importButton.Enabled = false;
}

// If the configuration to import has the same label as an existing configuration in the project folder
// then overwrite the existing configuration.
var existingConfigurationInTheWay = _configurations.FirstOrDefault(config => config.Label == NewConfigToImport.Label &&
Path.GetDirectoryName(config.FilePath) == _projectConfigDir);
// We have re-loaded the model from disk to preserve custom field state so the Label must be set here
NewConfigToImport.FilePath = _temporaryImportConfigLocation;
NewConfigToImport.Load(_cache);
Expand All @@ -163,7 +159,8 @@ internal void DoImport()
NewConfigToImport.Label = _proposedNewConfigLabel;
}

// Set a filename for the new configuration. Use a unique filename that isn't either registered with another configuration, or existing on disk. Note that in this way, we ignore what the original filename was of the configuration file in the .zip file.
// Set a filename for the new configuration. Use a unique filename that isn't either registered with another configuration, or existing on disk.
// Note that in this way, we ignore what the original filename was of the configuration file in the .zip file.
DictionaryConfigurationManagerController.GenerateFilePath(_projectConfigDir, _configurations, NewConfigToImport);

var outputConfigPath = existingConfigurationInTheWay != null ? existingConfigurationInTheWay.FilePath : NewConfigToImport.FilePath;
Expand Down Expand Up @@ -356,7 +353,6 @@ private IEnumerable<string> CustomFieldsInLiftFile(string liftFilePath)
/// <summary>
/// Connect to and show a view for the user to perform an import.
/// </summary>
/// <param name="dialog"></param>
public void DisplayView(DictionaryConfigurationImportDlg dialog)
{
_view = dialog;
Expand Down Expand Up @@ -397,50 +393,46 @@ public void OnBrowse()

public void RefreshStatusDisplay()
{
string mainStatus;
var publicationStatus = string.Empty;
var customFieldStatus = string.Empty;
var statusBldr = new StringBuilder();
_view.explanationLabel.Text = "";

if (NewConfigToImport == null)
{
string invalidConfigFileMsg = string.Empty;
if (_isInvalidConfigFile)
{
var configType = Path.GetFileName(_projectConfigDir) == DictionaryConfigurationListener.DictConfigDirName
? xWorksStrings.ReversalIndex : xWorksStrings.Dictionary;
invalidConfigFileMsg = string.Format(xWorksStrings.DictionaryConfigurationMismatch, configType)
+ Environment.NewLine;
? xWorksStrings.ReversalIndex : xWorksStrings.Dictionary;
statusBldr.AppendFormat(xWorksStrings.DictionaryConfigurationMismatch, configType).AppendLine();
}
_view.explanationLabel.Text = invalidConfigFileMsg + xWorksStrings.kstidCannotImport;
_view.explanationLabel.Text = statusBldr.Append(xWorksStrings.kstidCannotImport).ToString();
return;
}

if (_originalConfigLabel == _proposedNewConfigLabel)
{
mainStatus = string.Format(xWorksStrings.kstidImportingConfig, NewConfigToImport.Label);
statusBldr.AppendFormat(xWorksStrings.kstidImportingConfig, NewConfigToImport.Label).AppendLine();
}
else
{
mainStatus = string.Format(NewConfigToImport.Label == _proposedNewConfigLabel
statusBldr.AppendFormat(NewConfigToImport.Label == _proposedNewConfigLabel
? xWorksStrings.kstidImportingConfigNewName
: xWorksStrings.kstidImportingAndOverwritingConfiguration,
NewConfigToImport.Label);
NewConfigToImport.Label).AppendLine();
}

if (_newPublications != null && _newPublications.Any())
{
publicationStatus = xWorksStrings.kstidPublicationsWillBeAdded + Environment.NewLine + string.Join(", ", _newPublications);
statusBldr.AppendLine().AppendLine(xWorksStrings.kstidPublicationsWillBeAdded).AppendLine(string.Join(", ", _newPublications));
}

if (_customFieldsToImport != null && _customFieldsToImport.Any())
{
customFieldStatus = xWorksStrings.kstidCustomFieldsWillBeAdded + Environment.NewLine + string.Join(", ", _customFieldsToImport);
statusBldr.AppendLine().AppendLine(xWorksStrings.kstidCustomFieldsWillBeAdded).AppendLine(string.Join(", ", _customFieldsToImport));
}
// TODO (Hasso) 2026-01: WSs
_view.explanationLabel.Text = string.Format("{0}{1}{2}{1}{3}{1}{4}",
mainStatus, Environment.NewLine + Environment.NewLine, publicationStatus, customFieldStatus,
xWorksStrings.DictionaryConfigurationDictionaryConfigurationUser_StyleOverwriteWarning);

statusBldr.AppendLine().Append(xWorksStrings.DictionaryConfigurationDictionaryConfigurationUser_StyleOverwriteWarning);

_view.explanationLabel.Text = statusBldr.ToString();
_view.Refresh();
}

Expand Down
Loading