MCPcopy
hub / github.com/CopyTranslator/CopyTranslator / handle

Method handle

src/main/translate-controller.ts:127–219  ·  view source on GitHub ↗
(identifier: Identifier, param: any)

Source from the content-addressed store, hash-verified

125 }
126
127 handle(identifier: Identifier, param: any): boolean {
128 switch (identifier) {
129 case "capture":
130 recognizer.capture();
131 break;
132 case "translate":
133 this.translateWithOption({
134 text: param as string,
135 updateLanguage: true,
136 clearResult: true,
137 dict: true,
138 });
139 break;
140 case "translateClipboard":
141 this.checkClipboard(false); //不需要进行检查
142 break;
143 case "doubleCopyTranslate":
144 this.doubleCopyTranslate();
145 break;
146 case "clear":
147 this.clear();
148 break;
149 case "copySource":
150 clipboard.writeText(this.text);
151 logger.toast("已复制原文");
152 break;
153 case "copyResult":
154 if (!param) {
155 clipboard.writeText(this.resultString);
156 logger.toast("已复制译文");
157 } else {
158 //带参数的话就是复制特定的引擎的结果
159 const buffer = this.getResultBuffer(param) as
160 | SharedResult
161 | undefined;
162 if (buffer && buffer.status != "Translating") {
163 clipboard.writeText(buffer.translation);
164 console.log("复制成功", param);
165 } else {
166 console.log("复制失败", param);
167 }
168 }
169 break;
170 case "pasteResult":
171 this.handle("copyResult", null);
172 simulate.paste();
173 break;
174 case "incrementCounter":
175 if (typeof param != "number") {
176 param = 1; //下一次监听剪贴板是增量选中
177 }
178 this.incrementCounter = param as number;
179 this.setCurrentStatus();
180 break;
181 case "retryTranslate":
182 this.translateWithOption({
183 updateLanguage: true,
184 clearResult: true,

Callers 1

setSrcMethod · 0.95

Calls 13

translateWithOptionMethod · 0.95
checkClipboardMethod · 0.95
doubleCopyTranslateMethod · 0.95
clearMethod · 0.95
getResultBufferMethod · 0.95
setCurrentStatusMethod · 0.95
selectionQuaryMethod · 0.95
getTranslatorFunction · 0.90
captureMethod · 0.80
writeTextMethod · 0.80
toastMethod · 0.80
reloadMethod · 0.80

Tested by

no test coverage detected