Skip to content

Commit

Permalink
Settings cleanup and option to hide import on the edit menu
Browse files Browse the repository at this point in the history
  • Loading branch information
wandyezj committed Aug 21, 2024
1 parent ae3e8e2 commit 7e081bf
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/components/ButtonOpenMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { DrawerSnips } from "./DrawerSnips";
import { getId, idEditButtonOpen, idEditButtonOpenSnip } from "./id";
import { DrawerSamples } from "./DrawerSamples";
import { DrawerEmbed } from "./DrawerEmbed";
import { embedEnabled } from "../core/embedEnabled";
import { enableEmbed } from "../core/enableEmbed";
import { newDefaultSnip } from "../core/newDefaultSnip";
import { LogTag, log } from "../core/log";
import { DrawerGists } from "./DrawerGists";
Expand Down Expand Up @@ -74,7 +74,7 @@ export function ButtonOpenMenu({
New
</MenuItem>

{embedEnabled() ? (
{enableEmbed() ? (
<MenuItem icon={<DocumentRegular />} onClick={() => setIsOpenDrawerEmbed(true)}>
Embed
</MenuItem>
Expand Down Expand Up @@ -103,7 +103,7 @@ export function ButtonOpenMenu({
</Menu>
<DrawerSnips openSnip={openSnip} isOpen={isOpenLocal} setIsOpen={setIsOpenLocal} />
<DrawerSamples openSnip={openSnip} isOpen={isOpenDrawerSamples} setIsOpen={setIsOpenDrawerSamples} />
{embedEnabled() ? (
{enableEmbed() ? (
<DrawerEmbed openSnip={openSnip} isOpen={isOpenDrawerEmbed} setIsOpen={setIsOpenDrawerEmbed} />
) : (
<></>
Expand Down
23 changes: 14 additions & 9 deletions src/components/PageEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import { copyTextToClipboard } from "../core/copyTextToClipboard";
import { LogTag, log } from "../core/log";
import { ButtonEmbedCopy } from "./ButtonEmbedCopy";
import { ButtonOpenMenu } from "./ButtonOpenMenu";
import { embedEnabled } from "../core/embedEnabled";
import { enableEmbed } from "../core/enableEmbed";
import { idEditButtonCopyToClipboard } from "./id";
import { getSetting } from "../core/setting";
import { enableEditImport } from "../core/enableEditImport";

function buttonRun() {
window.location.href = "./run.html#back";
Expand Down Expand Up @@ -129,14 +130,18 @@ export function PageEdit({ initialSnip }: { initialSnip: SnipWithSource }) {
onClick={buttonCopySnipToClipboard}
/>

<TooltipButton tip="Import" icon={<ArrowImportRegular />} onClick={() => setDialogImportOpen(true)} />
{/* <ButtonImport openSnip={openSnip}>
<TooltipButton tip="Import" icon={<ArrowImportRegular />} />
</ButtonImport> */}
{embedEnabled() ? <ButtonEmbedCopy snip={snip} /> : <></>}
{/*
<TooltipButton tip="Settings" icon={<SettingsRegular />} />
*/}
{enableEditImport() ? (
<TooltipButton
tip="Import"
icon={<ArrowImportRegular />}
onClick={() => setDialogImportOpen(true)}
/>
) : (
<></>
)}

{enableEmbed() ? <ButtonEmbedCopy snip={snip} /> : <></>}

<TooltipButton tip="Delete" icon={<DeleteRegular />} onClick={buttonDeleteSnip} />

{/** Label */}
Expand Down
9 changes: 9 additions & 0 deletions src/core/enableEditImport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getSetting } from "./setting";

/**
* Enable the import button on the edit page
*/
export function enableEditImport(): boolean {
const enable = getSetting("enableEditImport");
return enable;
}
2 changes: 1 addition & 1 deletion src/core/embedEnabled.tsx → src/core/enableEmbed.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getHost } from "./globals";
import { getSetting } from "./setting";

export function embedEnabled(): boolean {
export function enableEmbed(): boolean {
const host = getHost();
const enableForHost = host === Office.HostType.Excel || host === Office.HostType.Word;
const enableSetting = getSetting("enableEmbed");
Expand Down
31 changes: 23 additions & 8 deletions src/core/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ import { loadSettings, saveSettings } from "./storage";
* All of the settings.
*/
export const settingsMetadata = {
/**
* Show the GitHub button in the open menu.
*/
githubPersonalAccessToken: {
name: "GitHub Personal Access Token",
tooltip: `Settings -> Developer settings -> Personal access tokens -> Fine-grained tokens -> Generate new token
Account Permissions:
Gists Read and Write`,
type: "string",
defaultValue: "",
} as SettingString,

/**
* Show the embed button on the edit page and in the open menu.
*/
enableEmbed: {
name: "Enable Embed",
type: "boolean",
Expand All @@ -20,14 +35,14 @@ export const settingsMetadata = {
defaultValue: true,
} as SettingBoolean,

githubPersonalAccessToken: {
name: "GitHub Personal Access Token",
tooltip: `Settings -> Developer settings -> Personal access tokens -> Fine-grained tokens -> Generate new token
Account Permissions:
Gists Read and Write`,
type: "string",
defaultValue: "",
} as SettingString,
/**
* Show the import button on the edit page.
*/
enableEditImport: {
name: "Enable Edit Import",
type: "boolean",
defaultValue: false,
} as SettingBoolean,
};
Object.freeze(settingsMetadata);

Expand Down

0 comments on commit 7e081bf

Please sign in to comment.