Skip to content

Commit ea31623

Browse files
committed
Revised the IsSelectionAcrossHiddenAttributesMetadata() function to provide the user with a more understandable warning message. This routine also had a couple faulty msg.Format(...) statements that were not constructed properly resulting in the loss of the messages that were to be displayed, and only displayed the contents of the %s substitution strings.
Revised the AppendSrcPhraseEndingInfo() function to insert an EOL before certain markers that have been swept up markers in the process of filtering, such as a \c n chapter marker that should have an EOL before it so that it starts on a new line in exports. Removed the "empty-key" filler words that can appear in the ParsePostWordPunctsAndEndMkrs() function. I think it is better to simply leave the m_key and m_srcPhrase empty as we do in other places for markers empty of content. Made some adjustments to the DoMarkerHousekeeping() function to make it conform to the handling of inline nonbinding end markers elsewhere. Provided more smarts for the GetPriorityBeginMkr() function and renamed it to GetPriorityTextTypeChangingBeginMkr(). The function now does not simply return the first or the last marker within m_markers, but examines the markers present and returns the last marker present that has an effect on the textType. Added a return len statement at a critical juncture in ParseWord() which is needed to properly re-filter a data hiding marker after it has been unfiltered. Needed to add an appropriate test within ParseWord() in order to properly call SetInlineBindingEndMarkers(), or etInlineBindingEndMarkers(). Added a fill filtering routine within an otherwise empty if (bIsToBeFiltered) block in TokenizeText(), to make it conform to other filtering blocks elsewhere. Added a bKeepPtrFromAdvancing = TRUE statement at one point in TokenizeText() for when the marker detected is a within m_charAttributeMkrs. Added a GetInlineNonbindingEndMarkersAsArray() function to CSourcePhrase class.
1 parent 899b2c1 commit ea31623

8 files changed

+992
-267
lines changed

source/Adapt_ItDoc.cpp

+882-251
Large diffs are not rendered by default.

source/Adapt_ItDoc.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,14 @@ bool bMarkAsDirty); // might want it instantly saveable
498498
wxString GetLastBeginMkr(wxString mkrs); // BEW 13Dec22 get the last one in m_markers, but the last one
499499
// does not always result in getting the correct TextType; but some places need this so keep it.
500500
// However, GetPriorityBeginMkr() -- see next line, should do better job; get \v if present
501-
wxString GetPriorityBeginMkr(wxString mkrs); // BEW 2Aug23 get the priority beginMkr from m_markers, to set the TextType - \v if present
501+
//
502+
// whm 12Mar2024 refactored and changed the name of the next function call.
503+
// The function previously was named GetPriorityMkr(), but is now named
504+
// GetPriorityTextTypeChangingBeginMkr(). It now returns the first marker
505+
// found within m_markers that is also found in the App's m_RegBeginMarkers
506+
// set, or if not present there, the last marker in m_markers is returned,
507+
// or wxEmptyString if no markers are within m_markers.
508+
wxString GetPriorityTextTypeChangingBeginMkr(wxString mkrs); // BEW 2Aug23 get the priority beginMkr from m_markers, to set the TextType - \v if present
502509
void GetLengthToWhitespace(wxChar* pChar, unsigned int& counter, wxChar* pEnd); // BEW 20Oct22
503510
bool IsClosedParenthesisAhead(wxChar* pChar, unsigned int& count, wxChar* pEnd, CSourcePhrase* pSrcPhrase, bool& bTokenizingTargetText);
504511
bool IsClosedBraceAhead(wxChar* pChar, unsigned int& count, wxChar* pEnd, CSourcePhrase* pSrcPhrase, bool& bTokenizingTargetText);

source/Adapt_ItView.cpp

