Skip to content

Commit

Permalink
Merge pull request #1201 from IrishBruse/vscode-command-setting
Browse files Browse the repository at this point in the history
  • Loading branch information
IrishBruse authored Sep 12, 2024
2 parents 24577ff + b8f40cf commit d9972c6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/main/Extensions/VSCode/VSCodeExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ export class VSCodeExtension implements Extension {
const url = new URL(decodeURIComponent(uri));
const path = Url.fileURLToPath(url, { windows: this.operatingSystem === "Windows" });

const template = this.settingsManager.getValue<string>(
`extension[${this.id}].command`,
this.getSettingDefaultValue("command"),
);

const command = template.replace("%s", path);

return {
id: "vscode-" + path,
name: Path.basename(path),
Expand All @@ -109,7 +116,7 @@ export class VSCodeExtension implements Extension {
defaultAction: {
handlerId: "Commandline",
description: `Open ${description} in VSCode`,
argument: `code ${path}`,
argument: command,
},
};
}
Expand All @@ -121,6 +128,7 @@ export class VSCodeExtension implements Extension {
public getSettingDefaultValue<T>(key: string) {
const defaultSettings = {
prefix: "vscode",
command: 'code "%s"',
};

return defaultSettings[key] as T;
Expand Down Expand Up @@ -149,6 +157,8 @@ export class VSCodeExtension implements Extension {
prefix: "Prefix",
prefixDescription:
"The prefix to trigger visual studio code. Open recently opened files and projects: <prefix> <command>",
command: "Command",
commandTooltip: "Use %s where the selected file/project should go in the command be sure to quote it",
},
};
}
Expand Down
19 changes: 18 additions & 1 deletion src/renderer/Extensions/VSCode/VSCodeSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { useExtensionSetting } from "@Core/Hooks";
import { Setting } from "@Core/Settings/Setting";
import { SettingGroup } from "@Core/Settings/SettingGroup";
import { SettingGroupList } from "@Core/Settings/SettingGroupList";
import { Input } from "@fluentui/react-components";
import { Input, Tooltip } from "@fluentui/react-components";
import { Info16Regular } from "@fluentui/react-icons";
import { useTranslation } from "react-i18next";

export const VSCodeSettings = () => {
Expand All @@ -15,13 +16,29 @@ export const VSCodeSettings = () => {
key: "prefix",
});

const { value: command, updateValue: setCommand } = useExtensionSetting<string>({
extensionId,
key: "command",
});

return (
<SettingGroupList>
<SettingGroup title={t("extensionName")}>
<Setting
label={t("prefix")}
control={<Input value={prefix} onChange={(_, { value }) => setPrefix(value)} />}
/>
<Setting
label={t("command")}
control={
<>
<Tooltip relationship="description" content={t("commandTooltip")}>
<Info16Regular style={{ marginRight: 20 }} />
</Tooltip>
<Input value={command} onChange={(_, { value }) => setCommand(value)} />
</>
}
/>
</SettingGroup>
</SettingGroupList>
);
Expand Down

0 comments on commit d9972c6

Please sign in to comment.