Add measure separator "/" on Popup Editing mode with tooltip

This commit is contained in:
Hasinjato 2026-06-01 15:16:55 +03:00
parent d59eeac52e
commit c6cae93dff
3 changed files with 96 additions and 25 deletions

View file

@ -780,9 +780,12 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
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
* Et tant qu'une marker est ajouter */ * Et tant qu'un marker est ajouter
* Ou une séparateur de mesure est ajouter */
val notesByVoice = editState.notesByVoice val notesByVoice = editState.notesByVoice
val originalNotes = editState.originalNotes val originalNotes = editState.originalNotes
val separat = editState.sep
val originalSeparat = editState.originalSep
var anyNoteModified = false var anyNoteModified = false
for (voiceNum in 0..3) { for (voiceNum in 0..3) {
val newNot = notesByVoice[voiceNum] ?: "" val newNot = notesByVoice[voiceNum] ?: ""
@ -793,6 +796,9 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
break break
} }
} }
if((originalSeparat != separat)) {
anyNoteModified = true
}
if (!anyNoteModified && newMarkerValue.isEmpty()) { if (!anyNoteModified && newMarkerValue.isEmpty()) {
println("Aucune modification détectée, on retourne le template original.") println("Aucune modification détectée, on retourne le template original.")
return templateLine return templateLine
@ -885,7 +891,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
} }
} }
val rawProcessed = leadingCloseParentheses + newMarkerValue + existingMarker + adjustedTemplate val rawProcessed = separat + leadingCloseParentheses + newMarkerValue + existingMarker + adjustedTemplate
var cleanedProcessed = rawProcessed var cleanedProcessed = rawProcessed
while (cleanedProcessed.contains("((") || cleanedProcessed.contains("))")) { while (cleanedProcessed.contains("((") || cleanedProcessed.contains("))")) {
@ -969,7 +975,14 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
// currentLogicalIdx, rawBlockText, actionTaken, compactedBlock.toString())) // currentLogicalIdx, rawBlockText, actionTaken, compactedBlock.toString()))
resultBody.append(compactedBlock) resultBody.append(compactedBlock)
if (i < body.length) resultBody.append(body[i]) if (i < body.length) {
// println("$currentLogicalIdx == ${targetPointer - 1} && ($separat) && ${body[i]} in separators")
if (currentLogicalIdx == (targetPointer-1) && separat.isEmpty() && body[i] in separators) {
resultBody.append('|')
} else {
resultBody.append(body[i])
}
}
currentBlock.clear() currentBlock.clear()
currentLogicalIdx++ currentLogicalIdx++

View file

@ -11,11 +11,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.automirrored.filled.ArrowForward import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.*
import androidx.compose.material.icons.filled.Build
import androidx.compose.material.icons.filled.Clear
import androidx.compose.material.icons.filled.KeyboardDoubleArrowLeft
import androidx.compose.material.icons.filled.KeyboardDoubleArrowRight
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -23,12 +19,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.* import androidx.compose.ui.unit.*
import androidx.compose.ui.window.Popup import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupProperties import androidx.compose.ui.window.PopupProperties
@ -63,10 +58,14 @@ fun TUODetailDialog(
} }
var templateFragment by remember { mutableStateOf(editState.templateFragment) } var templateFragment by remember { mutableStateOf(editState.templateFragment) }
var newSep by remember { mutableStateOf(editState.sep) }
var marker by remember { mutableStateOf(editState.marker) } var marker by remember { mutableStateOf(editState.marker) }
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,
@ -237,7 +236,62 @@ fun TUODetailDialog(
.verticalScroll(rememberScrollState()) .verticalScroll(rememberScrollState())
) { ) {
// --- SECTION TEMPLATE --- // --- SECTION TEMPLATE ---
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { Row(horizontalArrangement = Arrangement.SpaceEvenly, verticalAlignment = Alignment.CenterVertically) {
if(globalIndex != 0) {
Column(
modifier = Modifier.width(20.dp)
) {
val isSeparator = (newSep.isNotEmpty() || canAddSep.value) && newSep == "/"
val tooltipText = if (isSeparator) {
"Enlever la barre de mesure"
} else {
"Ajouter une barre de mesure"
}
TooltipBox(
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
tooltip = {
PlainTooltip(
containerColor = Color.DarkGray,
contentColor = Color.White
) {
Text(text = tooltipText, fontSize = 12.sp)
}
},
state = rememberTooltipState()
) {
if(isSeparator) {
IconButton(
modifier = Modifier.size(20.dp),
onClick = {
canAddSep.value = false
newSep = ""
}) {
Text(
text = "/",
color = Color.Cyan,
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center
)
}
} else {
IconButton(
modifier = Modifier.size(20.dp),
onClick = {
canAddSep.value = true
newSep = "/"
}) {
Icon(
imageVector = Icons.Default.Add,
tint = Color.Cyan,
contentDescription = null
)
}
}
}
}
}
Column( Column(
modifier = Modifier.weight(1f) modifier = Modifier.weight(1f)
) { ) {
@ -403,6 +457,8 @@ fun TUODetailDialog(
templateFragment = templateFragment, templateFragment = templateFragment,
/* On ne ré-insere pas la même marker*/ /* On ne ré-insere pas la même marker*/
marker = if(marker != initialMarker) marker else "", marker = if(marker != initialMarker) marker else "",
originalSep = initialSep,
sep = if(newSep != initialSep) newSep else ""
) )
onSave(state) onSave(state)
}, },
@ -420,7 +476,7 @@ fun TUODetailDialog(
} }
} }
} }
fun transformMusicalInput(input: String): String { private fun transformMusicalInput(input: String): String {
return input.lowercase() return input.lowercase()
.replace(";", "• ,") .replace(";", "• ,")
.replace(".", "") .replace(".", "")

View file

@ -8,5 +8,7 @@ data class TUOEditState(
val originalLyricsByStanza: MutableMap<Int, String> = mutableMapOf(), val originalLyricsByStanza: MutableMap<Int, String> = mutableMapOf(),
val templateFragment: String = "", val templateFragment: String = "",
val marker: String = "", val marker: String = "",
val silentDuration: String = "-1" val silentDuration: String = "-1",
val originalSep: String = " ",
val sep: String = " "
) )