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
24 changes: 20 additions & 4 deletions Src/xWorks/ConfiguredLcmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2476,12 +2476,28 @@ private static string GetSenseNumber(string numberingStyle, ILexSense sense,
break;
default: // handles %d and %O. We no longer support "%z" (1 b iii) because users can hand-configure its equivalent
nextNumber = senseCount.ToString();
// Use the digits from the CustomHomographNumbers if they are defined
if (info.HomographConfig.CustomHomographNumbers.Count == 10)
// For the sense numbers, use the numbering system associated with the sense number writing system, if there is one.
var senseNumberWs = info.HomographConfig.WritingSystem;
if (senseNumberWs != null)
{
for (var digit = 0; digit < 10; ++digit)
CoreWritingSystemDefinition writingSystem = null;
try
{
nextNumber = nextNumber.Replace(digit.ToString(), info.HomographConfig.CustomHomographNumbers[digit]);
writingSystem = sense?.Cache.ServiceLocator.WritingSystemManager.Get(senseNumberWs);
}
catch (KeyNotFoundException)
{
//Don't replace sense number digits.
break;
}
var unicodeCharacters = HeadWordNumbersHelper.GetUnicodeCharacters(writingSystem?.NumberingSystem?.Digits);
if (unicodeCharacters != null)
{
for (var digit = 0; digit < 10; ++digit)
{
nextNumber = nextNumber.Replace(digit.ToString(),
unicodeCharacters[digit]);
}
}
}
break;
Expand Down
20 changes: 0 additions & 20 deletions Src/xWorks/DictionaryConfigurationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ public void Load(LcmCache cache)
else
{
HomographConfiguration.HomographWritingSystem = string.Empty;
HomographConfiguration.CustomHomographNumbers = string.Empty;
}
}

Expand Down Expand Up @@ -370,7 +369,6 @@ public DictionaryHomographConfiguration(DictionaryHomographConfiguration other)
ShowSenseNumberReversal = other.ShowSenseNumberReversal;
HomographNumberBefore = other.HomographNumberBefore;
HomographWritingSystem = other.HomographWritingSystem;
CustomHomographNumberList = other.CustomHomographNumberList != null ? new List<string>(other.CustomHomographNumberList) : null;
}

public DictionaryHomographConfiguration(HomographConfiguration config)
Expand All @@ -382,7 +380,6 @@ public DictionaryHomographConfiguration(HomographConfiguration config)
ShowHwNumInCrossRef = config.ShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef);
ShowHwNumInReversalCrossRef = config.ShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef);
HomographWritingSystem = config.WritingSystem;
CustomHomographNumberList = config.CustomHomographNumbers;
}

/// <summary>
Expand All @@ -397,12 +394,8 @@ public void ExportToHomographConfiguration(HomographConfiguration config)
config.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef, ShowHwNumInCrossRef);
config.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef, ShowHwNumInReversalCrossRef);
config.WritingSystem = HomographWritingSystem;
config.CustomHomographNumbers = CustomHomographNumberList;
}

[XmlIgnore]
public List<string> CustomHomographNumberList { get; internal set; }

[XmlAttribute("showHwNumInReversalCrossRef")]
public bool ShowHwNumInReversalCrossRef { get; set; }

Expand All @@ -421,19 +414,6 @@ public void ExportToHomographConfiguration(HomographConfiguration config)
[XmlAttribute("homographNumberBefore")]
public bool HomographNumberBefore { get; set; }

[XmlAttribute("customHomographNumbers")]
public string CustomHomographNumbers
{
get
{
return CustomHomographNumberList == null ? string.Empty : WebUtility.HtmlEncode(string.Join(",", CustomHomographNumberList));
}
set
{
CustomHomographNumberList = new List<string>(WebUtility.HtmlDecode(value).Split(new []{','}, StringSplitOptions.RemoveEmptyEntries));
}
}

