Skip to content

Commit e458813

Browse files
committed
✨ feat: 增加context meun功能
1 parent c674775 commit e458813

File tree

6 files changed

+113
-85
lines changed

6 files changed

+113
-85
lines changed

README.md

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
# Flow.Launcher.Plugin.RecentProjectsOpen
22

3-
A plugin that allows users to quickly open recent projects with ease.
3+
A plugin that enables quick access to recent projects across various IDEs like VSCode and PDF readers efficiency.
44

55
## Installation
66

77
Download from the store
88

9+
## Supported applications
10+
11+
- [X] visual studio code
12+
- [X] pycharm
13+
- [X] clion
14+
- [X] goland
15+
- [X] intellij idea
16+
- [X] android studio
17+
- [X] cursor
18+
- [X] sumatra pdf
19+
- [ ] vscode ssh
20+
21+
You can access different IDEs using the following format:
22+
23+
```python
24+
ABBREVIATE = {
25+
"vsc": "VISUAL_STUDIO_CODE",
26+
"py": "PYCHARM",
27+
"cl": "CLION",
28+
"go": "GOLAND",
29+
"in": "INTELLIJ_IDEA",
30+
"as": "ANDROID_STUDIO",
31+
"cur":"CURSOR"
32+
}
33+
```
34+
935
## Configuration
1036

