Add or remove marker & separator on Editing Dialog
This commit is contained in:
parent
c6cae93dff
commit
9207be5387
2 changed files with 47 additions and 31 deletions
|
|
@ -776,7 +776,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
private fun updateMarkerSource(
|
||||
templateLine: String,
|
||||
targetPointer: Int,
|
||||
newMarkerValue: String,
|
||||
initMarkerValue: String,
|
||||
editState: TUOEditState
|
||||
): String {
|
||||
/* 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
|
||||
}
|
||||
}
|
||||
if((originalSeparat != separat)) {
|
||||
val isExplicitDeletion = (initMarkerValue == "\${_}")
|
||||
|
||||
if((originalSeparat != separat) || isExplicitDeletion) {
|
||||
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
|
||||
}
|
||||
val isT0 = templateLine.startsWith("T0")
|
||||
|
|
@ -869,11 +874,13 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
var blockToProcess = if (currentLogicalIdx == targetPointer) {
|
||||
actionTaken = if (newMarkerValue.isEmpty()) "DELETE" else "UPDATE"
|
||||
|
||||
val markerMatch = Regex("""\$\{.*?\}|\$.""").find(rawBlockText)
|
||||
val existingMarker = markerMatch?.value ?: ""
|
||||
|
||||
val leadingCloseParentheses = rawBlockText.takeWhile { it == ')' }
|
||||
val oldCleaned = rawBlockText.substring(leadingCloseParentheses.length)
|
||||
/* On ne ré-insere pas la même marker*/
|
||||
val markerRegex = Regex("""\$\{.*?\}|\$.""")
|
||||
val blockWithoutOldMarkers = rawBlockText.replace(markerRegex, "")
|
||||
|
||||
val leadingCloseParentheses = blockWithoutOldMarkers.takeWhile { it == ')' }
|
||||
val oldCleaned = blockWithoutOldMarkers.substring(leadingCloseParentheses.length)
|
||||
|
||||
val newTemplate = getGlobalTemplate(editState)
|
||||
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
|
||||
while (cleanedProcessed.contains("((") || cleanedProcessed.contains("))")) {
|
||||
|
|
@ -992,7 +999,8 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
i++
|
||||
}
|
||||
|
||||
val finalResult = "$prefix$resultBody$suffix"
|
||||
val cleannedBody = resultBody.toString().replace("//", "/")
|
||||
val finalResult = "$prefix$cleannedBody$suffix"
|
||||
// println("-".repeat(100))
|
||||
// println("RÉSULTAT FINAL COMPACTÉ : $finalResult")
|
||||
// println("=".repeat(100))
|
||||
|
|
|
|||
|
|
@ -64,8 +64,6 @@ fun TUODetailDialog(
|
|||
val initialSep = remember { editState.sep }
|
||||
val initialMarker = remember { editState.marker }
|
||||
|
||||
var canAddSep = mutableStateOf(false)
|
||||
|
||||
LaunchedEffect(notes.toMap()) {
|
||||
val tempState = TUOEditState(
|
||||
tuoIndex = editState.tuoIndex,
|
||||
|
|
@ -141,7 +139,7 @@ fun TUODetailDialog(
|
|||
originalLyricsByStanza = originalLyricsByStz.toMutableMap(),
|
||||
lyricsByStanza = mutableMapOf(currentStanza to lyricsLines.joinToString(" ")),
|
||||
templateFragment = templateFragment,
|
||||
marker = if(marker != initialMarker) marker else "",
|
||||
marker = if(marker.isEmpty()) "_" else marker,
|
||||
silentDuration = newDuration
|
||||
)
|
||||
onSave(state)
|
||||
|
|
@ -175,7 +173,7 @@ fun TUODetailDialog(
|
|||
originalLyricsByStanza = originalLyricsByStz.toMutableMap(),
|
||||
lyricsByStanza = mutableMapOf(currentStanza to lyricsLines.joinToString(" ")),
|
||||
templateFragment = templateFragment,
|
||||
marker = if(marker != initialMarker) marker else "",
|
||||
marker = if(marker.isEmpty()) "_" else marker,
|
||||
silentDuration = newDuration
|
||||
)
|
||||
onSave(state)
|
||||
|
|
@ -237,11 +235,11 @@ fun TUODetailDialog(
|
|||
) {
|
||||
// --- SECTION TEMPLATE ---
|
||||
Row(horizontalArrangement = Arrangement.SpaceEvenly, verticalAlignment = Alignment.CenterVertically) {
|
||||
if(globalIndex != 0) {
|
||||
if(globalIndex != 0 && templateFragment != "-") {
|
||||
Column(
|
||||
modifier = Modifier.width(20.dp)
|
||||
) {
|
||||
val isSeparator = (newSep.isNotEmpty() || canAddSep.value) && newSep == "/"
|
||||
val isSeparator = newSep == "/"
|
||||
val tooltipText = if (isSeparator) {
|
||||
"Enlever la barre de mesure"
|
||||
} else {
|
||||
|
|
@ -264,7 +262,6 @@ fun TUODetailDialog(
|
|||
IconButton(
|
||||
modifier = Modifier.size(20.dp),
|
||||
onClick = {
|
||||
canAddSep.value = false
|
||||
newSep = ""
|
||||
}) {
|
||||
Text(
|
||||
|
|
@ -279,7 +276,6 @@ fun TUODetailDialog(
|
|||
IconButton(
|
||||
modifier = Modifier.size(20.dp),
|
||||
onClick = {
|
||||
canAddSep.value = true
|
||||
newSep = "/"
|
||||
}) {
|
||||
Icon(
|
||||
|
|
@ -324,16 +320,29 @@ fun TUODetailDialog(
|
|||
)
|
||||
}
|
||||
} else {
|
||||
IconButton(
|
||||
modifier = Modifier.size(30.dp),
|
||||
onClick = {
|
||||
canAddMark.value = true
|
||||
}) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Add,
|
||||
tint = Color.Green,
|
||||
contentDescription = null
|
||||
)
|
||||
TooltipBox(
|
||||
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
|
||||
tooltip = {
|
||||
PlainTooltip(
|
||||
containerColor = Color.DarkGray,
|
||||
contentColor = Color.White
|
||||
) {
|
||||
Text(text = "Ajouter une marqueur", fontSize = 12.sp)
|
||||
}
|
||||
},
|
||||
state = rememberTooltipState()
|
||||
) {
|
||||
IconButton(
|
||||
modifier = Modifier.size(30.dp),
|
||||
onClick = {
|
||||
canAddMark.value = true
|
||||
}) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Add,
|
||||
tint = Color.Green,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -455,10 +464,9 @@ fun TUODetailDialog(
|
|||
originalLyricsByStanza = originalLyricsByStz.toMutableMap(),
|
||||
lyricsByStanza = mutableMapOf(currentStanza to lyricsLines.joinToString(" ")),
|
||||
templateFragment = templateFragment,
|
||||
/* On ne ré-insere pas la même marker*/
|
||||
marker = if(marker != initialMarker) marker else "",
|
||||
marker = if(marker.isEmpty()) "_" else marker,
|
||||
originalSep = initialSep,
|
||||
sep = if(newSep != initialSep) newSep else ""
|
||||
sep = newSep
|
||||
)
|
||||
onSave(state)
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue