Skip to content

[Feat] right click the mouse and the toolbar will display the corresp… #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
90c5f43
[Feat] right click the mouse and the toolbar will display the corresp…
RAOE Nov 7, 2024
3c304bd
[Feat] right click and get code Text
RAOE Nov 7, 2024
c3b579c
[Feat] Code Snap Drop-down tab option feature development
RAOE Nov 10, 2024
5a491a4
[Feat] Code Snap Drop-down tab option feature development
RAOE Nov 10, 2024
294ba61
[Feat] Code Snap Drop-down tab option feature development
RAOE Nov 10, 2024
b107cf3
[Feat] Code Snap Drop-down tab option feature development
RAOE Nov 10, 2024
cf3c9ba
[UPDATE] DOC update
RAOE Nov 13, 2024
990db10
Revert "[UPDATE] DOC update"
RAOE Nov 13, 2024
19c0470
[feature_dev_0.1] CodeSnap Configuration Setting function develop
RAOE Nov 13, 2024
bb20a8e
[feature_dev_0.1] CodeSnap Configuration Setting function develop
RAOE Nov 13, 2024
3c6c9f1
[feature_dev_0.1] develop the Default Save Path Text
RAOE Nov 17, 2024
7499b72
[feature_dev_0.1] UI design
RAOE Nov 17, 2024
8ffd539
[Feat] CodeSnap Configuration Setting function develop
RAOE Nov 13, 2024
fa826d5
[Feat] develop the Default Save Path Text
RAOE Nov 17, 2024
420d604
[Feat] UI design
RAOE Nov 17, 2024
40db024
Merge branch 'feautre_dev_0.1' of https://github.com/RAOE/CodeSnap.id…
RAOE Nov 17, 2024
743fc94
[Feat] optimized package management and annotation
RAOE Feb 12, 2025
f35826e
[Feat] lib->codesnap.exe
RAOE Feb 13, 2025
b902f82
[Feat] lib->codesnap.exe execute cli from windows
RAOE Feb 18, 2025
4ed7224
[Feat] lib->codesnap.exe execute cli from windows
RAOE Feb 18, 2025
169ba4b
[Feat] lib->codesnap.exe execute cli from windows
RAOE Feb 18, 2025
9882dc5
[Feat] Improve the generation methods for JPG and SVG by default.
RAOE Feb 20, 2025
c8588f6
[Feat] Improve the generation methods for JPG and SVG by default.
RAOE Feb 20, 2025
fd088e9
[Feat] Improve the generation methods for JPG and SVG by default.
RAOE Feb 20, 2025
99dd048
[Feat] Improve the generation methods for JPG and SVG by default.
RAOE Feb 20, 2025
3365021
[Feat] ASCII into clipborad function develop
RAOE Feb 22, 2025
fd8502f
[Feat] release update
RAOE Feb 22, 2025
95040b3
[Feat] Since the -c command may cause content overflow due to its exc…
RAOE Feb 24, 2025
b227ed5
[Feat] Since the -c command may cause content overflow due to its exc…
RAOE Feb 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .run/Run Plugin.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="scriptParameters" value="--info --continuous --build-cache" />
<option name="taskDescriptions">
<list />
</option>
Expand All @@ -22,4 +22,4 @@
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
</component>
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pluginGroup = com.github.raoe.codesnapidea
pluginName = CodeSnap.idea
pluginRepositoryUrl = https://github.com/RAOE/CodeSnap.idea
# SemVer format -> https://semver.org
pluginVersion = 0.0.1
pluginVersion = 0.0.2

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 233
pluginUntilBuild = 242.*
pluginUntilBuild = 243.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
Expand Down
Binary file added images/CodeSnap.idea原型图V0.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/kotlin/com/github/raoe/codesnapidea/MyBundle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.jetbrains.annotations.PropertyKey

