Skip to content

Commit c1e36f6

Browse files
committed
v0.0.5
0 parents  commit c1e36f6

File tree

10 files changed

+421
-0
lines changed

10 files changed

+421
-0
lines changed

.gitignore

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/kotlin,windows,java,jetbrains+all
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=kotlin,windows,java,jetbrains+all
4+
5+
### Java ###
6+
# Compiled class file
7+
*.class
8+
9+
# Log file
10+
*.log
11+
12+
# BlueJ files
13+
*.ctxt
14+
15+
# Mobile Tools for Java (J2ME)
16+
.mtj.tmp/
17+
18+
# Package Files #
19+
*.jar
20+
*.war
21+
*.nar
22+
*.ear
23+
*.zip
24+
*.tar.gz
25+
*.rar
26+
27+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
28+
hs_err_pid*
29+
30+
### JetBrains+all ###
31+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
32+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
33+
34+
# User-specific stuff
35+
.idea/**/workspace.xml
36+
.idea/**/tasks.xml
37+
.idea/**/usage.statistics.xml
38+
.idea/**/dictionaries
39+
.idea/**/shelf
40+
41+
# Generated files
42+
.idea/**/contentModel.xml
43+
44+
# Sensitive or high-churn files
45+
.idea/**/dataSources/
46+
.idea/**/dataSources.ids
47+
.idea/**/dataSources.local.xml
48+
.idea/**/sqlDataSources.xml
49+
.idea/**/dynamic.xml
50+
.idea/**/uiDesigner.xml
51+
.idea/**/dbnavigator.xml
52+
53+
# Gradle
54+
.idea/**/gradle.xml
55+
.idea/**/libraries
56+
57+
# Gradle and Maven with auto-import
58+
# When using Gradle or Maven with auto-import, you should exclude module files,
59+
# since they will be recreated, and may cause churn. Uncomment if using
60+
# auto-import.
61+
# .idea/artifacts
62+
# .idea/compiler.xml
63+
# .idea/jarRepositories.xml
64+
# .idea/modules.xml
65+
# .idea/*.iml
66+
# .idea/modules
67+
# *.iml
68+
# *.ipr
69+
70+
# CMake
71+
cmake-build-*/
72+
73+
# Mongo Explorer plugin
74+
.idea/**/mongoSettings.xml
75+
76+
# File-based project format
77+
*.iws
78+
79+
# IntelliJ
80+
out/
81+
82+
# mpeltonen/sbt-idea plugin
83+
.idea_modules/
84+
85+
# JIRA plugin
86+
atlassian-ide-plugin.xml
87+
88+
# Cursive Clojure plugin
89+
.idea/replstate.xml
90+
91+
# Crashlytics plugin (for Android Studio and IntelliJ)
92+
com_crashlytics_export_strings.xml
93+
crashlytics.properties
94+
crashlytics-build.properties
95+
fabric.properties
96+
97+
# Editor-based Rest Client
98+
.idea/httpRequests
99+
100+
# Android studio 3.1+ serialized cache file
101+
.idea/caches/build_file_checksums.ser
102+
103+
### JetBrains+all Patch ###
104+
# Ignores the whole .idea folder and all .iml files
105+
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
106+
107+
.idea/
108+
109+
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
110+
111+
*.iml
112+
modules.xml
113+
.idea/misc.xml
114+
*.ipr
115+
116+
# Sonarlint plugin
117+
.idea/sonarlint
118+
119+
### Kotlin ###
120+
# Compiled class file
121+
122+
# Log file
123+
124+
# BlueJ files
125+
126+
# Mobile Tools for Java (J2ME)
127+
128+
# Package Files #
129+
130+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
131+
132+
### Windows ###
133+
# Windows thumbnail cache files
134+
Thumbs.db
135+
Thumbs.db:encryptable
136+
ehthumbs.db
137+
ehthumbs_vista.db
138+
139+
# Dump file
140+
*.stackdump
141+
142+
# Folder config file
143+
[Dd]esktop.ini
144+
145+
# Recycle Bin used on file shares
146+
$RECYCLE.BIN/
147+
148+
# Windows Installer files
149+
*.cab
150+
*.msi
151+
*.msix
152+
*.msm
153+
*.msp
154+
155+
# Windows shortcuts
156+
*.lnk
157+
158+
# End of https://www.toptal.com/developers/gitignore/api/kotlin,windows,java,jetbrains+all

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Copyright (c) 2021 ChenY <xfcypc@foxmail.com>
2+
CopyThePath is licensed under Mulan PSL v2.
3+
You can use this software according to the terms and conditions of the Mulan PSL v2.
4+
You may obtain a copy of Mulan PSL v2 at:
5+
http://license.coscl.org.cn/MulanPSL2
6+
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7+
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8+
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9+
See the Mulan PSL v2 for more details.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# CopyThePath
2+
3+
TODO