[XmlAttribute("homographWritingSystem")]
public string HomographWritingSystem { get; set; }
}
Expand Down
1 change: 0 additions & 1 deletion Src/xWorks/DictionaryDetailsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,6 @@ private void HandleHeadwordNumbersButton()
// ReSharper disable once AccessToDisposedClosure - can only be used before the dialog is disposed
dlg.RunStylesDialog += (sender, e) => HandleStylesBtn((ComboBox) sender, ((ComboBox)sender).Text);
dlg.SetupDialog(m_propertyTable.GetValue<IHelpTopicProvider>("HelpTopicProvider"));
dlg.SetStyleSheet = FontHeightAdjuster.StyleSheetFromPropertyTable(m_propertyTable);
//dlg.StartPosition = FormStartPosition.CenterScreen;
if (dlg.ShowDialog(View.TopLevelControl) != DialogResult.OK)
return;
Expand Down
34 changes: 21 additions & 13 deletions Src/xWorks/HeadWordNumbersController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) 2017 SIL International
// Copyright (c) 2017 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

using System;
using System.Collections.Generic;
using System.Linq;
using SIL.LCModel;
using SIL.LCModel.Core.WritingSystems;
using SIL.LCModel.DomainImpl;

namespace SIL.FieldWorks.XWorks
Expand Down Expand Up @@ -33,9 +34,7 @@ public HeadwordNumbersController(IHeadwordNumbersView view, DictionaryConfigurat
model.IsReversal ? xWorksStrings.ReversalIndex : xWorksStrings.Dictionary,
Environment.NewLine,
model.Label);
_view.SetWsFactoryForCustomDigits(cache.WritingSystemFactory);
_view.AvailableWritingSystems = cache.LangProject.CurrentAnalysisWritingSystems.Union(cache.LangProject.CurrentVernacularWritingSystems);
_view.CustomDigits = _homographConfig.CustomHomographNumberList;
if (_cache.LangProject.AllWritingSystems.Any(ws => ws.Id == _homographConfig.HomographWritingSystem))
{
_view.HomographWritingSystem = string.IsNullOrEmpty(_homographConfig.HomographWritingSystem)
Expand All @@ -46,19 +45,29 @@ public HeadwordNumbersController(IHeadwordNumbersView view, DictionaryConfigurat
{
_view.HomographWritingSystem = _cache.LangProject.AllWritingSystems.First().DisplayLabel;
}
// If possible, get digits from the writing system's numbering system,
// otherwise use an empty list (which will be treated as default digits in the view).
IEnumerable<string> wsCustomDigits = new List<string>();
CoreWritingSystemDefinition writingSystem = null;
try
{
writingSystem = cache.ServiceLocator.WritingSystemManager?.Get(_homographConfig.HomographWritingSystem);
}
catch(KeyNotFoundException)
{
// Do nothing; writingSystem is already null.
}
var unicodeCharacters = HeadWordNumbersHelper.GetUnicodeCharacters(writingSystem?.NumberingSystem?.Digits);
if (unicodeCharacters != null)
{
wsCustomDigits = unicodeCharacters;
}
_view.CustomDigits = wsCustomDigits;
_view.HomographBefore = _homographConfig.HomographNumberBefore;
_view.ShowHomograph = _homographConfig.ShowHwNumber;
_view.ShowHomographOnCrossRef = _model.IsReversal ? _homographConfig.ShowHwNumInReversalCrossRef : _homographConfig.ShowHwNumInCrossRef;
_view.ShowSenseNumber = _model.IsReversal ? _homographConfig.ShowSenseNumberReversal : _homographConfig.ShowSenseNumber;
_view.OkButtonEnabled = _homographConfig.CustomHomographNumberList == null
|| !_homographConfig.CustomHomographNumberList.Any() || _homographConfig.CustomHomographNumberList.Count == 10;
_view.CustomDigitsChanged += OnViewCustomDigitsChanged;
}

private void OnViewCustomDigitsChanged(object sender, EventArgs eventArgs)
{
_view.OkButtonEnabled = !_view.CustomDigits.Any()
|| _view.CustomDigits.Count(digit => !string.IsNullOrWhiteSpace(digit)) == 10;
_view.OkButtonEnabled = true;
}

/// <summary>
Expand Down Expand Up @@ -93,7 +102,6 @@ public void Save()
}
_homographConfig.HomographWritingSystem = string.IsNullOrEmpty(_view.HomographWritingSystem) ? null :
_cache.LangProject.AllWritingSystems.First(ws => ws.DisplayLabel == _view.HomographWritingSystem).Id;
_homographConfig.CustomHomographNumberList = _view.CustomDigits == null ? new List<string>() : new List<string>(_view.CustomDigits);
_model.HomographConfiguration = _homographConfig;
_homographConfig.ExportToHomographConfiguration(_cache.ServiceLocator.GetInstance<HomographConfiguration>());
}
Expand Down
69 changes: 15 additions & 54 deletions Src/xWorks/HeadWordNumbersDlg.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017 SIL International
// Copyright (c) 2017 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 @@ -24,7 +24,7 @@ namespace SIL.FieldWorks.XWorks
/// </summary>
public partial class HeadwordNumbersDlg : Form, IHeadwordNumbersView
{
private FwTextBox[] _digitBoxes;
private Label[] _digitBoxes;

public HeadwordNumbersDlg()
{
Expand All @@ -42,7 +42,6 @@ public HeadwordNumbersDlg()
m_digitZero, m_digitOne, m_digitTwo, m_digitThree, m_digitFour, m_digitFive,
m_digitSix, m_digitSeven, m_digitEight, m_digitNine
};
Shown += (sender, args) => { UpdateWritingSystemCodeInDigits(); };
}

