Skip to content

Commit

Permalink
Refactors the placeholder insertion code for the toolbar buttons maki…
Browse files Browse the repository at this point in the history
…ng the handlers for those buttons do essentially the same as the hotkey commands Shift+Alt+LeftArrow and Shift+Alt+RightArrow.

Modified the wording of the dialog that asks user for more information about placeholder insertion location - using BEW's suggested wording. This dialog also contextualizes whether a selection is made or not at the time of the placeholder insertion command.
Also added a mainframe OnSize() command that results in better pile gap spacing especially after removing a placeholder.
  • Loading branch information
pngbill committed Dec 30, 2024
1 parent c8da48b commit e0181ef
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 67 deletions.
107 changes: 67 additions & 40 deletions source/Adapt_ItDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9883,6 +9883,7 @@ void CAdapt_ItDoc::TransferFixedSpaceInfo(CSourcePhrase* pDestSrcPhrase, CSource
/// \param pos_callers -> the iterator position locating the passed in pSrcPhrase
/// pointer (its use herein is deprecated)
/// \param pSrcPhrase <- pointer of the source phrase
/// \param pPrevSrcPhrase <- pointer of the previous source phrase // whm 28Dec2024 added
/// \param fixesStr -> (its use herein is deprecated, the caller adds to it if
/// FALSE is returned)
/// \param pNewList <- the parsed new source phrase instances
Expand Down Expand Up @@ -9910,6 +9911,7 @@ void CAdapt_ItDoc::TransferFixedSpaceInfo(CSourcePhrase* pDestSrcPhrase, CSource
///////////////////////////////////////////////////////////////////////////////
bool CAdapt_ItDoc::ReconstituteOneAfterPunctuationChange(CAdapt_ItView* pView,
SPList*& WXUNUSED(pList), SPList::Node* WXUNUSED(pos_callers), CSourcePhrase*& pSrcPhrase,
CSourcePhrase*& pPrevSrcPhrase, // whm 28Dec2024 added
wxString& WXUNUSED(fixesStr), SPList*& pNewList, bool bIsOwned)
{
// BEW added 5Apr05
Expand All @@ -9932,7 +9934,8 @@ bool CAdapt_ItDoc::ReconstituteOneAfterPunctuationChange(CAdapt_ItView* pView,
// regardless of the current mode (whether adapting or not)
int numElements = 1; // default

srcPhrase = FromSingleMakeSstr2(pSrcPhrase); // whm 5Feb2024 removed unused parameters - now calls FromSingleMakeSstr2()
// whm 5Feb2024 removed unused parameters - now calls FromSingleMakeSstr2()
srcPhrase = FromSingleMakeSstr2(pSrcPhrase, pPrevSrcPhrase); // whm 28Dec2024 added pPrevSrcPhrase parameter

gloss = pSrcPhrase->m_gloss; // we don't care if glosses have punctuation or not
if (pSrcPhrase->m_adaption.IsEmpty())
Expand Down Expand Up @@ -24588,6 +24591,7 @@ int CAdapt_ItDoc::RetokenizeText(bool bChangedPunctuation, bool bChangedFilterin
if (bChangedPunctuation)
{
pos_pSP = gpApp->m_pSourcePhrases->GetFirst();
CSourcePhrase* pPrevSrcPhrase = NULL; // whm 28Dec2024 added
while (pos_pSP != NULL)
{
oldPos = pos_pSP;
Expand All @@ -24597,7 +24601,9 @@ int CAdapt_ItDoc::RetokenizeText(bool bChangedPunctuation, bool bChangedFilterin
// acts on ONE instance of pSrcPhrase only each time it loops, & it may add
// many to the list, or remove some, or leave number in the list unchanged
bSuccessful = ReconstituteAfterPunctuationChange(pView,
gpApp->m_pSourcePhrases, oldPos, pSrcPhrase, fixesStr);
gpApp->m_pSourcePhrases, oldPos, pSrcPhrase,
pPrevSrcPhrase, // whm 28Dec2024 added
fixesStr);
if (!bSuccessful)
{
// adaptation abandoned, so add a chapter:verse reference to the fixesStr
Expand Down Expand Up @@ -24625,7 +24631,8 @@ int CAdapt_ItDoc::RetokenizeText(bool bChangedPunctuation, bool bChangedFilterin
// //wxString progMsg = _("Retokenizing - File: %s - %d of %d Total words and phrases");
// //progMsg = progMsg.Format(progMsg,gpApp->m_curOutputFilename.c_str(),nOldCount,nOldTotal);
//}
}
pPrevSrcPhrase = pSrcPhrase; // whm 28Dec2024 added
} // end of while (pos_pSP != NULL)
}

if (bChangedSfmSet)
Expand Down Expand Up @@ -26288,6 +26295,8 @@ wxString CAdapt_ItDoc::MakeAdaptionAfterPunctuationChange(wxString& targetStrWit
/// \param pos_callers -> the node location which stores the passed in pSrcPhrase
/// \param pSrcPhrase <- the pointer to the CSourcePhrase instance on the pos_callers
/// Node passed in as the previous parameter
/// \param pPrevSrcPhrase <- the pointer to the previous CSourcePhrase instance on the pos_callers
/// Node passed in as the previous parameter
/// \param fixesStr <- reference to the caller's storage string for accumulating
/// a list of references to the locations where the rebuild
/// potentially isn't quite fully right, for specific
Expand Down Expand Up @@ -26336,9 +26345,11 @@ wxString CAdapt_ItDoc::MakeAdaptionAfterPunctuationChange(wxString& targetStrWit
/// result should be a much better rebuild, keeping much more (or all) of the information
/// without loss, and alerting the user to where we think a visual inspection should be
/// done in order to verify the results are acceptable - and edit if not.
/// whm 28Dec2024 added a CSourcePhrase*& pPrevSrcPhrase parameter to the function header.
///////////////////////////////////////////////////////////////////////////////
bool CAdapt_ItDoc::ReconstituteAfterPunctuationChange(CAdapt_ItView* pView,
SPList*& pList, SPList::Node* pos_callers, CSourcePhrase*& pSrcPhrase,
CSourcePhrase*& pPrevSrcPhrase, // whm 28Dec2024 added
wxString& fixesStr)
{
int nOriginalCount = pSrcPhrase->m_nSrcWords;
Expand Down Expand Up @@ -26376,42 +26387,42 @@ bool CAdapt_ItDoc::ReconstituteAfterPunctuationChange(CAdapt_ItView* pView,
// pSrcPhrase->m_nSequNumber, pSrcPhrase->m_srcPhrase.c_str());
//#endif

// BEW 10Mar11, the protocol we use for mergers is the following:
// (a) we must change the punctuation & src & tgt language members not just of the
// merged instance, but also for each of the instances in it's m_pSavedWords
// sublist of originals. (Why? Because the user may sometime unmerge it, and we
// don't want to be restoring instances to be viewed, which reflect the old
// punctuation settings.)
// (b)Care must be exercised, merging creates another level of CSourcePhrase
// instances, so our algorithm must avoid calling Merge() (see SourcePhrase.cpp)
// on the instances in the saved sublist, such as m_pSavedWords. But we also want
// to keep the converted target text, where it exists, so....
// (c)We use FromMergerMakeSstr() to get a source text string, srcPhrase, with all
// the markers, unfilterings, punctuations etc in their proper place;
// (d) We use TokenizeTextString(), passing in pResultList to get returned newly
// created CSourcePhrase instances returned, having passed in srcPhrase wxString;
// (e) provided, and only provided, the number of elements in pResultList equals
// the element count of pSrcPhrase->m_pSavedWords, we iterate in parallel over
// both the latter and the CSourcePhrase instances in pResultList, and copy over
// from the latter the changed text and punctuation strings, to the former; we
// also obtain from the pResultList's instances, each m_targetStr contents, and
// using the new punctuation settings (ie. making a RemovePunctuation() call with
// the appropriate punctuation string passed in)calculate a new m_adaption value
// for each instance, and we then transfer the m_adaption values back to the same
// members on the equivalent CSourcePhrase instances within the
// pSrcPhrase->m_pSavedWords list (the m_targetStr values won't have changed)
// (f) pSrcPhrase->m_pSavedWords's contents are now up-to-date for the changed
// punctuation settings. The owning merged CSourcePhrase instance's m_srcPhrase
// member will not have changed (punctuation settings changes don't add or remove
// or alter the location of punctuation and word building characters in the source
// text, it just redefines where the boundaries are between "the words" and the
// punctuation characters at the start and end of them. So, to get the new value
// for the m_adaption member of the merger (ie. of pSrcPhrase), all we need do is
// pass pSrcPhrase->m_srcPhrase through RemovePunctuation() using the final
// parameter from_target_text so as to do it with the target language's new
// punctuation settings (which may, or may not, have changed).
// Once (f) is completed, the whole original merged pSrcPhrase has been
// successfully updated to the new punctuation settings.
// BEW 10Mar11, the protocol we use for mergers is the following:
// (a) we must change the punctuation & src & tgt language members not just of the
// merged instance, but also for each of the instances in it's m_pSavedWords
// sublist of originals. (Why? Because the user may sometime unmerge it, and we
// don't want to be restoring instances to be viewed, which reflect the old
// punctuation settings.)
// (b)Care must be exercised, merging creates another level of CSourcePhrase
// instances, so our algorithm must avoid calling Merge() (see SourcePhrase.cpp)
// on the instances in the saved sublist, such as m_pSavedWords. But we also want
// to keep the converted target text, where it exists, so....
// (c)We use FromMergerMakeSstr() to get a source text string, srcPhrase, with all
// the markers, unfilterings, punctuations etc in their proper place;
// (d) We use TokenizeTextString(), passing in pResultList to get returned newly
// created CSourcePhrase instances returned, having passed in srcPhrase wxString;
// (e) provided, and only provided, the number of elements in pResultList equals
// the element count of pSrcPhrase->m_pSavedWords, we iterate in parallel over
// both the latter and the CSourcePhrase instances in pResultList, and copy over
// from the latter the changed text and punctuation strings, to the former; we
// also obtain from the pResultList's instances, each m_targetStr contents, and
// using the new punctuation settings (ie. making a RemovePunctuation() call with
// the appropriate punctuation string passed in)calculate a new m_adaption value
// for each instance, and we then transfer the m_adaption values back to the same
// members on the equivalent CSourcePhrase instances within the
// pSrcPhrase->m_pSavedWords list (the m_targetStr values won't have changed)
// (f) pSrcPhrase->m_pSavedWords's contents are now up-to-date for the changed
// punctuation settings. The owning merged CSourcePhrase instance's m_srcPhrase
// member will not have changed (punctuation settings changes don't add or remove
// or alter the location of punctuation and word building characters in the source
// text, it just redefines where the boundaries are between "the words" and the
// punctuation characters at the start and end of them. So, to get the new value
// for the m_adaption member of the merger (ie. of pSrcPhrase), all we need do is
// pass pSrcPhrase->m_srcPhrase through RemovePunctuation() using the final
// parameter from_target_text so as to do it with the target language's new
// punctuation settings (which may, or may not, have changed).
// Once (f) is completed, the whole original merged pSrcPhrase has been
// successfully updated to the new punctuation settings.
SPList* pOwnedList = pSrcPhrase->m_pSavedWords; // for convenience's sake

// placeholders can't be merged, and so won't be in the merger, so this block can
Expand Down Expand Up @@ -26641,7 +26652,8 @@ bool CAdapt_ItDoc::ReconstituteAfterPunctuationChange(CAdapt_ItView* pView,
// if TRUE, it is one which is stored in the m_pSavedWords list of an unowned
// CSourcePhrase and so is not visible in the layout
bool bWasOK = ReconstituteOneAfterPunctuationChange(
pView, pList, pos_callers, pSrcPhrase, fixesStr, pResultList, FALSE);
pView, pList, pos_callers, pSrcPhrase,
pPrevSrcPhrase, fixesStr, pResultList, FALSE); // whm 28Dec2024 added pPrevSrcPhrase parameter

//#ifdef _DEBUG
// wxLogDebug(_T(" 17950 After ...One..., RETURNED bWasOK = %d , pSrcPhrase sn = %d m_srcPhrase = %s"),
Expand Down Expand Up @@ -48432,6 +48444,21 @@ int CAdapt_ItDoc::TokenizeText(int nStartingSequNum, SPList* pList, wxString& rB
pSrcPhrase->m_precPunct += precWordDelim;
}
ptr += itemLen;
// whm 28Dec2024 removed the following bKeepPtrFromAdvancing TRUE assignment as it causes
// a path through TokenizeText() that results in the creation of an spurious empty source
// phrase. Making this change revealed a need to handle better the restoration order of
// filtered information in exported source text - in FromSingleMakeSstr2(), where we need to
// delay the restoration of filtered info until a following source phrase is being processed,
// that is, we need to have a PREVIOUS source phrase named pPrevSingleSrcPhrase hanging
// around during export execution that can be referenced while processing the data of a
// current pSingleSrcPhrase (like what is done when tokenizing filtered information, but in
// reverse as we process exports). This is so that filtered info for a pPrevSingleSrcPhrase
// item can be placed in the exported output AFTER the m_markers of the pSingleSrcPhrase.
// For example, in the _Bob_Eaton_va_vp_filtering_with_id_lineA.xml unittest doc, when
// restoring the doc during source export, the filtered info at sn=6 (\va 1\va*) needs to
// go AFTER the m_markers data of sn=7 (\d ) for proper ordering. This may also help to
// correct the undesirable reordering of verse numbers and other markers that Roland F
// reports he has been experiencing when inserting placeholders in Kuni texts.
bKeepPtrFromAdvancing = TRUE; // causes ParsePreWord() to be skipped - might help or might not
break;
}
Expand Down
5 changes: 4 additions & 1 deletion source/Adapt_ItDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,12 @@ bool bMarkAsDirty); // might want it instantly saveable
#endif
void RemoveVenturaOptionalHyphens(wxString*& pstr);
bool ReconstituteAfterPunctuationChange(CAdapt_ItView* pView, SPList*& pList,
SPList::Node* pos_callers, CSourcePhrase*& pSrcPhrase, wxString& fixesStr);
SPList::Node* pos_callers, CSourcePhrase*& pSrcPhrase,
CSourcePhrase*& pPrevSrcPhrase, // whm 28Dec2024 added
wxString& fixesStr);
bool ReconstituteOneAfterPunctuationChange(CAdapt_ItView* pView, SPList*& WXUNUSED(pList),
SPList::Node* WXUNUSED(pos_callers), CSourcePhrase*& pSrcPhrase,
CSourcePhrase*& pPrevSrcPhrase, // whm 28Dec2024 added
wxString& WXUNUSED(fixesStr), SPList*& pNewList, bool bIsOwned);
bool ReconstituteAfterFilteringChange(CAdapt_ItView* pView, SPList*& pList, wxString& fixesStr);
void SetupForSFMSetChange(enum SfmSet oldSet, enum SfmSet newSet, wxString oldFilterMarkers,
Expand Down
Loading

0 comments on commit e0181ef

Please sign in to comment.