resources/META-INF/plugin.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<idea-plugin>
2+
<id>me.xfcy.idea.CopyThePath</id>
3+
<name>Copy The Path</name>
4+
<version>0.0.5</version>
5+
<vendor email="xfcypc@foxmail.com" url="https://www.xfcy.me/">ChenY Wang</vendor>
6+
7+
<description><![CDATA[
8+
The function for this plugin is to copy the relative path from the project root directory of the files which has been opened in the edtior.<br>
9+
[Usage]<br>
10+
menu bar->Tools->Copy The Path->Copy The Path<br>
11+
or binding shortcut like ctrl+shift+c.<br>
12+
Then paste it to anywhere you want.<br>
13+
Plugin icon is from RemixIcon.<br>
14+
<br>
15+
这个插件可以复制编辑器中打开的文件相对于其所在项目根目录的相对路径。<br>
16+
[使用方式]<br>
17+
菜单栏->Tools->Copy The Path->Copy The Path<br>
18+
或者给他绑定一个快捷键,比如 ctrl+shift+c<br>
19+
然后在需要使用的地方粘贴。<br>
20+
插件图标来自RemixIcon。<br>
21+
]]></description>
22+
23+
<change-notes><![CDATA[
24+
1. Refactor the project with Kotlin.<br>
25+
2. Remove deprecated methods.<br>
26+
3. Add plugin icons, icons from RemixIcon.<br>
27+
4. <b><font color="red">I lost the code from the previous version, so this version is a complete rewrite. If you encounter that you can't read the previous configuration, or if the configured shortcuts don't work, please do the configuration again XD I'm sorry about that!</font></b>
28+
]]></change-notes>
29+
30+
<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
31+
<idea-version since-build="173.0"/>
32+
33+
<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
34+
on how to target different products -->
35+
<depends>com.intellij.modules.platform</depends>
36+
37+
<extensions defaultExtensionNs="com.intellij">
38+
<!-- Add your extensions here -->
39+
<projectConfigurable parentId="tools" displayName="CopyThePath" id="tools.ChenY.CopyThePath" instance="me.xfcy.idea.copy_the_path.setting.SettingConfigurable" />
40+
<projectService serviceImplementation="me.xfcy.idea.copy_the_path.setting.SettingState" />
41+
</extensions>
42+
43+
<actions>
44+
<!-- Add your actions here -->
45+
<group id="me.xfcy.idea.copy_the_path.action_group"
46+
text="Copy the Path"
47+
popup="true">
48+
<add-to-group group-id="ToolsMenu" anchor="last"/>
49+
<action id="me.xfcy.idea.copy_the_path.action.CopyAction"
50+
class="me.xfcy.idea.copy_the_path.action.CopyAction"
51+
text="_Copy the Path" description="Copy the Path">
52+
</action>
53+
</group>
54+
</actions>
55+
56+
</idea-plugin>

