@@ -37,6 +37,7 @@ import kotlinx.coroutines.Dispatchers
3737import kotlinx.coroutines.flow.first
3838import kotlinx.coroutines.launch
3939import kotlinx.coroutines.withContext
40+ import kotlin.time.Clock
4041import me.rosuh.easywatermark.data.db.buildTemplateDatabase
4142import me.rosuh.easywatermark.data.db.unpackDefaultTemplateSeed
4243import me.rosuh.easywatermark.data.model.ImageFormat
@@ -179,7 +180,8 @@ private fun resolveDesktopOutputDir(): File {
179180 * onto the window loads it through the same Open-image save spine (`Modifier.dragAndDropTarget` + the AWT
180181 * file-list flavor; updates `lastImage` + `lastSavedFile`; unsupported/empty/while-busy drops fail softly).
181182 * S4d-160: a minimal "Templates" section over the shared Desktop Room path saves the current watermark
182- * text, lists saved templates, and applies (Use → `WatermarkConfigEditor.updateText`) or deletes them.
183+ * text, lists saved templates, and applies (Use → `WatermarkConfigEditor.updateText`), updates in place
184+ * (Update → `TemplateEditor.update`), or deletes them.
183185 * S4d-198: REACTIVE preview — every successful explicit editor action (Apply text/degree/color/opacity/
184186 * gaps/text-size, the tile/typeface/style buttons, "Use text watermark", and template "Use") now
185187 * auto-refreshes the on-screen preview through the SAME `refreshPreview()` → `runSaveFlow` temp-file spine
@@ -1059,10 +1061,12 @@ fun launchDesktopWindow() = application {
10591061 },
10601062 ) { Text (" Copy output path" ) }
10611063 }
1062- // S4d-160: minimal Templates section over the shared Desktop Room template path. "Save current
1063- // text" stores the edited watermark text (templateEditor.add); each saved row applies it (Use →
1064- // WatermarkConfigEditor.updateText + sync the text field) or deletes it. S4d-198: Use auto-refreshes
1065- // the preview after a successful apply. `content` is the watermark TEXT (S4d-159).
1064+ // S4d-160/S4d-226: minimal Templates section over the shared Desktop Room template path. "Save
1065+ // current text" stores the edited watermark text (templateEditor.add); each saved row applies it
1066+ // (Use → WatermarkConfigEditor.updateText + sync the text field), updates in place from the
1067+ // current watermark text (Update → TemplateEditor.update, preserving id/creationDate), or deletes
1068+ // it. S4d-198: Use auto-refreshes the preview after a successful apply. `content` is the watermark
1069+ // TEXT (S4d-159).
10661070 Text (" Templates" , style = MaterialTheme .typography.subtitle1)
10671071 Button (
10681072 // S4d-162: require nonblank text so an empty template can't be saved.
@@ -1121,6 +1125,31 @@ fun launchDesktopWindow() = application {
11211125 }
11221126 },
11231127 ) { Text (" Use" ) }
1128+ Button (
1129+ // S4d-226: update the existing row from the current watermark text.
1130+ enabled = ! busy && watermarkText.isNotBlank(),
1131+ onClick = {
1132+ val text = watermarkText
1133+ scope.launch {
1134+ busy = true
1135+ val next = withContext(Dispatchers .IO ) {
1136+ try {
1137+ templateEditor.update(
1138+ template.copy(
1139+ content = text,
1140+ lastModifiedDate = Clock .System .now(),
1141+ )
1142+ )
1143+ " Updated template to: \" $text \" "
1144+ } catch (t: Throwable ) {
1145+ " Failed: ${t.message} "
1146+ }
1147+ }
1148+ status = next
1149+ busy = false
1150+ }
1151+ },
1152+ ) { Text (" Update" ) }
11241153 Button (
11251154 enabled = ! busy,
11261155 onClick = {
0 commit comments