-
Notifications
You must be signed in to change notification settings - Fork 17
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
8 changed files
with
157 additions
and
72 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
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/github/patou/gitmoji/GitmojiCellRenderer.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,25 @@ | ||
package com.github.patou.gitmoji | ||
|
||
import com.intellij.vcs.log.ui.table.VcsLogGraphTable | ||
import com.intellij.vcs.log.ui.table.VcsLogIconCellRenderer | ||
|
||
class GitmojiCellRenderer : VcsLogIconCellRenderer() { | ||
override fun customize( | ||
table: VcsLogGraphTable, | ||
value: Any?, | ||
selected: Boolean, | ||
hasFocus: Boolean, | ||
row: Int, | ||
column: Int | ||
) { | ||
if (value == null || value !is GitmojiData) { | ||
return | ||
} | ||
if (value.name == "anguished") { | ||
append("-") | ||
return | ||
} | ||
icon = value.getIcon() | ||
toolTipText = value.localeDescription | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/kotlin/com/github/patou/gitmoji/GitmojiCustomColumn.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,47 @@ | ||
package com.github.patou.gitmoji | ||
|
||
import com.intellij.ide.util.PropertiesComponent | ||
import com.intellij.openapi.project.ProjectManager | ||
import com.intellij.vcs.log.ui.table.GraphTableModel | ||
import com.intellij.vcs.log.ui.table.VcsLogGraphTable | ||
import com.intellij.vcs.log.ui.table.column.VcsLogCustomColumn | ||
import javax.swing.table.TableCellRenderer | ||
|
||
|
||
@Suppress("UnstableApiUsage") | ||
class GitmojiCustomColumn : VcsLogCustomColumn<GitmojiData> { | ||
override val id: String | ||
get() = "gitmoji" | ||
override val isDynamic: Boolean | ||
get() = true | ||
override val localizedName: String | ||
get() = "Gitmoji" | ||
override val isResizable: Boolean | ||
get() = false | ||
|
||
override fun createTableCellRenderer(table: VcsLogGraphTable): TableCellRenderer { | ||
return GitmojiCellRenderer() | ||
} | ||
|
||
override fun isEnabledByDefault(): Boolean { | ||
val projectInstance = PropertiesComponent.getInstance(ProjectManager.getInstance().defaultProject) | ||
val useUnicode = projectInstance.getBoolean(CONFIG_USE_UNICODE, false) | ||
return useUnicode | ||
} | ||
|
||
override fun getStubValue(model: GraphTableModel): GitmojiData { | ||
return GitmojiData("anguished", "😧", "anguished", "anguished") | ||
} | ||
|
||
override fun getValue(model: GraphTableModel, row: Int): GitmojiData? { | ||
model.getCommitMetadata(row).let { | ||
for (moji in Gitmojis.gitmojis) { | ||
if (it.subject.contains(moji.emoji) || it.subject.contains(moji.code)) { | ||
return moji | ||
} | ||
} | ||
} | ||
return null | ||
} | ||
|
||
} |
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,26 @@ | ||
package com.github.patou.gitmoji | ||
|
||
import com.intellij.openapi.util.SystemInfo | ||
|
||
fun defaultDisplayType(): String { | ||
return if (SystemInfo.isWindows) "icon" else "emoji" | ||
} | ||
|
||
fun insertAt(target: String, position: Int, insert: String): String { | ||
val targetLen = target.length | ||
require(!(position < 0 || position > targetLen)) { "position=$position" } | ||
if (insert.isEmpty()) { | ||
return target | ||
} | ||
if (position == 0) { | ||
return insert + target | ||
} else if (position == targetLen) { | ||
return target + insert | ||
} | ||
val insertLen = insert.length | ||
val buffer = CharArray(targetLen + insertLen) | ||
target.toCharArray(buffer, 0, 0, position) | ||
insert.toCharArray(buffer, position, 0, insertLen) | ||
target.toCharArray(buffer, position + insertLen, position, targetLen) | ||
return String(buffer) | ||
} |
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 |
---|---|---|
@@ -1,32 +1,54 @@ | ||
package com.github.patou.gitmoji | ||
|
||
import com.intellij.openapi.util.SystemInfo | ||
import com.google.gson.Gson | ||
import okhttp3.* | ||
import okhttp3.Request.Builder | ||
import java.io.IOException | ||
|
||
class Gitmojis(val gitmojis: List<Gitmoji>) { | ||
class Gitmoji(val emoji: String, val code: String, val description: String, val name: String) | ||
object Gitmojis { | ||
val gitmojis = ArrayList<GitmojiData>() | ||
|
||
companion object { | ||
fun defaultDisplayType(): String { | ||
return if (SystemInfo.isWindows) "icon" else "emoji" | ||
} | ||
init { | ||
loadGitmojiFromHTTP() | ||
} | ||
|
||
private fun loadGitmojiFromHTTP() { | ||
val client = OkHttpClient().newBuilder().addInterceptor(SafeGuardInterceptor()).build() | ||
val request: Request = Builder() | ||
.url("https://gitmoji.dev/api/gitmojis") | ||
.build() | ||
client.newCall(request).enqueue(object : Callback { | ||
override fun onFailure(call: Call, e: IOException) { | ||
loadDefaultGitmoji() | ||
} | ||
|
||
fun insertAt(target: String, position: Int, insert: String): String { | ||
val targetLen = target.length | ||
require(!(position < 0 || position > targetLen)) { "position=$position" } | ||
if (insert.isEmpty()) { | ||
return target | ||
override fun onResponse(call: Call, response: Response) { | ||
response.use { | ||
if (!response.isSuccessful) loadDefaultGitmoji() | ||
else { | ||
loadGitmoji(response.body!!.string()) | ||
} | ||
} | ||
} | ||
if (position == 0) { | ||
return insert + target | ||
} else if (position == targetLen) { | ||
return target + insert | ||
}) | ||
} | ||
|
||
private fun loadDefaultGitmoji() { | ||
javaClass.getResourceAsStream("/gitmojis.json").use { inputStream -> | ||
if (inputStream != null) { | ||
val text = inputStream.bufferedReader().readText() | ||
loadGitmoji(text) | ||
} | ||
val insertLen = insert.length | ||
val buffer = CharArray(targetLen + insertLen) | ||
target.toCharArray(buffer, 0, 0, position) | ||
insert.toCharArray(buffer, position, 0, insertLen) | ||
target.toCharArray(buffer, position + insertLen, position, targetLen) | ||
return String(buffer) | ||
} | ||
} | ||
} | ||
|
||
private fun loadGitmoji(text: String) { | ||
Gson().fromJson(text, JsonGitmojis::class.java).also { | ||
it.gitmojis.forEach { gitmoji -> | ||
gitmojis.add(GitmojiData(gitmoji.code, gitmoji.emoji, gitmoji.description, gitmoji.name)) | ||
} | ||
} | ||
GitmojiLocale.loadTranslations() | ||
} | ||
|
||
} |
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,5 @@ | ||
package com.github.patou.gitmoji | ||
|
||
class JsonGitmojis(val gitmojis: List<JsonGitmoji>) { | ||
class JsonGitmoji(val emoji: String, val code: String, val description: String, val name: String) | ||
} |
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