diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/ClipeveryApp.kt b/composeApp/src/commonMain/kotlin/com/clipevery/ClipeveryApp.kt index 8f7cadb3b..d5f2f063d 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/ClipeveryApp.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/ClipeveryApp.kt @@ -18,8 +18,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.shadow import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.ImageBitmap -import androidx.compose.ui.graphics.toComposeImageBitmap import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.unit.dp import com.clipevery.ui.AboutView @@ -115,11 +113,3 @@ fun ClipeveryContent() { } } } - -fun loadImageBitmap(resourcePath: String): ImageBitmap { - // Assuming `resourcePath` is a valid path for an image file within your resources directory. - val image = org.jetbrains.skia.Image.makeFromEncoded( - Thread.currentThread().contextClassLoader.getResourceAsStream(resourcePath) - ?.readBytes()!!) - return image.toComposeImageBitmap() -} diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/clip/item/ClipFile.kt b/composeApp/src/commonMain/kotlin/com/clipevery/clip/item/ClipFile.kt index ffe506acb..647cff0b6 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/clip/item/ClipFile.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/clip/item/ClipFile.kt @@ -4,6 +4,8 @@ import java.nio.file.Path interface ClipFile { + var isFile: Boolean + fun getFilePath(): Path fun getExtension(): String diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/dao/clip/ClipAppearItem.kt b/composeApp/src/commonMain/kotlin/com/clipevery/dao/clip/ClipAppearItem.kt index 20aacd299..f1b8ab7d0 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/dao/clip/ClipAppearItem.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/dao/clip/ClipAppearItem.kt @@ -23,10 +23,6 @@ interface ClipAppearItem { } } -fun sortClipAppearItems(clipAppearItems: List): List { - return clipAppearItems.sortedBy { it.getClipType() } -} - data class ClipAppearItemId(val clipType: Int, val md5: String) { override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/ui/HomeView.kt b/composeApp/src/commonMain/kotlin/com/clipevery/ui/HomeView.kt index 2a7e82a3b..00122a328 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/ui/HomeView.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/ui/HomeView.kt @@ -56,8 +56,8 @@ import androidx.compose.ui.window.PopupProperties import com.clipevery.LocalExitApplication import com.clipevery.LocalKoinApplication import com.clipevery.i18n.GlobalCopywriter -import com.clipevery.loadImageBitmap import com.clipevery.ui.base.ClipIconButton +import com.clipevery.utils.ResourceUtils.loadImageBitmap import java.awt.Desktop import java.net.URI diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/ui/base/ClipIcon.kt b/composeApp/src/commonMain/kotlin/com/clipevery/ui/base/ClipIcon.kt index c7c84570a..884de1e86 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/ui/base/ClipIcon.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/ui/base/ClipIcon.kt @@ -235,4 +235,103 @@ fun image(): ImageVector { } .build() } +} + +@Composable +fun file(): ImageVector { + return remember { + ImageVector.Builder( + name = "File", defaultWidth = 24.0.dp, defaultHeight = 24.0.dp, + viewportWidth = 960.0f, viewportHeight = 960.0f + ).apply { + path(fill = SolidColor(Color(0xFF000000)), stroke = null, strokeLineWidth = 0.0f, + strokeLineCap = Butt, strokeLineJoin = Miter, strokeLineMiter = 4.0f, + pathFillType = NonZero) { + moveTo(320.0f, 720.0f) + horizontalLineToRelative(320.0f) + verticalLineToRelative(-80.0f) + lineTo(320.0f, 640.0f) + verticalLineToRelative(80.0f) + close() + moveTo(320.0f, 560.0f) + horizontalLineToRelative(320.0f) + verticalLineToRelative(-80.0f) + lineTo(320.0f, 480.0f) + verticalLineToRelative(80.0f) + close() + moveTo(240.0f, 880.0f) + quadToRelative(-33.0f, 0.0f, -56.5f, -23.5f) + reflectiveQuadTo(160.0f, 800.0f) + verticalLineToRelative(-640.0f) + quadToRelative(0.0f, -33.0f, 23.5f, -56.5f) + reflectiveQuadTo(240.0f, 80.0f) + horizontalLineToRelative(320.0f) + lineToRelative(240.0f, 240.0f) + verticalLineToRelative(480.0f) + quadToRelative(0.0f, 33.0f, -23.5f, 56.5f) + reflectiveQuadTo(720.0f, 880.0f) + lineTo(240.0f, 880.0f) + close() + moveTo(520.0f, 360.0f) + verticalLineToRelative(-200.0f) + lineTo(240.0f, 160.0f) + verticalLineToRelative(640.0f) + horizontalLineToRelative(480.0f) + verticalLineToRelative(-440.0f) + lineTo(520.0f, 360.0f) + close() + moveTo(240.0f, 160.0f) + verticalLineToRelative(200.0f) + verticalLineToRelative(-200.0f) + verticalLineToRelative(640.0f) + verticalLineToRelative(-640.0f) + close() + } + } + .build() + } +} + +@Composable +fun folder(): ImageVector { + return remember { + ImageVector.Builder( + name = "Folder", defaultWidth = 24.0.dp, defaultHeight = 24.0.dp, + viewportWidth = 960.0f, viewportHeight = 960.0f + ).apply { + path(fill = SolidColor(Color(0xFF000000)), stroke = null, strokeLineWidth = 0.0f, + strokeLineCap = Butt, strokeLineJoin = Miter, strokeLineMiter = 4.0f, + pathFillType = NonZero) { + moveTo(160.0f, 800.0f) + quadToRelative(-33.0f, 0.0f, -56.5f, -23.5f) + reflectiveQuadTo(80.0f, 720.0f) + verticalLineToRelative(-480.0f) + quadToRelative(0.0f, -33.0f, 23.5f, -56.5f) + reflectiveQuadTo(160.0f, 160.0f) + horizontalLineToRelative(240.0f) + lineToRelative(80.0f, 80.0f) + horizontalLineToRelative(320.0f) + quadToRelative(33.0f, 0.0f, 56.5f, 23.5f) + reflectiveQuadTo(880.0f, 320.0f) + verticalLineToRelative(400.0f) + quadToRelative(0.0f, 33.0f, -23.5f, 56.5f) + reflectiveQuadTo(800.0f, 800.0f) + lineTo(160.0f, 800.0f) + close() + moveTo(160.0f, 720.0f) + horizontalLineToRelative(640.0f) + verticalLineToRelative(-400.0f) + lineTo(447.0f, 320.0f) + lineToRelative(-80.0f, -80.0f) + lineTo(160.0f, 240.0f) + verticalLineToRelative(480.0f) + close() + moveTo(160.0f, 720.0f) + verticalLineToRelative(-480.0f) + verticalLineToRelative(480.0f) + close() + } + } + .build() + } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/ClipPreviewItemView.kt b/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/ClipPreviewItemView.kt index 90d8f18b3..7b8719e69 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/ClipPreviewItemView.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/ClipPreviewItemView.kt @@ -65,7 +65,8 @@ fun ClipPreviewItemView(clipData: ClipData, isLast: Boolean, clipContent: @Compo if (it.getClipType() == ClipType.TEXT || it.getClipType() == ClipType.URL || it.getClipType() == ClipType.HTML || - it.getClipType() == ClipType.IMAGE + it.getClipType() == ClipType.IMAGE || + it.getClipType() == ClipType.FILE ) { var hover by remember { mutableStateOf(false) } @@ -154,6 +155,7 @@ fun ClipSpecificPreviewItemView(clipData: ClipData) { ClipType.URL -> UrlPreviewView(clipData) ClipType.HTML -> HtmlPreviewView(clipData) ClipType.IMAGE -> ImagePreviewView(clipData) + ClipType.FILE -> FilePreviewView(clipData) } } } diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/FilePreviewView.kt b/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/FilePreviewView.kt new file mode 100644 index 000000000..1c86702ae --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/clipevery/ui/clip/FilePreviewView.kt @@ -0,0 +1,130 @@ +package com.clipevery.ui.clip + +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.wrapContentWidth +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Icon +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.clipevery.LocalKoinApplication +import com.clipevery.clip.item.ClipFile +import com.clipevery.dao.clip.ClipData +import com.clipevery.i18n.GlobalCopywriter +import com.clipevery.ui.base.file +import com.clipevery.ui.base.folder +import com.clipevery.utils.FileExtUtils.getExtImage +import com.clipevery.utils.FileUtils + +@Composable +fun FilePreviewView(clipData: ClipData) { + clipData.getClipItem(ClipFile::class)?.let { + val current = LocalKoinApplication.current + val copywriter = current.koin.get() + val fileUtils = current.koin.get() + + val imageBitmap: ImageBitmap? = remember(it.getExtension()) { + getExtImage(it.getExtension()) + } + + val isFile: Boolean = remember(it) { + it.isFile + } + + val fileSize = remember(it) { + fileUtils.formatBytes(fileUtils.getFileSize(it.getFilePath())) + } + + Row(modifier = Modifier.fillMaxSize() + .padding(10.dp), + horizontalArrangement = Arrangement.SpaceBetween + ) { + Row { + imageBitmap?.let { + Image( + modifier = Modifier.size(100.dp) + .clip(RoundedCornerShape(5.dp)), + bitmap = it, + contentDescription = "fileType" + ) + } ?: run { + Icon( + modifier = Modifier.size(100.dp), + imageVector = if (isFile) file() else folder(), + contentDescription = "fileType", + tint = MaterialTheme.colors.onBackground + ) + } + + Column( + modifier = Modifier.fillMaxHeight() + .wrapContentWidth() + .padding(horizontal = 8.dp), + verticalArrangement = Arrangement.Bottom + ) { + Text( + text = "${copywriter.getText("File_Name")}: ${fileUtils.getFileNameFromRelativePath(it.getFilePath())}", + color = MaterialTheme.colors.onBackground, + style = TextStyle( + fontWeight = FontWeight.Light, + color = MaterialTheme.colors.onBackground, + fontSize = 10.sp + ) + ) + + Text( + text = "${copywriter.getText("Size")}: $fileSize", + color = MaterialTheme.colors.onBackground, + style = TextStyle( + fontWeight = FontWeight.Light, + color = MaterialTheme.colors.onBackground, + fontSize = 10.sp + ) + ) + } + } + + Row( + modifier = Modifier.wrapContentWidth() + .padding(end = 8.dp), + horizontalArrangement = Arrangement.End, + verticalAlignment = Alignment.CenterVertically + ) { + Icon( + file(), + contentDescription = "File", + modifier = Modifier.padding(3.dp).size(14.dp), + tint = MaterialTheme.colors.onBackground + ) + + Text( + text = copywriter.getText("File"), + fontFamily = FontFamily.SansSerif, + style = TextStyle( + fontWeight = FontWeight.Light, + color = MaterialTheme.colors.onBackground, + fontSize = 10.sp + ) + ) + } + } + } + +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/utils/FileExtUtils.kt b/composeApp/src/commonMain/kotlin/com/clipevery/utils/FileExtUtils.kt new file mode 100644 index 000000000..575ef9b3d --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/clipevery/utils/FileExtUtils.kt @@ -0,0 +1,22 @@ +package com.clipevery.utils + +import androidx.compose.ui.graphics.ImageBitmap + +object FileExtUtils { + + private val extImageMap = mapOf( + Pair("pdf", "pdf"), + Pair("doc", "word"), + Pair("docx", "word"), + Pair("ppt", "ppt"), + Pair("pptx", "ppt"), + Pair("xls", "excel"), + Pair("xlsx", "excel"), + Pair("pages", "pages"), + Pair("key", "keynote"), + Pair("numbers", "numbers") + ) + + fun getExtImage(ext: String): ImageBitmap? = + extImageMap[ext]?.let { ResourceUtils.loadImageBitmap("file-ext/$it.png") } +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/utils/FileUtils.kt b/composeApp/src/commonMain/kotlin/com/clipevery/utils/FileUtils.kt index 119309a77..f9ae104a6 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/utils/FileUtils.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/utils/FileUtils.kt @@ -1,5 +1,6 @@ package com.clipevery.utils +import com.clipevery.app.AppFileType import java.nio.file.Path interface FileUtils { @@ -14,9 +15,11 @@ interface FileUtils { fun getFileNameFromRelativePath(relativePath: Path): String - fun createClipPath(fileRelativePath: String, isFile: Boolean, isImage: Boolean = false): Path + fun createClipPath(fileRelativePath: String, isFile: Boolean, appFileType: AppFileType): Path fun getFileSize(path: Path): Long fun getFileMd5(path: Path): String + + fun copyFile(src: Path, dest: Path): Boolean } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/utils/ResourceUtils.kt b/composeApp/src/commonMain/kotlin/com/clipevery/utils/ResourceUtils.kt new file mode 100644 index 000000000..2c41622a5 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/clipevery/utils/ResourceUtils.kt @@ -0,0 +1,15 @@ +package com.clipevery.utils + +import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.toComposeImageBitmap + +object ResourceUtils { + + fun loadImageBitmap(resourcePath: String): ImageBitmap { + // Assuming `resourcePath` is a valid path for an image file within your resources directory. + val image = org.jetbrains.skia.Image.makeFromEncoded( + Thread.currentThread().contextClassLoader.getResourceAsStream(resourcePath) + ?.readBytes()!!) + return image.toComposeImageBitmap() + } +} \ No newline at end of file diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/DesktopClipeveryKoinApplication.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/DesktopClipeveryKoinApplication.kt index 261576c40..29654684d 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/DesktopClipeveryKoinApplication.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/DesktopClipeveryKoinApplication.kt @@ -12,6 +12,7 @@ import com.clipevery.clip.TransferableConsumer import com.clipevery.clip.getDesktopClipboardService import com.clipevery.clip.plugin.ImageHtmlCombinePlugin import com.clipevery.clip.plugin.MultiImagePlugin +import com.clipevery.clip.plugin.SortPlugin import com.clipevery.clip.plugin.UrlTextCombinePlugin import com.clipevery.clip.service.FileItemService import com.clipevery.clip.service.HtmlItemService @@ -130,7 +131,10 @@ object Dependencies { UrlItemService() ), listOf(UrlTextCombinePlugin, ImageHtmlCombinePlugin, - MultiImagePlugin)) } + MultiImagePlugin, + SortPlugin + ) + ) } // ui component single { AppUI(width = 460.dp, height = 710.dp) } diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/FileClipItem.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/FileClipItem.kt index f7cc16a18..64c9bd4b2 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/FileClipItem.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/FileClipItem.kt @@ -1,6 +1,6 @@ package com.clipevery.clip.item -import com.clipevery.clip.service.FileItemService +import com.clipevery.app.AppFileType import com.clipevery.dao.clip.ClipAppearItem import com.clipevery.dao.clip.ClipType import com.clipevery.path.DesktopPathProvider @@ -18,7 +18,7 @@ class FileClipItem: RealmObject, ClipAppearItem, ClipFile { override var id: ObjectId = BsonObjectId() var identifier: String = "" var relativePath: String = "" - var isFile: Boolean = false + override var isFile: Boolean = false override var md5: String = "" constructor() @@ -31,7 +31,9 @@ class FileClipItem: RealmObject, ClipAppearItem, ClipFile { } override fun getFilePath(): Path { - return DesktopPathProvider.resolve(FileItemService.FILE_BASE_PATH, relativePath, autoCreate = false) + return DesktopPathProvider.resolve( + DesktopPathProvider.resolve(appFileType = AppFileType.FILE), + relativePath, autoCreate = false) } override fun getIdentifiers(): List { diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/FilesClipItem.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/FilesClipItem.kt index 8f7ec4135..9c9d5d9ab 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/FilesClipItem.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/FilesClipItem.kt @@ -1,6 +1,6 @@ package com.clipevery.clip.item -import com.clipevery.clip.service.FileItemService +import com.clipevery.app.AppFileType import com.clipevery.dao.clip.ClipAppearItem import com.clipevery.dao.clip.ClipType import com.clipevery.path.DesktopPathProvider @@ -25,8 +25,9 @@ class FilesClipItem: RealmObject, ClipAppearItem, ClipFiles { override var md5: String = "" override fun getFilePaths(): List { + val basePath = DesktopPathProvider.resolve(appFileType = AppFileType.FILE) return fileList.map { relativePath -> - DesktopPathProvider.resolve(FileItemService.FILE_BASE_PATH, relativePath, autoCreate = false) + DesktopPathProvider.resolve(basePath, relativePath, autoCreate = false) } } diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/ImageClipItem.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/ImageClipItem.kt index 950814392..c8f1bf984 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/ImageClipItem.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/item/ImageClipItem.kt @@ -2,7 +2,7 @@ package com.clipevery.clip.item import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.res.loadImageBitmap -import com.clipevery.clip.service.ImageItemService +import com.clipevery.app.AppFileType import com.clipevery.dao.clip.ClipAppearItem import com.clipevery.dao.clip.ClipType import com.clipevery.path.DesktopPathProvider @@ -26,7 +26,8 @@ class ImageClipItem: RealmObject, ClipAppearItem, ClipImage { } override fun getImagePath(): Path { - return DesktopPathProvider.resolve(ImageItemService.IMAGE_BASE_PATH, relativePath, autoCreate = false) + val basePath = DesktopPathProvider.resolve(appFileType = AppFileType.IMAGE) + return DesktopPathProvider.resolve(basePath, relativePath, autoCreate = false) } override fun getIdentifiers(): List { diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/plugin/SortPlugin.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/plugin/SortPlugin.kt new file mode 100644 index 000000000..28faefc7a --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/plugin/SortPlugin.kt @@ -0,0 +1,10 @@ +package com.clipevery.clip.plugin + +import com.clipevery.clip.ClipPlugin +import com.clipevery.dao.clip.ClipAppearItem + +object SortPlugin: ClipPlugin { + override fun pluginProcess(clipAppearItems: List): List { + return clipAppearItems.sortedByDescending { it.getClipType() } + } +} \ No newline at end of file diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/service/FileItemService.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/service/FileItemService.kt index 74eeeff76..f0bfad021 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/service/FileItemService.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/service/FileItemService.kt @@ -3,19 +3,24 @@ package com.clipevery.clip.service import com.clipevery.app.AppFileType import com.clipevery.clip.ClipCollector import com.clipevery.clip.ClipItemService -import com.clipevery.path.DesktopPathProvider +import com.clipevery.clip.item.FileClipItem +import com.clipevery.dao.clip.ClipAppearItem +import com.clipevery.utils.DesktopFileUtils +import com.clipevery.utils.DesktopFileUtils.copyFile +import com.clipevery.utils.DesktopFileUtils.createClipRelativePath import java.awt.datatransfer.DataFlavor import java.awt.datatransfer.Transferable -import java.nio.file.Path +import java.io.File class FileItemService: ClipItemService { companion object FileItemService { - val FILE_BASE_PATH: Path = DesktopPathProvider.resolve(appFileType = AppFileType.FILE) + + const val FILE_LIST_ID = "application/x-java-file-list" } override fun getIdentifiers(): List { - return listOf() + return listOf(FILE_LIST_ID) } override fun doCreateClipItem( @@ -27,7 +32,25 @@ class FileItemService: ClipItemService { transferable: Transferable, clipCollector: ClipCollector ) { - TODO("Not yet implemented") + if (transferData is List<*>) { + val files = transferData.filterIsInstance() + if (files.size == 1) { + var clipItem: ClipAppearItem? = null + val fileName = files[0].name + val relativePath = createClipRelativePath(clipId, fileName) + val filePath = DesktopFileUtils.createClipPath(relativePath, isFile = true, AppFileType.FILE) + if (copyFile(files[0].toPath(), filePath)) { + clipItem = FileClipItem().apply { + this.identifier = dataFlavor.humanPresentableName + this.relativePath = relativePath + this.md5 = DesktopFileUtils.getFileMd5(filePath) + } + } + clipItem?.let { clipCollector.collectItem(itemIndex, this::class, it) } + } else if (files.size > 1) { + // todo multi files + } + } } } \ No newline at end of file diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/service/ImageItemService.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/service/ImageItemService.kt index a06a4a7d7..3cffd97d4 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/service/ImageItemService.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/service/ImageItemService.kt @@ -6,7 +6,6 @@ import com.clipevery.clip.ClipItemService import com.clipevery.clip.item.ImageClipItem import com.clipevery.clip.service.HtmlItemService.HtmlItemService.HTML_ID import com.clipevery.dao.clip.ClipAppearItem -import com.clipevery.path.DesktopPathProvider import com.clipevery.utils.DesktopFileUtils.createClipPath import com.clipevery.utils.DesktopFileUtils.createClipRelativePath import com.clipevery.utils.DesktopFileUtils.createRandomFileName @@ -27,8 +26,6 @@ class ImageItemService: ClipItemService { companion object ImageItemService { const val IMAGE_ID = "image/x-java-image" - - val IMAGE_BASE_PATH: Path = DesktopPathProvider.resolve(appFileType = AppFileType.IMAGE) } override fun getIdentifiers(): List { @@ -53,10 +50,7 @@ class ImageItemService: ClipItemService { "png" } val relativePath = createClipRelativePath(clipId, name) - val imagePath = createClipPath(relativePath, isFile = true, isImage = true) - ImageIO.getWriterFormatNames().forEach { - println(it) - } + val imagePath = createClipPath(relativePath, isFile = true, AppFileType.IMAGE) if (writeImage(image, ext, imagePath)) { clipItem = ImageClipItem().apply { this.identifier = dataFlavor.humanPresentableName diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/utils/DesktopFileUtils.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/utils/DesktopFileUtils.kt index cb9389f8e..195045e9b 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/utils/DesktopFileUtils.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/utils/DesktopFileUtils.kt @@ -1,7 +1,6 @@ package com.clipevery.utils -import com.clipevery.clip.service.FileItemService.FileItemService.FILE_BASE_PATH -import com.clipevery.clip.service.ImageItemService.ImageItemService.IMAGE_BASE_PATH +import com.clipevery.app.AppFileType import com.clipevery.path.DesktopPathProvider import com.google.common.hash.Hashing import com.google.common.io.Files @@ -50,12 +49,8 @@ object DesktopFileUtils: FileUtils { return clipFileName.split("_", limit = 2)[1] } - override fun createClipPath(fileRelativePath: String, isFile: Boolean, isImage: Boolean): Path { - val basePath = if (isImage) { - IMAGE_BASE_PATH - } else { - FILE_BASE_PATH - } + override fun createClipPath(fileRelativePath: String, isFile: Boolean, appFileType: AppFileType): Path { + val basePath = DesktopPathProvider.resolve(appFileType = appFileType) return DesktopPathProvider.resolve(basePath, fileRelativePath, isFile = isFile) } @@ -69,4 +64,13 @@ object DesktopFileUtils: FileUtils { val hc = byteSource.hash(Hashing.sha256()) return hc.toString() } + + override fun copyFile(src: Path, dest: Path): Boolean { + return try { + Files.copy(src.toFile(), dest.toFile()) + true + } catch (e: Exception) { + false + } + } } \ No newline at end of file diff --git a/composeApp/src/desktopMain/resources/file-ext/excel.png b/composeApp/src/desktopMain/resources/file-ext/excel.png new file mode 100644 index 000000000..f059d57a8 Binary files /dev/null and b/composeApp/src/desktopMain/resources/file-ext/excel.png differ diff --git a/composeApp/src/desktopMain/resources/file-ext/keynote.png b/composeApp/src/desktopMain/resources/file-ext/keynote.png new file mode 100644 index 000000000..0ee8df7c6 Binary files /dev/null and b/composeApp/src/desktopMain/resources/file-ext/keynote.png differ diff --git a/composeApp/src/desktopMain/resources/file-ext/numbers.png b/composeApp/src/desktopMain/resources/file-ext/numbers.png new file mode 100644 index 000000000..7b0312f51 Binary files /dev/null and b/composeApp/src/desktopMain/resources/file-ext/numbers.png differ diff --git a/composeApp/src/desktopMain/resources/file-ext/pages.png b/composeApp/src/desktopMain/resources/file-ext/pages.png new file mode 100644 index 000000000..e93b99250 Binary files /dev/null and b/composeApp/src/desktopMain/resources/file-ext/pages.png differ diff --git a/composeApp/src/desktopMain/resources/file-ext/pdf.png b/composeApp/src/desktopMain/resources/file-ext/pdf.png new file mode 100644 index 000000000..ff9d2bb68 Binary files /dev/null and b/composeApp/src/desktopMain/resources/file-ext/pdf.png differ diff --git a/composeApp/src/desktopMain/resources/file-ext/ppt.png b/composeApp/src/desktopMain/resources/file-ext/ppt.png new file mode 100644 index 000000000..750a171f3 Binary files /dev/null and b/composeApp/src/desktopMain/resources/file-ext/ppt.png differ diff --git a/composeApp/src/desktopMain/resources/file-ext/word.png b/composeApp/src/desktopMain/resources/file-ext/word.png new file mode 100644 index 000000000..719201709 Binary files /dev/null and b/composeApp/src/desktopMain/resources/file-ext/word.png differ diff --git a/composeApp/src/desktopMain/resources/i18n/en.properties b/composeApp/src/desktopMain/resources/i18n/en.properties index 047c9d461..14877d776 100644 --- a/composeApp/src/desktopMain/resources/i18n/en.properties +++ b/composeApp/src/desktopMain/resources/i18n/en.properties @@ -44,6 +44,7 @@ Text=Text Link=Link Html=Html Image=Image +File=File Just_now=Just now Today=Today Yesterday=Yesterday diff --git a/composeApp/src/desktopMain/resources/i18n/es.properties b/composeApp/src/desktopMain/resources/i18n/es.properties index 74f1e4afc..fbb3c241e 100644 --- a/composeApp/src/desktopMain/resources/i18n/es.properties +++ b/composeApp/src/desktopMain/resources/i18n/es.properties @@ -44,6 +44,7 @@ Text=Texto Link=Enlace Html=Página web Image=Imagen +File=Archivo Just_now=Justo ahora Today=Hoy Yesterday=Ayer diff --git a/composeApp/src/desktopMain/resources/i18n/jp.properties b/composeApp/src/desktopMain/resources/i18n/jp.properties index 393a11088..61ab081e1 100644 --- a/composeApp/src/desktopMain/resources/i18n/jp.properties +++ b/composeApp/src/desktopMain/resources/i18n/jp.properties @@ -44,6 +44,7 @@ Text=テキスト Link=リンク Html=ウェブページ Image=画像 +File=ファイル Just_now=たった今 Today=今日 Yesterday=昨日 diff --git a/composeApp/src/desktopMain/resources/i18n/zh.properties b/composeApp/src/desktopMain/resources/i18n/zh.properties index 6b2a046d4..6be70624d 100644 --- a/composeApp/src/desktopMain/resources/i18n/zh.properties +++ b/composeApp/src/desktopMain/resources/i18n/zh.properties @@ -44,6 +44,7 @@ Text=文本 Link=链接 Html=网页 Image=图片 +File=文件 Just_now=刚刚 Today=今天 Yesterday=昨天