Skip to content

Commit 3368b3f

Browse files
feat(js): impl onecommander compat functions
1 parent a883d2e commit 3368b3f

File tree

5 files changed

+90
-24
lines changed

5 files changed

+90
-24
lines changed

src/shell/script/script.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { menu_controller, value_reset } from "mshell"
2+
3+
export const doExplorerCompat = () => {
4+
menu_controller.add_menu_listener(ctx => {
5+
for (const items of ctx.menu.items) {
6+
const data = items.data()
7+
if (data.name_resid === '[email protected]' /* 清空回收站 */ || data.name === '清空回收站') {
8+
items.set_data({
9+
disabled: false
10+
})
11+
}
12+
13+
if (data.name?.startsWith('NVIDIA ')) {
14+
items.set_data({
15+
icon_svg: `<svg viewBox="0 0 271.7 179.7" xmlns="http://www.w3.org/2000/svg" width="2500" height="1653" fill="#000000"><path d="M101.3 53.6V37.4c1.6-.1 3.2-.2 4.8-.2 44.4-1.4 73.5 38.2 73.5 38.2S148.2 119 114.5 119c-4.5 0-8.9-.7-13.1-2.1V67.7c17.3 2.1 20.8 9.7 31.1 27l23.1-19.4s-16.9-22.1-45.3-22.1c-3-.1-6 .1-9 .4m0-53.6v24.2l4.8-.3c61.7-2.1 102 50.6 102 50.6s-46.2 56.2-94.3 56.2c-4.2 0-8.3-.4-12.4-1.1v15c3.4.4 6.9.7 10.3.7 44.8 0 77.2-22.9 108.6-49.9 5.2 4.2 26.5 14.3 30.9 18.7-29.8 25-99.3 45.1-138.7 45.1-3.8 0-7.4-.2-11-.6v21.1h170.2V0H101.3zm0 116.9v12.8c-41.4-7.4-52.9-50.5-52.9-50.5s19.9-22 52.9-25.6v14h-.1c-17.3-2.1-30.9 14.1-30.9 14.1s7.7 27.3 31 35.2M27.8 77.4s24.5-36.2 73.6-40V24.2C47 28.6 0 74.6 0 74.6s26.6 77 101.3 84v-14c-54.8-6.8-73.5-67.2-73.5-67.2z" fill="#76b900"/></svg>`,
16+
icon_bitmap: new value_reset()
17+
})
18+
}
19+
}
20+
})
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { breeze } from "mshell";
2+
import { doOneCommanderCompat } from "./onecommander_compat";
3+
import { doExplorerCompat } from "./explorer_compat";
4+
5+
export const doCompats = () => {
6+
if (breeze.current_process_name() == "OneCommander.exe")
7+
doOneCommanderCompat();
8+
else if (breeze.current_process_name() == "explorer.exe")
9+
doExplorerCompat();
10+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as shell from "mshell";
2+
export const doOneCommanderCompat = () => {
3+
shell.menu_controller.add_menu_listener(m => {
4+
const do_action = (keys: string[]) => () => {
5+
m.menu.close();
6+
shell.infra.setTimeout(() => {
7+
shell.win32.simulate_hotkeys(keys);
8+
}, 50);
9+
shell.infra.setTimeout(() => {
10+
shell.win32.simulate_hotkeys(keys);
11+
}, 70);
12+
shell.infra.setTimeout(() => {
13+
shell.win32.simulate_hotkeys(keys);
14+
}, 100);
15+
}
16+
17+
for (const i of m.menu.items) {
18+
if (i.data().name === "重命名" || i.data().name === "Rename") {
19+
i.set_data({
20+
action: do_action(['f2'])
21+
})
22+
}
23+
}
24+
25+
const fill = shell.breeze.is_light_theme() ? "fill=\"#000000\"" : "fill=\"#FFFFFF\"";
26+
const zh = shell.breeze.user_language().startsWith('zh');
27+
const NEW_NAME = zh ? "新建" : "New";
28+
const CREATE_FOLDER_NAME = zh ? "文件夹" : "Folder";
29+
const CREATE_FILE_NAME = zh ? "文件" : "File";
30+
m.menu.append_item_after({
31+
name: NEW_NAME,
32+
icon_svg: `<svg xmlns="http://www.w3.org/2000/svg" ${fill} viewBox="0 0 24 24"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></svg>`,
33+
submenu(m) {
34+
m.append_item({
35+
name: CREATE_FOLDER_NAME,
36+
action: do_action(['ctrl', 'shift', 'n']),
37+
icon_svg: `<svg xmlns="http://www.w3.org/2000/svg" ${fill} viewBox="0 0 24 24"><path d="M10 4H2v16h20V6H12l-2-2z"/></svg>`
38+
})
39+
m.append_item({
40+
name: CREATE_FILE_NAME,
41+
action: do_action(['ctrl', 'n']),
42+
icon_svg: `<svg xmlns="http://www.w3.org/2000/svg" ${fill} viewBox="0 0 24 24"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zM13 3.5L18.5 9H13V3.5z"/></svg>`
43+
})
44+
}
45+
}, -2)
46+
})
47+
}
48+
49+

src/shell/script/ts/src/entry.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { plugin } from "./plugin";
77

88
import { createRenderer } from "./react/renderer";
99
import { showConfigPage } from "./config_page";
10+
import { doCompats } from "./compats";
1011

1112
const SVG_CONFIG = `<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="${shell.breeze.is_light_theme() ? '#000000' : '#e3e3e3'}"><path d="m370-80-16-128q-13-5-24.5-12T307-235l-119 50L78-375l103-78q-1-7-1-13.5v-27q0-6.5 1-13.5L78-585l110-190 119 50q11-8 23-15t24-12l16-128h220l16 128q13 5 24.5 12t22.5 15l119-50 110 190-103 78q1 7 1 13.5v27q0 6.5-2 13.5l103 78-110 190-118-50q-11 8-23 15t-24 12L590-80H370Zm70-80h79l14-106q31-8 57.5-23.5T639-327l99 41 39-68-86-65q5-14 7-29.5t2-31.5q0-16-2-31.5t-7-29.5l86-65-39-68-99 42q-22-23-48.5-38.5T533-694l-13-106h-79l-14 106q-31 8-57.5 23.5T321-633l-99-41-39 68 86 64q-5 15-7 30t-2 32q0 16 2 31t7 30l-86 65 39 68 99-42q22 23 48.5 38.5T427-266l13 106Zm42-180q58 0 99-41t41-99q0-58-41-99t-99-41q-59 0-99.5 41T342-480q0 58 40.5 99t99.5 41Zm-2-140Z"/></svg>`
1213

@@ -34,25 +35,10 @@ shell.menu_controller.add_menu_listener(ctx => {
3435
ctx.menu.close()
3536
showConfigPage()
3637
})
37-
38-
// fixtures
39-
for (const items of ctx.menu.items) {
40-
const data = items.data()
41-
if (data.name_resid === '[email protected]' /* 清空回收站 */ || data.name === '清空回收站') {
42-
items.set_data({
43-
disabled: false
44-
})
45-
}
46-
47-
if (data.name?.startsWith('NVIDIA ')) {
48-
items.set_data({
49-
icon_svg: `<svg viewBox="0 0 271.7 179.7" xmlns="http://www.w3.org/2000/svg" width="2500" height="1653" fill="#000000"><path d="M101.3 53.6V37.4c1.6-.1 3.2-.2 4.8-.2 44.4-1.4 73.5 38.2 73.5 38.2S148.2 119 114.5 119c-4.5 0-8.9-.7-13.1-2.1V67.7c17.3 2.1 20.8 9.7 31.1 27l23.1-19.4s-16.9-22.1-45.3-22.1c-3-.1-6 .1-9 .4m0-53.6v24.2l4.8-.3c61.7-2.1 102 50.6 102 50.6s-46.2 56.2-94.3 56.2c-4.2 0-8.3-.4-12.4-1.1v15c3.4.4 6.9.7 10.3.7 44.8 0 77.2-22.9 108.6-49.9 5.2 4.2 26.5 14.3 30.9 18.7-29.8 25-99.3 45.1-138.7 45.1-3.8 0-7.4-.2-11-.6v21.1h170.2V0H101.3zm0 116.9v12.8c-41.4-7.4-52.9-50.5-52.9-50.5s19.9-22 52.9-25.6v14h-.1c-17.3-2.1-30.9 14.1-30.9 14.1s7.7 27.3 31 35.2M27.8 77.4s24.5-36.2 73.6-40V24.2C47 28.6 0 74.6 0 74.6s26.6 77 101.3 84v-14c-54.8-6.8-73.5-67.2-73.5-67.2z" fill="#76b900"/></svg>`,
50-
icon_bitmap: new shell.value_reset()
51-
})
52-
}
53-
}
5438
})
5539

40+
doCompats();
41+
5642
globalThis.plugin = plugin as any
5743
globalThis.React = React
5844
globalThis.createRenderer = createRenderer

0 commit comments

Comments
 (0)