Skip to content

Commit

Permalink
Update plugin name
Browse files Browse the repository at this point in the history
  • Loading branch information
alvince committed Aug 8, 2017
1 parent cfebc01 commit 7e552ec
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
8 changes: 6 additions & 2 deletions src/main/java/com/alvincezy/tinypic2/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
* Created by alvince on 17-6-28.
*
* @author [email protected]
* @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 = "<a href='" + HTML_DESCRIPTION_IGNORE + "'>不再提示</a>";
String HTML_LINK_SETTINGS = "<a href='" + HTML_DESCRIPTION_SETTINGS + "'>设置</a>";

String LINK_TINY_PNG_DEVELOPER = "https://tinypng.com/developers";
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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() }
Expand All @@ -71,8 +74,7 @@ class TinyPicUploadAction : TinifyAction() {
private fun parseFilePicked(file: VirtualFile) {
VfsUtilCore.visitChildrenRecursively(file, object : VirtualFileVisitor<Any>() {
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
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import javax.swing.event.HyperlinkEvent
* Created by alvince on 17-7-20.
*
* @author [email protected]
* @version 1.0.1, 7/20/2017
* @version 1.0.1, 7/21/2017
* @since 1.0.1
*/
class TinifyComponent(project: Project) : AbstractProjectComponent(project) {
Expand All @@ -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" +
"<br/>%s&nbsp;&nbsp;&nbsp;&nbsp;%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<br/>%s&nbsp;&nbsp;&nbsp;&nbsp;%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()
Expand Down
22 changes: 19 additions & 3 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
<idea-plugin>
<id>com.alvincezy.TinyPic2</id>
<name>TinyPic 2</name>
<name>Tinify Picture</name>
<version>1.0.1</version>
<vendor email="[email protected]" url="https://github.com/alvince/TinyPic2">alvince</vendor>

<description><![CDATA[
Compress images with TinyPng api.<br/>
See <a href="https://tinypng.com">https://tinypng.com</a>
<h1>Tinify Picture</h1>
<br/>
<b>
<a href="https://github.com/alvince/TinyPic2">Home Page</a> |
<a href="https://github.com/alvince/TinyPic2">GitHub</a> |
<a href="https://github.com/alvince/TinyPic2/issues">Issues</a>
</b>
<!--<a href="https://plugins.jetbrains.com/idea/plugin/8579">Plugin Page</a> |-->
<br/>
<br/>
Compress images with TinyPng api.
<br/>
<br/>
👁️‍️ Website <a href="https://tinypng.com">https://tinypng.com</a>
<br/>
<br/>
<i>Compiled with Java 1.8 and Kotlin 1.1</i>
]]></description>

<change-notes><![CDATA[
Expand Down

0 comments on commit 7e552ec

Please sign in to comment.