Skip to content

Commit

Permalink
✨ Implement collection of text pasted items (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang authored Feb 16, 2024
1 parent af7e47c commit 1db9194
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ package com.clipevery.clip.service

import com.clipevery.clip.ClipCollector
import com.clipevery.clip.ClipItemService
import com.clipevery.clip.item.TextClipItem
import com.clipevery.dao.clip.ClipAppearItem
import com.clipevery.utils.md5ByString
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.Transferable

class TextItemService: ClipItemService {

companion object TextItemService {

const val UNICODE_STRING = "Unicode String"
const val TEXT = "text/plain"
const val PLAIN_TEXT = "Plain Text"
}

override fun getIdentifiers(): List<String> {
return listOf()
return listOf(UNICODE_STRING, TEXT, PLAIN_TEXT)
}

override fun doCreateClipItem(
Expand All @@ -18,6 +29,14 @@ class TextItemService: ClipItemService {
transferable: Transferable,
clipCollector: ClipCollector
) {
TODO("Not yet implemented")
var clipItem: ClipAppearItem? = null
if (transferData is String) {
clipItem = TextClipItem().apply {
identifier = dataFlavor.humanPresentableName
text = transferData
md5 = md5ByString(text)
}
}
clipItem?.let { clipCollector.collectItem(itemIndex, this::class, it) }
}
}

0 comments on commit 1db9194

Please sign in to comment.