2121using SIL . LCModel . DomainServices ;
2222using SIL . LCModel . Infrastructure ;
2323using System . IO ;
24+ using SIL . LCModel . Core . Phonology ;
2425
2526namespace SIL . FieldWorks . IText
2627{
@@ -1004,16 +1005,26 @@ private ITsString MakeLabel(string labelText)
10041005 return tssLabel ;
10051006 }
10061007
1007- private void AddNoMediaMessage ( IVwEnv vwenv , ITsString tssMediaLabel , bool lineAndSegSameDir , bool lineAndUserSameDir , string mediaFile )
1008+ private ITsString GetSpeakerName ( ICmPerson speakerRA , int ws )
1009+ {
1010+ // If speaker name is available in the writing system we want, use that.
1011+ // Otherwise, use the default stored in ChooserNameTS. Otherwise an empty string.
1012+ ITsString speakerName = speakerRA ? . Name ? . get_String ( ws ) ;
1013+ if ( string . IsNullOrEmpty ( speakerName ? . ToString ( ) ) )
1014+ speakerName = speakerRA ? . ChooserNameTS ?? m_tssEmptyString ;
1015+ return speakerName ;
1016+ }
1017+
1018+ private void AddNoMediaMessage ( IVwEnv vwenv , ITsString tssMediaLabel , ITsString tssFileLabel , int wsForSeg , string mediaFileName )
10081019 {
10091020 var defUserWs = m_cache . DefaultUserWs ;
1010- bool isFilePathSpecified = ! string . IsNullOrEmpty ( mediaFile ) ;
1011- ITsString tssFilePath = null ;
1021+ bool isFilePathSpecified = ! string . IsNullOrEmpty ( mediaFileName ) ;
1022+ ITsString tssFileName = null ;
10121023 ITsString tssNoMediaMessage ;
10131024
10141025 if ( isFilePathSpecified )
10151026 {
1016- tssFilePath = TsStringUtils . MakeString ( mediaFile , defUserWs ) ;
1027+ tssFileName = MakeUiElementString ( mediaFileName , defUserWs , null ) ;
10171028 // We have a media filepath, but file was not found. Build media not found message.
10181029 // Use normal label settings, except make it italic instead of bold.
10191030 tssNoMediaMessage = MakeUiElementString (
@@ -1029,7 +1040,7 @@ private void AddNoMediaMessage(IVwEnv vwenv, ITsString tssMediaLabel, bool lineA
10291040 else
10301041 {
10311042 // No media filepath was given. Build no media message.
1032- // Use normal label settings, except make it italic instead of bold.
1043+ // Use normal label settings, except not bold.
10331044 tssNoMediaMessage = MakeUiElementString (
10341045 ITextStrings . ksNoMedia , defUserWs ,
10351046 propsBldr =>
@@ -1041,12 +1052,18 @@ private void AddNoMediaMessage(IVwEnv vwenv, ITsString tssMediaLabel, bool lineA
10411052 } ) ;
10421053 }
10431054
1044- // If the line WS and segment WS are not the same direction, OR the line WS and user WS
1045- // are not the same direction, but not both, then we need to insert pieces in reverse
1055+ // If the user WS and segment WS are not the same direction, then we need to insert pieces in reverse
10461056 // logical order.
10471057 AddTssDirForWs ( vwenv , defUserWs ) ;
1048- if ( ! lineAndSegSameDir ^ ! lineAndUserSameDir )
1058+ if ( IsWsRtl ( wsForSeg ) != IsWsRtl ( defUserWs ) )
10491059 {
1060+ if ( isFilePathSpecified )
1061+ {
1062+ vwenv . AddString ( tssFileName ) ;
1063+ vwenv . AddString ( m_tssDefaultSpace ) ;
1064+ vwenv . AddString ( tssFileLabel ) ;
1065+ AddSeparator ( vwenv ) ;
1066+ }
10501067 vwenv . AddString ( tssNoMediaMessage ) ;
10511068 vwenv . AddString ( m_tssDefaultSpace ) ;
10521069 vwenv . AddString ( tssMediaLabel ) ;
@@ -1056,6 +1073,13 @@ private void AddNoMediaMessage(IVwEnv vwenv, ITsString tssMediaLabel, bool lineA
10561073 vwenv . AddString ( tssMediaLabel ) ;
10571074 vwenv . AddString ( m_tssDefaultSpace ) ;
10581075 vwenv . AddString ( tssNoMediaMessage ) ;
1076+ if ( isFilePathSpecified )
1077+ {
1078+ AddSeparator ( vwenv ) ;
1079+ vwenv . AddString ( tssFileLabel ) ;
1080+ vwenv . AddString ( m_tssDefaultSpace ) ;
1081+ vwenv . AddString ( tssFileName ) ;
1082+ }
10591083 }
10601084 AddTssDirForWs ( vwenv , defUserWs ) ;
10611085 }
@@ -1105,22 +1129,24 @@ protected virtual void AddMedia(IVwEnv vwenv, int hvoSeg, int lineChoiceIndex)
11051129 // => 1 himetric = 720/25.4 millipoints = 7200/254 millipoints
11061130 int mediaPlayPicWidth = m_PlayArrowPic . Picture . Width * 7200 / 254 ;
11071131
1108- // Build labels for begin/end offsets and speaker .
1132+ // Build labels for begin/end offsets, speaker, and file .
11091133 var tssBeginTimeLabel = MakeLabel ( ITextStrings . ksBeginTimeOffset ) ;
11101134 var tssEndTimeLabel = MakeLabel ( ITextStrings . ksEndTimeOffset ) ;
11111135 var tssSpeakerLabel = MakeLabel ( ITextStrings . ksSpeaker ) ;
1136+ var tssFileLabel = MakeLabel ( ITextStrings . ksFile ) ;
11121137
1113- // If there is no media file, add Media line label and a "No Media" message and skip the rest of the media line display.
11141138 var mediaFile = segment . MediaURIRA ? . MediaURI ;
1115- bool fileExists = CheckFileExistsFromUri ( mediaFile ) ;
1139+ string mediaFileName ;
1140+ bool fileExists = CheckFileExistsFromUri ( mediaFile , out mediaFileName ) ;
1141+
1142+ // If there is no media file, add Media line label and a "No Media" message and skip the rest of the media line display.
11161143 if ( ! fileExists )
11171144 {
11181145 vwenv . OpenDiv ( ) ;
1119- SetParaDirectionAndAlignment ( vwenv , wssOptions [ 0 ] ) ;
1146+ // No Media Message uses the default user ws
1147+ SetParaDirectionAndAlignment ( vwenv , defUserWs ) ;
11201148 vwenv . OpenParagraph ( ) ;
1121- bool lineAndSegSameDir = IsWsRtl ( wssOptions [ 0 ] ) == IsWsRtl ( wsForSeg ) ;
1122- bool lineAndUserSameDir = ( IsWsRtl ( wssOptions [ 0 ] ) == IsWsRtl ( defUserWs ) ) ;
1123- AddNoMediaMessage ( vwenv , tssMediaLabel , lineAndSegSameDir , lineAndUserSameDir , mediaFile ) ;
1149+ AddNoMediaMessage ( vwenv , tssMediaLabel , tssFileLabel , wsForSeg , mediaFileName ) ;
11241150 vwenv . CloseParagraph ( ) ;
11251151 vwenv . CloseDiv ( ) ;
11261152 return ;
@@ -1181,14 +1207,29 @@ protected virtual void AddMedia(IVwEnv vwenv, int hvoSeg, int lineChoiceIndex)
11811207 // then content within each piece needs to be in reverse logical order.
11821208 //
11831209 // In the order in which they should appear, pieces for the media line are:
1184- // [Label WS - media label], [Line content WS - playback button], [Label WS - optional WS label & Begin time label],
1185- // [Line content WS - Begin time value], [Label WS - End time label], [Line content WS - End time value],
1186- // [Label WS - Speaker label], [Line content WS - Speaker value].
1210+ // [Default user WS - media label], [Line content WS - playback button], [Default user WS - optional WS label & Begin time label],
1211+ // [Line content WS - Begin time value], [Default user WS - End time label], [Line content WS - End time value],
1212+ // [Default user WS - Speaker label], [Line content WS - Speaker value], [Default user WS - File label & filename ].
11871213 if ( ! lineAndSegSameDir )
11881214 {
1215+ // Add the file name section.
1216+ // Piece 1: default user WS - Add file label and filename
1217+ if ( lineAndUserSameDir )
1218+ {
1219+ // content within the piece is in reverse logical order, so add filename and then label
1220+ AddITsStringProperty ( vwenv , defUserWs , MakeUiElementString ( mediaFileName , defUserWs , null ) ) ;
1221+ AddFormattedLabel ( vwenv , tssFileLabel , lineAndSegSameDir , lineAndUserSameDir ) ;
1222+ }
1223+ else
1224+ {
1225+ // content within the piece is in logical order, so add label and then filename
1226+ AddFormattedLabel ( vwenv , tssFileLabel , lineAndSegSameDir , lineAndUserSameDir ) ;
1227+ AddITsStringProperty ( vwenv , defUserWs , MakeUiElementString ( mediaFileName , defUserWs , null ) ) ;
1228+ }
1229+
11891230 // Add the speaker section.
11901231 // Piece 1: Line content WS - Add speaker value.
1191- AddITsStringProperty ( vwenv , wssOptions [ i ] , segment . SpeakerRA ? . ChooserNameTS ?? m_tssEmptyString ) ;
1232+ AddITsStringProperty ( vwenv , wssOptions [ i ] , GetSpeakerName ( segment . SpeakerRA , wssOptions [ i ] ) ) ;
11921233 // Piece 2: default user WS - Add speaker label.
11931234 AddFormattedLabel ( vwenv , tssSpeakerLabel , lineAndSegSameDir , lineAndUserSameDir ) ;
11941235
@@ -1375,7 +1416,22 @@ protected virtual void AddMedia(IVwEnv vwenv, int hvoSeg, int lineChoiceIndex)
13751416 // Speaker label Piece: default user WS.
13761417 AddFormattedLabel ( vwenv , tssSpeakerLabel , lineAndSegSameDir , lineAndUserSameDir ) ;
13771418 // Speaker value piece: Line content WS.
1378- AddITsStringProperty ( vwenv , wssOptions [ i ] , segment . SpeakerRA ? . ChooserNameTS ?? m_tssEmptyString ) ;
1419+ AddITsStringProperty ( vwenv , wssOptions [ i ] , GetSpeakerName ( segment . SpeakerRA , wssOptions [ i ] ) ) ;
1420+
1421+ // Add the file name piece.
1422+ // Default user WS - Add file label and filename
1423+ if ( lineAndUserSameDir )
1424+ {
1425+ // content within the piece should be in logical order, so add label and then filename
1426+ AddFormattedLabel ( vwenv , tssFileLabel , lineAndSegSameDir , lineAndUserSameDir ) ;
1427+ AddITsStringProperty ( vwenv , defUserWs , MakeUiElementString ( mediaFileName , defUserWs , null ) ) ;
1428+ }
1429+ else
1430+ {
1431+ // content within the piece should be in reverse logical order, so add filename and then label
1432+ AddITsStringProperty ( vwenv , defUserWs , MakeUiElementString ( mediaFileName , defUserWs , null ) ) ;
1433+ AddFormattedLabel ( vwenv , tssFileLabel , lineAndSegSameDir , lineAndUserSameDir ) ;
1434+ }
13791435 }
13801436 vwenv . CloseParagraph ( ) ;
13811437 }
@@ -1991,9 +2047,11 @@ private void DisplayMorphBundle(IVwEnv vwenv, int hvo)
19912047 /// Checks if a file associated with a file URI string exists.
19922048 /// </summary>
19932049 /// <param name="uriString">The string containing the file URI.</param>
2050+ /// <param name="fileName">The name of the file extracted from the URI, if it exists.</param>
19942051 /// <returns>True if the file exists, false otherwise.</returns>
1995- private static bool CheckFileExistsFromUri ( string uriString )
2052+ private static bool CheckFileExistsFromUri ( string uriString , out string fileName )
19962053 {
2054+ fileName = null ;
19972055 if ( string . IsNullOrEmpty ( uriString ) )
19982056 {
19992057 return false ;
@@ -2007,8 +2065,9 @@ private static bool CheckFileExistsFromUri(string uriString)
20072065 // 2. Check if it's a local file path (scheme "file").
20082066 if ( uri . IsFile )
20092067 {
2010- // 3. Get the local file path using uri.LocalPath or uri.OriginalString (for UNC paths) .
2068+ // 3. Get the file path using uri.LocalPath.
20112069 string localPath = uri . LocalPath ;
2070+ fileName = Path . GetFileName ( uri . LocalPath ) ;
20122071
20132072 // 4. Use File.Exists to verify if the file exists at that path.
20142073 return File . Exists ( localPath ) ;
0 commit comments