@NonNls
private const val BUNDLE = "messages.MyBundle"
//just a test
object MyBundle : DynamicBundle(BUNDLE) {

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.raoe.codesnapidea.actions
import com.intellij.openapi.actionSystem.AnActionEvent
/**
* ClassName:AsciiCodeSnapAction
Package:com.github.raoe.codesnapidea.actions
@DATE:10/11/2024 4:02 pm
@Author:XuYuanFeng
*/
class AsciiCodeSnapAction: DefaultCodeSnapAction() {
override fun actionPerformed(event: AnActionEvent) {
outputToClipboard = true;
outputToImg = false;
super.actionPerformed(event)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package com.github.raoe.codesnapidea.actions
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import groovy.util.logging.Slf4j
import java.io.BufferedReader
import java.io.File
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.util.UUID
import javax.swing.Icon
import kotlin.jvm.java
import org.slf4j.LoggerFactory
/**
* ClassName:DefaultCodeSnapAction
Package:com.github.raoe.codesnapidea.actions
@DATE:10/11/2024 3:13 pm
@Author:XuYuanFeng
*/
@Slf4j
open class DefaultCodeSnapAction: AnAction() {
val DEFAULT_CODE_SNAP_PATH = "C:\\code_snap.idea\\CodeSnap.idea\\src\\main\\resources\\lib\\codesnap.exe";
//默认png
var formatter = ".png";
//生成到桌面还是剪贴板 默认剪贴板
var outputToClipboard = true;
//生成类型为img还是ascii
var outputToImg = true;
companion object {
// 初始化 Slf4j 日志记录器
private val logger = LoggerFactory.getLogger(DefaultCodeSnapAction::class.java)
}
/**
* 默认数据
* @param event
*/
override fun actionPerformed(event: AnActionEvent) {
val editor: Editor? = event.getData(CommonDataKeys.EDITOR)
val project: Project? = event.getData(CommonDataKeys.PROJECT)
var selectedText: String? = editor?.selectionModel?.selectedText
val message = StringBuilder()
var codesnapExePath = DEFAULT_CODE_SNAP_PATH;
var codesnapExeExists = File(codesnapExePath).exists()
if(!codesnapExeExists){
codesnapExePath = getCodesnapExePath()
codesnapExeExists = File(codesnapExePath).exists()
}
logger.info("codesnapExePath: $codesnapExePath");

if (!selectedText.isNullOrEmpty()) {
if (codesnapExeExists) {
try {
executeCommand(codesnapExePath, selectedText, message,formatter,outputToImg)
message.append("\n process execute success!")
} catch (e: IOException) {
message.append("\n执行 codesnap.exe excuted failed! Error message:${e.message}")
}
} else {
message.append("\ncan't find codesnap.exe file,execute failed!")
}
} else {
message.append("No text selected!")
}

val title = "CodeSnap: Capture Code Snapshot"
val icon: Icon = Messages.getInformationIcon()
Messages.showMessageDialog(
project,
message.toString(),
title,
icon
)
}

/**
* 获取codesnap.exe路径
*/
fun getCodesnapExePath(): String {
val userHome = System.getProperty("user.home")
val targetDir = File("$userHome/codeSnap")
val targetFile = File(targetDir, "codesnap.exe")

// 如果目标文件已经存在,直接返回路径
if (targetFile.exists()) {
logger.info("codesnap.exe already exists at ${targetFile.absolutePath}")
return targetFile.absolutePath
}

// 确保目标文件夹存在
if (!targetDir.exists()) {
targetDir.mkdirs()
}
val resourcePath = "/lib/codesnap.exe"
val inputStream: InputStream? = Class.forName("com.github.raoe.codesnapidea.actions.DefaultCodeSnapAction").getResourceAsStream(resourcePath)
if (inputStream == null) {
logger.info("Unable to find codesnap.exe in resources: $resourcePath")
return ""
}
// 将资源文件写入目标路径
try {
Files.copy(inputStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
logger.info("Successfully copied codesnap.exe to ${targetFile.absolutePath}")
return targetFile.absolutePath
} catch (e: Exception) {
logger.error("Failed to copy codesnap.exe: ${e.message}", e)
return ""
}
}
/**
* 执行命令
*/
private fun executeCommand(codesnapExePath: String, selectedText: String, message: StringBuilder,format: String,outputImgType: Boolean):String {
try {
val userHome = System.getProperty("user.home")
val tempDir = File(userHome, "codeSnap")
if (!tempDir.exists()) {
tempDir.mkdirs()
}
val tempFile = File(tempDir, UUID.randomUUID().toString()+".txt")
tempFile.writeText(selectedText)
val tempFilePath = tempFile.absolutePath
var command = """$codesnapExePath -f $tempFilePath --output clipboard"""
if(outputToClipboard){
command = """$codesnapExePath -f "$tempFilePath" --output clipboard"""
}else{
command = "$codesnapExePath -f $tempFilePath --output $userHome\\desktop\\output"+format
}
if(outputImgType){
command = command +""" --type image"""
}else{
command = command +""" --type ascii"""
}
println("command: $command")
val process = Runtime.getRuntime().exec(command)
val stdInput = BufferedReader(InputStreamReader(process.getInputStream()))
var s: String?
logger.info("命令执行中...")
val sb = StringBuilder();
while ((stdInput.readLine().also { s = it }) != null) {
sb.append(s);
println(s)
}
// 捕获错误输出
val stdError = BufferedReader(InputStreamReader(process.getErrorStream()))
logger.info("错误输出:")
while ((stdError.readLine().also { s = it }) != null) {
println(s)
}
val exitCode = process.waitFor()
logger.info("命令执行完毕,退出码: $exitCode")
//清空临时文件
if (tempFile.exists()){
tempFile.delete()
}
return sb.toString();
} catch (e: Exception) {
e.printStackTrace()
return "执行命令失败!错误信息:${e.message}"
}
return ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.raoe.codesnapidea.actions
import com.intellij.openapi.actionSystem.AnActionEvent
import groovy.util.logging.Slf4j
/**
* ClassName:DefaultCodeSnapAction
Package:com.github.raoe.codesnapidea.actions
@DATE:10/11/2024 3:13 pm
@Author:XuYuanFeng
*/
@Slf4j
open class DefaultDeskTopCodeSnapAction: DefaultCodeSnapAction() {

override fun actionPerformed(event: AnActionEvent) {
outputToClipboard = false;
super.actionPerformed(event)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.raoe.codesnapidea.actions
import com.intellij.openapi.actionSystem.AnActionEvent
/**
* ClassName:JpgCodeSnapAction
Package:com.github.raoe.codesnapidea.actions
@DATE:10/11/2024 3:15 pm
@Author:XuYuanFeng
*/

class PngCodeSnapAction: DefaultCodeSnapAction() {
/**
* 执行命令
* @param event
*/
override fun actionPerformed(event: AnActionEvent) {
super.actionPerformed(event)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.raoe.codesnapidea.actions

import com.intellij.openapi.actionSystem.AnActionEvent

/**
* ClassName:SvgCodeSnapAction
Package:com.github.raoe.codesnapidea.actions
@DATE:10/11/2024 3:14 pm
@Author:XuYuanFeng
*/
//继承Default
class SvgCodeSnapAction: DefaultCodeSnapAction() {
//重写actionPerformed
override fun actionPerformed(event: AnActionEvent) {
formatter = ".svg"
outputToClipboard = true;
super.actionPerformed(event)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.github.raoe.codesnapidea.actions.pop

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.project.Project
import javax.swing.Icon

/**
* ClassName:PopupDialogAction
Package:com.github.raoe.codesnapidea.actions
@DATE:06/11/2024 10:34 pm
@Author:XuYuanFeng
*/

class PopupDialogAction: AnAction {
constructor() : super() {
// This default constructor is used by the IntelliJ Platform framework to instantiate this class based on plugin.xml
// declarations. Only needed in `PopupDialogAction` class because a second constructor is overridden.
}

constructor(text: String?, description: String?, icon: Icon?) : super(text, description, icon) {
// This constructor is used to support dynamically added menu actions.
// It sets the text, description to be displayed for the menu item.
// Otherwise, the default AnAction constructor is used by the IntelliJ Platform.
}

override fun actionPerformed(event: AnActionEvent) {
ShowSettingsUtil.getInstance().showSettingsDialog(event.getProject(), "OtherSettings");
}

override fun update(event: AnActionEvent) {
// Set the availability based on whether a project is open
val project: Project? = event.project
event.presentation.isEnabledAndVisible = project != null
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.github.raoe.codesnapidea.configuration;

import CodeSnapSettingsUI

import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.ConfigurationException
import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.Nullable
import javax.swing.JComponent


/**
* ClassName:CodeSnapConfiguration
* Package:com.github.raoe.codesnapidea.configuration
*
* @DATE:13/11/2024 9:34 pm
* @Author:XuYuanFeng TODO:
*/
class CodeSnap: Configurable {
private var mySettingsUI: CodeSnapSettingsUI? = null
@Nls
override fun getDisplayName(): String {
return "CodeSnap Configuration" // 配置页面的显示名称
}

@Nullable
override fun getHelpTopic(): String? {
return "help-topic-id" // 配置页面的帮助主题ID
}

@Nullable
override fun createComponent(): JComponent? {
mySettingsUI = CodeSnapSettingsUI()
return mySettingsUI?.getPanel() // 返回配置界面的组件
}

override fun isModified(): Boolean {
return mySettingsUI?.isModified() ?: false // 检查设置是否被修改
}

@Throws(ConfigurationException::class)
override fun apply() {
mySettingsUI?.apply() // 应用设置
}

override fun reset() {
mySettingsUI?.reset() // 重置设置
}

override fun disposeUIResources() {
mySettingsUI = null // 释放UI资源
}

}
Loading
Loading