Add or remove marker & separator on Editing Dialog

This commit is contained in:
Hasinjato 2026-06-03 09:38:39 +03:00
parent c6cae93dff
commit 9207be5387
2 changed files with 47 additions and 31 deletions

View file

@ -776,7 +776,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
private fun updateMarkerSource( private fun updateMarkerSource(
templateLine: String, templateLine: String,
targetPointer: Int, targetPointer: Int,
newMarkerValue: String, initMarkerValue: String,
editState: TUOEditState editState: TUOEditState
): String { ): String {
/* On ne modifie pas le template tant que les notes ne sont pas modifiées /* On ne modifie pas le template tant que les notes ne sont pas modifiées
@ -796,11 +796,16 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
break break
} }
} }
if((originalSeparat != separat)) { val isExplicitDeletion = (initMarkerValue == "\${_}")
if((originalSeparat != separat) || isExplicitDeletion) {
anyNoteModified = true anyNoteModified = true
} }
if (!anyNoteModified && newMarkerValue.isEmpty()) {
println("Aucune modification détectée, on retourne le template original.") var newMarkerValue = if(isExplicitDeletion) "" else initMarkerValue
if(!anyNoteModified && newMarkerValue.isEmpty() && (originalSeparat == separat)) {
// println("Aucune modification détectée")
return templateLine return templateLine
} }
val isT0 = templateLine.startsWith("T0") val isT0 = templateLine.startsWith("T0")
@ -869,11 +874,13 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
var blockToProcess = if (currentLogicalIdx == targetPointer) { var blockToProcess = if (currentLogicalIdx == targetPointer) {
actionTaken = if (newMarkerValue.isEmpty()) "DELETE" else "UPDATE" actionTaken = if (newMarkerValue.isEmpty()) "DELETE" else "UPDATE"
val markerMatch = Regex("""\$\{.*?\}|\$.""").find(rawBlockText)
val existingMarker = markerMatch?.value ?: ""
val leadingCloseParentheses = rawBlockText.takeWhile { it == ')' } /* On ne ré-insere pas la même marker*/
val oldCleaned = rawBlockText.substring(leadingCloseParentheses.length) val markerRegex = Regex("""\$\{.*?\}|\$.""")
val blockWithoutOldMarkers = rawBlockText.replace(markerRegex, "")
val leadingCloseParentheses = blockWithoutOldMarkers.takeWhile { it == ')' }
val oldCleaned = blockWithoutOldMarkers.substring(leadingCloseParentheses.length)
val newTemplate = getGlobalTemplate(editState) val newTemplate = getGlobalTemplate(editState)
val oldHadOpen = oldCleaned.contains("(") val oldHadOpen = oldCleaned.contains("(")
@ -891,7 +898,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
} }
} }
val rawProcessed = separat + leadingCloseParentheses + newMarkerValue + existingMarker + adjustedTemplate val rawProcessed = separat + leadingCloseParentheses + newMarkerValue + adjustedTemplate
var cleanedProcessed = rawProcessed var cleanedProcessed = rawProcessed
while (cleanedProcessed.contains("((") || cleanedProcessed.contains("))")) { while (cleanedProcessed.contains("((") || cleanedProcessed.contains("))")) {
@ -992,7 +999,8 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
i++ i++
} }
val finalResult = "$prefix$resultBody$suffix" val cleannedBody = resultBody.toString().replace("//", "/")
val finalResult = "$prefix$cleannedBody$suffix"
// println("-".repeat(100)) // println("-".repeat(100))
// println("RÉSULTAT FINAL COMPACTÉ : $finalResult") // println("RÉSULTAT FINAL COMPACTÉ : $finalResult")
// println("=".repeat(100)) // println("=".repeat(100))

View file