resources/META-INF/pluginIcon.svg

Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright (c) 2021 ChenY <xfcypc@foxmail.com>
3+
* CopyThePath is licensed under Mulan PSL v2.
4+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
5+
* You may obtain a copy of Mulan PSL v2 at:
6+
* http://license.coscl.org.cn/MulanPSL2
7+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10+
* See the Mulan PSL v2 for more details.
11+
*/
12+
package me.xfcy.idea.copy_the_path.action
13+
14+
import com.intellij.openapi.actionSystem.AnAction
15+
import com.intellij.openapi.actionSystem.AnActionEvent
16+
import com.intellij.openapi.actionSystem.CommonDataKeys
17+
import me.xfcy.idea.copy_the_path.setting.SettingState
18+
import java.awt.Toolkit
19+
import java.awt.datatransfer.StringSelection
20+
21+
class CopyAction: AnAction() {
22+
23+
override fun actionPerformed(e: AnActionEvent) {
24+
25+
val project = e.project
26+
val projectPath = project?.basePath ?: ""
27+
28+
val state = project?.getService(SettingState::class.java)
29+
val prefix = state?.pathPrefix ?: ""
30+
31+
val file = CommonDataKeys.VIRTUAL_FILE.getData(e.dataContext)
32+
var filePath = file?.canonicalPath ?: ""
33+
34+
if (projectPath.isNotBlank() && filePath.startsWith(projectPath)) {
35+
val subStart = projectPath.length + 1
36+
filePath = prefix + filePath.substring(subStart)
37+
}
38+
39+
val stringSelection = StringSelection(filePath)
40+
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
41+
clipboard.setContents(stringSelection, stringSelection)
42+
43+
}
44+
45+
override fun update(e: AnActionEvent) {
46+
e.presentation.isEnabledAndVisible = (e.project != null)
47+
}
48+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright (c) 2021 ChenY <xfcypc@foxmail.com>
3+
* CopyThePath is licensed under Mulan PSL v2.
4+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
5+
* You may obtain a copy of Mulan PSL v2 at:
6+
* http://license.coscl.org.cn/MulanPSL2
7+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10+
* See the Mulan PSL v2 for more details.
11+
*/
12+
package me.xfcy.idea.copy_the_path.setting
13+
14+
import com.intellij.openapi.project.Project
15+
import com.intellij.ui.components.JBLabel
16+
import com.intellij.ui.components.JBTextField
17+
import com.intellij.util.ui.FormBuilder
18+
import javax.swing.JPanel
19+
import javax.swing.event.DocumentEvent
20+
import javax.swing.event.DocumentListener
21+
22+
class SettingComponent(project: Project) {
23+
24+
private var prefix = ""
25+
private val examplePath = "path/to/your/file.ext"
26+
27+
val mainPanel: JPanel
28+
val pathPrefixText: JBTextField
29+
val preview: JBLabel
30+
31+
init {
32+
val state = SettingState.getInstance(project)
33+
prefix = state?.pathPrefix ?: ""
34+
pathPrefixText = JBTextField(prefix)
35+
preview = JBLabel(prefix + examplePath)
36+
37+
mainPanel = FormBuilder.createFormBuilder()
38+
.addLabeledComponent(JBLabel("Path prefix: "), pathPrefixText, 1, false)
39+
.addLabeledComponent(JBLabel("Preview: "), preview, 1, false)
40+
.addComponentFillVertically(JPanel(), 0)
41+
.panel
42+
43+
pathPrefixText.document.addDocumentListener(object: DocumentListener {
44+
override fun insertUpdate(p0: DocumentEvent?) { changePreview() }
45+
override fun removeUpdate(p0: DocumentEvent?) { changePreview() }
46+
override fun changedUpdate(p0: DocumentEvent?) { changePreview() }
47+
fun changePreview() {
48+
preview.text = pathPrefixText.text + examplePath
49+
}
50+
})
51+
}
52+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright (c) 2021 ChenY <xfcypc@foxmail.com>
3+
* CopyThePath is licensed under Mulan PSL v2.
4+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
5+
* You may obtain a copy of Mulan PSL v2 at:
6+
* http://license.coscl.org.cn/MulanPSL2
7+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10+
* See the Mulan PSL v2 for more details.
11+
*/
12+
package me.xfcy.idea.copy_the_path.setting
13+
14+
import com.intellij.openapi.options.Configurable
15+
import com.intellij.openapi.project.Project
16+
import javax.swing.JComponent
17+
18+
class SettingConfigurable(private val project: Project): Configurable {
19+
20+
private val component = SettingComponent(project)
21+
22+
override fun createComponent(): JComponent? {
23+
return component.mainPanel
24+
}
25+
26+
override fun isModified(): Boolean {
27+
val state = SettingState.getInstance(project)
28+
val prefix = state?.pathPrefix ?: ""
29+
return (prefix != component.pathPrefixText.text)
30+
}
31+
32+
override fun apply() {
33+
val state = SettingState.getInstance(project)
34+
state?.pathPrefix = component.pathPrefixText.text
35+
}
36+
37+
override fun getDisplayName(): String {
38+
return "Copy the Path"
39+
}
40+
41+
override fun reset() {
42+
val state = SettingState.getInstance(project)
43+
component.pathPrefixText.text = state?.pathPrefix
44+
}
45+
}

0 commit comments

Comments
 (0)