-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
72 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
* Created by alvince on 17-6-28. | ||
* | ||
* @author [email protected] | ||
* @version 2.0.1, 7/20/2017 | ||
* @since 2.0 | ||
* @version 1.0.1, 7/20/2017 | ||
* @since 1.0 | ||
*/ | ||
public interface Constants { | ||
String LINK_TINY_PNG_DEVELOPER = "https://tinypng.com/developers"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ | |
* Created by alvince on 2017/6/28. | ||
* | ||
* @author [email protected] | ||
* @version 2.0.1, 7/20/2017 | ||
* @since 2.0 | ||
* @version 1.0.1, 7/20/2017 | ||
* @since 1.0 | ||
*/ | ||
@State(name = "TinyPicPreferences", storages = @Storage(value = "$APP_CONFIG$/TinyPic2.xml")) | ||
public class Preferences implements PersistentStateComponent<Preferences> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
* Created by alvince on 17-7-12. | ||
* | ||
* @author [email protected] | ||
* @version 2.0, 7/12/2017 | ||
* @since 2.0 | ||
* @version 1.0, 7/12/2017 | ||
* @since 1.0 | ||
*/ | ||
public class TinifyExcutor { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,8 @@ import javax.swing.* | |
* Created by alvince on 2017/6/28. | ||
* | ||
* @author [email protected] | ||
* @version 2.0, 7/18/2017 | ||
* @since 2.0 | ||
* @version 1.0, 7/18/2017 | ||
* @since 1.0 | ||
*/ | ||
class TinyPicOptionsConfigurable : SearchableConfigurable, Configurable.NoScroll, Disposable { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,8 @@ | |
* Created by alvince on 2017/6/28. | ||
* | ||
* @author [email protected] | ||
* @version 2.0, 7/18/2017 | ||
* @since 2.0 | ||
* @version 1.0, 7/18/2017 | ||
* @since 1.0 | ||
*/ | ||
public class PreferencesPanel { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ | |
* Created by alvince on 17-6-29. | ||
* | ||
* @author [email protected] | ||
* @version 2.0, 6/28/2017 | ||
* @since 2.0 | ||
* @version 1.0, 6/28/2017 | ||
* @since 1.0 | ||
*/ | ||
public class ComponentUtil { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ | |
* Created by alvince on 17-6-29. | ||
* | ||
* @author [email protected] | ||
* @version 2.0, 6/28/2017 | ||
* @since 2.0 | ||
* @version 1.0, 6/28/2017 | ||
* @since 1.0 | ||
*/ | ||
public class StringUtil { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ import com.intellij.openapi.project.Project | |
* Created by alvince on 17-7-11. | ||
* | ||
* @author [email protected] | ||
* @version 2.0, 7/12/2017 | ||
* @since 2.0 | ||
* @version 1.0, 7/12/2017 | ||
* @since 1.0 | ||
*/ | ||
open class TinifyAction internal constructor() : AnAction() { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ package com.alvincezy.tinypic2.actions | |
|
||
import com.alvincezy.tinypic2.TinifyFlowable | ||
import com.alvincezy.tinypic2.TinyPicOptionsConfigurable | ||
import com.alvincezy.tinypic2.model.VirtualFileAware | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.fileChooser.FileChooser | ||
import com.intellij.openapi.fileChooser.FileChooserDescriptor | ||
import com.intellij.openapi.progress.ProgressIndicator | ||
|
@@ -26,8 +28,8 @@ import java.util.concurrent.Executors | |
* Created by alvince on 2017/6/28. | ||
* | ||
* @author [email protected] | ||
* @version 2.0, 7/18/2017 | ||
* @since 2.0 | ||
* @version 1.0.1, 7/21/2017 | ||
* @since 1.0 | ||
*/ | ||
class TinyPicUploadAction : TinifyAction() { | ||
|
||
|
@@ -37,7 +39,8 @@ class TinyPicUploadAction : TinifyAction() { | |
|
||
@Volatile internal var taskPool = HashMap<String, Runnable>() | ||
|
||
private val tinifySource = ArrayList<VirtualFile>() | ||
private val logger = Logger.getInstance(javaClass) | ||
private val tinifySource = ArrayList<VirtualFileAware>() | ||
private val tinifyThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()) | ||
|
||
override fun performAction(actionEvent: AnActionEvent, project: Project) { | ||
|
@@ -54,15 +57,14 @@ class TinyPicUploadAction : TinifyAction() { | |
tinifySource.clear() | ||
val descriptor = FileChooserDescriptor(true, true, false, false, false, true) | ||
val selectedFiles = FileChooser.chooseFiles(descriptor, project, null) | ||
Observable.from(selectedFiles) | ||
Observable.just(selectedFiles) | ||
.subscribeOn(Schedulers.io()) | ||
.filter { | ||
if (selectedFiles.isNotEmpty()) { | ||
selectedFiles.forEach { parseFilePicked(it) } | ||
} | ||
tinifySource.isNotEmpty() | ||
} | ||
.subscribe({ uploadAndTinify() }, { it.printStackTrace() }) | ||
.filter { selectedFiles.isNotEmpty() } | ||
.subscribe({ | ||
selectedFiles.forEach { parseFilePicked(it) } | ||
// logger.debug("${tinifySource.toArray()}") | ||
uploadAndTinify() | ||
}, { it.printStackTrace() }) | ||
} | ||
|
||
@Suppress("name_shadowing") | ||
|
@@ -71,7 +73,10 @@ class TinyPicUploadAction : TinifyAction() { | |
override fun visitFile(file: VirtualFile): Boolean { | ||
val filename = file.name.toLowerCase() | ||
if (filename.endsWith(".jpg") || filename.endsWith(".png")) { | ||
tinifySource.add(file) | ||
val fileW = VirtualFileAware(file) | ||
if (tinifySource.contains(fileW)) | ||
return false | ||
tinifySource.add(fileW) | ||
} | ||
return true | ||
} | ||
|
@@ -84,7 +89,8 @@ class TinyPicUploadAction : TinifyAction() { | |
isEnabledInModalContext = false | ||
ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Perform Picture Tinify") { | ||
override fun run(indicator: ProgressIndicator) { | ||
tinifySource.forEach { file -> tinifyThreadPool.execute(TaskRunnable(file)) } | ||
tinifySource.map { it.file } | ||
.forEach { file -> tinifyThreadPool.execute(TaskRunnable(file)) } | ||
while (true) { | ||
if (taskPool.isEmpty()) break | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,8 @@ import javax.swing.event.HyperlinkEvent | |
* Created by alvince on 17-7-20. | ||
* | ||
* @author [email protected] | ||
* @version 2.0.1, 7/20/2017 | ||
* @since 2.0.1 | ||
* @version 1.0.1, 7/20/2017 | ||
* @since 1.0.1 | ||
*/ | ||
class TinifyComponent(project: Project) : AbstractProjectComponent(project) { | ||
|
||
|
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/com/alvincezy/tinypic2/model/VirtualFileAware.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.alvincezy.tinypic2.model | ||
|
||
import com.intellij.openapi.vfs.VirtualFile | ||
|
||
/** | ||
* Created by alvince on 2017/7/21. | ||
* | ||
* @author [email protected] | ||
* @version 1.0.1, 7/21/2017 | ||
*/ | ||
class VirtualFileAware(val file: VirtualFile) { | ||
|
||
var fileUri = file.url | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other?.javaClass != javaClass) return false | ||
|
||
other as VirtualFileAware | ||
|
||
if (fileUri != other.fileUri) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return fileUri.hashCode() | ||
} | ||
|
||
override fun toString(): String { | ||
return fileUri | ||
} | ||
} |