+43-7
Original file line numberDiff line numberDiff line change
@@ -11022,7 +11022,15 @@ bool CAdapt_ItView::IsSelectionAcrossFreeTranslationEnd(SPList* pList)
1102211022
// Placement dialog which otherwise would not show, will show and the the user will have
1102311023
// to do a manual placement within it. (It's safer that way, than letting the cache data
1102411024
// be lost)
11025-
bool CAdapt_ItView::IsSelectionAcrossHiddenAttributesMetadata(SPList* pList, wxString &strAt)
11025+
// whm 8Mar2024 modified this function to return more information so the user warning the
11026+
// caller creates will be more understandable in the two places this function is called:
11027+
// In the View's OnButtonMerge(), and in Retranslation.cpp's OnButtonRetranslation().
11028+
// The additional information is returned via ref parameters srcWords and mkrSpan
11029+
//bool CAdapt_ItView::IsSelectionAcrossHiddenAttributesMetadata(SPList* pList, wxString &strAt)
11030+
bool CAdapt_ItView::IsSelectionAcrossHiddenAttributesMetadata(SPList* pList,
11031+
wxString& srcWords,
11032+
wxString& strAt,
11033+
wxString& mkrSpan)
1102611034
{
1102711035
CSourcePhrase* pSrcPhrase;
1102811036
SPList::Node* pos_pList = pList->GetFirst();
@@ -11035,17 +11043,35 @@ bool CAdapt_ItView::IsSelectionAcrossHiddenAttributesMetadata(SPList* pList, wxS
1103511043
// the span has both at different locations, the there is no clash, but the
1103611044
// presence of attribute hiding wins out in the suppression stakes. So the
1103711045
// simple double test below suffices
11046+
srcWords.Empty();
11047+
mkrSpan.Empty();
11048+
wxString beginMkr; beginMkr.Empty();
11049+
int wordNumber = 1;
11050+
int wordNumberAtHiddenData = -1;
1103811051
while (pos_pList != NULL)
1103911052
{
1104011053
pSrcPhrase = (CSourcePhrase*)pos_pList->GetData();
11041-
11054+
srcWords += (_T(" ") + pSrcPhrase->m_srcPhrase);
11055+
beginMkr += pSrcPhrase->GetInlineNonbindingMarkers(); // the \jmp ...\jmp* maker is an inline nonbinding one
11056+
beginMkr += pSrcPhrase->GetInlineBindingMarkers(); // the \w ...\w* marker is an inline binding one
1104211057
pos_pList = pos_pList->GetNext();
1104311058
if ((pSrcPhrase->m_bUnused == TRUE) && (pSrcPhrase->m_bHasInternalPunct == FALSE))
1104411059
{
1104511060
bIllegalInternalHiddenMetadata = TRUE;
11061+
mkrSpan = pSrcPhrase->m_punctsPattern;
1104611062
strAt = pSrcPhrase->m_srcPhrase;
11047-
break;
11063+
wordNumberAtHiddenData = wordNumber;
11064+
//break; // we want the whole sublist traversed to collect the mkrSpan
1104811065
}
11066+
wordNumber++;
11067+
}
11068+
if (bIllegalInternalHiddenMetadata)
11069+
{
11070+
wxString addEllipsis; addEllipsis.Empty();
11071+
srcWords.Trim(FALSE); // remove initial space
11072+
if (wordNumberAtHiddenData > 1)
11073+
addEllipsis = _T(" ... ");
11074+
mkrSpan = addEllipsis + beginMkr + mkrSpan; // the inline binding/nonbinding begin marker + m_punctsPattern contents.
1104911075
}
1105011076
return bIllegalInternalHiddenMetadata;
1105111077
}
@@ -11577,14 +11603,24 @@ void CAdapt_ItView::OnButtonMerge(wxCommandEvent& WXUNUSED(event))
1157711603
// The signature param bIsMerger is default FALSE - see comment in Adapt_ItView.h for
1157811604
// more information; since this is a merger attempt, TRUE must be overtly supplied
1157911605
wxString strAt = wxEmptyString;
11580-
bIllegalInternalHiddenMetadata = IsSelectionAcrossHiddenAttributesMetadata(pList, strAt);
11606+
wxString srcWords = wxEmptyString;
11607+
wxString mkrSpan = wxEmptyString;
11608+
bIllegalInternalHiddenMetadata = IsSelectionAcrossHiddenAttributesMetadata(pList, srcWords, strAt, mkrSpan);
1158111609
if (bIllegalInternalHiddenMetadata)
1158211610
{
11583-
wxString msg = _("Merging across stored(hidden) USFM3 metadata is not allowed. The metadata is hidden at the word: %s");
11584-
msg = msg.Format(strAt.c_str());
11611+
// whm 8Mar2024 revised the warning message below to be more understandable to the user and also
11612+
// its original form didn't actually include the warning, only the single word passed into the %s due
11613+
// to a faulty .Format() call that didn't have the msg as first parameter of .Format().
11614+
// Also to supply more helpful information in the warning, I've added two parameters to the
11615+
// IsSelectionAcrossHiddenAttributesMetadata() function call above, with the necessary internal
11616+
// modifications.
11617+
//wxString msg = _("Merging across stored(hidden) USFM3 metadata is not allowed. The metadata is hidden at the word: %s");
11618+
//msg = msg.Format(strAt.c_str());
11619+
wxString msg = _("Adapt It attempted to make a phrase of the source words \" %s\".\nHowever, the word \"%s\" within this marker span:\n\n%s\n\nhas stored (hidden/filtered) data.\nMaking a phrase across stored (hidden/filtered) data is not allowed.");
11620+
msg = msg.Format(msg, srcWords.c_str(), strAt.c_str(), mkrSpan.c_str());
1158511621
// whm 15May2020 added below to supress phrasebox run-on due to handling of ENTER in CPhraseBox::OnKeyUp()
1158611622
pApp->m_bUserDlgOrMessageRequested = TRUE;
11587-
wxMessageBox(msg, _T(""), wxICON_EXCLAMATION | wxOK);
11623+
wxMessageBox(msg, _("Making a phrase across hidden data not allowed"), wxICON_EXCLAMATION | wxOK);
1158811624
pList->Clear();
1158911625
if (pList != NULL) // whm 11Jun12 added NULL test
1159011626
delete pList;

source/Adapt_ItView.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,14 @@ class CAdapt_ItView : public wxView
367367
// BEW added 30Sept19 - function below: disallow Merge() or Retranslation if the returned bool
368368
// is TRUE. Tests; and does not allow hidden attribute metadata to be in *ANY* of the
369369
// CSourcePhrase instances of the selection
370-
bool IsSelectionAcrossHiddenAttributesMetadata(SPList* pList, wxString &strAt);
370+
// whm 8Mar2024 revised the following function to return more information to the caller so the
371+
// caller can create a more informative warning message to the user.
372+
//bool IsSelectionAcrossHiddenAttributesMetadata(SPList* pList, wxString &strAt);
373+
bool IsSelectionAcrossHiddenAttributesMetadata(SPList* pList,
374+
wxString& srcWords,
375+
wxString& strAt,
376+
wxString& mkrSpan);
377+
371378
protected:
372379
bool RemoveInformationDuringEdit(CSourcePhrase* pSrcPhrase, int nSequNum, EditRecord* pRec,
373380
wxArrayString* pAdaptList, wxArrayString* pGlossList, wxArrayString* pFTList,

source/ExportFunctions.cpp

+25-1
Original file line numberDiff line numberDiff line change
@@ -17182,7 +17182,7 @@ wxString AppendSrcPhraseEndingInfo(wxString appendHere, CSourcePhrase* pSrcPhras
1718217182
{
1718317183
if (!pSrcPhrase->GetInlineBindingEndMarkers().IsEmpty())
1718417184
{
17185-
appendHere += pSrcPhrase->GetInlineBindingEndMarkers();
17185+
appendHere = pSrcPhrase->GetInlineBindingEndMarkers();
1718617186
bAddedSomething = TRUE;
1718717187
}
1718817188
if (!pSrcPhrase->m_follPunct.IsEmpty())
@@ -17210,6 +17210,30 @@ wxString AppendSrcPhraseEndingInfo(wxString appendHere, CSourcePhrase* pSrcPhras
1721017210
// function to this function since it should be the last thing added to appendHere.
1721117211
if (!filteredInfo.IsEmpty())
1721217212
{
17213+
// whm 13Mar2024 added a little hack to ensure that any initial swept up marker that
17214+
// is prefixed to the filteredInfo will start on a new line in the exported output. If the
17215+
// filteredInfo has one of the swept up markers initially, and appendHere isn't empty
17216+
// and doesn't end with and EOL sequence, then we add an EOL between the appendHere and
17217+
// the swept up marker at the beginning of filteredInfo. This results in better formatting
17218+
// of the exported text and shouldn't foul up the other filtering routines that get called
17219+
// to normalize the exported text.
17220+
wxString initialMkr; initialMkr.Empty();
17221+
if (filteredInfo.Find(_T("\\")) == 0)
17222+
{
17223+
wxString space = _T(" ");
17224+
int spPos = filteredInfo.Find(space);
17225+
if (spPos != wxNOT_FOUND)
17226+
{
17227+
initialMkr = filteredInfo.Mid(0, spPos);
17228+
initialMkr.Trim();
17229+
initialMkr += space; // augmented for searching in m_markersCanBeSweptUpByFilteredMarker
17230+
}
17231+
}
17232+
if (!appendHere.IsEmpty() && appendHere.Last() != _T('\n') && appendHere.Last() != _T('\r')
17233+
&& !initialMkr.IsEmpty() && gpApp->m_markersCanBeSweptUpByFilteredMarker.Find(initialMkr) != wxNOT_FOUND)
17234+
{
17235+
appendHere += _T("\r\n");
17236+
}
1721317237
appendHere += filteredInfo;
1721417238
bAddedSomething = TRUE;
1721517239
}

source/Retranslation.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -2119,13 +2119,17 @@ void CRetranslation::OnButtonRetranslation(wxCommandEvent& event)
21192119
// the CSourcePhrase instances of the selection. In the call, signature's bIsMerger
21202120
// is default FALSE - which is appropriate for a retranslation
21212121
wxString strAt = wxEmptyString;
2122-
if (m_pView->IsSelectionAcrossHiddenAttributesMetadata(pList, strAt))
2123-
{
2124-
wxString msg = _("Sorry, this operation is not allowed when the selection contains hidden(stored) USFM3 metadata. Instead, try making retranslations either side of the word at %s.");
2125-
msg = msg.Format(strAt.c_str());
2126-
// whm 15May2020 added below to supress phrasebox run-on due to handling of ENTER in CPhraseBox::OnKeyUp()
2122+
wxString srcWords = wxEmptyString; wxUnusedVar(srcWords); // not used here
2123+
wxString mkrSpan = wxEmptyString;
2124+
if (m_pView->IsSelectionAcrossHiddenAttributesMetadata(pList, srcWords, strAt, mkrSpan))
2125+
{
2126+
wxString msg = _("Sorry, this operation is not allowed when the selection contains hidden (stored) data.\nThe hidden data is in this span of text:\n\n%s\n\nInstead, try making retranslations either side of the word at %s.");
2127+
// whm 8Mar2024 fixed the .Format() call below. The msg must be first parameter in the formatting call, i.e., .Format(msg, strAt.c_str())
2128+
// When the msg is missing the only string shown in the message box is the strAt word
2129+
msg = msg.Format(msg, mkrSpan.c_str(), strAt.c_str());
2130+
// whm 15May2020 added below to supress phrasebox run-on due to handling of ENTER in CPhraseBox::OnKeyUp()
21272131
m_pApp->m_bUserDlgOrMessageRequested = TRUE;
2128-
wxMessageBox(msg, _T(""), wxICON_EXCLAMATION | wxOK);
2132+
wxMessageBox(msg, _("Cannot make a retranslation across hidden/stored data"), wxICON_EXCLAMATION | wxOK);
21292133
pList->Clear();
21302134
if (pList != NULL) // whm 11Jun12 added NULL test
21312135
delete pList;

source/SourcePhrase.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,21 @@ bool CSourcePhrase::GetEndMarkersAsArray(wxArrayString* pEndmarkersArray)
29242924
return bGotSome;
29252925
}
29262926

2927+
bool CSourcePhrase::GetInlineNonbindingEndMarkersAsArray(wxArrayString* pINB_EndMkrsArray)
2928+
{
2929+
pINB_EndMkrsArray->Empty();
2930+
bool bGotSome = FALSE;
2931+
if (m_inlineNonbindingEndMarkers.IsEmpty())
2932+
{
2933+
return FALSE;
2934+
}
2935+
else
2936+
{
2937+
bGotSome = GetSFMarkersAsArray(m_inlineNonbindingEndMarkers, *pINB_EndMkrsArray);
2938+
}
2939+
return bGotSome;
2940+
}
2941+
29272942
/* wrote this then found I didn't need it
29282943
// GetAllEndMarkersAsArray gets from all storage locations for endmarkers on a
29292944
// CSourcePhrase instance - there are 3 wxStrings it then must check and collect from.

source/SourcePhrase.h

+1
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ class CSourcePhrase : public wxObject
306306
//#endif
307307
wxString GetEndMarkers();
308308
bool GetEndMarkersAsArray(wxArrayString* pEndmarkersArray); // return FALSE if empty, else TRUE
309+
bool GetInlineNonbindingEndMarkersAsArray(wxArrayString* pINB_EndMkrsArray); // whm 11Mar2024 added
309310
//bool GetAllEndMarkersAsArray(wxArrayString* pEndmarkersArray); // ditto, gets not just from
310311
// m_endMarkers, but also from the two storage members for inline endmarkers
311312
void SetFreeTrans(wxString freeTrans);

0 commit comments

Comments
 (0)