diff --git a/src/main/java/com/alvincezy/tinypic2/Constants.java b/src/main/java/com/alvincezy/tinypic2/Constants.java index 83fc6ad..605eea2 100644 --- a/src/main/java/com/alvincezy/tinypic2/Constants.java +++ b/src/main/java/com/alvincezy/tinypic2/Constants.java @@ -4,14 +4,18 @@ * Created by alvince on 17-6-28. * * @author alvince.zy@gmail.com - * @version 1.0.1, 7/20/2017 + * @version 1.0.1, 7/21/2017 * @since 1.0 */ public interface Constants { - String LINK_TINY_PNG_DEVELOPER = "https://tinypng.com/developers"; + String APP_NAME = "Tinify Picture"; // Plugin name + + String DISPLAY_GROUP_PROMPT = "Tinify Picture Prompt"; String HTML_DESCRIPTION_IGNORE = "#ignore"; String HTML_DESCRIPTION_SETTINGS = "#settings"; String HTML_LINK_IGNORE = "不再提示"; String HTML_LINK_SETTINGS = "设置"; + + String LINK_TINY_PNG_DEVELOPER = "https://tinypng.com/developers"; } diff --git a/src/main/kotlin/com/alvincezy/tinypic2/actions/TinyPicUploadAction.kt b/src/main/kotlin/com/alvincezy/tinypic2/actions/TinyPicUploadAction.kt index d261cab..a909488 100644 --- a/src/main/kotlin/com/alvincezy/tinypic2/actions/TinyPicUploadAction.kt +++ b/src/main/kotlin/com/alvincezy/tinypic2/actions/TinyPicUploadAction.kt @@ -1,8 +1,12 @@ package com.alvincezy.tinypic2.actions +import com.alvincezy.tinypic2.Constants import com.alvincezy.tinypic2.TinifyFlowable import com.alvincezy.tinypic2.TinyPicOptionsConfigurable import com.alvincezy.tinypic2.model.VirtualFileAware +import com.intellij.notification.Notification +import com.intellij.notification.NotificationType +import com.intellij.notification.Notifications import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.fileChooser.FileChooser @@ -15,7 +19,6 @@ import com.intellij.openapi.ui.Messages import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileVisitor -import com.intellij.openapi.wm.impl.status.StatusBarUtil import com.tinify.Tinify import org.apache.commons.lang.StringUtils import rx.Observable @@ -56,7 +59,7 @@ class TinyPicUploadAction : TinifyAction() { private fun pickFiles(project: Project) { tinifySource.clear() val descriptor = FileChooserDescriptor(true, true, false, false, false, true) - val selectedFiles = FileChooser.chooseFiles(descriptor, project, null) + val selectedFiles = FileChooser.chooseFiles(descriptor, project, project.baseDir) Observable.just(selectedFiles) .subscribeOn(Schedulers.io()) .filter { selectedFiles.isNotEmpty() } @@ -71,8 +74,7 @@ class TinyPicUploadAction : TinifyAction() { private fun parseFilePicked(file: VirtualFile) { VfsUtilCore.visitChildrenRecursively(file, object : VirtualFileVisitor() { override fun visitFile(file: VirtualFile): Boolean { - val filename = file.name.toLowerCase() - if (filename.endsWith(".jpg") || filename.endsWith(".png")) { + if (file.name.endsWith(".jpg", true) || file.name.endsWith(".png", true)) { val fileW = VirtualFileAware(file) if (tinifySource.contains(fileW)) return false @@ -87,17 +89,20 @@ class TinyPicUploadAction : TinifyAction() { taskPool.clear() if (Tinify.validate()) { isEnabledInModalContext = false - ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Perform Picture Tinify") { - override fun run(indicator: ProgressIndicator) { - tinifySource.map { it.file } - .forEach { file -> tinifyThreadPool.execute(TaskRunnable(file)) } - while (true) { - if (taskPool.isEmpty()) break - } - indicator.text = "Complete Picture Tinify" - StatusBarUtil.setStatusBarInfo(project, "图片压缩完成") - } - }) + ProgressManager.getInstance().run( + object : Task.Backgroundable(project, Constants.APP_NAME, false) { + override fun run(indicator: ProgressIndicator) { + indicator.text = "Perform Picture Tinify" + tinifySource.map { it.file } + .forEach { file -> tinifyThreadPool.execute(TaskRunnable(file)) } + while (true) { + if (taskPool.isEmpty()) break + } + indicator.text2 = "Complete Picture Tinify" + Notifications.Bus.notify(Notification(Constants.DISPLAY_GROUP_PROMPT, + Constants.APP_NAME, "图片压缩完成", NotificationType.INFORMATION)) + } + }) } else { Messages.showInfoMessage("Validate failure.", TAG) } @@ -118,12 +123,10 @@ class TinyPicUploadAction : TinifyAction() { if (flowable.performTinify()) { try { - flowable.result()!!.toFile(name) } catch (e: IOException) { e.printStackTrace() } - } flowable.file().refresh(true, false) taskPool.remove(name) diff --git a/src/main/kotlin/com/alvincezy/tinypic2/components/TinifyComponent.kt b/src/main/kotlin/com/alvincezy/tinypic2/components/TinifyComponent.kt index fe9db79..b268467 100644 --- a/src/main/kotlin/com/alvincezy/tinypic2/components/TinifyComponent.kt +++ b/src/main/kotlin/com/alvincezy/tinypic2/components/TinifyComponent.kt @@ -17,7 +17,7 @@ import javax.swing.event.HyperlinkEvent * Created by alvince on 17-7-20. * * @author alvince.zy@gmail.com - * @version 1.0.1, 7/20/2017 + * @version 1.0.1, 7/21/2017 * @since 1.0.1 */ class TinifyComponent(project: Project) : AbstractProjectComponent(project) { @@ -36,11 +36,10 @@ class TinifyComponent(project: Project) : AbstractProjectComponent(project) { override fun projectOpened() { if (StringUtils.isEmpty(preferences.apiKey) && !PropertiesComponent.getInstance().getBoolean(PROP_PROMPT_SETTINGS_IGNORE, false)) { - val notificationContent = ("当前 Api Key 为空,请设置 Api Key" + - "
%s    %s").format(Constants.HTML_LINK_SETTINGS, Constants.HTML_LINK_IGNORE) - val notification = Notification( - "TinyPic2 Settings", "TinyPic 2", - notificationContent, NotificationType.WARNING, + val notificationContent = "当前 Api Key 为空,请设置 Api Key
%s    %s" + .format(Constants.HTML_LINK_SETTINGS, Constants.HTML_LINK_IGNORE) + val notification = Notification(Constants.DISPLAY_GROUP_PROMPT, + Constants.APP_NAME, notificationContent, NotificationType.WARNING, object : NotificationListener.Adapter() { override fun hyperlinkActivated(notification: Notification, event: HyperlinkEvent) { notification.expire() diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 9a5d2be..d51d2c5 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,12 +1,28 @@ com.alvincezy.TinyPic2 - TinyPic 2 + Tinify Picture 1.0.1 alvince - See https://tinypng.com +

Tinify Picture

+
+ + Home Page | + GitHub | + Issues + + +
+
+ + Compress images with TinyPng api. +
+
+ 👁️‍️ Website https://tinypng.com +
+
+ Compiled with Java 1.8 and Kotlin 1.1 ]]>