1137
To configure the `RecentProjectsOpen` plugin, you should edit the plugin's configuration file.
@@ -24,8 +50,8 @@ To configure the `RecentProjectsOpen` plugin, you should edit the plugin's confi
2450
- Add or modify the paths for your IDEs and their storage files as shown in the example above.
2551
2652
```plaintext
27-
VISUAL_STUDIO_CODE_DOWNLOAD=D:/VSCode/bin/code
28-
VISUAL_STUDIO_CODE_STORAGE=C:/Users/YourUsername/AppData/Roaming/Code/User/globalStorage/storage.json
53+
VSCODE_DOWNLOAD=D:/VSCode/bin/code
54+
VSCODE_STORAGE=C:/Users/YourUsername/AppData/Roaming/Code/User/globalStorage/storage.json
2955
ANDROID_STUDIO_DOWNLOAD=D:/Android Studio/bin/studio64.exe
3056
ANDROID_STUDIO_STORAGE=C:/Users/YourUsername/AppData/Roaming/Google/AndroidStudio2024.1/options/recentProjects.xml
3157
INTELLIJ_IDEA_DOWNLOAD=D:/IntelliJ IDEA 2024.3/bin/idea64.exe
@@ -47,30 +73,7 @@ To configure the `RecentProjectsOpen` plugin, you should edit the plugin's confi
4773
- **Permissions**: Make sure that Flow Launcher has the necessary permissions to access the specified directories and files.
4874
- **Backup**: Before making changes to the `.env` file, create a backup copy in case you need to revert to the original settings.
4975

50-
## Usage and Supported applications
51-
52-
- [X] visual studio code
53-
- [X] pycharm
54-
- [X] clion
55-
- [X] goland
56-
- [X] intellij idea
57-
- [X] android studio
58-
- [X] cursor
59-
- [X] sumatra pdf
60-
61-
You can access different IDEs using the following format:
62-
63-
```python
64-
ABBREVIATE = {
65-
"vsc": "VISUAL_STUDIO_CODE",
66-
"py": "PYCHARM",
67-
"cl": "CLION",
68-
"go": "GOLAND",
69-
"in": "INTELLIJ_IDEA",
70-
"as": "ANDROID_STUDIO",
71-
"cur":"CURSOR"
72-
}
73-
```
76+
## Usage
7477

7578
To open a project named "MyProject" in Visual Studio Code, you would use:
7679

@@ -86,11 +89,16 @@ r vsc 空
8689

8790
![1733284760505](image/README/1733284760505.png)
8891

92+
context menu
93+
94+
![1742873448581](image/README/1742873448581.png)
95+
8996
## Feature
9097

9198
- [X] fuzzy search
9299
- [X] support pinyin
93100
- [X] prevent configurations from disappearing after updates
101+
- [X] open in file explorer and copy absolute path
94102

95103
## Contribute
96104

image/README/1742873448581.png

26.7 KB
Loading

plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"ID": "7f805128-d4f3-4bfa-bd6e-b4ca0ff58ee9",
33
"ActionKeyword": "r",
44
"Name": "RecentProjectsOpen",
5-
"Description": "A plugin that allows users to quickly open recent projects with ease.",
5+
"Description": "A plugin that enables quick access to recent projects across various IDEs like VSCode and PDF readers efficiency.",
66
"Author": "Attack825",
7-
"Version": "1.2.1",
7+
"Version": "1.2.2",
88
"Language": "python",
99
"Website": "https://github.com/Attack825/RecentProjectsOpen",
1010
"IcoPath": "icons/app.png",

src/core/main.py

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919

2020
class RecentProjectsOpen(FlowLauncher):
21+
def __init__(self):
22+
super().__init__()
23+
self.context = {}
24+
2125
def query(self, param: str) -> list:
2226
# 读取参数,解析acronyms和query
2327
args = param.strip()
@@ -52,7 +56,7 @@ def query(self, param: str) -> list:
5256
try:
5357
app = ConcreteFactory.create_app(app_name, app_download, app_storage)
5458
projects = app.get_projects()
55-
res = Fuzzy_Filter.query_filter(query, projects)
59+
res = Fuzzy_Filter.query_filter(query, projects) # 项目查询结果
5660
except NotImplementedError:
5761
return MessageDTO.asWarnFlowMessage(
5862
"this app is not supported", "Welcome to provide PR"
@@ -68,36 +72,77 @@ def query(self, param: str) -> list:
6872
app_download,
6973
)
7074

71-
def open_url(self, url):
72-
webbrowser.open(url)
73-
74-
def context_menu(self, data):
75+
def context_menu(self, data: str) -> list:
7576
"""
76-
TODO:
77-
使用软件打开
7877
使用任务管理器打开文件夹
7978
复制文件夹路径
8079
"""
81-
pass
80+
if data is None:
81+
return MessageDTO.asDebugFlowMessage("data is None")
82+
83+
return [
84+
{
85+
"title": "Open in explorer",
86+
"subTitle": "Press enter to open the explorer",
87+
"icoPath": "icons/app.png", # related path to the image
88+
"jsonRPCAction": {
89+
"method": "cmd_command",
90+
"parameters": ["start", data[1]],
91+
},
92+
"score": 0,
93+
},
94+
{
95+
"title": "Copy path",
96+
"subTitle": "Press enter to copy the path",
97+
"icoPath": "icons/app.png", # related path to the image
98+
"jsonRPCAction": {
99+
"method": "copy_to_clipboard",
100+
"parameters": [data[1]],
101+
},
102+
"score": 0,
103+
},
104+
{
105+
"title": "RecentProjectsOpen's Context menu",
106+
"subTitle": "Press enter to open Flow the plugin's repo in GitHub",
107+
"icoPath": "icons/app.png",
108+
"jsonRPCAction": {
109+
"method": "open_url",
110+
"parameters": ["https://github.com/Attack825/RecentProjectsOpen"],
111+
},
112+
},
113+
]
114+
115+
def open_url(self, url):
116+
webbrowser.open(url)
82117

83-
def cmd_command(self, app_download, project_path):
118+
def cmd_command(self, command: str, argument: str):
84119
"""
85120
由于json_rpc只会传输字符串,所以需要将字符串转换为list
86121
["D:/IntelliJ IDEA 2024.3/bin/idea64.exe", "D:/Project/CloneProject/JavaProject/LeetcodeHot"]
87122
"""
88-
command = [app_download, project_path]
89-
logger.debug(f"command: {command}")
123+
commandLineExpression = [command, argument]
124+
_ = subprocess.Popen(
125+
commandLineExpression,
126+
stdout=subprocess.PIPE,
127+
stderr=subprocess.PIPE,
128+
shell=True,
129+
)
130+
131+
def copy_to_clipboard(self, text: str):
90132
_ = subprocess.Popen(
91-
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
133+
["echo", text, "|", "clip"],
134+
stdout=subprocess.PIPE,
135+
stderr=subprocess.PIPE,
136+
shell=True,
92137
)
93138

94139

95140
if __name__ == "__main__":
96-
test = RecentProjectsOpen()
141+
RecentProjectsOpen()
97142

98-
# liunx
99-
# python your_script.py '{"method": "query", "parameters": ["test"]}'
100-
# win
101-
# 需要为'"'添加\
143+
# query
102144
# & D:\PythonPackage\Python311\python.exe D:\Project\MyProject\PythonProject\RecentProjectsOpen\src\core\main.py '{\"method\": \"query\", \"parameters\": [\"vsc \"], \"settings\": {\"VISUAL_STUDIO_CODE_DOWNLOAD\": \"D:/VSCode/bin/code\", \"VISUAL_STUDIO_CODE_STORAGE\": \"C:/Users/xuwenjie/AppData/Roaming/Code/User/globalStorage/storage.json\"}}'
103145
# & D:\PythonPackage\Python311\python.exe D:\Project\MyProject\PythonProject\RecentProjectsOpen\src\core\main.py '{\"method\": \"query\", \"parameters\": [\"vsc \"]}'
146+
147+
# context_menu
148+
# & D:\PythonPackage\Python311\python.exe D:\Project\MyProject\PythonProject\RecentProjectsOpen\src\core\main.py '{\"method\": \"context_menu\", \"parameters\": [{\"title\": \"D:/Project/CloneProject/JavaProject/LeetcodeHot\"}]}'

src/core/message.py

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import urllib.parse
21
from typing import List
32

43
from .logger import get_logger
@@ -10,33 +9,6 @@
109
class MessageDTO:
1110
"""消息传输对象"""
1211

13-
def __init__(
14-
self,
15-
title: str = "title",
16-
subtitle: str = "subtitle",
17-
icopath: str = "images/app.png",
18-
method: str = "open_url",
19-
parameters: list[str] = [""],
20-
) -> None:
21-
self.title = title
22-
self.subtitle = subtitle
23-
self.icopath = icopath
24-
self.method = method
25-
self.parameters = parameters
26-
27-
def asFlowMessage(self) -> list:
28-
return [
29-
{
30-
"Title": urllib.parse.unquote(self.title),
31-
"SubTitle": self.subtitle,
32-
"IcoPath": self.icopath,
33-
"jsonRPCAction": {
34-
"method": self.method,
35-
"parameters": self.parameters,
36-
},
37-
}
38-
]
39-
4012
@staticmethod
4113
def asMultiFlowMessage(
4214
projects: list[Project], icopath, method: str, app_download: str
@@ -56,6 +28,7 @@ def asMultiFlowMessage(
5628
"Title": titles[i], # unquote指示中文转码
5729
"SubTitle": subtitles[i],
5830
"IcoPath": icopath,
31+
"ContextData": parameters[i], # 传递参数给context menu
5932
"jsonRPCAction": {
6033
"method": method,
6134
"parameters": parameters[i],
@@ -65,12 +38,12 @@ def asMultiFlowMessage(
6538
return message_list
6639

6740
@staticmethod
68-
def asWarnFlowMessage(msg, operation) -> List:
41+
def asWarnFlowMessage(title, subTitle) -> List:
6942
return [
7043
{
71-
"Title": msg,
72-
"SubTitle": operation,
73-
"IcoPath": "icons/app.png",
44+
"Title": title,
45+
"SubTitle": subTitle,
46+
"IcoPath": "icons/warn.png",
7447
}
7548
]
7649

@@ -80,6 +53,6 @@ def asDebugFlowMessage(msg) -> List:
8053
{
8154
"Title": msg,
8255
"SubTitle": "Debug",
83-
"IcoPath": "icons/warn.png",
56+
"IcoPath": "icons/app.png",
8457
}
8558
]

test/test_cmd.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ def cmd_command(command: List[str]):
99

1010

1111
if __name__ == "__main__":
12-
cmd_command(
13-
[
14-
"C:/Users/xuwenjie/AppData/Local/Programs/cursor/Cursor.exe",
15-
"D:/Project/CloneProject/PythonProject/langchain",
16-
],
17-
)
12+
# cmd_command(
13+
# [
14+
# "C:/Users/xuwenjie/AppData/Local/Programs/cursor/Cursor.exe",
15+
# "D:/Project/CloneProject/PythonProject/langchain",
16+
# ],
17+
# )
18+
# cmd_command(["echo", "c", "|", "clip"])
19+
cmd_command(["start", "D:/Project/MyProject/AndroidStudioProject/HelloWorld"])

0 commit comments

Comments
 (0)