/// <summary>
Expand Down Expand Up @@ -197,22 +196,6 @@ public string HomographWritingSystem
}
}

/// <summary>
/// Set the writing system code in each digit textbox
/// </summary>
private void UpdateWritingSystemCodeInDigits()
{
var wsHandle = ((CoreWritingSystemDefinition)m_writingSystemCombo.SelectedItem).Handle;
foreach (var digit in _digitBoxes)
{
digit.WritingSystemCode = wsHandle;
digit.SelectAll();
digit.ApplyWS(wsHandle);
digit.ApplyStyle("UiElement");
digit.RemoveSelection();
}
}

public IEnumerable<CoreWritingSystemDefinition> AvailableWritingSystems
{
set
Expand All @@ -234,54 +217,32 @@ public IEnumerable<string> CustomDigits
for (var i = 0; i < 10; ++i)
{
_digitBoxes[i].Text = digitsArray[i];
_digitBoxes[i].Visible = true;
// Set UseCompatibleTextRendering to false. This causes WindowsForms to use TextRenderer, which provides better fallback font performance.
_digitBoxes[i].UseCompatibleTextRendering = false;
}
}

get { return _digitBoxes.Select(db => db.Text).Where(text => !string.IsNullOrEmpty(text)); }
}

public event EventHandler CustomDigitsChanged
{
add
{
foreach (var textBox in _digitBoxes)
{
textBox.TextChanged += value;
}
}
remove
{
foreach (var textBox in _digitBoxes)
{
textBox.TextChanged -= value;
}
}
}

public bool OkButtonEnabled { get { return m_btnOk.Enabled; } set { m_btnOk.Enabled = value; } }

public LcmStyleSheet SetStyleSheet
private void m_writingSystemCombo_SelectedIndexChanged(object sender, EventArgs e)
{
set
// Populate digits from ws.
var selectedWs = m_writingSystemCombo.SelectedItem as CoreWritingSystemDefinition;
if (selectedWs?.NumberingSystem != null)
{
for (var i = 0; i < 10; ++i)
var digits = selectedWs.NumberingSystem.Digits;
if (!string.IsNullOrEmpty(digits))
{
_digitBoxes[i].StyleSheet = value;
// Populate the custom digits from writing system, if all digits are specified.
var unicodeCharacters = HeadWordNumbersHelper.GetUnicodeCharacters(digits);
if (unicodeCharacters != null)
CustomDigits = unicodeCharacters;
}
}
}

public void SetWsFactoryForCustomDigits(ILgWritingSystemFactory factory)
{
for (var i = 0; i < 10; ++i)
{
_digitBoxes[i].WritingSystemFactory = factory;
}
}

private void m_writingSystemCombo_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateWritingSystemCodeInDigits();
}
}
}
Loading
Loading