@ -64,8 +64,6 @@ fun TUODetailDialog(
val initialSep = remember { editState.sep } val initialSep = remember { editState.sep }
val initialMarker = remember { editState.marker } val initialMarker = remember { editState.marker }
var canAddSep = mutableStateOf(false)
LaunchedEffect(notes.toMap()) { LaunchedEffect(notes.toMap()) {
val tempState = TUOEditState( val tempState = TUOEditState(
tuoIndex = editState.tuoIndex, tuoIndex = editState.tuoIndex,
@ -141,7 +139,7 @@ fun TUODetailDialog(
originalLyricsByStanza = originalLyricsByStz.toMutableMap(), originalLyricsByStanza = originalLyricsByStz.toMutableMap(),
lyricsByStanza = mutableMapOf(currentStanza to lyricsLines.joinToString(" ")), lyricsByStanza = mutableMapOf(currentStanza to lyricsLines.joinToString(" ")),
templateFragment = templateFragment, templateFragment = templateFragment,
marker = if(marker != initialMarker) marker else "", marker = if(marker.isEmpty()) "_" else marker,
silentDuration = newDuration silentDuration = newDuration
) )
onSave(state) onSave(state)
@ -175,7 +173,7 @@ fun TUODetailDialog(
originalLyricsByStanza = originalLyricsByStz.toMutableMap(), originalLyricsByStanza = originalLyricsByStz.toMutableMap(),
lyricsByStanza = mutableMapOf(currentStanza to lyricsLines.joinToString(" ")), lyricsByStanza = mutableMapOf(currentStanza to lyricsLines.joinToString(" ")),
templateFragment = templateFragment, templateFragment = templateFragment,
marker = if(marker != initialMarker) marker else "", marker = if(marker.isEmpty()) "_" else marker,
silentDuration = newDuration silentDuration = newDuration
) )
onSave(state) onSave(state)
@ -237,11 +235,11 @@ fun TUODetailDialog(
) { ) {
// --- SECTION TEMPLATE --- // --- SECTION TEMPLATE ---
Row(horizontalArrangement = Arrangement.SpaceEvenly, verticalAlignment = Alignment.CenterVertically) { Row(horizontalArrangement = Arrangement.SpaceEvenly, verticalAlignment = Alignment.CenterVertically) {
if(globalIndex != 0) { if(globalIndex != 0 && templateFragment != "-") {
Column( Column(
modifier = Modifier.width(20.dp) modifier = Modifier.width(20.dp)
) { ) {
val isSeparator = (newSep.isNotEmpty() || canAddSep.value) && newSep == "/" val isSeparator = newSep == "/"
val tooltipText = if (isSeparator) { val tooltipText = if (isSeparator) {
"Enlever la barre de mesure" "Enlever la barre de mesure"
} else { } else {
@ -264,7 +262,6 @@ fun TUODetailDialog(
IconButton( IconButton(
modifier = Modifier.size(20.dp), modifier = Modifier.size(20.dp),
onClick = { onClick = {
canAddSep.value = false
newSep = "" newSep = ""
}) { }) {
Text( Text(
@ -279,7 +276,6 @@ fun TUODetailDialog(
IconButton( IconButton(
modifier = Modifier.size(20.dp), modifier = Modifier.size(20.dp),
onClick = { onClick = {
canAddSep.value = true
newSep = "/" newSep = "/"
}) { }) {
Icon( Icon(
@ -324,6 +320,18 @@ fun TUODetailDialog(
) )
} }
} else { } else {
TooltipBox(
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
tooltip = {
PlainTooltip(
containerColor = Color.DarkGray,
contentColor = Color.White
) {
Text(text = "Ajouter une marqueur", fontSize = 12.sp)
}
},
state = rememberTooltipState()
) {
IconButton( IconButton(
modifier = Modifier.size(30.dp), modifier = Modifier.size(30.dp),
onClick = { onClick = {
@ -337,6 +345,7 @@ fun TUODetailDialog(
} }
} }
} }
}
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
@ -455,10 +464,9 @@ fun TUODetailDialog(
originalLyricsByStanza = originalLyricsByStz.toMutableMap(), originalLyricsByStanza = originalLyricsByStz.toMutableMap(),
lyricsByStanza = mutableMapOf(currentStanza to lyricsLines.joinToString(" ")), lyricsByStanza = mutableMapOf(currentStanza to lyricsLines.joinToString(" ")),
templateFragment = templateFragment, templateFragment = templateFragment,
/* On ne ré-insere pas la même marker*/ marker = if(marker.isEmpty()) "_" else marker,
marker = if(marker != initialMarker) marker else "",
originalSep = initialSep, originalSep = initialSep,
sep = if(newSep != initialSep) newSep else "" sep = newSep
) )
onSave(state) onSave(state)
}, },